229 url for downloads (#369)
* Allow file uploads for subfleet * Allow URL to be used for a download * Remove old FileUploadRequest * Move file removal logic to service layer * Remove unused import * Remove unused packages
This commit is contained in:
@@ -4,10 +4,10 @@ namespace App\Services;
|
||||
|
||||
use App\Contracts\Service;
|
||||
use App\Models\File;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* Class FileService
|
||||
*/
|
||||
class FileService extends Service
|
||||
{
|
||||
/**
|
||||
@@ -37,13 +37,11 @@ class FileService extends Service
|
||||
|
||||
// Create the file, add the ID to the front of the file to account
|
||||
// for any duplicate filenames, but still can be found in an `ls`
|
||||
|
||||
$filename = $id.'_'
|
||||
.str_slug(trim($path_info['filename']))
|
||||
.'.'.$path_info['extension'];
|
||||
|
||||
$filename = $id.'_'.str_slug(trim($path_info['filename'])).'.'.$path_info['extension'];
|
||||
$file_path = $file->storeAs($folder, $filename, $attrs['disk']);
|
||||
|
||||
Log::info('File saved to '.$file_path);
|
||||
|
||||
$asset = new File($attrs);
|
||||
$asset->id = $id;
|
||||
$asset->path = $file_path;
|
||||
@@ -51,4 +49,21 @@ class FileService extends Service
|
||||
|
||||
return $asset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a file, if it exists on disk
|
||||
*
|
||||
* @param File $file
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function removeFile($file)
|
||||
{
|
||||
if (!Str::startsWith($file->path, 'http')) {
|
||||
Storage::disk(config('filesystems.public_files'))
|
||||
->delete($file->path);
|
||||
}
|
||||
|
||||
$file->delete();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user