Update config() to config_cache()

This commit is contained in:
Daniel Supernault 2021-05-10 21:04:23 -06:00
parent 1d54204635
commit a9f009305c
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
7 changed files with 83 additions and 83 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -252,7 +252,7 @@ class Inbox
$photos = 0;
$videos = 0;
$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) {
$type = $a['mediaType'];
$url = $a['url'];

View file

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

View file

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