2024-03-11 23:32:38 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use Illuminate\Http\Request;
|
2024-05-28 21:16:50 +02:00
|
|
|
use App\Services\Assets\FileUploadService;
|
2024-05-31 20:56:38 +02:00
|
|
|
use App\Interfaces\MemberRepositoryInterface;
|
|
|
|
use App\Services\Data\SettingsService;
|
2024-03-11 23:32:38 +01:00
|
|
|
|
|
|
|
class FileUploadAPIController extends Controller
|
|
|
|
{
|
|
|
|
protected $upload;
|
2024-05-31 20:56:38 +02:00
|
|
|
protected $member;
|
|
|
|
protected $settings;
|
2024-03-11 23:32:38 +01:00
|
|
|
|
2024-05-31 20:56:38 +02:00
|
|
|
public function __construct(
|
|
|
|
FileUploadService $fileUploadService,
|
|
|
|
MemberRepositoryInterface $memberRepo,
|
|
|
|
SettingsService $settingsService
|
|
|
|
) {
|
|
|
|
$this->upload = $fileUploadService;
|
|
|
|
$this->member = $memberRepo;
|
|
|
|
$this->settings = $settingsService;
|
2024-03-11 23:32:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function upload(Request $request, $type = null)
|
|
|
|
{
|
2024-05-31 20:56:38 +02:00
|
|
|
$result = $this->upload->handleFile($request, $type);
|
|
|
|
//update configs for specfic uploads
|
|
|
|
switch ($request['source']) {
|
|
|
|
case 'avatar-upload':
|
|
|
|
$member = [];
|
|
|
|
$member = session('member');
|
|
|
|
$member['avatar'] = $result['filePath'];
|
|
|
|
$member = (object) $member;
|
|
|
|
$this->member->update($member);
|
|
|
|
break;
|
|
|
|
case 'background-upload':
|
|
|
|
$this->settings->updateGlobalData('background', $result['filePath']);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return $result;
|
2024-03-11 23:32:38 +01:00
|
|
|
}
|
|
|
|
}
|