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');
if (! config('instance.embed.profile')) {
if (! (bool) config_cache('instance.embed.profile')) {
return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']);
}

View file

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

View file

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