Update config() to config_cache()

pull/2753/head
Daniel Supernault 4 years ago
parent 1d54204635
commit a9f009305c
No known key found for this signature in database
GPG Key ID: 0DEF1C662C9033F7

@ -983,7 +983,7 @@ class ApiV1Controller extends Controller
'max_avatar_size' => (int) config('pixelfed.max_avatar_size'), 'max_avatar_size' => (int) config('pixelfed.max_avatar_size'),
'max_caption_length' => (int) config('pixelfed.max_caption_length'), 'max_caption_length' => (int) config('pixelfed.max_caption_length'),
'max_bio_length' => (int) config('pixelfed.max_bio_length'), 'max_bio_length' => (int) config('pixelfed.max_bio_length'),
'max_album_length' => (int) config('pixelfed.max_album_length'), 'max_album_length' => (int) config_cache('pixelfed.max_album_length'),
'mobile_apis' => config('pixelfed.oauth_enabled') 'mobile_apis' => config('pixelfed.oauth_enabled')
] ]
@ -1742,7 +1742,7 @@ class ApiV1Controller extends Controller
$this->validate($request, [ $this->validate($request, [
'status' => 'nullable|string', 'status' => 'nullable|string',
'in_reply_to_id' => 'nullable|integer', 'in_reply_to_id' => 'nullable|integer',
'media_ids' => 'array|max:' . config('pixelfed.max_album_length'), 'media_ids' => 'array|max:' . config_cache('pixelfed.max_album_length'),
'media_ids.*' => 'integer|min:1', 'media_ids.*' => 'integer|min:1',
'sensitive' => 'nullable|boolean', 'sensitive' => 'nullable|boolean',
'visibility' => 'string|in:private,unlisted,public', 'visibility' => 'string|in:private,unlisted,public',
@ -1824,7 +1824,7 @@ class ApiV1Controller extends Controller
$mimes = []; $mimes = [];
foreach($ids as $k => $v) { foreach($ids as $k => $v) {
if($k + 1 > config('pixelfed.max_album_length')) { if($k + 1 > config_cache('pixelfed.max_album_length')) {
continue; continue;
} }
$m = Media::whereUserId($user->id)->whereNull('status_id')->findOrFail($v); $m = Media::whereUserId($user->id)->whereNull('status_id')->findOrFail($v);

@ -72,7 +72,7 @@ class ComposeController extends Controller
return [ return [
'required', 'required',
'mimes:' . config('pixelfed.media_types'), 'mimes:' . config('pixelfed.media_types'),
'max:' . config('pixelfed.max_photo_size'), 'max:' . config_cache('pixelfed.max_photo_size'),
]; ];
}, },
'filter_name' => 'nullable|string|max:24', 'filter_name' => 'nullable|string|max:24',
@ -165,7 +165,7 @@ class ComposeController extends Controller
return [ return [
'required', 'required',
'mimes:' . config('pixelfed.media_types'), 'mimes:' . config('pixelfed.media_types'),
'max:' . config('pixelfed.max_photo_size'), 'max:' . config_cache('pixelfed.max_photo_size'),
]; ];
}, },
]); ]);
@ -454,7 +454,7 @@ class ComposeController extends Controller
$optimize_media = (bool) $request->input('optimize_media'); $optimize_media = (bool) $request->input('optimize_media');
foreach($medias as $k => $media) { foreach($medias as $k => $media) {
if($k + 1 > config('pixelfed.max_album_length')) { if($k + 1 > config_cache('pixelfed.max_album_length')) {
continue; continue;
} }
$m = Media::findOrFail($media['id']); $m = Media::findOrFail($media['id']);

@ -94,7 +94,7 @@ class StoryController extends Controller
$fpath = storage_path('app/' . $path); $fpath = storage_path('app/' . $path);
$img = Intervention::make($fpath); $img = Intervention::make($fpath);
$img->orientate(); $img->orientate();
$img->save($fpath, config('pixelfed.image_quality')); $img->save($fpath, config_cache('pixelfed.image_quality'));
$img->destroy(); $img->destroy();
} }
return $path; return $path;
@ -133,7 +133,7 @@ class StoryController extends Controller
$img->resize(1080, 1920, function ($constraint) { $img->resize(1080, 1920, function ($constraint) {
$constraint->aspectRatio(); $constraint->aspectRatio();
}); });
$img->save($path, config('pixelfed.image_quality')); $img->save($path, config_cache('pixelfed.image_quality'));
} }
return [ return [

@ -16,67 +16,67 @@ use Image as Intervention;
class AvatarOptimize implements ShouldQueue class AvatarOptimize implements ShouldQueue
{ {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $profile; protected $profile;
protected $current; protected $current;
/** /**
* Delete the job if its models no longer exist. * Delete the job if its models no longer exist.
* *
* @var bool * @var bool
*/ */
public $deleteWhenMissingModels = true; public $deleteWhenMissingModels = true;
/** /**
* Create a new job instance. * Create a new job instance.
* *
* @return void * @return void
*/ */
public function __construct(Profile $profile, $current) public function __construct(Profile $profile, $current)
{ {
$this->profile = $profile; $this->profile = $profile;
$this->current = $current; $this->current = $current;
} }
/** /**
* Execute the job. * Execute the job.
* *
* @return void * @return void
*/ */
public function handle() public function handle()
{ {
$avatar = $this->profile->avatar; $avatar = $this->profile->avatar;
$file = storage_path("app/$avatar->media_path"); $file = storage_path("app/$avatar->media_path");
try { try {
$img = Intervention::make($file)->orientate(); $img = Intervention::make($file)->orientate();
$img->fit(200, 200, function ($constraint) { $img->fit(200, 200, function ($constraint) {
$constraint->upsize(); $constraint->upsize();
}); });
$quality = config('pixelfed.image_quality'); $quality = config_cache('pixelfed.image_quality');
$img->save($file, $quality); $img->save($file, $quality);
$avatar = Avatar::whereProfileId($this->profile->id)->firstOrFail(); $avatar = Avatar::whereProfileId($this->profile->id)->firstOrFail();
$avatar->change_count = ++$avatar->change_count; $avatar->change_count = ++$avatar->change_count;
$avatar->last_processed_at = Carbon::now(); $avatar->last_processed_at = Carbon::now();
$avatar->save(); $avatar->save();
Cache::forget('avatar:' . $avatar->profile_id); Cache::forget('avatar:' . $avatar->profile_id);
$this->deleteOldAvatar($avatar->media_path, $this->current); $this->deleteOldAvatar($avatar->media_path, $this->current);
} catch (Exception $e) { } catch (Exception $e) {
} }
} }
protected function deleteOldAvatar($new, $current) protected function deleteOldAvatar($new, $current)
{ {
if ( storage_path('app/'.$new) == $current || if ( storage_path('app/'.$new) == $current ||
Str::endsWith($current, 'avatars/default.png') || Str::endsWith($current, 'avatars/default.png') ||
Str::endsWith($current, 'avatars/default.jpg')) Str::endsWith($current, 'avatars/default.jpg'))
{ {
return; return;
} }
if (is_file($current)) { if (is_file($current)) {
@unlink($current); @unlink($current);
} }
} }
} }

@ -252,7 +252,7 @@ class Inbox
$photos = 0; $photos = 0;
$videos = 0; $videos = 0;
$allowed = explode(',', config('pixelfed.media_types')); $allowed = explode(',', config('pixelfed.media_types'));
$activity['attachment'] = array_slice($activity['attachment'], 0, config('pixelfed.max_album_length')); $activity['attachment'] = array_slice($activity['attachment'], 0, config_cache('pixelfed.max_album_length'));
foreach($activity['attachment'] as $a) { foreach($activity['attachment'] as $a) {
$type = $a['mediaType']; $type = $a['mediaType'];
$url = $a['url']; $url = $a['url'];

@ -163,7 +163,7 @@ class Image
$converted = $this->setBaseName($path, $thumbnail, $img->extension); $converted = $this->setBaseName($path, $thumbnail, $img->extension);
$newPath = storage_path('app/'.$converted['path']); $newPath = storage_path('app/'.$converted['path']);
$quality = config('pixelfed.image_quality'); $quality = config_cache('pixelfed.image_quality');
$img->save($newPath, $quality); $img->save($newPath, $quality);
if ($thumbnail == true) { if ($thumbnail == true) {

@ -14,8 +14,8 @@ class Config {
'uploader' => [ 'uploader' => [
'max_photo_size' => config('pixelfed.max_photo_size'), 'max_photo_size' => config('pixelfed.max_photo_size'),
'max_caption_length' => config('pixelfed.max_caption_length'), 'max_caption_length' => config('pixelfed.max_caption_length'),
'album_limit' => config('pixelfed.max_album_length'), 'album_limit' => config_cache('pixelfed.max_album_length'),
'image_quality' => config('pixelfed.image_quality'), 'image_quality' => config_cache('pixelfed.image_quality'),
'max_collection_length' => config('pixelfed.max_collection_length', 18), 'max_collection_length' => config('pixelfed.max_collection_length', 18),

Loading…
Cancel
Save