From fffede1c107f21b8624c7c7d882e3aebfb448439 Mon Sep 17 00:00:00 2001 From: Peter Papp Date: Thu, 22 Jul 2021 17:26:22 +0200 Subject: [PATCH] fixes --- psalm.xml.dist | 2 +- public/mix-manifest.json | 16 +++++++++++++--- .../js/components/Others/ShareEditPopup.vue | 2 +- resources/js/helpers.js | 2 +- .../js/views/Shared/SharedAuthentication.vue | 2 +- routes/share.php | 4 ++-- routes/web.php | 4 ++-- .../Sharing/Controllers/ShareController.php | 14 +++++++------- .../Controllers/SharePublicIndexController.php | 14 +++++++------- .../WebCrawlerOpenGraphController.php | 18 +++++++++--------- src/Domain/Sharing/Models/Share.php | 5 +---- src/Support/helpers.php | 14 ++++++++------ 12 files changed, 53 insertions(+), 44 deletions(-) diff --git a/psalm.xml.dist b/psalm.xml.dist index f327d329..c6df33e7 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -8,7 +8,7 @@ xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" > - + diff --git a/public/mix-manifest.json b/public/mix-manifest.json index 67289b4f..7625d8ac 100644 --- a/public/mix-manifest.json +++ b/public/mix-manifest.json @@ -55,7 +55,7 @@ "/chunks/plan-settings.js": "/chunks/plan-settings.js?id=dbc08f8cdc23900ef40a", "/chunks/plan-subscribers.js": "/chunks/plan-subscribers.js?id=8c4b655b9286e06894c5", "/chunks/plans.js": "/chunks/plans.js?id=2b26173a02ed9f86e875", - "/chunks/platform.js": "/chunks/platform.js?id=96e35689e3b71e7097eb", + "/chunks/platform.js": "/chunks/platform.js?id=5e32d71dd20b421c0339", "/chunks/platform~chunks/shared.js": "/chunks/platform~chunks/shared.js?id=be3d7cf51585313cf53b", "/chunks/profile.js": "/chunks/profile.js?id=03526296e71df827ff47", "/chunks/profile~chunks/settings-password.js": "/chunks/profile~chunks/settings-password.js?id=fd25990d1ccec0294602", @@ -70,7 +70,7 @@ "/chunks/settings~chunks/settings-password.js": "/chunks/settings~chunks/settings-password.js?id=1c49c2c5bcef4395dedb", "/chunks/setup-wizard.js": "/chunks/setup-wizard.js?id=41d3478184ec24644a1c", "/chunks/shared.js": "/chunks/shared.js?id=7524b7a783d4aed23794", - "/chunks/shared/authenticate.js": "/chunks/shared/authenticate.js?id=bfdf9bb904d354bdcbd1", + "/chunks/shared/authenticate.js": "/chunks/shared/authenticate.js?id=0d55b9570c2e4dffc6c4", "/chunks/shared/file-browser.js": "/chunks/shared/file-browser.js?id=0f6c34512740fca7e007", "/chunks/shared/single-file.js": "/chunks/shared/single-file.js?id=7886247bb35deada28a2", "/chunks/sign-in.js": "/chunks/sign-in.js?id=0709543b76769c50a873", @@ -98,5 +98,15 @@ "/chunks/sign-in.5fb05f1c4d2f285ebf61.hot-update.js": "/chunks/sign-in.5fb05f1c4d2f285ebf61.hot-update.js", "/chunks/sign-in.64892e5fdc888eba9b23.hot-update.js": "/chunks/sign-in.64892e5fdc888eba9b23.hot-update.js", "/chunks/sign-in.62aa097b63d9b34e26cd.hot-update.js": "/chunks/sign-in.62aa097b63d9b34e26cd.hot-update.js", - "/chunks/platform.cc7392304bf1bf06dc6c.hot-update.js": "/chunks/platform.cc7392304bf1bf06dc6c.hot-update.js" + "/chunks/platform.cc7392304bf1bf06dc6c.hot-update.js": "/chunks/platform.cc7392304bf1bf06dc6c.hot-update.js", + "/js/main.c485ebce07a04a22b7c9.hot-update.js": "/js/main.c485ebce07a04a22b7c9.hot-update.js", + "/js/main.7a0c892ef84793506a82.hot-update.js": "/js/main.7a0c892ef84793506a82.hot-update.js", + "/js/main.a19fe043abb3a32f0608.hot-update.js": "/js/main.a19fe043abb3a32f0608.hot-update.js", + "/js/main.d571f0bdb43cf090c45d.hot-update.js": "/js/main.d571f0bdb43cf090c45d.hot-update.js", + "/js/main.2b5b1fcef9e9ba3a7ae7.hot-update.js": "/js/main.2b5b1fcef9e9ba3a7ae7.hot-update.js", + "/js/main.b416b2d7971524a86f46.hot-update.js": "/js/main.b416b2d7971524a86f46.hot-update.js", + "/chunks/profile.bbadcc644cb3b3e11ae7.hot-update.js": "/chunks/profile.bbadcc644cb3b3e11ae7.hot-update.js", + "/chunks/profile.c0f226e939dbf079715a.hot-update.js": "/chunks/profile.c0f226e939dbf079715a.hot-update.js", + "/chunks/platform.529c72b59492c1c39e5c.hot-update.js": "/chunks/platform.529c72b59492c1c39e5c.hot-update.js", + "/chunks/shared/authenticate.79f7d04085475dc9cf9e.hot-update.js": "/chunks/shared/authenticate.79f7d04085475dc9cf9e.hot-update.js" } diff --git a/resources/js/components/Others/ShareEditPopup.vue b/resources/js/components/Others/ShareEditPopup.vue index d95ba473..0403627e 100644 --- a/resources/js/components/Others/ShareEditPopup.vue +++ b/resources/js/components/Others/ShareEditPopup.vue @@ -284,7 +284,7 @@ // Send request to get share link axios - .post('/api/share/' + this.shareOptions.id, { + .post('/api/share/' + this.shareOptions.token, { permission: this.shareOptions.permission, protected: this.shareOptions.isProtected, expiration: this.shareOptions.expiration, diff --git a/resources/js/helpers.js b/resources/js/helpers.js index 4a9cdaa0..0ef5962a 100644 --- a/resources/js/helpers.js +++ b/resources/js/helpers.js @@ -68,7 +68,7 @@ const Helpers = { Vue.prototype.$updateText = debounce(function (route, name, value, allowEmpty = false) { - if ((value === '' || value === ' ') && !allowEmpty) return + if ((value === '' || value === ' ' || typeof value === 'object') && !allowEmpty) return axios.post(this.$store.getters.api + route, {name, value, _method: 'patch'}) .catch(() => { diff --git a/resources/js/views/Shared/SharedAuthentication.vue b/resources/js/views/Shared/SharedAuthentication.vue index 47e43b57..599492e5 100644 --- a/resources/js/views/Shared/SharedAuthentication.vue +++ b/resources/js/views/Shared/SharedAuthentication.vue @@ -42,7 +42,7 @@ }, data() { return { - password: 'secret', + password: '', isLoading: false, } }, diff --git a/routes/share.php b/routes/share.php index 3dfeeb22..d75dbf94 100644 --- a/routes/share.php +++ b/routes/share.php @@ -38,7 +38,7 @@ Route::group(['prefix' => 'browse'], function () { Route::get('/navigation/{shared}', VisitorNavigationFolderTreeController::class); Route::get('/search/{shared}', VisitorSearchFilesAndFoldersController::class); Route::get('/file/{shared}', VisitorShowFileController::class); - Route::get('/share/{shared}', [ShareController::class, 'show']); + Route::get('/share/{share}', [ShareController::class, 'show']); }); -Route::get('/og-site/{shared}', WebCrawlerOpenGraphController::class); +Route::get('/og-site/{share}', WebCrawlerOpenGraphController::class); diff --git a/routes/web.php b/routes/web.php index 3daec34e..47f5e703 100644 --- a/routes/web.php +++ b/routes/web.php @@ -16,9 +16,9 @@ Route::get('/translations/{lang}', CurrentLocalizationController::class); // Get og site for web crawlers if (Crawler::isCrawler()) { - Route::get('/share/{shared}', WebCrawlerOpenGraphController::class); + Route::get('/share/{share}', WebCrawlerOpenGraphController::class); } else { - Route::get('/share/{shared}', SharePublicIndexController::class); + Route::get('/share/{share}', SharePublicIndexController::class); } // Index diff --git a/src/Domain/Sharing/Controllers/ShareController.php b/src/Domain/Sharing/Controllers/ShareController.php index 005a7f5d..c3327ff7 100644 --- a/src/Domain/Sharing/Controllers/ShareController.php +++ b/src/Domain/Sharing/Controllers/ShareController.php @@ -1,7 +1,6 @@ update([ + $share->update([ 'permission' => $request->input('permission'), 'is_protected' => $request->input('protected'), 'expire_in' => $request->input('expiration'), 'password' => $request->input('password') ? bcrypt($request->input('password')) - : $shared->password, + : $share->password, ]); // Return shared record - return new ShareResource($shared); + return new ShareResource($share); } /** diff --git a/src/Domain/Sharing/Controllers/SharePublicIndexController.php b/src/Domain/Sharing/Controllers/SharePublicIndexController.php index 01e2290a..7edd6360 100644 --- a/src/Domain/Sharing/Controllers/SharePublicIndexController.php +++ b/src/Domain/Sharing/Controllers/SharePublicIndexController.php @@ -20,18 +20,18 @@ class SharePublicIndexController extends Controller } public function __invoke( - Share $shared, + Share $share, ): View | StreamedResponse { // Delete share_session if exist - if ($shared->is_protected) { + if ($share->is_protected) { cookie()->queue('share_session', '', -1); } // Check if shared is image file and then show it - if ($shared->type === 'file' && ! $shared->is_protected) { - $image = File::whereUserId($shared->user_id) + if ($share->type === 'file' && ! $share->is_protected) { + $image = File::whereUserId($share->user_id) ->whereType('image') - ->whereId($shared->item_id) + ->whereId($share->item_id) ->first(); if ($image) { @@ -39,9 +39,9 @@ class SharePublicIndexController extends Controller $fileSize = (int) $image->getRawOriginal('filesize'); // Store user download size - ($this->recordDownload)($fileSize, $shared->user->id); + ($this->recordDownload)($fileSize, $share->user->id); - return $this->get_single_image($image, $shared->user_id); + return $this->get_single_image($image, $share->user_id); } } diff --git a/src/Domain/Sharing/Controllers/WebCrawlerOpenGraphController.php b/src/Domain/Sharing/Controllers/WebCrawlerOpenGraphController.php index d8fa5cd8..1fee24de 100644 --- a/src/Domain/Sharing/Controllers/WebCrawlerOpenGraphController.php +++ b/src/Domain/Sharing/Controllers/WebCrawlerOpenGraphController.php @@ -11,30 +11,30 @@ class WebCrawlerOpenGraphController extends Controller * Get og site for web crawlers */ public function __invoke( - Share $shared + Share $share ): View { - $namespace = match ($shared->type) { + $namespace = match ($share->type) { 'folder' => 'Domain\\Folders\\Models\\Folder', 'file' => 'Domain\\Files\\Models\\File', }; // Get file/folder record - $item = ($namespace)::where('user_id', $shared->user->id) - ->where('id', $shared->item_id) + $item = ($namespace)::where('user_id', $share->user->id) + ->where('id', $share->item_id) ->first(); if ($item->thumbnail) { - $item->setPublicUrl($shared->token); + $item->setPublicUrl($share->token); } return view('vuefilemanager.crawler.og-view') ->with('settings', get_settings_in_json()) ->with('metadata', [ - 'url' => url('/share', ['token' => $shared->token]), - 'is_protected' => $shared->is_protected, - 'user' => $shared->user->settings->name, + 'url' => url('/share', ['token' => $share->token]), + 'is_protected' => $share->is_protected, + 'user' => $share->user->settings->name, 'name' => $item->name, - 'size' => $shared->type === 'folder' + 'size' => $share->type === 'folder' ? $item->items : $item->filesize, 'thumbnail' => $item->thumbnail ?? null, diff --git a/src/Domain/Sharing/Models/Share.php b/src/Domain/Sharing/Models/Share.php index 8ed21b1c..fcdf3a83 100644 --- a/src/Domain/Sharing/Models/Share.php +++ b/src/Domain/Sharing/Models/Share.php @@ -43,12 +43,9 @@ class Share extends Model return ShareFactory::new(); } - /** - * Generate share link - */ public function getLinkAttribute(): string { - return url('/share', ['token' => $this->attributes['token']]); + return url("/share/{$this->token}"); } public function user(): HasOne diff --git a/src/Support/helpers.php b/src/Support/helpers.php index fd15d53c..86f5161d 100644 --- a/src/Support/helpers.php +++ b/src/Support/helpers.php @@ -3,6 +3,8 @@ use Carbon\Carbon; use ByteUnits\Metric; use App\Users\Models\User; +use Domain\Files\Models\File; +use Domain\Folders\Models\Folder; use Illuminate\Support\Str; use Domain\Sharing\Models\Share; use Illuminate\Support\Collection; @@ -249,14 +251,14 @@ if (! function_exists('is_demo_account')) { if (! function_exists('get_item')) { /** * Get folder or file item - * - * @param $type - * @param $id - * @return \Illuminate\Database\Eloquent\Builder|Model */ - function get_item($type, $id) + function get_item(string $type, string $id): Folder|File { - $namespace = match ($type) { + $model = $type === 'Folder' + ? 'folder' + : 'file'; + + $namespace = match ($model) { 'folder' => 'Domain\\Folders\\Models\\Folder', 'file' => 'Domain\\Files\\Models\\File', };