Update ComposeController, refactor compose_settings

This commit is contained in:
Daniel Supernault 2021-12-19 04:19:26 -07:00
parent aee9b994e3
commit edc2958bf2
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -38,6 +38,7 @@ use App\Jobs\VideoPipeline\{
VideoPostProcess, VideoPostProcess,
VideoThumbnail VideoThumbnail
}; };
use App\Services\AccountService;
use App\Services\NotificationService; use App\Services\NotificationService;
use App\Services\MediaPathService; use App\Services\MediaPathService;
use App\Services\MediaBlocklistService; use App\Services\MediaBlocklistService;
@ -116,6 +117,7 @@ class ComposeController extends Controller
$storagePath = MediaPathService::get($user, 2); $storagePath = MediaPathService::get($user, 2);
$path = $photo->store($storagePath); $path = $photo->store($storagePath);
$hash = \hash_file('sha256', $photo); $hash = \hash_file('sha256', $photo);
$mime = $photo->getMimeType();
abort_if(MediaBlocklistService::exists($hash) == true, 451); abort_if(MediaBlocklistService::exists($hash) == true, 451);
@ -126,7 +128,7 @@ class ComposeController extends Controller
$media->media_path = $path; $media->media_path = $path;
$media->original_sha256 = $hash; $media->original_sha256 = $hash;
$media->size = $photo->getSize(); $media->size = $photo->getSize();
$media->mime = $photo->getMimeType(); $media->mime = $mime;
$media->filter_class = $filterClass; $media->filter_class = $filterClass;
$media->filter_name = $filterName; $media->filter_name = $filterName;
$media->version = 3; $media->version = 3;
@ -672,16 +674,14 @@ class ComposeController extends Controller
'media_descriptions' => false, 'media_descriptions' => false,
'max_altext_length' => config_cache('pixelfed.max_altext_length') 'max_altext_length' => config_cache('pixelfed.max_altext_length')
]; ];
$settings = AccountService::settings($uid);
return array_merge($default, Cache::remember('profile:compose:settings:' . $uid, now()->addHours(12), function() use($uid) { if(isset($settings['other']) && isset($settings['other']['scope'])) {
$res = UserSetting::whereUserId($uid)->first(); $s = $settings['compose_settings'];
$s['default_scope'] = $settings['other']['scope'];
if(!$res || empty($res->compose_settings)) { $settings['compose_settings'] = $s;
return [];
} }
return json_decode($res->compose_settings, true); return array_merge($default, $settings['compose_settings']);
}));
} }
public function createPoll(Request $request) public function createPoll(Request $request)