feat: update assignment file handling to use temporary storage, include custom media properties, and remove redundant file preservation

This commit is contained in:
Yoga Pangestu 2026-04-04 02:22:07 +07:00
parent 80c1da3d5d
commit b13133ce71
5 changed files with 11 additions and 5 deletions

View File

@ -79,7 +79,6 @@ public function handleRecordCreation(array $data): Model
$filePath = is_array($pdf) ? reset($pdf) : $pdf; $filePath = is_array($pdf) ? reset($pdf) : $pdf;
$assignment->addMediaFromDisk($filePath, config('filesystems.default')) $assignment->addMediaFromDisk($filePath, config('filesystems.default'))
->preservingOriginal()
->withCustomProperties([ ->withCustomProperties([
'feature' => 'assignments', 'feature' => 'assignments',
'date' => now()->toDateString(), 'date' => now()->toDateString(),

View File

@ -102,7 +102,6 @@ public function handleRecordUpdate(Model $record, array $data): Model
if (! empty($filePath)) { if (! empty($filePath)) {
$record->addMediaFromDisk($filePath, config('filesystems.default')) $record->addMediaFromDisk($filePath, config('filesystems.default'))
->preservingOriginal()
->withCustomProperties([ ->withCustomProperties([
'feature' => 'assignments', 'feature' => 'assignments',
'date' => now()->toDateString(), 'date' => now()->toDateString(),

View File

@ -264,6 +264,11 @@ public function submit(): void
if ($state['file']) { if ($state['file']) {
$existingSubmission->clearMediaCollection('submission'); $existingSubmission->clearMediaCollection('submission');
$existingSubmission->addMediaFromDisk($state['file'], config('filesystems.default')) $existingSubmission->addMediaFromDisk($state['file'], config('filesystems.default'))
->withCustomProperties([
'feature' => 'assignments',
'date' => now()->toDateString(),
'doc_type' => 'submission',
])
->toMediaCollection('submission'); ->toMediaCollection('submission');
} }
@ -283,6 +288,11 @@ public function submit(): void
if ($state['file']) { if ($state['file']) {
$submission->addMediaFromDisk($state['file'], config('filesystems.default')) $submission->addMediaFromDisk($state['file'], config('filesystems.default'))
->withCustomProperties([
'feature' => 'assignments',
'date' => now()->toDateString(),
'doc_type' => 'submission',
])
->toMediaCollection('submission'); ->toMediaCollection('submission');
} }

View File

@ -121,7 +121,7 @@ public static function configure(Schema $schema): Schema
->disk(config('filesystems.default')) ->disk(config('filesystems.default'))
->acceptedFileTypes(['application/pdf']) ->acceptedFileTypes(['application/pdf'])
->maxSize(1024 * 5) ->maxSize(1024 * 5)
->directory('assignments/'.now()->toDateString()) ->directory('assignments-tmp/'.now()->toDateString())
->nullable() ->nullable()
->columnSpanFull(), ->columnSpanFull(),
]) ])

View File

@ -1,2 +0,0 @@
*
!.gitignore