From 923ef67f3ee3eddc0ca046132c7cfd044616469b Mon Sep 17 00:00:00 2001 From: Andrew Schmelyun Date: Sun, 16 Apr 2023 02:58:18 -0400 Subject: [PATCH] Fixes #13, shows max upload filesize, block uploads larger than set size --- src/.env.example | 2 +- src/resources/js/components/FileDrop.vue | 20 ++++++++++++++++++++ src/resources/views/app.blade.php | 8 +++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/.env.example b/src/.env.example index 4474523..7d17f88 100644 --- a/src/.env.example +++ b/src/.env.example @@ -3,7 +3,7 @@ APP_ENV=local APP_KEY= APP_DEBUG=true APP_URL=http://localhost -APP_VERSION=1.0.6 +APP_VERSION=1.0.7 LOG_CHANNEL=stack LOG_DEPRECATIONS_CHANNEL=null diff --git a/src/resources/js/components/FileDrop.vue b/src/resources/js/components/FileDrop.vue index 3ff1506..7f5cba3 100644 --- a/src/resources/js/components/FileDrop.vue +++ b/src/resources/js/components/FileDrop.vue @@ -74,7 +74,21 @@ const buttonStyles = reactive({ 'active': 'mt-4 bg-purple-500 border border-purple-500 text-white font-medium py-1.5 px-4 rounded mx-2' }) +const checkFilesize = (size) => { + let sizes = ['B', 'K', 'M', 'G'] + let maxSize = parseInt(window.maxFilesize.substring(0, window.maxFilesize.length - 1)) + + maxSize = maxSize * Math.pow(1024, sizes.indexOf(window.maxFilesize.slice(-1))) + + return size < maxSize +} + const onChange = () => { + if (!checkFilesize(file.value.files[0].size)) { + alert(`The file you selected is too large. Please select a file smaller than ${window.maxFilesize}.`) + return + } + video.value = file.value.files[0] } @@ -94,6 +108,12 @@ const drop = (e) => { e.preventDefault() e.stopPropagation() classes.value = 'w-full py-24 border-2 border-dashed mt-12' + + if (!checkFilesize(e.dataTransfer.files[0].size)) { + alert(`The file you selected is too large. Please select a file smaller than ${window.maxFilesize}.`) + return + } + video.value = e.dataTransfer.files[0] } diff --git a/src/resources/views/app.blade.php b/src/resources/views/app.blade.php index 010f648..a9d5623 100644 --- a/src/resources/views/app.blade.php +++ b/src/resources/views/app.blade.php @@ -4,6 +4,9 @@ Sub⊻ert @vite(['resources/css/app.css', 'resources/js/app.js']) +
@@ -14,6 +17,9 @@
@yield('content') \ No newline at end of file