mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-05 18:23:48 +00:00
- direct download link
This commit is contained in:
@@ -32,10 +32,10 @@ REDIS_HOST=127.0.0.1
|
||||
REDIS_PASSWORD=null
|
||||
REDIS_PORT=6379
|
||||
|
||||
MAIL_DRIVER=
|
||||
MAIL_DRIVER=log
|
||||
MAIL_HOST=
|
||||
MAIL_PORT=
|
||||
MAIL_USERNAME=
|
||||
MAIL_USERNAME=example@domain.com
|
||||
MAIL_PASSWORD=
|
||||
MAIL_ENCRYPTION=
|
||||
MAIL_FROM_ADDRESS="${MAIL_USERNAME}"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
APP_NAME=Laravel
|
||||
APP_ENV=local
|
||||
APP_KEY=base64:yMMyV3sJ87ArJwlbTKlr9O2JBr/eB4w3AEKj3Z1SoPM=
|
||||
APP_KEY=base64:IOcs+sRmD3FGF8qveF6VTgxB26b0ShnwmqIZp/fYNGo=
|
||||
APP_DEBUG=true
|
||||
APP_URL=http://localhost
|
||||
APP_DEMO=false
|
||||
|
||||
@@ -927,5 +927,7 @@ return [
|
||||
'password_doesnt_match' => 'The provided password does not match your current password.',
|
||||
'amount' => 'Amount',
|
||||
'upload_request_default_folder' => 'Upload Request from :timestamp',
|
||||
'copy_direct_download_link' => 'Copy Direct Download Link',
|
||||
'direct_link_copied' => 'Your direct download link was copied',
|
||||
],
|
||||
];
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"/chunks/environment-setup.js": "/chunks/environment-setup.js?id=e1ad83583367917a",
|
||||
"/chunks/app-setup.js": "/chunks/app-setup.js?id=288594cd7f628cf8",
|
||||
"/chunks/admin-account.js": "/chunks/admin-account.js?id=916450217130f3b8",
|
||||
"/chunks/shared.js": "/chunks/shared.js?id=96268e9b7e8e8a19",
|
||||
"/chunks/shared.js": "/chunks/shared.js?id=4b3807fb6a40bdee",
|
||||
"/chunks/shared/browser.js": "/chunks/shared/browser.js?id=3dc8fdb008b6ff5f",
|
||||
"/chunks/shared/single-file.js": "/chunks/shared/single-file.js?id=9ccb8bb19b95a23f",
|
||||
"/chunks/shared/authenticate.js": "/chunks/shared/authenticate.js?id=672e931a9fb0b672",
|
||||
@@ -53,7 +53,7 @@
|
||||
"/chunks/contact-us.js": "/chunks/contact-us.js?id=2e0b16655d2d85d7",
|
||||
"/chunks/successfully-email-verified.js": "/chunks/successfully-email-verified.js?id=25b805ade5230382",
|
||||
"/chunks/successfully-email-send.js": "/chunks/successfully-email-send.js?id=f4562229776d9f56",
|
||||
"/chunks/sign-in.js": "/chunks/sign-in.js?id=0ca5a083976c88ae",
|
||||
"/chunks/sign-in.js": "/chunks/sign-in.js?id=0d48d229038a3a1e",
|
||||
"/chunks/sign-up.js": "/chunks/sign-up.js?id=bb92bad614e60d45",
|
||||
"/chunks/forgotten-password.js": "/chunks/forgotten-password.js?id=50a1bc5e4ed86ec9",
|
||||
"/chunks/create-new-password.js": "/chunks/create-new-password.js?id=f652de052dba55c1",
|
||||
@@ -62,7 +62,7 @@
|
||||
"/chunks/settings-password.js": "/chunks/settings-password.js?id=11d4331650cac280",
|
||||
"/chunks/settings-storage.js": "/chunks/settings-storage.js?id=994b669a56fd417b",
|
||||
"/chunks/billing.js": "/chunks/billing.js?id=c00460dcfd3403a8",
|
||||
"/chunks/platform.js": "/chunks/platform.js?id=86aefe46c825e07d",
|
||||
"/chunks/platform.js": "/chunks/platform.js?id=412bb89ebf742edb",
|
||||
"/chunks/files.js": "/chunks/files.js?id=060b1a34dfdbe97c",
|
||||
"/chunks/recent-uploads.js": "/chunks/recent-uploads.js?id=0f63bbc02ad8f3e1",
|
||||
"/chunks/my-shared-items.js": "/chunks/my-shared-items.js?id=0a06d32b4cf8b52c",
|
||||
|
||||
@@ -25,6 +25,18 @@
|
||||
v-if="isOpenedMoreOptions"
|
||||
class="absolute top-12 left-0 right-0 z-10 select-none overflow-y-auto overflow-x-hidden rounded-lg shadow-xl"
|
||||
>
|
||||
<li
|
||||
v-if="item.data.type !== 'folder' && !item.data.relationships.shared.data.attributes.protected"
|
||||
@click="copyDirectLink"
|
||||
class="block flex cursor-pointer items-center bg-white py-2.5 px-5 hover:bg-light-background dark:bg-2x-dark-foreground dark:hover:bg-4x-dark-foreground"
|
||||
>
|
||||
<div class="w-8">
|
||||
<download-icon size="14" />
|
||||
</div>
|
||||
<span class="text-sm font-bold">
|
||||
{{ $t('copy_direct_download_link') }}
|
||||
</span>
|
||||
</li>
|
||||
<li
|
||||
@click="getQrCode"
|
||||
class="block flex cursor-pointer items-center bg-white py-2.5 px-5 hover:bg-light-background dark:bg-2x-dark-foreground dark:hover:bg-4x-dark-foreground"
|
||||
@@ -60,6 +72,12 @@
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<textarea
|
||||
v-model="directLink"
|
||||
ref="directLinkTextarea"
|
||||
class="pointer-events-none absolute right-full opacity-0"
|
||||
></textarea>
|
||||
|
||||
<textarea
|
||||
v-model="iframeCode"
|
||||
ref="iframe"
|
||||
@@ -69,7 +87,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { CameraIcon, CopyIcon, CheckIcon, SendIcon, MoreHorizontalIcon, CodeIcon } from 'vue-feather-icons'
|
||||
import { DownloadIcon, CameraIcon, CopyIcon, CheckIcon, SendIcon, MoreHorizontalIcon, CodeIcon } from 'vue-feather-icons'
|
||||
import { events } from '../../../bus'
|
||||
|
||||
export default {
|
||||
@@ -82,11 +100,13 @@ export default {
|
||||
CopyIcon,
|
||||
CodeIcon,
|
||||
SendIcon,
|
||||
DownloadIcon,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
id: 'link-input-' + Math.floor(Math.random() * 10000000),
|
||||
iframeCode: '',
|
||||
directLink: undefined,
|
||||
iframeCode: undefined,
|
||||
isCopiedLink: false,
|
||||
isOpenedMoreOptions: false,
|
||||
}
|
||||
@@ -113,11 +133,8 @@ export default {
|
||||
|
||||
this.isOpenedMoreOptions = false
|
||||
},
|
||||
copyIframe() {
|
||||
// generate iframe
|
||||
this.iframeCode = `<iframe src="${this.item.data.relationships.shared.link}" width="790" height="400" allowfullscreen frameborder="0"></iframe>`
|
||||
|
||||
let copyText = this.$refs.iframe
|
||||
copyDirectLink() {
|
||||
let copyText = this.$refs.directLinkTextarea
|
||||
|
||||
copyText.select()
|
||||
copyText.setSelectionRange(0, 99999)
|
||||
@@ -126,14 +143,29 @@ export default {
|
||||
|
||||
events.$emit('toaster', {
|
||||
type: 'success',
|
||||
message: this.$t('web_code_copied'),
|
||||
message: this.$t('direct_link_copied'),
|
||||
})
|
||||
|
||||
this.isOpenedMoreOptions = false
|
||||
this.isOpenedMoreOptions = false
|
||||
},
|
||||
copyIframe() {
|
||||
let copyText = this.$refs.iframe
|
||||
|
||||
copyText.select()
|
||||
copyText.setSelectionRange(0, 99999)
|
||||
|
||||
document.execCommand('copy')
|
||||
|
||||
events.$emit('toaster', {
|
||||
type: 'success',
|
||||
message: this.$t('web_code_copied'),
|
||||
})
|
||||
|
||||
this.isOpenedMoreOptions = false
|
||||
},
|
||||
copyUrl() {
|
||||
// Get input value
|
||||
var copyText = document.getElementById(this.id)
|
||||
let copyText = document.getElementById(this.id)
|
||||
|
||||
// select link
|
||||
copyText.select()
|
||||
@@ -151,5 +183,10 @@ export default {
|
||||
}, 1000)
|
||||
},
|
||||
},
|
||||
created() {
|
||||
// Generate copied
|
||||
this.directLink = this.item.data.relationships.shared.data.attributes.link + '/direct'
|
||||
this.iframeCode = `<iframe src="${this.item.data.relationships.shared.data.attributes.link}" width="790" height="400" allowfullscreen frameborder="0"></iframe>`
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -4,6 +4,7 @@ use Domain\Homepage\Controllers\IndexController;
|
||||
use Domain\Invoices\Controllers\GetInvoiceController;
|
||||
use Domain\Settings\Controllers\DownloadLogController;
|
||||
use App\Socialite\Controllers\SocialiteCallbackController;
|
||||
use Domain\Sharing\Controllers\DirectlyDownloadFileController;
|
||||
use Domain\Sharing\Controllers\SharePublicIndexController;
|
||||
use Domain\Sharing\Controllers\WebCrawlerOpenGraphController;
|
||||
use Domain\Localization\Controllers\CurrentLocalizationController;
|
||||
@@ -22,8 +23,10 @@ Route::get('/admin/log/{log}', DownloadLogController::class)
|
||||
|
||||
// Get og site for web crawlers
|
||||
if (Crawler::isCrawler()) {
|
||||
Route::get('/share/{share}/direct', WebCrawlerOpenGraphController::class);
|
||||
Route::get('/share/{share}', WebCrawlerOpenGraphController::class);
|
||||
} else {
|
||||
Route::get('/share/{share}/direct', DirectlyDownloadFileController::class);
|
||||
Route::get('/share/{share}', SharePublicIndexController::class);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Domain\Sharing\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Domain\Files\Actions\DownloadFileAction;
|
||||
use Domain\Files\Models\File;
|
||||
use Domain\Sharing\Actions\ProtectShareRecordAction;
|
||||
use Domain\Sharing\Actions\VerifyAccessToItemWithinAction;
|
||||
use Domain\Sharing\Models\Share;
|
||||
use Domain\Traffic\Actions\RecordDownloadAction;
|
||||
use Illuminate\Http\Response;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
|
||||
class DirectlyDownloadFileController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private DownloadFileAction $downloadFile,
|
||||
private RecordDownloadAction $recordDownload,
|
||||
private ProtectShareRecordAction $protectShareRecord,
|
||||
private VerifyAccessToItemWithinAction $verifyAccessToItemWithin,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(
|
||||
Share $share
|
||||
): BinaryFileResponse|Response {
|
||||
|
||||
// Check if item is not a folder
|
||||
if ($share->type !== 'file') {
|
||||
return response('This content is not downloadable');
|
||||
}
|
||||
|
||||
// Check ability to access protected share files
|
||||
($this->protectShareRecord)($share);
|
||||
|
||||
// Check if user can download file
|
||||
if (! $share->user->canDownload()) {
|
||||
return response([
|
||||
'type' => 'error',
|
||||
'message' => 'This user action is not allowed.',
|
||||
], 401);
|
||||
}
|
||||
|
||||
// Get file record
|
||||
$file = File::where('user_id', $share->user_id)
|
||||
->where('id', $share->item_id)
|
||||
->firstOrFail();
|
||||
|
||||
// Check file access
|
||||
($this->verifyAccessToItemWithin)($share, $file);
|
||||
|
||||
// Store user download size
|
||||
($this->recordDownload)(
|
||||
file_size: (int) $file->getRawOriginal('filesize'),
|
||||
user_id: $share->user_id,
|
||||
);
|
||||
|
||||
// Finally, download file
|
||||
return ($this->downloadFile)($file, $share->user_id);
|
||||
}
|
||||
}
|
||||
@@ -686,7 +686,7 @@ if (! function_exists('mapTrafficRecords')) {
|
||||
|
||||
$record->upload = 0;
|
||||
$record->download = 0;
|
||||
$record->created_at = $day;
|
||||
$record->date = $day;
|
||||
|
||||
$records->add($record);
|
||||
}
|
||||
|
||||
@@ -61,6 +61,57 @@ class VisitorAccessToItemsTest extends TestCase
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_directly_download_file()
|
||||
{
|
||||
$user = User::factory()
|
||||
->create();
|
||||
|
||||
$document = UploadedFile::fake()
|
||||
->create(Str::random() . '-fake-file.pdf', 1000, 'application/pdf');
|
||||
|
||||
Storage::putFileAs("files/$user->id", $document, $document->name);
|
||||
|
||||
$file = File::factory()
|
||||
->create([
|
||||
'filesize' => $document->getSize(),
|
||||
'user_id' => $user->id,
|
||||
'basename' => $document->name,
|
||||
'name' => $document->name,
|
||||
]);
|
||||
|
||||
$share = Share::factory()
|
||||
->create([
|
||||
'item_id' => $file->id,
|
||||
'user_id' => $user->id,
|
||||
'type' => 'file',
|
||||
'is_protected' => false,
|
||||
]);
|
||||
|
||||
// Get shared file
|
||||
$this->get("/share/$share->token/direct")
|
||||
->assertStatus(200)
|
||||
->assertDownload($document->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_try_directly_download_protected_file()
|
||||
{
|
||||
$share = Share::factory()
|
||||
->create([
|
||||
'type' => 'file',
|
||||
'is_protected' => true,
|
||||
]);
|
||||
|
||||
// Get shared file
|
||||
$this->get("/share/$share->token/direct")
|
||||
->assertStatus(403);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user