Skip to content

Commit

Permalink
feat: Download Slip
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisToxz committed Aug 8, 2023
1 parent 3c09de2 commit 8cf7be6
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 6 deletions.
16 changes: 16 additions & 0 deletions app/Http/Controllers/SlipDownloadController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Http\Controllers;

use App\Models\Slip;
use Storage;


class SlipDownloadController extends Controller
{
public function __invoke(Slip $slip)
{

return Storage::disk('slips')->download($slip->mediable->localPath);
}
}
39 changes: 36 additions & 3 deletions resources/js/Components/Dashboard/VideoCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Download from '~icons/ion/download'
import Trash from '~icons/mdi/trash'
import PrimaryButton from '@/Components/UI/PrimaryButton.vue'
import WarningButton from '@/Components/UI/WarningButton.vue'
import Loading from '@/Components/UI/Loading.vue'
const hoverEffect = ref(false)
const hover = ref(false)
Expand Down Expand Up @@ -55,6 +56,35 @@ const deleteJob = () => {
router.delete(route('job.destroy', props.slip))
}
const downloading = ref(false)
const download = () => {
downloading.value = true
status.value = 'Downloading'
axios({
url: 'http://localhost/download/' + props.slip.token,
method: 'GET',
responseType: 'blob',
onDownloadProgress: (progress) => {
percentage.value = (progress.progress * 100).toFixed(0)
console.log(percentage.value)
},
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]))
console.log(response)
const link = document.createElement('a')
link.href = url
alert(props.slip.title)
link.setAttribute('download', '.mp5')
alert(link)
document.body.appendChild(link)
link.click()
link.remove()
downloading.value = false
status.value = null
percentage.value = 0
})
}
</script>

<template>
Expand Down Expand Up @@ -104,8 +134,11 @@ const deleteJob = () => {
<li v-tooltip="'Edit'" class="rounded-full w-10 h-10 flex items-center justify-center self-center cursor-pointer transition-all hover:bg-brand-primary-500 mr-2" @click="showEditSlip = true">
<Settings color="white" width="25" height="25" />
</li>
<li v-tooltip="'Download'" class="px-1 rounded-full w-10 h-10 flex items-center justify-center self-center cursor-pointer transition-all hover:bg-brand-primary-500 mr-2">
<Download color="white" width="25" height="25" />
<li v-if="!downloading" v-tooltip="'Download'" class="rounded-full w-10 h-10 flex items-center justify-center self-center cursor-pointer transition-all hover:bg-brand-primary-500 mr-2" @click="download()">
<Download width="25" height="25" />
</li>
<li v-else class="rounded-full w-10 h-10 flex items-center justify-center self-center cursor-pointer mr-2 animate-pulse">
<Loading />
</li>
<li v-tooltip="'Delete'" class="px-1 rounded-full w-10 h-10 flex items-center justify-center self-center cursor-pointer transition-all hover:bg-brand-primary-500" @click="showDeleteDialog = true">
<Trash color="white" width="25" height="25" />
Expand All @@ -114,7 +147,7 @@ const deleteJob = () => {
</div>
</div>
</div>
<div v-if="slip.status !== 'finished'" class="z-2 absolute w-full h-full bg-[rgba(0,0,0,0.6)]">
<div v-if="slip.status !== 'finished' || downloading" class="z-2 absolute w-full h-full bg-[rgba(0,0,0,0.6)]">
<div v-if="slip.status !== 'failed'" class="flex flex-col justify-between items-center h-full">
<ProgressBar :percentage="percentage" />
<div>
Expand Down
2 changes: 1 addition & 1 deletion resources/js/Components/UI/Loading.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<svg aria-hidden="true" class="w-8 h-8 mr-2 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg">
<svg aria-hidden="true" class="w-8 h-8 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor" />
<path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill" />
</svg>
Expand Down
5 changes: 3 additions & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use App\Http\Controllers\JobController;
use App\Http\Controllers\SettingsController;
use App\Http\Controllers\SlipController;
use App\Http\Controllers\SlipDownloadController;
use Illuminate\Support\Facades\Route;

/*
Expand All @@ -22,8 +23,8 @@
Route::middleware('auth')->group(function () {
Route::get('/dashboard', [SlipController::class, 'index'])->name('dashboard');
Route::get('/v/{slip}', [SlipController::class, 'show'])->name('slip');


Route::get('/download/{slip}', SlipDownloadController::class);
Route::post('/slips/tempupload', [SlipController::class, 'tempUpload'])->name('slips.tempupload');
Route::resource('slips', SlipController::class);

Expand Down

0 comments on commit 8cf7be6

Please sign in to comment.