Update config_cache

This commit is contained in:
Daniel Supernault 2024-03-10 05:42:25 -06:00
parent b0cb4456a9
commit bf46f6f5f4
No known key found for this signature in database
GPG key ID: 23740873EE6F76A1
4 changed files with 482 additions and 488 deletions

View file

@ -332,7 +332,7 @@ class ProfileController extends Controller
{ {
$res = view('profile.embed-removed'); $res = view('profile.embed-removed');
if (! config('instance.embed.profile')) { if (! (bool) config_cache('instance.embed.profile')) {
return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']); return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']);
} }

View file

@ -2,31 +2,25 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Jobs\ImageOptimizePipeline\ImageOptimize; use App\AccountInterstitial;
use App\Jobs\StatusPipeline\NewStatusPipeline;
use App\Jobs\StatusPipeline\StatusDelete;
use App\Jobs\StatusPipeline\RemoteStatusDelete;
use App\Jobs\SharePipeline\SharePipeline; use App\Jobs\SharePipeline\SharePipeline;
use App\Jobs\SharePipeline\UndoSharePipeline; use App\Jobs\SharePipeline\UndoSharePipeline;
use App\AccountInterstitial; use App\Jobs\StatusPipeline\RemoteStatusDelete;
use App\Media; use App\Jobs\StatusPipeline\StatusDelete;
use App\Profile; use App\Profile;
use App\Services\HashidService;
use App\Services\ReblogService;
use App\Services\StatusService;
use App\Status; use App\Status;
use App\StatusArchived;
use App\StatusView; use App\StatusView;
use App\Transformer\ActivityPub\StatusTransformer;
use App\Transformer\ActivityPub\Verb\Note; use App\Transformer\ActivityPub\Verb\Note;
use App\Transformer\ActivityPub\Verb\Question; use App\Transformer\ActivityPub\Verb\Question;
use App\User; use App\Util\Media\License;
use Auth, DB, Cache; use Auth;
use Cache;
use DB;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use League\Fractal; use League\Fractal;
use App\Util\Media\Filter;
use Illuminate\Support\Str;
use App\Services\HashidService;
use App\Services\StatusService;
use App\Util\Media\License;
use App\Services\ReblogService;
class StatusController extends Controller class StatusController extends Controller
{ {
@ -56,6 +50,7 @@ class StatusController extends Controller
if (ends_with($url, '/activity')) { if (ends_with($url, '/activity')) {
$url = str_replace('/activity', '', $url); $url = str_replace('/activity', '', $url);
} }
return redirect($url); return redirect($url);
} }
@ -79,7 +74,7 @@ class StatusController extends Controller
StatusView::firstOrCreate([ StatusView::firstOrCreate([
'status_id' => $status->id, 'status_id' => $status->id,
'status_profile_id' => $status->profile_id, 'status_profile_id' => $status->profile_id,
'profile_id' => $request->user()->profile_id 'profile_id' => $request->user()->profile_id,
]); ]);
} }
@ -88,12 +83,16 @@ class StatusController extends Controller
} }
$template = $status->in_reply_to_id ? 'status.reply' : 'status.show'; $template = $status->in_reply_to_id ? 'status.reply' : 'status.show';
return view($template, compact('user', 'status')); return view($template, compact('user', 'status'));
} }
public function shortcodeRedirect(Request $request, $id) public function shortcodeRedirect(Request $request, $id)
{ {
abort(404); $hid = HashidService::decode($id);
abort_if(! $hid, 404);
return redirect('/i/web/post/'.$hid);
} }
public function showId(int $id) public function showId(int $id)
@ -102,13 +101,15 @@ class StatusController extends Controller
$status = Status::whereNull('reblog_of_id') $status = Status::whereNull('reblog_of_id')
->whereIn('scope', ['public', 'unlisted']) ->whereIn('scope', ['public', 'unlisted'])
->findOrFail($id); ->findOrFail($id);
return redirect($status->url()); return redirect($status->url());
} }
public function showEmbed(Request $request, $username, int $id) public function showEmbed(Request $request, $username, int $id)
{ {
if(!config('instance.embed.post')) { if (! (bool) config_cache('instance.embed.post')) {
$res = view('status.embed-removed'); $res = view('status.embed-removed');
return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']); return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']);
} }
@ -119,6 +120,7 @@ class StatusController extends Controller
if (! $profile) { if (! $profile) {
$content = view('status.embed-removed'); $content = view('status.embed-removed');
return response($content)->header('X-Frame-Options', 'ALLOWALL'); return response($content)->header('X-Frame-Options', 'ALLOWALL');
} }
@ -133,6 +135,7 @@ class StatusController extends Controller
if ($aiCheck) { if ($aiCheck) {
$res = view('status.embed-removed'); $res = view('status.embed-removed');
return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']); return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']);
} }
$status = Status::whereProfileId($profile->id) $status = Status::whereProfileId($profile->id)
@ -143,12 +146,14 @@ class StatusController extends Controller
->find($id); ->find($id);
if (! $status) { if (! $status) {
$content = view('status.embed-removed'); $content = view('status.embed-removed');
return response($content)->header('X-Frame-Options', 'ALLOWALL'); return response($content)->header('X-Frame-Options', 'ALLOWALL');
} }
$showLikes = $request->filled('likes') && $request->likes == true; $showLikes = $request->filled('likes') && $request->likes == true;
$showCaption = $request->filled('caption') && $request->caption !== false; $showCaption = $request->filled('caption') && $request->caption !== false;
$layout = $request->filled('layout') && $request->layout == 'compact' ? 'compact' : 'full'; $layout = $request->filled('layout') && $request->layout == 'compact' ? 'compact' : 'full';
$content = view('status.embed', compact('status', 'showLikes', 'showCaption', 'layout')); $content = view('status.embed', compact('status', 'showLikes', 'showCaption', 'layout'));
return response($content)->withHeaders(['X-Frame-Options' => 'ALLOWALL']); return response($content)->withHeaders(['X-Frame-Options' => 'ALLOWALL']);
} }
@ -188,7 +193,7 @@ class StatusController extends Controller
public function store(Request $request) public function store(Request $request)
{ {
return;
} }
public function delete(Request $request) public function delete(Request $request)
@ -330,6 +335,7 @@ class StatusController extends Controller
->with(['media']) ->with(['media'])
->findOrFail($id); ->findOrFail($id);
$licenses = License::get(); $licenses = License::get();
return view('status.edit', compact('user', 'status', 'licenses')); return view('status.edit', compact('user', 'status', 'licenses'));
} }
@ -366,6 +372,7 @@ class StatusController extends Controller
protected function validateVisibility($visibility) protected function validateVisibility($visibility)
{ {
$allowed = ['public', 'unlisted', 'private']; $allowed = ['public', 'unlisted', 'private'];
return in_array($visibility, $allowed) ? $visibility : 'public'; return in_array($visibility, $allowed) ? $visibility : 'public';
} }
@ -405,11 +412,12 @@ class StatusController extends Controller
return 'text'; return 'text';
} }
public function toggleVisibility(Request $request) { public function toggleVisibility(Request $request)
{
$this->authCheck(); $this->authCheck();
$this->validate($request, [ $this->validate($request, [
'item' => 'required|string|min:1|max:20', 'item' => 'required|string|min:1|max:20',
'disableComments' => 'required|boolean' 'disableComments' => 'required|boolean',
]); ]);
$user = Auth::user(); $user = Auth::user();
@ -449,7 +457,7 @@ class StatusController extends Controller
StatusView::firstOrCreate([ StatusView::firstOrCreate([
'status_id' => $view['sid'], 'status_id' => $view['sid'],
'status_profile_id' => $view['pid'], 'status_profile_id' => $view['pid'],
'profile_id' => $uid 'profile_id' => $uid,
]); ]);
}); });
} }

View file

@ -87,6 +87,8 @@ class ConfigCacheService
'pixelfed.app_registration_rate_limit_decay', 'pixelfed.app_registration_rate_limit_decay',
'pixelfed.app_registration_confirm_rate_limit_attempts', 'pixelfed.app_registration_confirm_rate_limit_attempts',
'pixelfed.app_registration_confirm_rate_limit_decay', 'pixelfed.app_registration_confirm_rate_limit_decay',
'instance.embed.profile',
'instance.embed.post',
// 'system.user_mode' // 'system.user_mode'
]; ];

View file

@ -2,11 +2,8 @@
namespace App\Services; namespace App\Services;
use Cache; class HashidService
{
class HashidService {
public const MIN_LIMIT = 15;
public const CMAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'; public const CMAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
public static function encode($id, $minLimit = true) public static function encode($id, $minLimit = true)
@ -15,12 +12,6 @@ class HashidService {
return null; return null;
} }
if($minLimit && strlen($id) < self::MIN_LIMIT) {
return null;
}
$key = "hashids:{$id}";
return Cache::remember($key, now()->hours(48), function() use($id) {
$cmap = self::CMAP; $cmap = self::CMAP;
$base = strlen($cmap); $base = strlen($cmap);
$shortcode = ''; $shortcode = '';
@ -28,28 +19,21 @@ class HashidService {
$id = ($id - ($r = $id % $base)) / $base; $id = ($id - ($r = $id % $base)) / $base;
$shortcode = $cmap[$r].$shortcode; $shortcode = $cmap[$r].$shortcode;
} }
return $shortcode; return $shortcode;
});
} }
public static function decode($short) public static function decode($short = false)
{ {
$len = strlen($short); if (! $short) {
if($len < 3 || $len > 11) { return;
return null;
} }
$id = 0; $id = 0;
foreach (str_split($short) as $needle) { foreach (str_split($short) as $needle) {
$pos = strpos(self::CMAP, $needle); $pos = strpos(self::CMAP, $needle);
// if(!$pos) {
// return null;
// }
$id = ($id * 64) + $pos; $id = ($id * 64) + $pos;
} }
if(strlen($id) < self::MIN_LIMIT) {
return null;
}
return $id; return $id;
} }
} }