bugfixes
This commit is contained in:
parent
0859306ba2
commit
1fb7b6f69b
@ -156,4 +156,4 @@ HEALTHCHECK --interval=60s --timeout=10s --start-period=30s --retries=5 \
|
||||
CMD curl -f http://localhost:80/health || curl -f http://localhost:80/test.php || exit 1
|
||||
|
||||
# Start supervisor
|
||||
CMD ["sh", "-c", "mkdir -p storage/framework/cache storage/framework/sessions storage/framework/views storage/logs bootstrap/cache && chown -R www-data:www-data storage bootstrap/cache && chmod -R 775 storage bootstrap/cache && if [ -f .env ]; then chmod 666 .env; fi && php artisan optimize:clear && /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf"]
|
||||
CMD ["sh", "-c", "mkdir -p storage/framework/cache storage/framework/sessions storage/framework/views storage/logs bootstrap/cache && chown -R www-data:www-data storage bootstrap/cache && chmod -R 775 storage bootstrap/cache && touch storage/installed public/installed && if [ -f .env ]; then chmod 666 .env || true; fi && php artisan optimize:clear && /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf"]
|
||||
|
||||
@ -1,83 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Exam\Services;
|
||||
|
||||
use Modules\Exam\Models\Exam;
|
||||
use App\Models\ChunkedUpload;
|
||||
use Modules\Exam\Models\ExamResource;
|
||||
use App\Services\MediaService;
|
||||
use App\Services\LocalFileUploadService;
|
||||
use App\Services\S3MultipartUploadService;
|
||||
|
||||
class ExamResourceService
|
||||
{
|
||||
protected LocalFileUploadService | S3MultipartUploadService $uploaderService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->uploaderService = config('filesystems.default') === 's3' ? new S3MultipartUploadService() : new LocalFileUploadService();
|
||||
}
|
||||
|
||||
public function resourceStore(array $data): ExamResource
|
||||
{
|
||||
if ($data['type'] === 'link') {
|
||||
$resource = ExamResource::create($data);
|
||||
} else {
|
||||
$resource = ExamResource::create([...$data, 'resource' => $data['resource_url']]);
|
||||
}
|
||||
|
||||
return $resource;
|
||||
}
|
||||
|
||||
public function resourceUpdate(ExamResource $resource, array $data): bool
|
||||
{
|
||||
if ($data['type'] === 'link') {
|
||||
$resource->update($data);
|
||||
} else {
|
||||
$chunkedUpload = ChunkedUpload::where('file_url', $data['resource'])->first();
|
||||
$chunkedUpload && $this->uploaderService->deleteFile($chunkedUpload);
|
||||
|
||||
$resource->update([...$data, 'resource' => $data['resource_url']]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function resourceDelete(ExamResource $resource): bool
|
||||
{
|
||||
$chunkedUpload = ChunkedUpload::where('file_url', $resource->resource)->first();
|
||||
$chunkedUpload && $this->uploaderService->deleteFile($chunkedUpload);
|
||||
|
||||
$resource->delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getExamResources(string $exam_id)
|
||||
{
|
||||
$exam = Exam::find($exam_id);
|
||||
if (!$exam) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Get media files from Spatie Media Library
|
||||
$media = $exam->getMedia('resources');
|
||||
|
||||
if (!$media) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Convert media collection to array format
|
||||
return $media->map(function ($item) {
|
||||
return [
|
||||
'id' => $item->id,
|
||||
'name' => $item->name,
|
||||
'file_name' => $item->file_name,
|
||||
'mime_type' => $item->mime_type,
|
||||
'size' => $item->size,
|
||||
'url' => $item->getUrl(),
|
||||
'getUrl' => $item->getUrl(),
|
||||
];
|
||||
})->toArray();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user