Update config cache

This commit is contained in:
Daniel Supernault 2024-03-10 04:19:44 -06:00
parent a4bc5ce3d0
commit 5e4d4eff9d
No known key found for this signature in database
GPG key ID: 23740873EE6F76A1
8 changed files with 329 additions and 338 deletions

View file

@ -1664,7 +1664,7 @@ class ApiV1Controller extends Controller
],
'statuses' => [
'characters_reserved_per_url' => 23,
'max_characters' => (int) config('pixelfed.max_caption_length'),
'max_characters' => (int) config_cache('pixelfed.max_caption_length'),
'max_media_attachments' => (int) config('pixelfed.max_album_length'),
],
],
@ -3308,7 +3308,7 @@ class ApiV1Controller extends Controller
abort_unless($request->user()->tokenCan('write'), 403);
$this->validate($request, [
'status' => 'nullable|string',
'status' => 'nullable|string|max:' . config_cache('pixelfed.max_caption_length'),
'in_reply_to_id' => 'nullable',
'media_ids' => 'sometimes|array|max:'.config_cache('pixelfed.max_album_length'),
'sensitive' => 'nullable',

View file

@ -104,7 +104,7 @@ class ApiV2Controller extends Controller
'max_featured_tags' => 0,
],
'statuses' => [
'max_characters' => (int) config('pixelfed.max_caption_length'),
'max_characters' => (int) config_cache('pixelfed.max_caption_length'),
'max_media_attachments' => (int) config_cache('pixelfed.max_album_length'),
'characters_reserved_per_url' => 23
],

View file

@ -2,23 +2,18 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Auth;
use DB;
use Cache;
use App\Comment;
use App\Jobs\CommentPipeline\CommentPipeline;
use App\Jobs\StatusPipeline\NewStatusPipeline;
use App\Util\Lexer\Autolink;
use App\Profile;
use App\Status;
use App\UserFilter;
use League\Fractal;
use App\Transformer\Api\StatusTransformer;
use League\Fractal\Serializer\ArraySerializer;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use App\Services\StatusService;
use App\Status;
use App\Transformer\Api\StatusTransformer;
use App\UserFilter;
use App\Util\Lexer\Autolink;
use Auth;
use DB;
use Illuminate\Http\Request;
use League\Fractal;
use League\Fractal\Serializer\ArraySerializer;
class CommentController extends Controller
{
@ -34,8 +29,8 @@ class CommentController extends Controller
}
$this->validate($request, [
'item' => 'required|integer|min:1',
'comment' => 'required|string|max:'.(int) config('pixelfed.max_caption_length'),
'sensitive' => 'nullable|boolean'
'comment' => 'required|string|max:'.config_cache('pixelfed.max_caption_length'),
'sensitive' => 'nullable|boolean',
]);
$comment = $request->input('comment');
$statusId = $request->input('item');

View file

@ -2,59 +2,38 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Auth, Cache, DB, Storage, URL;
use Carbon\Carbon;
use App\{
Avatar,
Collection,
CollectionItem,
Hashtag,
Like,
Media,
MediaTag,
Notification,
Profile,
Place,
Status,
UserFilter,
UserSetting
};
use App\Models\Poll;
use App\Transformer\Api\{
MediaTransformer,
MediaDraftTransformer,
StatusTransformer,
StatusStatelessTransformer
};
use League\Fractal;
use App\Util\Media\Filter;
use League\Fractal\Serializer\ArraySerializer;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use App\Jobs\AvatarPipeline\AvatarOptimize;
use App\Collection;
use App\CollectionItem;
use App\Hashtag;
use App\Jobs\ImageOptimizePipeline\ImageOptimize;
use App\Jobs\ImageOptimizePipeline\ImageThumbnail;
use App\Jobs\StatusPipeline\NewStatusPipeline;
use App\Jobs\VideoPipeline\{
VideoOptimize,
VideoPostProcess,
VideoThumbnail
};
use App\Jobs\VideoPipeline\VideoThumbnail;
use App\Media;
use App\MediaTag;
use App\Models\Poll;
use App\Notification;
use App\Profile;
use App\Services\AccountService;
use App\Services\CollectionService;
use App\Services\NotificationService;
use App\Services\MediaPathService;
use App\Services\MediaBlocklistService;
use App\Services\MediaPathService;
use App\Services\MediaStorageService;
use App\Services\MediaTagService;
use App\Services\StatusService;
use App\Services\SnowflakeService;
use Illuminate\Support\Str;
use App\Util\Lexer\Autolink;
use App\Util\Lexer\Extractor;
use App\Util\Media\License;
use Image;
use App\Services\UserRoleService;
use App\Status;
use App\Transformer\Api\MediaTransformer;
use App\UserFilter;
use App\Util\Lexer\Autolink;
use App\Util\Media\Filter;
use App\Util\Media\License;
use Auth;
use Cache;
use DB;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use League\Fractal;
use League\Fractal\Serializer\ArraySerializer;
class ComposeController extends Controller
{
@ -88,7 +67,7 @@ class ComposeController extends Controller
'max:'.config_cache('pixelfed.max_photo_size'),
],
'filter_name' => 'nullable|string|max:24',
'filter_class' => 'nullable|alpha_dash|max:24'
'filter_class' => 'nullable|alpha_dash|max:24',
]);
$user = Auth::user();
@ -169,6 +148,7 @@ class ComposeController extends Controller
$res = $this->fractal->createData($resource)->toArray();
$res['preview_url'] = $preview_url;
$res['url'] = $url;
return response()->json($res);
}
@ -214,10 +194,11 @@ class ComposeController extends Controller
$dir = implode('/', $fragments);
$path = $photo->storePubliclyAs($dir, $name);
$res = [
'url' => $media->url() . '?v=' . time()
'url' => $media->url().'?v='.time(),
];
ImageOptimize::dispatch($media)->onQueue('mmo');
Cache::forget($limitKey);
return $res;
}
@ -226,7 +207,7 @@ class ComposeController extends Controller
abort_if(! $request->user(), 403);
$this->validate($request, [
'id' => 'required|integer|min:1|exists:media,id'
'id' => 'required|integer|min:1|exists:media,id',
]);
abort_if($request->user()->has_roles && ! UserRoleService::can('can-post', $request->user()->id), 403, 'Invalid permissions for this action');
@ -239,7 +220,7 @@ class ComposeController extends Controller
return response()->json([
'msg' => 'Successfully deleted',
'code' => 200
'code' => 200,
]);
}
@ -248,7 +229,7 @@ class ComposeController extends Controller
abort_if(! $request->user(), 403);
$this->validate($request, [
'q' => 'required|string|min:1|max:50'
'q' => 'required|string|min:1|max:50',
]);
$q = $request->input('q');
@ -282,7 +263,7 @@ class ComposeController extends Controller
'id' => (string) $r->id,
'name' => $r->username,
'privacy' => true,
'avatar' => $r->avatarUrl()
'avatar' => $r->avatarUrl(),
];
});
@ -295,7 +276,7 @@ class ComposeController extends Controller
$this->validate($request, [
'status_id' => 'required',
'profile_id' => 'required'
'profile_id' => 'required',
]);
abort_if($request->user()->has_roles && ! UserRoleService::can('can-post', $request->user()->id), 403, 'Invalid permissions for this action');
@ -328,7 +309,7 @@ class ComposeController extends Controller
{
abort_if(! $request->user(), 403);
$this->validate($request, [
'q' => 'required|string|max:100'
'q' => 'required|string|max:100',
]);
abort_if($request->user()->has_roles && ! UserRoleService::can('can-post', $request->user()->id), 403, 'Invalid permissions for this action');
$pid = $request->user()->profile_id;
@ -351,12 +332,13 @@ class ComposeController extends Controller
->map(function ($place) {
return [
'id' => $place->place_id,
'count' => $place->pc
'count' => $place->pc,
];
})
->unique('id')
->values();
}
return Status::selectRaw('id, place_id, count(place_id) as pc')
->whereNotNull('place_id')
->where('id', '>', $minId)
@ -370,7 +352,7 @@ class ComposeController extends Controller
->map(function ($place) {
return [
'id' => $place->place_id,
'count' => $place->pc
'count' => $place->pc,
];
});
});
@ -393,11 +375,12 @@ class ComposeController extends Controller
'id' => $r->id,
'name' => $r->name,
'country' => $r->country,
'url' => url('/discover/places/' . $r->id . '/' . $r->slug)
'url' => url('/discover/places/'.$r->id.'/'.$r->slug),
];
})
->values()
->all();
return $places;
}
@ -406,7 +389,7 @@ class ComposeController extends Controller
abort_if(! $request->user(), 403);
$this->validate($request, [
'q' => 'required|string|min:2|max:50'
'q' => 'required|string|min:2|max:50',
]);
abort_if($request->user()->has_roles && ! UserRoleService::can('can-post', $request->user()->id), 403, 'Invalid permissions for this action');
@ -434,6 +417,7 @@ class ComposeController extends Controller
->get()
->map(function ($profile) {
$username = $profile->domain ? substr($profile->username, 1) : $profile->username;
return [
'key' => '@'.str_limit($username, 30),
'value' => $username,
@ -448,7 +432,7 @@ class ComposeController extends Controller
abort_if(! $request->user(), 403);
$this->validate($request, [
'q' => 'required|string|min:2|max:50'
'q' => 'required|string|min:2|max:50',
]);
abort_if($request->user()->has_roles && ! UserRoleService::can('can-post', $request->user()->id), 403, 'Invalid permissions for this action');
@ -464,7 +448,7 @@ class ComposeController extends Controller
->map(function ($tag) {
return [
'key' => '#'.$tag->slug,
'value' => $tag->slug
'value' => $tag->slug,
];
});
@ -474,7 +458,7 @@ class ComposeController extends Controller
public function store(Request $request)
{
$this->validate($request, [
'caption' => 'nullable|string|max:'.config('pixelfed.max_caption_length', 500),
'caption' => 'nullable|string|max:'.config_cache('pixelfed.max_caption_length', 500),
'media.*' => 'required',
'media.*.id' => 'required|integer|min:1',
'media.*.filter_class' => 'nullable|alpha_dash|max:30',
@ -620,9 +604,9 @@ class ComposeController extends Controller
CollectionItem::firstOrCreate([
'collection_id' => $collection->id,
'object_type' => 'App\Status',
'object_id' => $status->id
'object_id' => $status->id,
], [
'order' => $count
'order' => $count,
]);
CollectionService::addItem(
@ -653,7 +637,7 @@ class ComposeController extends Controller
{
abort_unless(config('exp.top'), 404);
$this->validate($request, [
'caption' => 'nullable|string|max:'.config('pixelfed.max_caption_length', 500),
'caption' => 'nullable|string|max:'.config_cache('pixelfed.max_caption_length', 500),
'cw' => 'nullable|boolean',
'visibility' => 'required|string|in:public,private,unlisted|min:2|max:10',
'place' => 'nullable',
@ -707,7 +691,7 @@ class ComposeController extends Controller
'bg_id' => 1,
'font_size' => strlen($status->caption) <= 140 ? 'h1' : 'h3',
'length' => strlen($status->caption),
]
],
], $entities), JSON_UNESCAPED_SLASHES);
$status->save();
@ -726,7 +710,6 @@ class ComposeController extends Controller
MediaTagService::sendNotification($mt);
}
Cache::forget('user:account:id:'.$profile->user_id);
Cache::forget('_api:statuses:recent_9:'.$profile->id);
Cache::forget('profile:status_count:'.$profile->id);
@ -737,7 +720,7 @@ class ComposeController extends Controller
public function mediaProcessingCheck(Request $request)
{
$this->validate($request, [
'id' => 'required|integer|min:1'
'id' => 'required|integer|min:1',
]);
abort_if($request->user()->has_roles && ! UserRoleService::can('can-post', $request->user()->id), 403, 'Invalid permissions for this action');
@ -748,7 +731,7 @@ class ComposeController extends Controller
if (config('pixelfed.media_fast_process')) {
return [
'finished' => true
'finished' => true,
];
}
@ -762,12 +745,12 @@ class ComposeController extends Controller
break;
default:
# code...
// code...
break;
}
return [
'finished' => $finished
'finished' => $finished,
];
}
@ -779,7 +762,7 @@ class ComposeController extends Controller
$default = [
'default_license' => 1,
'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);
if (isset($settings['other']) && isset($settings['other']['scope'])) {
@ -794,12 +777,12 @@ class ComposeController extends Controller
public function createPoll(Request $request)
{
$this->validate($request, [
'caption' => 'nullable|string|max:'.config('pixelfed.max_caption_length', 500),
'caption' => 'nullable|string|max:'.config_cache('pixelfed.max_caption_length', 500),
'cw' => 'nullable|boolean',
'visibility' => 'required|string|in:public,private',
'comments_disabled' => 'nullable',
'expiry' => 'required|in:60,360,1440,10080',
'pollOptions' => 'required|array|min:1|max:4'
'pollOptions' => 'required|array|min:1|max:4',
]);
abort(404);
abort_if(config('instance.polls.enabled') == false, 404, 'Polls not enabled');
@ -809,8 +792,7 @@ class ComposeController extends Controller
->whereProfileId($request->user()->profile_id)
->whereCaption($request->input('caption'))
->where('created_at', '>', now()->subDays(2))
->exists()
, 422, 'Duplicate detected.');
->exists(), 422, 'Duplicate detected.');
$status = new Status;
$status->profile_id = $request->user()->profile_id;

View file

@ -75,6 +75,18 @@ class ConfigCacheService
'instance.curated_registration.enabled',
'federation.migration',
'pixelfed.max_caption_length',
'pixelfed.max_bio_length',
'pixelfed.max_name_length',
'pixelfed.min_password_length',
'pixelfed.max_avatar_size',
'pixelfed.max_altext_length',
'pixelfed.allow_app_registration',
'pixelfed.app_registration_rate_limit_attempts',
'pixelfed.app_registration_rate_limit_decay',
'pixelfed.app_registration_confirm_rate_limit_attempts',
'pixelfed.app_registration_confirm_rate_limit_decay',
// 'system.user_mode'
];

View file

@ -2,14 +2,11 @@
namespace App\Services;
use App\Util\ActivityPub\Helpers;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Redis;
use App\Status;
use App\User;
use App\Services\AccountService;
use App\Util\Site\Nodeinfo;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;
class LandingService
{
@ -30,6 +27,7 @@ class LandingService
return AccountService::getMastodon(config_cache('instance.admin.pid'), true);
}
$admin = User::whereIsAdmin(true)->first();
return $admin && isset($admin->profile_id) ?
AccountService::getMastodon($admin->profile_id, true) :
null;
@ -40,9 +38,10 @@ class LandingService
collect(json_decode(config_cache('app.rules'), true))
->map(function ($rule, $key) {
$id = $key + 1;
return [
'id' => "{$id}",
'text' => $rule
'text' => $rule,
];
})
->toArray() : [];
@ -67,34 +66,34 @@ class LandingService
'stats' => [
'active_users' => (int) $activeMonth,
'posts_count' => (int) $postCount,
'total_users' => (int) $totalUsers
'total_users' => (int) $totalUsers,
],
'contact' => [
'account' => $contactAccount,
'email' => config('instance.email')
'email' => config('instance.email'),
],
'rules' => $rules,
'uploader' => [
'max_photo_size' => (int) (config('pixelfed.max_photo_size') * 1024),
'max_caption_length' => (int) config('pixelfed.max_caption_length'),
'max_altext_length' => (int) config('pixelfed.max_altext_length', 150),
'max_photo_size' => (int) (config_cache('pixelfed.max_photo_size') * 1024),
'max_caption_length' => (int) config_cache('pixelfed.max_caption_length'),
'max_altext_length' => (int) config_cache('pixelfed.max_altext_length', 150),
'album_limit' => (int) config_cache('pixelfed.max_album_length'),
'image_quality' => (int) config_cache('pixelfed.image_quality'),
'max_collection_length' => (int) config('pixelfed.max_collection_length', 18),
'optimize_image' => (bool) config('pixelfed.optimize_image'),
'optimize_video' => (bool) config('pixelfed.optimize_video'),
'optimize_image' => (bool) config_cache('pixelfed.optimize_image'),
'optimize_video' => (bool) config_cache('pixelfed.optimize_video'),
'media_types' => config_cache('pixelfed.media_types'),
],
'features' => [
'federation' => config_cache('federation.activitypub.enabled'),
'timelines' => [
'local' => true,
'network' => (bool) config('federation.network_timeline'),
'network' => (bool) config_cache('federation.network_timeline'),
],
'mobile_apis' => (bool) config_cache('pixelfed.oauth_enabled'),
'stories' => (bool) config_cache('instance.stories.enabled'),
'video' => Str::contains(config_cache('pixelfed.media_types'), 'video/mp4'),
]
],
];
if ($json) {

View file

@ -5,11 +5,12 @@ namespace App\Util\Site;
use Cache;
use Illuminate\Support\Str;
class Config {
class Config
{
const CACHE_KEY = 'api:site:configuration:_v0.8';
public static function get() {
public static function get()
{
return Cache::remember(self::CACHE_KEY, 900, function () {
$hls = [
'enabled' => config('media.hls.enabled'),
@ -21,15 +22,16 @@ class Config {
'p2p' => (bool) config('media.hls.p2p'),
'p2p_debug' => (bool) config('media.hls.p2p_debug'),
'tracker' => config('media.hls.tracker'),
'ice' => config('media.hls.ice')
'ice' => config('media.hls.ice'),
];
}
return [
'version' => config('pixelfed.version'),
'open_registration' => (bool) config_cache('pixelfed.open_registration'),
'uploader' => [
'max_photo_size' => (int) config('pixelfed.max_photo_size'),
'max_caption_length' => (int) config('pixelfed.max_caption_length'),
'max_caption_length' => (int) config_cache('pixelfed.max_caption_length'),
'max_altext_length' => (int) config('pixelfed.max_altext_length', 150),
'album_limit' => (int) config_cache('pixelfed.max_album_length'),
'image_quality' => (int) config_cache('pixelfed.image_quality'),
@ -41,12 +43,12 @@ class Config {
'media_types' => config_cache('pixelfed.media_types'),
'mime_types' => config_cache('pixelfed.media_types') ? explode(',', config_cache('pixelfed.media_types')) : [],
'enforce_account_limit' => (bool) config_cache('pixelfed.enforce_account_limit')
'enforce_account_limit' => (bool) config_cache('pixelfed.enforce_account_limit'),
],
'activitypub' => [
'enabled' => (bool) config_cache('federation.activitypub.enabled'),
'remote_follow' => config('federation.activitypub.remoteFollow')
'remote_follow' => config('federation.activitypub.remoteFollow'),
],
'ab' => config('exp'),
@ -55,7 +57,7 @@ class Config {
'name' => config_cache('app.name'),
'domain' => config('pixelfed.domain.app'),
'url' => config('app.url'),
'description' => config_cache('app.short_description')
'description' => config_cache('app.short_description'),
],
'account' => [
@ -63,15 +65,15 @@ class Config {
'max_bio_length' => config('pixelfed.max_bio_length'),
'max_name_length' => config('pixelfed.max_name_length'),
'min_password_length' => config('pixelfed.min_password_length'),
'max_account_size' => config('pixelfed.max_account_size')
'max_account_size' => config('pixelfed.max_account_size'),
],
'username' => [
'remote' => [
'formats' => config('instance.username.remote.formats'),
'format' => config('instance.username.remote.format'),
'custom' => config('instance.username.remote.custom')
]
'custom' => config('instance.username.remote.custom'),
],
],
'features' => [
@ -85,22 +87,23 @@ class Config {
'import' => [
'instagram' => (bool) config_cache('pixelfed.import.instagram.enabled'),
'mastodon' => false,
'pixelfed' => false
'pixelfed' => false,
],
'label' => [
'covid' => [
'enabled' => (bool) config('instance.label.covid.enabled'),
'org' => config('instance.label.covid.org'),
'url' => config('instance.label.covid.url'),
]
],
'hls' => $hls
]
],
'hls' => $hls,
],
];
});
}
public static function json() {
public static function json()
{
return json_encode(self::get(), JSON_FORCE_OBJECT);
}
}

View file

@ -50,7 +50,7 @@
</a>
<div class="collapse" id="collapse3">
<div>
During the compose process, you will see the <span class="font-weight-bold">Caption</span> input. Captions are optional and limited to <span class="font-weight-bold">{{config('pixelfed.max_caption_length')}}</span> characters.
During the compose process, you will see the <span class="font-weight-bold">Caption</span> input. Captions are optional and limited to <span class="font-weight-bold">{{config_cache('pixelfed.max_caption_length')}}</span> characters.
</div>
</div>
</p>