2021-12-22 04:44:52 +00:00
|
|
|
<?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;
|
2021-12-24 00:37:08 +00:00
|
|
|
use App\Util\Localization\Localization;
|
2021-12-22 04:44:52 +00:00
|
|
|
|
|
|
|
class SpaController extends Controller
|
|
|
|
{
|
2022-02-18 11:16:31 +00:00
|
|
|
public function index(Request $req)
|
2021-12-22 04:44:52 +00:00
|
|
|
{
|
|
|
|
abort_unless(config('exp.spa'), 404);
|
2022-02-18 11:16:31 +00:00
|
|
|
if(!$req->user()) { return redirect('/login'); }
|
2021-12-22 04:44:52 +00:00
|
|
|
return view('layouts.spa');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function webPost(Request $request, $id)
|
|
|
|
{
|
|
|
|
abort_unless(config('exp.spa'), 404);
|
|
|
|
if($request->user()) {
|
|
|
|
return view('layouts.spa');
|
|
|
|
}
|
|
|
|
|
2022-08-14 04:51:02 +00:00
|
|
|
$post = StatusService::get($id, false);
|
|
|
|
|
|
|
|
if($post && !in_array($post['visibility'], ['public', 'unlisted'])) {
|
|
|
|
return redirect('/login');
|
|
|
|
}
|
2021-12-22 04:44:52 +00:00
|
|
|
|
|
|
|
if(
|
|
|
|
$post &&
|
|
|
|
isset($post['url']) &&
|
|
|
|
isset($post['local']) &&
|
|
|
|
$post['local'] === true
|
|
|
|
) {
|
|
|
|
return redirect($post['url']);
|
|
|
|
}
|
|
|
|
|
2022-02-18 11:16:31 +00:00
|
|
|
return redirect('/login');
|
2021-12-22 04:44:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
2022-03-09 05:22:40 +00:00
|
|
|
$account = AccountService::get($id);
|
2021-12-22 04:44:52 +00:00
|
|
|
|
2022-03-09 05:22:40 +00:00
|
|
|
if($account && isset($account['url']) && $account['local']) {
|
|
|
|
return redirect($account['url']);
|
|
|
|
}
|
2021-12-22 04:44:52 +00:00
|
|
|
|
2022-02-18 11:16:31 +00:00
|
|
|
return redirect('/login');
|
2021-12-22 04:44:52 +00:00
|
|
|
}
|
|
|
|
|
2021-12-24 00:37:08 +00:00
|
|
|
public function updateLanguage(Request $request)
|
|
|
|
{
|
2022-02-18 11:16:31 +00:00
|
|
|
abort_unless(config('exp.spa'), 404);
|
2022-04-03 07:47:20 +00:00
|
|
|
abort_unless($request->user(), 404);
|
2021-12-24 00:37:08 +00:00
|
|
|
$this->validate($request, [
|
|
|
|
'v' => 'required|in:0.1,0.2',
|
|
|
|
'l' => 'required|alpha_dash|max:5'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$lang = $request->input('l');
|
|
|
|
$user = $request->user();
|
|
|
|
|
|
|
|
abort_if(!in_array($lang, Localization::languages()), 400);
|
|
|
|
|
|
|
|
$user->language = $lang;
|
|
|
|
$user->save();
|
|
|
|
session()->put('locale', $lang);
|
|
|
|
|
|
|
|
return ['language' => $lang];
|
|
|
|
}
|
|
|
|
|
2022-05-17 08:34:21 +00:00
|
|
|
public function getPrivacy(Request $request)
|
2021-12-22 04:44:52 +00:00
|
|
|
{
|
2022-05-17 08:34:21 +00:00
|
|
|
abort_unless($request->user(), 404);
|
2021-12-22 04:44:52 +00:00
|
|
|
$body = $this->markdownToHtml('views/page/privacy.md');
|
|
|
|
return [
|
|
|
|
'body' => $body
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-05-17 08:34:21 +00:00
|
|
|
public function getTerms(Request $request)
|
2021-12-22 04:44:52 +00:00
|
|
|
{
|
2022-05-17 08:34:21 +00:00
|
|
|
abort_unless($request->user(), 404);
|
2021-12-22 04:44:52 +00:00
|
|
|
$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);
|
|
|
|
});
|
|
|
|
}
|
2021-12-26 07:08:18 +00:00
|
|
|
|
|
|
|
public function usernameRedirect(Request $request, $username)
|
|
|
|
{
|
2022-02-19 19:42:16 +00:00
|
|
|
abort_unless($request->user(), 404);
|
2021-12-26 07:08:18 +00:00
|
|
|
$id = AccountService::usernameToId($username);
|
|
|
|
if(!$id) {
|
|
|
|
return redirect('/i/web/404');
|
|
|
|
}
|
|
|
|
return redirect('/i/web/profile/' . $id);
|
|
|
|
}
|
2022-03-04 03:51:13 +00:00
|
|
|
|
|
|
|
public function hashtagRedirect(Request $request, $tag)
|
|
|
|
{
|
|
|
|
if(!$request->user()) {
|
|
|
|
return redirect('/discover/tags/' . $tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
return view('layouts.spa');
|
|
|
|
}
|
2021-12-22 04:44:52 +00:00
|
|
|
}
|