Forráskód Böngészése

Update config() to config_cache()

Daniel Supernault 4 éve
szülő
commit
a9f009305c

+ 3 - 3
app/Http/Controllers/Api/ApiV1Controller.php

@@ -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);

+ 6 - 6
app/Http/Controllers/ComposeController.php

@@ -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',
@@ -95,7 +95,7 @@ class ComposeController extends Controller
 		if(config('pixelfed.enforce_account_limit') == true) {
 		if(config('pixelfed.enforce_account_limit') == true) {
 			$size = Cache::remember($user->storageUsedKey(), now()->addDays(3), function() use($user) {
 			$size = Cache::remember($user->storageUsedKey(), now()->addDays(3), function() use($user) {
 				return Media::whereUserId($user->id)->sum('size') / 1000;
 				return Media::whereUserId($user->id)->sum('size') / 1000;
-			}); 
+			});
 			$limit = (int) config('pixelfed.max_account_size');
 			$limit = (int) config('pixelfed.max_account_size');
 			if ($size >= $limit) {
 			if ($size >= $limit) {
 				abort(403, 'Account size limit reached.');
 				abort(403, 'Account size limit reached.');
@@ -132,7 +132,7 @@ class ComposeController extends Controller
 
 
 		$preview_url = $media->url() . '?v=' . time();
 		$preview_url = $media->url() . '?v=' . time();
 		$url = $media->url() . '?v=' . time();
 		$url = $media->url() . '?v=' . time();
-		
+
 		switch ($media->mime) {
 		switch ($media->mime) {
 			case 'image/jpeg':
 			case 'image/jpeg':
 			case 'image/png':
 			case 'image/png':
@@ -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']);
@@ -648,7 +648,7 @@ class ComposeController extends Controller
 			case 'video/mp4':
 			case 'video/mp4':
 				$finished = config('pixelfed.cloud_storage') ? (bool) $media->cdn_url : (bool) $media->processed_at;
 				$finished = config('pixelfed.cloud_storage') ? (bool) $media->cdn_url : (bool) $media->processed_at;
 				break;
 				break;
-			
+
 			default:
 			default:
 				# code...
 				# code...
 				break;
 				break;

+ 2 - 2
app/Http/Controllers/StoryController.php

@@ -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 [

+ 56 - 56
app/Jobs/AvatarPipeline/AvatarOptimize.php

@@ -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 $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);
+		}
+	}
 }
 }

+ 12 - 12
app/Util/ActivityPub/Inbox.php

@@ -115,8 +115,8 @@ class Inbox
     {
     {
         $activity = $this->payload['object'];
         $activity = $this->payload['object'];
 
 
-        if(isset($activity['inReplyTo']) && 
-            !empty($activity['inReplyTo']) && 
+        if(isset($activity['inReplyTo']) &&
+            !empty($activity['inReplyTo']) &&
             Helpers::validateUrl($activity['inReplyTo'])
             Helpers::validateUrl($activity['inReplyTo'])
         ) {
         ) {
             // reply detected, skip attachment check
             // reply detected, skip attachment check
@@ -147,8 +147,8 @@ class Inbox
         }
         }
         $to = $activity['to'];
         $to = $activity['to'];
         $cc = isset($activity['cc']) ? $activity['cc'] : [];
         $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')
             parse_url($to[0], PHP_URL_HOST) == config('pixelfed.domain.app')
         ) {
         ) {
             $this->handleDirectMessage();
             $this->handleDirectMessage();
@@ -175,7 +175,7 @@ class Inbox
 
 
         $inReplyTo = $activity['inReplyTo'];
         $inReplyTo = $activity['inReplyTo'];
         $url = isset($activity['url']) ? $activity['url'] : $activity['id'];
         $url = isset($activity['url']) ? $activity['url'] : $activity['id'];
-        
+
         Helpers::statusFirstOrFetch($url, true);
         Helpers::statusFirstOrFetch($url, true);
         return;
         return;
     }
     }
@@ -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'];
@@ -293,7 +293,7 @@ class Inbox
                 $dm->type = 'link';
                 $dm->type = 'link';
                 $dm->meta = [
                 $dm->meta = [
                     'domain' => parse_url($msgText, PHP_URL_HOST),
                     '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)
                         parse_url(config('app.url'), PHP_URL_HOST)
                 ];
                 ];
                 $dm->save();
                 $dm->save();
@@ -459,8 +459,8 @@ class Inbox
     public function handleDeleteActivity()
     public function handleDeleteActivity()
     {
     {
         if(!isset(
         if(!isset(
-            $this->payload['actor'], 
-            $this->payload['object'] 
+            $this->payload['actor'],
+            $this->payload['object']
         )) {
         )) {
             return;
             return;
         }
         }
@@ -510,7 +510,7 @@ class Inbox
                         $status->delete();
                         $status->delete();
                         return;
                         return;
                     break;
                     break;
-                
+
                 default:
                 default:
                     return;
                     return;
                     break;
                     break;
@@ -564,7 +564,7 @@ class Inbox
         switch ($obj['type']) {
         switch ($obj['type']) {
             case 'Accept':
             case 'Accept':
                 break;
                 break;
-                
+
             case 'Announce':
             case 'Announce':
                 $obj = $obj['object'];
                 $obj = $obj['object'];
                 if(!Helpers::validateLocalUrl($obj)) {
                 if(!Helpers::validateLocalUrl($obj)) {
@@ -603,7 +603,7 @@ class Inbox
                     ->whereItemType('App\Profile')
                     ->whereItemType('App\Profile')
                     ->forceDelete();
                     ->forceDelete();
                 break;
                 break;
-                
+
             case 'Like':
             case 'Like':
                 $status = Helpers::statusFirstOrFetch($obj['object']);
                 $status = Helpers::statusFirstOrFetch($obj['object']);
                 if(!$status) {
                 if(!$status) {

+ 2 - 2
app/Util/Media/Image.php

@@ -154,7 +154,7 @@ class Image
 						}
 						}
 					}
 					}
 					$media->metadata = json_encode($meta);
 					$media->metadata = json_encode($meta);
-				} 
+				}
 
 
 				$img->resize($aspect['width'], $aspect['height'], function ($constraint) {
 				$img->resize($aspect['width'], $aspect['height'], function ($constraint) {
 					$constraint->aspectRatio();
 					$constraint->aspectRatio();
@@ -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) {

+ 2 - 2
app/Util/Site/Config.php

@@ -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'),
-					'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),
 					'max_collection_length' => config('pixelfed.max_collection_length', 18),