mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 14:31:26 +00:00
Update config() to config_cache()
This commit is contained in:
parent
1d54204635
commit
a9f009305c
7 changed files with 83 additions and 83 deletions
|
@ -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);
|
||||
|
|
|
@ -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',
|
||||
|
@ -95,7 +95,7 @@ class ComposeController extends Controller
|
|||
if(config('pixelfed.enforce_account_limit') == true) {
|
||||
$size = Cache::remember($user->storageUsedKey(), now()->addDays(3), function() use($user) {
|
||||
return Media::whereUserId($user->id)->sum('size') / 1000;
|
||||
});
|
||||
});
|
||||
$limit = (int) config('pixelfed.max_account_size');
|
||||
if ($size >= $limit) {
|
||||
abort(403, 'Account size limit reached.');
|
||||
|
@ -132,7 +132,7 @@ class ComposeController extends Controller
|
|||
|
||||
$preview_url = $media->url() . '?v=' . time();
|
||||
$url = $media->url() . '?v=' . time();
|
||||
|
||||
|
||||
switch ($media->mime) {
|
||||
case 'image/jpeg':
|
||||
case 'image/png':
|
||||
|
@ -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']);
|
||||
|
@ -648,7 +648,7 @@ class ComposeController extends Controller
|
|||
case 'video/mp4':
|
||||
$finished = config('pixelfed.cloud_storage') ? (bool) $media->cdn_url : (bool) $media->processed_at;
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
# code...
|
||||
break;
|
||||
|
|
|
@ -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 [
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -115,8 +115,8 @@ class Inbox
|
|||
{
|
||||
$activity = $this->payload['object'];
|
||||
|
||||
if(isset($activity['inReplyTo']) &&
|
||||
!empty($activity['inReplyTo']) &&
|
||||
if(isset($activity['inReplyTo']) &&
|
||||
!empty($activity['inReplyTo']) &&
|
||||
Helpers::validateUrl($activity['inReplyTo'])
|
||||
) {
|
||||
// reply detected, skip attachment check
|
||||
|
@ -147,8 +147,8 @@ class Inbox
|
|||
}
|
||||
$to = $activity['to'];
|
||||
$cc = isset($activity['cc']) ? $activity['cc'] : [];
|
||||
if(count($to) == 1 &&
|
||||
count($cc) == 0 &&
|
||||
if(count($to) == 1 &&
|
||||
count($cc) == 0 &&
|
||||
parse_url($to[0], PHP_URL_HOST) == config('pixelfed.domain.app')
|
||||
) {
|
||||
$this->handleDirectMessage();
|
||||
|
@ -175,7 +175,7 @@ class Inbox
|
|||
|
||||
$inReplyTo = $activity['inReplyTo'];
|
||||
$url = isset($activity['url']) ? $activity['url'] : $activity['id'];
|
||||
|
||||
|
||||
Helpers::statusFirstOrFetch($url, true);
|
||||
return;
|
||||
}
|
||||
|
@ -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'];
|
||||
|
@ -293,7 +293,7 @@ class Inbox
|
|||
$dm->type = 'link';
|
||||
$dm->meta = [
|
||||
'domain' => parse_url($msgText, PHP_URL_HOST),
|
||||
'local' => parse_url($msgText, PHP_URL_HOST) ==
|
||||
'local' => parse_url($msgText, PHP_URL_HOST) ==
|
||||
parse_url(config('app.url'), PHP_URL_HOST)
|
||||
];
|
||||
$dm->save();
|
||||
|
@ -459,8 +459,8 @@ class Inbox
|
|||
public function handleDeleteActivity()
|
||||
{
|
||||
if(!isset(
|
||||
$this->payload['actor'],
|
||||
$this->payload['object']
|
||||
$this->payload['actor'],
|
||||
$this->payload['object']
|
||||
)) {
|
||||
return;
|
||||
}
|
||||
|
@ -510,7 +510,7 @@ class Inbox
|
|||
$status->delete();
|
||||
return;
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
return;
|
||||
break;
|
||||
|
@ -564,7 +564,7 @@ class Inbox
|
|||
switch ($obj['type']) {
|
||||
case 'Accept':
|
||||
break;
|
||||
|
||||
|
||||
case 'Announce':
|
||||
$obj = $obj['object'];
|
||||
if(!Helpers::validateLocalUrl($obj)) {
|
||||
|
@ -603,7 +603,7 @@ class Inbox
|
|||
->whereItemType('App\Profile')
|
||||
->forceDelete();
|
||||
break;
|
||||
|
||||
|
||||
case 'Like':
|
||||
$status = Helpers::statusFirstOrFetch($obj['object']);
|
||||
if(!$status) {
|
||||
|
|
|
@ -154,7 +154,7 @@ class Image
|
|||
}
|
||||
}
|
||||
$media->metadata = json_encode($meta);
|
||||
}
|
||||
}
|
||||
|
||||
$img->resize($aspect['width'], $aspect['height'], function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
|
@ -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) {
|
||||
|
|
|
@ -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),
|
||||
|
||||
|
|
Loading…
Reference in a new issue