This commit is contained in:
Peter Papp
2021-07-22 17:26:22 +02:00
parent 093c9451ec
commit fffede1c10
12 changed files with 53 additions and 44 deletions

View File

@@ -8,7 +8,7 @@
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
> >
<projectFiles> <projectFiles>
<directory name="app"/> <directory name="src"/>
<ignoreFiles> <ignoreFiles>
<directory name="vendor"/> <directory name="vendor"/>
</ignoreFiles> </ignoreFiles>

View File

@@ -55,7 +55,7 @@
"/chunks/plan-settings.js": "/chunks/plan-settings.js?id=dbc08f8cdc23900ef40a", "/chunks/plan-settings.js": "/chunks/plan-settings.js?id=dbc08f8cdc23900ef40a",
"/chunks/plan-subscribers.js": "/chunks/plan-subscribers.js?id=8c4b655b9286e06894c5", "/chunks/plan-subscribers.js": "/chunks/plan-subscribers.js?id=8c4b655b9286e06894c5",
"/chunks/plans.js": "/chunks/plans.js?id=2b26173a02ed9f86e875", "/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/platform~chunks/shared.js": "/chunks/platform~chunks/shared.js?id=be3d7cf51585313cf53b",
"/chunks/profile.js": "/chunks/profile.js?id=03526296e71df827ff47", "/chunks/profile.js": "/chunks/profile.js?id=03526296e71df827ff47",
"/chunks/profile~chunks/settings-password.js": "/chunks/profile~chunks/settings-password.js?id=fd25990d1ccec0294602", "/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/settings~chunks/settings-password.js": "/chunks/settings~chunks/settings-password.js?id=1c49c2c5bcef4395dedb",
"/chunks/setup-wizard.js": "/chunks/setup-wizard.js?id=41d3478184ec24644a1c", "/chunks/setup-wizard.js": "/chunks/setup-wizard.js?id=41d3478184ec24644a1c",
"/chunks/shared.js": "/chunks/shared.js?id=7524b7a783d4aed23794", "/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/file-browser.js": "/chunks/shared/file-browser.js?id=0f6c34512740fca7e007",
"/chunks/shared/single-file.js": "/chunks/shared/single-file.js?id=7886247bb35deada28a2", "/chunks/shared/single-file.js": "/chunks/shared/single-file.js?id=7886247bb35deada28a2",
"/chunks/sign-in.js": "/chunks/sign-in.js?id=0709543b76769c50a873", "/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.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.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/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"
} }

View File

@@ -284,7 +284,7 @@
// Send request to get share link // Send request to get share link
axios axios
.post('/api/share/' + this.shareOptions.id, { .post('/api/share/' + this.shareOptions.token, {
permission: this.shareOptions.permission, permission: this.shareOptions.permission,
protected: this.shareOptions.isProtected, protected: this.shareOptions.isProtected,
expiration: this.shareOptions.expiration, expiration: this.shareOptions.expiration,

View File

@@ -68,7 +68,7 @@ const Helpers = {
Vue.prototype.$updateText = debounce(function (route, name, value, allowEmpty = false) { 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'}) axios.post(this.$store.getters.api + route, {name, value, _method: 'patch'})
.catch(() => { .catch(() => {

View File

@@ -42,7 +42,7 @@
}, },
data() { data() {
return { return {
password: 'secret', password: '',
isLoading: false, isLoading: false,
} }
}, },

View File

@@ -38,7 +38,7 @@ Route::group(['prefix' => 'browse'], function () {
Route::get('/navigation/{shared}', VisitorNavigationFolderTreeController::class); Route::get('/navigation/{shared}', VisitorNavigationFolderTreeController::class);
Route::get('/search/{shared}', VisitorSearchFilesAndFoldersController::class); Route::get('/search/{shared}', VisitorSearchFilesAndFoldersController::class);
Route::get('/file/{shared}', VisitorShowFileController::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);

View File

@@ -16,9 +16,9 @@ Route::get('/translations/{lang}', CurrentLocalizationController::class);
// Get og site for web crawlers // Get og site for web crawlers
if (Crawler::isCrawler()) { if (Crawler::isCrawler()) {
Route::get('/share/{shared}', WebCrawlerOpenGraphController::class); Route::get('/share/{share}', WebCrawlerOpenGraphController::class);
} else { } else {
Route::get('/share/{shared}', SharePublicIndexController::class); Route::get('/share/{share}', SharePublicIndexController::class);
} }
// Index // Index

View File

@@ -1,7 +1,6 @@
<?php <?php
namespace Domain\Sharing\Controllers; namespace Domain\Sharing\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response; use Illuminate\Http\Response;
use Domain\Zip\Models\Zip; use Domain\Zip\Models\Zip;
use Domain\Sharing\Models\Share; use Domain\Sharing\Models\Share;
@@ -18,9 +17,9 @@ class ShareController extends Controller
* Get shared record * Get shared record
*/ */
public function show( public function show(
Share $shared, Share $share,
): ShareResource { ): ShareResource {
return new ShareResource($shared); return new ShareResource($share);
} }
/** /**
@@ -57,20 +56,21 @@ class ShareController extends Controller
*/ */
public function update( public function update(
UpdateShareRequest $request, UpdateShareRequest $request,
Share $shared, Share $share,
): ShareResource { ): ShareResource {
// Update sharing record // Update sharing record
$shared->update([ $share->update([
'permission' => $request->input('permission'), 'permission' => $request->input('permission'),
'is_protected' => $request->input('protected'), 'is_protected' => $request->input('protected'),
'expire_in' => $request->input('expiration'), 'expire_in' => $request->input('expiration'),
'password' => $request->input('password') 'password' => $request->input('password')
? bcrypt($request->input('password')) ? bcrypt($request->input('password'))
: $shared->password, : $share->password,
]); ]);
// Return shared record // Return shared record
return new ShareResource($shared); return new ShareResource($share);
} }
/** /**

View File

@@ -20,18 +20,18 @@ class SharePublicIndexController extends Controller
} }
public function __invoke( public function __invoke(
Share $shared, Share $share,
): View | StreamedResponse { ): View | StreamedResponse {
// Delete share_session if exist // Delete share_session if exist
if ($shared->is_protected) { if ($share->is_protected) {
cookie()->queue('share_session', '', -1); cookie()->queue('share_session', '', -1);
} }
// Check if shared is image file and then show it // Check if shared is image file and then show it
if ($shared->type === 'file' && ! $shared->is_protected) { if ($share->type === 'file' && ! $share->is_protected) {
$image = File::whereUserId($shared->user_id) $image = File::whereUserId($share->user_id)
->whereType('image') ->whereType('image')
->whereId($shared->item_id) ->whereId($share->item_id)
->first(); ->first();
if ($image) { if ($image) {
@@ -39,9 +39,9 @@ class SharePublicIndexController extends Controller
$fileSize = (int) $image->getRawOriginal('filesize'); $fileSize = (int) $image->getRawOriginal('filesize');
// Store user download size // 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);
} }
} }

View File

@@ -11,30 +11,30 @@ class WebCrawlerOpenGraphController extends Controller
* Get og site for web crawlers * Get og site for web crawlers
*/ */
public function __invoke( public function __invoke(
Share $shared Share $share
): View { ): View {
$namespace = match ($shared->type) { $namespace = match ($share->type) {
'folder' => 'Domain\\Folders\\Models\\Folder', 'folder' => 'Domain\\Folders\\Models\\Folder',
'file' => 'Domain\\Files\\Models\\File', 'file' => 'Domain\\Files\\Models\\File',
}; };
// Get file/folder record // Get file/folder record
$item = ($namespace)::where('user_id', $shared->user->id) $item = ($namespace)::where('user_id', $share->user->id)
->where('id', $shared->item_id) ->where('id', $share->item_id)
->first(); ->first();
if ($item->thumbnail) { if ($item->thumbnail) {
$item->setPublicUrl($shared->token); $item->setPublicUrl($share->token);
} }
return view('vuefilemanager.crawler.og-view') return view('vuefilemanager.crawler.og-view')
->with('settings', get_settings_in_json()) ->with('settings', get_settings_in_json())
->with('metadata', [ ->with('metadata', [
'url' => url('/share', ['token' => $shared->token]), 'url' => url('/share', ['token' => $share->token]),
'is_protected' => $shared->is_protected, 'is_protected' => $share->is_protected,
'user' => $shared->user->settings->name, 'user' => $share->user->settings->name,
'name' => $item->name, 'name' => $item->name,
'size' => $shared->type === 'folder' 'size' => $share->type === 'folder'
? $item->items ? $item->items
: $item->filesize, : $item->filesize,
'thumbnail' => $item->thumbnail ?? null, 'thumbnail' => $item->thumbnail ?? null,

View File

@@ -43,12 +43,9 @@ class Share extends Model
return ShareFactory::new(); return ShareFactory::new();
} }
/**
* Generate share link
*/
public function getLinkAttribute(): string public function getLinkAttribute(): string
{ {
return url('/share', ['token' => $this->attributes['token']]); return url("/share/{$this->token}");
} }
public function user(): HasOne public function user(): HasOne

View File

@@ -3,6 +3,8 @@
use Carbon\Carbon; use Carbon\Carbon;
use ByteUnits\Metric; use ByteUnits\Metric;
use App\Users\Models\User; use App\Users\Models\User;
use Domain\Files\Models\File;
use Domain\Folders\Models\Folder;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Domain\Sharing\Models\Share; use Domain\Sharing\Models\Share;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
@@ -249,14 +251,14 @@ if (! function_exists('is_demo_account')) {
if (! function_exists('get_item')) { if (! function_exists('get_item')) {
/** /**
* Get folder or file 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', 'folder' => 'Domain\\Folders\\Models\\Folder',
'file' => 'Domain\\Files\\Models\\File', 'file' => 'Domain\\Files\\Models\\File',
}; };