Skip to content

Commit

Permalink
Fix local libraries regressions
Browse files Browse the repository at this point in the history
- New endpoint root option should only after S3 driver
- Add support for prefix_uuid_with_local_path in media library as well following support in file library (for backward compatibility with the way we've been using the local driver)
- Default local path to "uploads" instead of "libraries"
  • Loading branch information
ifox committed Jul 29, 2019
1 parent 6f449ac commit 876c93a
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion config/disks.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

$localRootPrefix = storage_path('app/public/');
$localUrlPrefix = env('APP_URL') . '/storage/';
$localUrlPrefix = request()->getScheme() . '://' . env('APP_URL') . '/storage/';

$mediaLocalConfig = [
'driver' => 'local',
Expand Down
3 changes: 2 additions & 1 deletion config/file-library.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
'disk' => 'file_library',
'endpoint_type' => env('FILE_LIBRARY_ENDPOINT_TYPE', 's3'),
'cascade_delete' => env('FILE_LIBRARY_CASCADE_DELETE', false),
'local_path' => env('FILE_LIBRARY_LOCAL_PATH', 'libraries'),
'local_path' => env('FILE_LIBRARY_LOCAL_PATH', 'uploads'),
'file_service' => env('FILE_LIBRARY_FILE_SERVICE', 'A17\Twill\Services\FileLibrary\Disk'),
'acl' => env('FILE_LIBRARY_ACL', 'public-read'),
'filesize_limit' => env('FILE_LIBRARY_FILESIZE_LIMIT', 50),
'allowed_extensions' => [],
'prefix_uuid_with_local_path' => false,
];
3 changes: 2 additions & 1 deletion config/media-library.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
'disk' => 'media_library',
'endpoint_type' => env('MEDIA_LIBRARY_ENDPOINT_TYPE', 's3'),
'cascade_delete' => env('MEDIA_LIBRARY_CASCADE_DELETE', false),
'local_path' => env('MEDIA_LIBRARY_LOCAL_PATH', 'libraries'),
'local_path' => env('MEDIA_LIBRARY_LOCAL_PATH', 'uploads'),
'image_service' => env('MEDIA_LIBRARY_IMAGE_SERVICE', 'A17\Twill\Services\MediaLibrary\Imgix'),
'acl' => env('MEDIA_LIBRARY_ACL', 'private'),
'filesize_limit' => env('MEDIA_LIBRARY_FILESIZE_LIMIT', 50),
'allowed_extensions' => ['svg', 'jpg', 'gif', 'png', 'jpeg'],
'init_alt_text_from_filename' => true,
'prefix_uuid_with_local_path' => config('twill.file_library.prefix_uuid_with_local_path', false),
];
12 changes: 8 additions & 4 deletions src/Http/Controllers/Admin/FileLibraryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,23 @@ public function store($parentModuleId = null)
public function storeFile($request)
{
$filename = $request->input('qqfilename');

$cleanFilename = preg_replace("/\s+/i", "-", $filename);

$fileDirectory = $request->input('unique_folder_name');
$disk = $this->config->get('twill.file_library.disk');

$request->file('qqfile')->storeAs($fileDirectory, $cleanFilename, $disk);

$uuid = $request->input('unique_folder_name') . '/' . $cleanFilename;

if ($this->config->get('twill.file_library.prefix_uuid_with_local_path', false)) {
$uuid = $this->config->get('twill.file_library.local_path') . $uuid;
$prefix = trim($this->config->get('twill.file_library.local_path'), '/ ') . '/';
$fileDirectory = $prefix . $fileDirectory;
$uuid = $prefix . $uuid;
}

$disk = $this->config->get('twill.file_library.disk');

$request->file('qqfile')->storeAs($fileDirectory, $cleanFilename, $disk);

$fields = [
'uuid' => $uuid,
'filename' => $cleanFilename,
Expand Down
11 changes: 10 additions & 1 deletion src/Http/Controllers/Admin/MediaLibraryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Illuminate\Routing\ResponseFactory;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Storage;

class MediaLibraryController extends ModuleController implements SignS3UploadListener
{
Expand Down Expand Up @@ -147,6 +148,14 @@ public function storeFile($request)

$fileDirectory = $request->input('unique_folder_name');

$uuid = $request->input('unique_folder_name') . '/' . $filename;

if ($this->config->get('twill.media_library.prefix_uuid_with_local_path', false)) {
$prefix = trim($this->config->get('twill.media_library.local_path'), '/ ') . '/';
$fileDirectory = $prefix . $fileDirectory;
$uuid = $prefix . $uuid;
}

$disk = $this->config->get('twill.media_library.disk');

$request->file('qqfile')->storeAs($fileDirectory, $filename, $disk);
Expand All @@ -156,7 +165,7 @@ public function storeFile($request)
list($w, $h) = getimagesize($filePath);

$fields = [
'uuid' => $request->input('unique_folder_name') . '/' . $filename,
'uuid' => $uuid,
'filename' => $originalFilename,
'width' => $w,
'height' => $h,
Expand Down
2 changes: 1 addition & 1 deletion src/Http/ViewComposers/FilesUploaderConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function compose(View $view)
'signatureEndpoint' => $this->urlGenerator->route('admin.file-library.sign-s3-upload'),
'endpointBucket' => $this->config->get('filesystems.disks.' . $libraryDisk . '.bucket', 'none'),
'endpointRegion' => $this->config->get('filesystems.disks.' . $libraryDisk . '.region', 'none'),
'endpointRoot' => $this->config->get('filesystems.disks.' . $libraryDisk . '.root', ''),
'endpointRoot' => $endpointType === 'local' ? '' : $this->config->get('filesystems.disks.' . $libraryDisk . '.root', ''),
'accessKey' => $this->config->get('filesystems.disks.' . $libraryDisk . '.key', 'none'),
'csrfToken' => $this->sessionStore->token(),
'acl' => $this->config->get('twill.file_library.acl'),
Expand Down
2 changes: 1 addition & 1 deletion src/Http/ViewComposers/MediasUploaderConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function compose(View $view)
'signatureEndpoint' => $this->urlGenerator->route('admin.media-library.sign-s3-upload'),
'endpointBucket' => $this->config->get('filesystems.disks.' . $libraryDisk . '.bucket', 'none'),
'endpointRegion' => $this->config->get('filesystems.disks.' . $libraryDisk . '.region', 'none'),
'endpointRoot' => $this->config->get('filesystems.disks.' . $libraryDisk . '.root', ''),
'endpointRoot' => $endpointType === 'local' ? '' : $this->config->get('filesystems.disks.' . $libraryDisk . '.root', ''),
'accessKey' => $this->config->get('filesystems.disks.' . $libraryDisk . '.key', 'none'),
'csrfToken' => $this->sessionStore->token(),
'acl' => $this->config->get('twill.media_library.acl'),
Expand Down
1 change: 0 additions & 1 deletion src/Services/MediaLibrary/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\Support\Facades\Storage;


class Local implements ImageServiceInterface
{
use ImageServiceDefaults;
Expand Down

0 comments on commit 876c93a

Please sign in to comment.