-
-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add private download feature #359
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
use Oneduo\NovaFileManager\Events\FileUnzipped; | ||
use Oneduo\NovaFileManager\Events\FileUnzipping; | ||
use Oneduo\NovaFileManager\Http\Requests\DeleteFileRequest; | ||
use Oneduo\NovaFileManager\Http\Requests\DownloadFileRequest; | ||
use Oneduo\NovaFileManager\Http\Requests\RenameFileRequest; | ||
use Oneduo\NovaFileManager\Http\Requests\UnzipFileRequest; | ||
use Oneduo\NovaFileManager\Http\Requests\UploadFileRequest; | ||
|
@@ -117,4 +118,19 @@ public function unzip(UnzipFileRequest $request): JsonResponse | |
'message' => __('nova-file-manager::messages.file.unzip'), | ||
]); | ||
} | ||
|
||
/** | ||
* Download a file | ||
* | ||
* @param \Oneduo\NovaFileManager\Http\Requests\DownloadFileRequest $request | ||
* @return \Illuminate\Http\JsonResponse | ||
*/ | ||
public function download(DownloadFileRequest $request) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a type hit for the return of this function |
||
{ | ||
$manager = $request->manager(); | ||
|
||
$file = $request->path; | ||
|
||
return $manager->filesystem->download($file); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,11 +157,18 @@ public function canUnzipArchive(): bool | |
return $this->element()?->resolveCanUnzipFile($this) ?? true; | ||
} | ||
|
||
public function canDownloadFile(): bool | ||
{ | ||
return $this->element()?->resolveCanDownloadFile($this) ?? true; | ||
} | ||
|
||
protected function failedAuthorization(): void | ||
{ | ||
throw ValidationException::withMessages([ | ||
$this->authorizationAttribute() => __('nova-file-manager::errors.authorization.unauthorized', | ||
['action' => $this->authorizationActionAttribute()]), | ||
$this->authorizationAttribute() => __( | ||
'nova-file-manager::errors.authorization.unauthorized', | ||
['action' => $this->authorizationActionAttribute()] | ||
), | ||
Comment on lines
-163
to
+171
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unnecessary code style change, please keep PR feature-only |
||
]); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Oneduo\NovaFileManager\Http\Requests; | ||
|
||
use Oneduo\NovaFileManager\Rules\DiskExistsRule; | ||
use Oneduo\NovaFileManager\Rules\ExistsInFilesystem; | ||
|
||
/** | ||
* @property-read string $path | ||
*/ | ||
class DownloadFileRequest extends BaseRequest | ||
{ | ||
public function authorize(): bool | ||
{ | ||
return $this->canDownloadFile(); | ||
} | ||
|
||
public function rules(): array | ||
{ | ||
return [ | ||
'path' => ['required', 'string', new ExistsInFilesystem($this)], | ||
]; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move these to an attribute, e.g
file.downloadUrl
should allow for a better centralization of data and easier refactoring/customization