diff --git a/app/Http/Controllers/SpaController.php b/app/Http/Controllers/SpaController.php new file mode 100644 index 000000000..ca4eb93b3 --- /dev/null +++ b/app/Http/Controllers/SpaController.php @@ -0,0 +1,99 @@ +middleware('auth'); + } + + public function index() + { + abort_unless(config('exp.spa'), 404); + return view('layouts.spa'); + } + + public function webPost(Request $request, $id) + { + abort_unless(config('exp.spa'), 404); + if($request->user()) { + return view('layouts.spa'); + } + + if(SnowflakeService::byDate(now()->subDays(30)) > $id) { + abort(404); + } + + $post = StatusService::get($id); + + if( + $post && + isset($post['url']) && + isset($post['local']) && + $post['local'] === true + ) { + return redirect($post['url']); + } + + abort(404); + } + + public function webProfile(Request $request, $id) + { + abort_unless(config('exp.spa'), 404); + if($request->user()) { + if(substr($id, 0, 1) == '@') { + $id = AccountService::usernameToId(substr($id, 1)); + return redirect("/i/web/profile/{$id}"); + } + return view('layouts.spa'); + } + + $account = AccountService::get($id); + + if($account && isset($account['url'])) { + return redirect($account['url']); + } + + return redirect('404'); + } + + public function getPrivacy() + { + $body = $this->markdownToHtml('views/page/privacy.md'); + return [ + 'body' => $body + ]; + } + + public function getTerms() + { + $body = $this->markdownToHtml('views/page/terms.md'); + return [ + 'body' => $body + ]; + } + + protected function markdownToHtml($src, $ttl = 600) + { + return Cache::remember( + 'pf:doc_cache:markdown:' . $src, + $ttl, + function() use($src) { + $path = resource_path($src); + $file = file_get_contents($path); + $converter = new CommonMarkConverter(); + return (string) $converter->convertToHtml($file); + }); + } +} diff --git a/config/exp.php b/config/exp.php index c90a2d33b..3db8817a6 100644 --- a/config/exp.php +++ b/config/exp.php @@ -8,4 +8,6 @@ return [ 'top' => env('EXP_TOP', false), 'polls' => env('EXP_POLLS', false), 'cached_public_timeline' => env('EXP_CPT', false), + 'gps' => env('EXP_GPS', false), + 'spa' => env('EXP_SPA', false), ]; diff --git a/resources/views/layouts/spa.blade.php b/resources/views/layouts/spa.blade.php new file mode 100644 index 000000000..a63f89465 --- /dev/null +++ b/resources/views/layouts/spa.blade.php @@ -0,0 +1,51 @@ + + + + + + + + + {{ $title ?? config_cache('app.name') }} + + + + + + @stack('meta') + + + + + + + + + @auth + + @endauth + + +
+ + + +
+ + + + + diff --git a/routes/web.php b/routes/web.php index 76f331545..951ffc993 100644 --- a/routes/web.php +++ b/routes/web.php @@ -333,6 +333,11 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact Route::get('warning', 'AccountInterstitialController@get'); Route::post('warning', 'AccountInterstitialController@read'); Route::get('my2020', 'SeasonalController@yearInReview'); + + Route::get('web/post/{id}', 'SpaController@webPost'); + Route::get('web/profile/{id}', 'SpaController@webProfile'); + Route::get('web/{q}', 'SpaController@index')->where('q', '.*'); + Route::get('web', 'SpaController@index'); }); Route::group(['prefix' => 'account'], function () {