Update web routes

This commit is contained in:
Daniel Supernault 2021-12-21 21:44:52 -07:00
parent 937cdfb7f9
commit 7e35ab80ad
No known key found for this signature in database
GPG Key ID: 0DEF1C662C9033F7
4 changed files with 157 additions and 0 deletions

View File

@ -0,0 +1,99 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Cache;
use DB;
use League\CommonMark\CommonMarkConverter;
use App\Services\AccountService;
use App\Services\StatusService;
use App\Services\SnowflakeService;
class SpaController extends Controller
{
public function __construct()
{
$this->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);
});
}
}

View File

@ -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),
];

View File

@ -0,0 +1,51 @@
<!DOCTYPE html>
<html lang="{{ app()->getLocale() }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{ csrf_token() }}">
<meta name="mobile-web-app-capable" content="yes">
<title>{{ $title ?? config_cache('app.name') }}</title>
<link rel="manifest" href="/manifest.json">
<meta property="og:site_name" content="{{ config_cache('app.name') }}">
<meta property="og:title" content="{{ $title ?? config_cache('app.name') }}">
<meta property="og:type" content="article">
<meta property="og:url" content="{{url(request()->url())}}">
@stack('meta')
<meta name="medium" content="image">
<meta name="theme-color" content="#10c5f8">
<meta name="apple-mobile-web-app-capable" content="yes">
<link rel="shortcut icon" type="image/png" href="/img/favicon.png?v=2">
<link rel="apple-touch-icon" type="image/png" href="/img/favicon.png?v=2">
<link rel="canonical" href="{{url(request()->url())}}">
<link href="{{ mix('css/app.css') }}" rel="stylesheet" data-stylesheet="light">
<link href="{{ mix('css/spa.css') }}" rel="stylesheet" data-stylesheet="light">
@auth
<script type="text/javascript">
window._sharedData = {
curUser: {},
user: {!! json_encode(\App\Services\ProfileService::get(request()->user()->profile_id)) !!},
version: 0
};
window.App = {
config: {!!App\Util\Site\Config::json()!!}
};
</script>
@endauth
</head>
<body class="loggedIn">
<main id="content">
<noscript>
<div class="container">
<p class="pt-5 text-center lead">Please enable javascript to view this content.</p>
</div>
</noscript>
<navbar></navbar>
<router-view></router-view>
</main>
<script type="text/javascript" src="{{ mix('js/manifest.js') }}"></script>
<script type="text/javascript" src="{{ mix('js/vendor.js') }}"></script>
<script type="text/javascript" src="{{ mix('js/spa.js') }}"></script>
</body>
</html>

View File

@ -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 () {