mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-26 00:03:16 +00:00
Update ApiV1Controller, add custom_emoji endpoint
This commit is contained in:
parent
d1ff86ee34
commit
16e725183e
3 changed files with 30 additions and 2 deletions
|
@ -360,6 +360,7 @@ class AdminController extends Controller
|
||||||
|
|
||||||
if($request->has('cc')) {
|
if($request->has('cc')) {
|
||||||
Cache::forget('pf:admin:custom_emoji:stats');
|
Cache::forget('pf:admin:custom_emoji:stats');
|
||||||
|
Cache::forget('pf:custom_emoji');
|
||||||
return redirect(route('admin.custom-emoji'));
|
return redirect(route('admin.custom-emoji'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -463,6 +464,7 @@ class AdminController extends Controller
|
||||||
$request->emoji->storeAs('public/emoji', $fileName);
|
$request->emoji->storeAs('public/emoji', $fileName);
|
||||||
$emoji->media_path = 'emoji/' . $fileName;
|
$emoji->media_path = 'emoji/' . $fileName;
|
||||||
$emoji->save();
|
$emoji->save();
|
||||||
|
Cache::forget('pf:custom_emoji');
|
||||||
return redirect(route('admin.custom-emoji'));
|
return redirect(route('admin.custom-emoji'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -471,6 +473,7 @@ class AdminController extends Controller
|
||||||
abort_unless(config('federation.custom_emoji.enabled'), 404);
|
abort_unless(config('federation.custom_emoji.enabled'), 404);
|
||||||
$emoji = CustomEmoji::findOrFail($id);
|
$emoji = CustomEmoji::findOrFail($id);
|
||||||
Storage::delete("public/{$emoji->media_path}");
|
Storage::delete("public/{$emoji->media_path}");
|
||||||
|
Cache::forget('pf:custom_emoji');
|
||||||
$emoji->delete();
|
$emoji->delete();
|
||||||
return redirect(route('admin.custom-emoji'));
|
return redirect(route('admin.custom-emoji'));
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,6 +77,7 @@ use App\Util\Localization\Localization;
|
||||||
use App\Util\Media\License;
|
use App\Util\Media\License;
|
||||||
use App\Jobs\MediaPipeline\MediaSyncLicensePipeline;
|
use App\Jobs\MediaPipeline\MediaSyncLicensePipeline;
|
||||||
use App\Services\DiscoverService;
|
use App\Services\DiscoverService;
|
||||||
|
use App\Services\CustomEmojiService;
|
||||||
|
|
||||||
class ApiV1Controller extends Controller
|
class ApiV1Controller extends Controller
|
||||||
{
|
{
|
||||||
|
@ -920,7 +921,7 @@ class ApiV1Controller extends Controller
|
||||||
*/
|
*/
|
||||||
public function customEmojis()
|
public function customEmojis()
|
||||||
{
|
{
|
||||||
return response()->json([]);
|
return response(CustomEmojiService::all())->header('Content-Type', 'application/json');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -71,8 +71,8 @@ class CustomEmojiService
|
||||||
$emoji->save();
|
$emoji->save();
|
||||||
|
|
||||||
$name = str_replace(':', '', $json['name']);
|
$name = str_replace(':', '', $json['name']);
|
||||||
|
Cache::forget('pf:custom_emoji');
|
||||||
Cache::forget('pf:custom_emoji:' . $name);
|
Cache::forget('pf:custom_emoji:' . $name);
|
||||||
|
|
||||||
if($id) {
|
if($id) {
|
||||||
StatusService::del($id);
|
StatusService::del($id);
|
||||||
}
|
}
|
||||||
|
@ -104,4 +104,28 @@ class CustomEmojiService
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function all()
|
||||||
|
{
|
||||||
|
return Cache::rememberForever('pf:custom_emoji', function() {
|
||||||
|
$pgsql = config('database.default') === 'pgsql';
|
||||||
|
return CustomEmoji::when(!$pgsql, function($q, $pgsql) {
|
||||||
|
return $q->groupBy('shortcode');
|
||||||
|
})
|
||||||
|
->get()
|
||||||
|
->map(function($emojo) {
|
||||||
|
$url = url('storage/' . $emojo->media_path);
|
||||||
|
return [
|
||||||
|
'shortcode' => str_replace(':', '', $emojo->shortcode),
|
||||||
|
'url' => $url,
|
||||||
|
'static_path' => $url,
|
||||||
|
'visible_in_picker' => $emojo->disabled == false
|
||||||
|
];
|
||||||
|
})
|
||||||
|
->when($pgsql, function($collection) {
|
||||||
|
return $collection->unique('shortcode');
|
||||||
|
})
|
||||||
|
->toJson(JSON_UNESCAPED_SLASHES);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue