2020-01-05 23:23:48 +01:00
|
|
|
<?php
|
|
|
|
|
2021-11-07 21:57:22 +01:00
|
|
|
namespace App\Api\v1\Controllers;
|
2020-01-05 23:23:48 +01:00
|
|
|
|
2021-11-07 21:57:22 +01:00
|
|
|
use App\Http\Controllers\Controller;
|
2022-07-20 13:32:31 +02:00
|
|
|
use App\Services\LogoService;
|
2022-11-22 15:15:52 +01:00
|
|
|
use Illuminate\Http\Request;
|
2022-07-20 13:32:31 +02:00
|
|
|
use Illuminate\Support\Facades\App;
|
2022-11-22 15:15:52 +01:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
2020-01-05 23:23:48 +01:00
|
|
|
|
|
|
|
class IconController extends Controller
|
|
|
|
{
|
2022-07-20 13:32:31 +02:00
|
|
|
/**
|
2020-01-08 15:24:34 +01:00
|
|
|
* Handle uploaded icon image
|
2020-01-05 23:23:48 +01:00
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
2021-11-26 11:18:58 +01:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
2020-01-05 23:23:48 +01:00
|
|
|
*/
|
|
|
|
public function upload(Request $request)
|
|
|
|
{
|
2020-01-19 23:02:20 +01:00
|
|
|
$this->validate($request, [
|
2020-01-09 16:33:32 +01:00
|
|
|
'icon' => 'required|image',
|
2020-01-12 19:55:17 +01:00
|
|
|
]);
|
2020-01-09 16:33:32 +01:00
|
|
|
|
2022-09-02 14:28:57 +02:00
|
|
|
$icon = $request->file('icon');
|
|
|
|
$path = $icon instanceof \Illuminate\Http\UploadedFile ? $icon->store('', 'icons') : false;
|
|
|
|
|
|
|
|
return $path
|
|
|
|
? response()->json(['filename' => pathinfo($path)['basename']], 201)
|
|
|
|
: response()->json(['message' => __('errors.file_upload_failed')], 500);
|
2020-01-05 23:23:48 +01:00
|
|
|
}
|
2022-07-20 13:32:31 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch a logo
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*/
|
|
|
|
public function fetch(Request $request)
|
|
|
|
{
|
|
|
|
$this->validate($request, [
|
|
|
|
'service' => 'string|regex:/^[^:]+$/i',
|
|
|
|
]);
|
2022-11-22 15:15:52 +01:00
|
|
|
|
2022-07-20 13:32:31 +02:00
|
|
|
$logoService = App::make(LogoService::class);
|
2022-11-22 15:15:52 +01:00
|
|
|
$icon = $logoService->getIcon($request->service);
|
2022-07-20 13:32:31 +02:00
|
|
|
|
|
|
|
return $icon
|
|
|
|
? response()->json(['filename' => $icon], 201)
|
|
|
|
: response()->json(null, 204);
|
|
|
|
}
|
2020-01-08 15:24:34 +01:00
|
|
|
|
2022-07-20 13:32:31 +02:00
|
|
|
/**
|
2020-01-08 15:24:34 +01:00
|
|
|
* delete an icon
|
|
|
|
*
|
2022-11-22 15:15:52 +01:00
|
|
|
* @param string $icon
|
2021-11-26 11:18:58 +01:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
2020-01-08 15:24:34 +01:00
|
|
|
*/
|
2022-08-26 15:57:18 +02:00
|
|
|
public function delete(string $icon)
|
2020-01-08 15:24:34 +01:00
|
|
|
{
|
2022-11-22 15:15:52 +01:00
|
|
|
Storage::disk('icons')->delete($icon);
|
2020-01-08 15:24:34 +01:00
|
|
|
|
|
|
|
return response()->json(null, 204);
|
|
|
|
}
|
2022-11-22 15:15:52 +01:00
|
|
|
}
|