should fix our issues?

This commit is contained in:
notCharles 2025-11-08 16:41:39 -05:00
parent 339efc754d
commit 227521b7bb
2 changed files with 364 additions and 305 deletions

View File

@ -78,7 +78,10 @@
try { try {
const uploadSizeLimit = await $wire.getUploadSizeLimit(); const uploadSizeLimit = await $wire.getUploadSizeLimit();
for (const { file } of filesWithPaths) { for (const {
file
}
of filesWithPaths) {
if (file.size > uploadSizeLimit) { if (file.size > uploadSizeLimit) {
new window.FilamentNotification() new window.FilamentNotification()
.title(`File ${file.name} exceeds the upload size limit of ${this.formatBytes(uploadSizeLimit)}`) .title(`File ${file.name} exceeds the upload size limit of ${this.formatBytes(uploadSizeLimit)}`)
@ -90,7 +93,10 @@
} }
const folderPaths = new Set(); const folderPaths = new Set();
for (const { path } of filesWithPaths) { for (const {
path
}
of filesWithPaths) {
if (path) { if (path) {
const parts = path.split('/').filter(Boolean); const parts = path.split('/').filter(Boolean);
let currentPath = ''; let currentPath = '';
@ -129,12 +135,17 @@
for (let i = 0; i < this.uploadQueue.length; i++) { for (let i = 0; i < this.uploadQueue.length; i++) {
const uploadPromise = this.uploadFile(i) const uploadPromise = this.uploadFile(i)
.then(() => { completedCount++; this.currentFileIndex = completedCount; .then(() => {
completedCount++;
this.currentFileIndex = completedCount;
const item = this.uploadQueue[i]; const item = this.uploadQueue[i];
const relativePath = (item.path ? item.path.replace(/^\/+/, '') + '/' : '') + item.name; const relativePath = (item.path ? item.path.replace(/^\/+/, '') + '/' : '') + item.name;
uploadedFiles.push(relativePath); uploadedFiles.push(relativePath);
}) })
.catch(() => { completedCount++; this.currentFileIndex = completedCount; }); .catch(() => {
completedCount++;
this.currentFileIndex = completedCount;
});
activeUploads.push(uploadPromise); activeUploads.push(uploadPromise);
@ -150,19 +161,32 @@
await $wire.$refresh(); await $wire.$refresh();
if (failed.length === 0) { if (failed.length === 0) {
new window.FilamentNotification().title('{{ trans('server/file.actions.upload.success') }}').success().send(); new window.FilamentNotification()
.title('{{ trans('server/file.actions.upload.success') }}')
.success()
.send();
} else if (failed.length === this.totalFiles) { } else if (failed.length === this.totalFiles) {
new window.FilamentNotification().title('{{ trans('server/file.actions.upload.error_all') }}').danger().send(); new window.FilamentNotification()
.title('{{ trans('server/file.actions.upload.failed') }}')
.danger()
.send();
} else { } else {
new window.FilamentNotification().title('{{ trans('server/file.actions.upload.error_partial') }}').warning().send(); new window.FilamentNotification()
.title('{{ trans('server/file.actions.upload.failed') }}')
.danger()
.send();
} }
if (uploadedFiles.length > 0) { if (uploadedFiles.length > 0) {
this.$nextTick(() => { this.$nextTick(() => {
try { if (typeof $wire !== 'undefined' && $wire && typeof $wire.call === 'function') {
@this.call('logUploadedFiles', uploadedFiles);
} catch (e) {
$wire.call('logUploadedFiles', uploadedFiles); $wire.call('logUploadedFiles', uploadedFiles);
} else if (typeof window.livewire !== 'undefined' && typeof window.livewire.call === 'function') {
window.livewire.call('logUploadedFiles', uploadedFiles);
} else if (typeof Livewire !== 'undefined' && typeof Livewire.call === 'function') {
Livewire.call('logUploadedFiles', uploadedFiles);
} else {
console.warn('Could not call Livewire method logUploadedFiles; Livewire not found.');
} }
}); });
} }
@ -171,10 +195,13 @@
this.autoCloseTimer = setTimeout(() => { this.autoCloseTimer = setTimeout(() => {
this.isUploading = false; this.isUploading = false;
this.uploadQueue = []; this.uploadQueue = [];
},1000); }, 1000);
} catch (error) { } catch (error) {
console.error('Upload error:', error); console.error('Upload error:', error);
new window.FilamentNotification().title('{{ trans('server/file.actions.upload.error') }}').danger().send(); new window.FilamentNotification()
.title('{{ trans('server/file.actions.upload.error') }}')
.danger()
.send();
this.isUploading = false; this.isUploading = false;
} }
}, },
@ -264,16 +291,18 @@
async handleFileSelect(e) { async handleFileSelect(e) {
const files = Array.from(e.target.files); const files = Array.from(e.target.files);
if (files.length > 0) { if (files.length > 0) {
const filesWithPaths = files.map(f => ({ file: f, path: '' })); const filesWithPaths = files.map(f => ({
file: f,
path: ''
}));
await this.uploadFilesWithFolders(filesWithPaths); await this.uploadFilesWithFolders(filesWithPaths);
} }
}, },
triggerBrowse() { triggerBrowse() {
this.$refs.fileInput.click(); this.$refs.fileInput.click();
}, },
}" }"
class="relative" class="relative">
>
<div class="p-4"> <div class="p-4">
<input type="file" x-ref="fileInput" class="hidden" multiple @change="handleFileSelect"> <input type="file" x-ref="fileInput" class="hidden" multiple @change="handleFileSelect">

View File

@ -44,7 +44,10 @@
} }
if (files && files.length > 0 && filesWithPaths.length === 0) { if (files && files.length > 0 && filesWithPaths.length === 0) {
filesWithPaths = Array.from(files).map(f => ({ file: f, path: '' })); filesWithPaths = Array.from(files).map(f => ({
file: f,
path: ''
}));
} }
if (filesWithPaths.length > 0) { if (filesWithPaths.length > 0) {
@ -124,7 +127,10 @@
try { try {
const uploadSizeLimit = await $wire.getUploadSizeLimit(); const uploadSizeLimit = await $wire.getUploadSizeLimit();
for (const { file } of filesWithPaths) { for (const {
file
}
of filesWithPaths) {
if (file.size > uploadSizeLimit) { if (file.size > uploadSizeLimit) {
new window.FilamentNotification() new window.FilamentNotification()
.title(`File ${file.name} exceeds the upload limit.`) .title(`File ${file.name} exceeds the upload limit.`)
@ -136,7 +142,10 @@
} }
const folderPaths = new Set(); const folderPaths = new Set();
for (const { path } of filesWithPaths) { for (const {
path
}
of filesWithPaths) {
if (path) { if (path) {
const parts = path.split('/').filter(Boolean); const parts = path.split('/').filter(Boolean);
let currentPath = ''; let currentPath = '';
@ -175,12 +184,17 @@
for (let i = 0; i < this.uploadQueue.length; i++) { for (let i = 0; i < this.uploadQueue.length; i++) {
const uploadPromise = this.uploadFile(i) const uploadPromise = this.uploadFile(i)
.then(() => { completedCount++; this.currentFileIndex = completedCount; .then(() => {
completedCount++;
this.currentFileIndex = completedCount;
const item = this.uploadQueue[i]; const item = this.uploadQueue[i];
const relativePath = (item.path ? item.path.replace(/^\/+/, '') + '/' : '') + item.name; const relativePath = (item.path ? item.path.replace(/^\/+/, '') + '/' : '') + item.name;
uploadedFiles.push(relativePath); uploadedFiles.push(relativePath);
}) })
.catch(() => { completedCount++; this.currentFileIndex = completedCount; }); .catch(() => {
completedCount++;
this.currentFileIndex = completedCount;
});
activeUploads.push(uploadPromise); activeUploads.push(uploadPromise);
@ -196,19 +210,32 @@
await $wire.$refresh(); await $wire.$refresh();
if (failed.length === 0) { if (failed.length === 0) {
new window.FilamentNotification().title('{{ trans('server/file.actions.upload.success') }}').success().send(); new window.FilamentNotification()
.title('{{ trans('server/file.actions.upload.success') }}')
.success()
.send();
} else if (failed.length === this.totalFiles) { } else if (failed.length === this.totalFiles) {
new window.FilamentNotification().title('{{ trans('server/file.actions.upload.failed') }}').danger().send(); new window.FilamentNotification()
.title('{{ trans('server/file.actions.upload.failed') }}')
.danger()
.send();
} else { } else {
new window.FilamentNotification().title('{{ trans('server/file.actions.upload.failed') }}').danger().send(); new window.FilamentNotification()
.title('{{ trans('server/file.actions.upload.failed') }}')
.danger()
.send();
} }
if (uploadedFiles.length > 0) { if (uploadedFiles.length > 0) {
this.$nextTick(() => { this.$nextTick(() => {
try { if (typeof $wire !== 'undefined' && $wire && typeof $wire.call === 'function') {
@this.call('logUploadedFiles', uploadedFiles);
} catch (e) {
$wire.call('logUploadedFiles', uploadedFiles); $wire.call('logUploadedFiles', uploadedFiles);
} else if (typeof window.livewire !== 'undefined' && typeof window.livewire.call === 'function') {
window.livewire.call('logUploadedFiles', uploadedFiles);
} else if (typeof Livewire !== 'undefined' && typeof Livewire.call === 'function') {
Livewire.call('logUploadedFiles', uploadedFiles);
} else {
console.warn('Could not call Livewire method logUploadedFiles; Livewire not found.');
} }
}); });
} }
@ -217,10 +244,13 @@
this.autoCloseTimer = setTimeout(() => { this.autoCloseTimer = setTimeout(() => {
this.isUploading = false; this.isUploading = false;
this.uploadQueue = []; this.uploadQueue = [];
},1000); }, 1000);
} catch (error) { } catch (error) {
console.error('Upload error:', error); console.error('Upload error:', error);
new window.FilamentNotification().title('{{ trans('server/file.actions.upload.error') }}').danger().send(); new window.FilamentNotification()
.title('{{ trans('server/file.actions.upload.error') }}')
.danger()
.send();
this.isUploading = false; this.isUploading = false;
} }
}, },