2020-01-30 15:25:10 -05:00
|
|
|
<template>
|
2024-04-07 09:45:26 -04:00
|
|
|
<div class="h-[calc(100vh-140px)]">
|
|
|
|
<nav class="text-sm breadcrumbs px-4">
|
|
|
|
<ul>
|
|
|
|
<li
|
|
|
|
v-for="(crumb, index) in mediaStore.crumbs"
|
|
|
|
:key="index"
|
|
|
|
:active="index === mediaStore.crumbs.length - 1"
|
|
|
|
@click="getPath(crumb.path)"
|
|
|
|
>
|
|
|
|
<a v-if="mediaStore.crumbs.length > 1 && mediaStore.crumbs.length - 1 > index" href="#">
|
|
|
|
<i class="bi-folder me-1" />
|
|
|
|
{{ crumb.text }}
|
|
|
|
</a>
|
|
|
|
<span v-else><i class="bi-folder me-1" /> {{ crumb.text }}</span>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</nav>
|
|
|
|
|
2024-04-07 09:55:08 -04:00
|
|
|
<div class="h-[calc(100%-34px)] bg-base-300">
|
2024-04-07 09:45:26 -04:00
|
|
|
<div
|
|
|
|
v-if="browserIsLoading"
|
|
|
|
class="w-full h-[calc(100%-174px)] absolute z-10 flex justify-center bg-base-100/70"
|
|
|
|
>
|
|
|
|
<span class="loading loading-spinner loading-lg"></span>
|
|
|
|
</div>
|
|
|
|
<splitpanes>
|
|
|
|
<pane min-size="14" max-size="80" size="24" class="h-full px-2">
|
|
|
|
<ul v-if="mediaStore.folderTree.parent" class="overflow-auto h-full m-1">
|
2024-04-06 17:16:13 -04:00
|
|
|
<li
|
2024-04-07 09:45:26 -04:00
|
|
|
class="grid grid-cols-[auto_18px] gap-1"
|
|
|
|
v-for="folder in mediaStore.folderTree.folders"
|
|
|
|
:key="folder.uid"
|
2024-04-06 17:16:13 -04:00
|
|
|
>
|
2024-04-07 09:45:26 -04:00
|
|
|
<button
|
|
|
|
class="truncate text-left"
|
|
|
|
@click="getPath(`/${mediaStore.folderTree.source}/${folder.name}`)"
|
2023-03-27 10:28:13 -04:00
|
|
|
>
|
2024-04-07 09:45:26 -04:00
|
|
|
<i class="bi-folder-fill" />
|
|
|
|
{{ folder.name }}
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
class="opacity-30 hover:opacity-100"
|
|
|
|
@click="
|
|
|
|
;(showDeleteModal = true),
|
|
|
|
(deleteName = `/${mediaStore.folderTree.source}/${folder.name}`.replace(
|
|
|
|
/\/[/]+/g,
|
|
|
|
'/'
|
|
|
|
))
|
|
|
|
"
|
2024-04-06 17:16:13 -04:00
|
|
|
>
|
2024-04-07 09:45:26 -04:00
|
|
|
<i class="bi-x-circle-fill" />
|
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</pane>
|
|
|
|
<pane class="h-full px-2">
|
|
|
|
<ul v-if="mediaStore.folderTree.parent" class="h-full overflow-auto m-1">
|
|
|
|
<li
|
|
|
|
v-for="(element, index) in mediaStore.folderTree.files"
|
|
|
|
:id="`file_${index}`"
|
|
|
|
class="grid grid-cols-[auto_176px]"
|
|
|
|
:key="element.name"
|
|
|
|
>
|
|
|
|
<div class="truncate">
|
|
|
|
<i v-if="mediaType(element.name) === 'audio'" class="bi-music-note-beamed" />
|
|
|
|
<i v-else-if="mediaType(element.name) === 'video'" class="bi-film" />
|
|
|
|
<i v-else-if="mediaType(element.name) === 'image'" class="bi-file-earmark-image" />
|
|
|
|
<i v-else class="bi-file-binary" />
|
|
|
|
|
|
|
|
{{ element.name }}
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<button class="w-7" @click=";(showPreviewModal = true), setPreviewData(element.name)">
|
|
|
|
<i class="bi-play-fill" />
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<div class="inline-block w-[82px]">{{ toMin(element.duration) }}</div>
|
|
|
|
|
|
|
|
<button
|
|
|
|
class="w-7"
|
|
|
|
@click="
|
|
|
|
;(showRenameModal = true),
|
|
|
|
setRenameValues(
|
|
|
|
`/${mediaStore.folderTree.source}/${element.name}`.replace(
|
2024-04-06 17:16:13 -04:00
|
|
|
/\/[/]+/g,
|
|
|
|
'/'
|
|
|
|
)
|
2024-04-07 09:45:26 -04:00
|
|
|
)
|
|
|
|
"
|
|
|
|
>
|
|
|
|
<i class="bi-pencil-square" />
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<button
|
|
|
|
class="w-7 opacity-30 hover:opacity-100"
|
|
|
|
data-bs-toggle="modal"
|
|
|
|
data-bs-target="#deleteModal"
|
|
|
|
@click="
|
|
|
|
;(showDeleteModal = true),
|
|
|
|
(deleteName = `/${mediaStore.folderTree.source}/${element.name}`.replace(
|
|
|
|
/\/[/]+/g,
|
|
|
|
'/'
|
|
|
|
))
|
|
|
|
"
|
|
|
|
>
|
|
|
|
<i class="bi-x-circle-fill" />
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</pane>
|
|
|
|
</splitpanes>
|
2024-04-06 17:16:13 -04:00
|
|
|
</div>
|
2024-04-07 09:45:26 -04:00
|
|
|
</div>
|
|
|
|
<div class="flex justify-end pe-10 mt-7">
|
|
|
|
<div class="join">
|
|
|
|
<button class="btn btn-sm btn-primary join-item" title="Create Folder" @click="showCreateModal = true">
|
|
|
|
<i class="bi-folder-plus" />
|
|
|
|
</button>
|
|
|
|
<button class="btn btn-sm btn-primary join-item" title="Upload File" @click="showUploadModal = true">
|
|
|
|
<i class="bi-upload" />
|
|
|
|
</button>
|
2024-04-06 17:16:13 -04:00
|
|
|
</div>
|
2024-04-07 09:45:26 -04:00
|
|
|
</div>
|
2023-03-27 10:28:13 -04:00
|
|
|
|
2024-04-07 09:45:26 -04:00
|
|
|
<Modal
|
|
|
|
:show="showDeleteModal"
|
|
|
|
title="Delete File/Folder"
|
|
|
|
:text="`Are you sure that you want to delete:<br /><strong>${deleteName}</strong>`"
|
|
|
|
:modal-action="deleteFileOrFolder"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Modal :show="showPreviewModal" :title="`Preview: ${previewName}`" :modal-action="closePlayer">
|
|
|
|
<div class="w-[1024px] max-w-full aspect-video">
|
|
|
|
<VideoPlayer v-if="isVideo && previewOpt" reference="previewPlayer" :options="previewOpt" />
|
|
|
|
<img v-else :src="previewUrl" class="img-fluid" :alt="previewName" />
|
2023-01-11 04:54:25 -05:00
|
|
|
</div>
|
2024-04-07 09:45:26 -04:00
|
|
|
</Modal>
|
2023-01-11 04:54:25 -05:00
|
|
|
|
2024-04-07 09:45:26 -04:00
|
|
|
<Modal :show="showRenameModal" title="Rename File" :modal-action="renameFile">
|
|
|
|
<label class="form-control w-full max-w-md">
|
|
|
|
<div class="label">
|
|
|
|
<span class="label-text">New filename</span>
|
2023-01-11 04:54:25 -05:00
|
|
|
</div>
|
2024-04-07 09:45:26 -04:00
|
|
|
<input type="text" class="input input-bordered w-full" v-model="renameNewName" />
|
|
|
|
</label>
|
|
|
|
</Modal>
|
|
|
|
|
|
|
|
<Modal :show="showCreateModal" title="Create Folder" :modal-action="createFolder">
|
|
|
|
<label class="form-control w-full max-w-md">
|
|
|
|
<div class="label">
|
|
|
|
<span class="label-text">Foldername</span>
|
2024-04-06 17:16:13 -04:00
|
|
|
</div>
|
2024-04-07 09:45:26 -04:00
|
|
|
<input type="text" class="input input-bordered w-full" v-model="folderName.name" />
|
|
|
|
</label>
|
|
|
|
</Modal>
|
|
|
|
|
|
|
|
<Modal :show="showUploadModal" title="Upload Files" :modal-action="uploadFiles">
|
|
|
|
<div class="w-[700px] max-w-full">
|
|
|
|
<input
|
|
|
|
type="file"
|
|
|
|
class="file-input file-input-bordered w-full"
|
|
|
|
ref="fileInputName"
|
|
|
|
:accept="extensions"
|
|
|
|
v-on:change="onFileChange"
|
|
|
|
multiple
|
|
|
|
/>
|
|
|
|
|
|
|
|
<label class="form-control w-full mt-3">
|
|
|
|
<div class="label">
|
|
|
|
<span class="label-text">Current:</span>
|
|
|
|
</div>
|
|
|
|
<progress class="progress progress-accent" :value="currentProgress" max="100" />
|
|
|
|
</label>
|
2023-01-11 04:54:25 -05:00
|
|
|
|
2024-04-07 09:45:26 -04:00
|
|
|
<label class="form-control w-full mt-1">
|
|
|
|
<div class="label">
|
|
|
|
<span class="label-text">Overall ({{ currentNumber }}/{{ inputFiles.length }}):</span>
|
2024-04-06 17:16:13 -04:00
|
|
|
</div>
|
2024-04-07 09:45:26 -04:00
|
|
|
<progress class="progress progress-accent" :value="overallProgress" max="100" />
|
|
|
|
</label>
|
|
|
|
<label class="form-control w-full mt-1">
|
|
|
|
<div class="label">
|
|
|
|
<span class="label-text">Uploading:</span>
|
|
|
|
</div>
|
|
|
|
<input type="text" class="input input-sm input-bordered w-full" v-model="uploadTask" disabled />
|
|
|
|
</label>
|
2023-01-11 04:54:25 -05:00
|
|
|
</div>
|
2024-04-07 09:45:26 -04:00
|
|
|
</Modal>
|
2020-01-30 15:25:10 -05:00
|
|
|
</template>
|
|
|
|
|
2023-01-11 04:54:25 -05:00
|
|
|
<script setup lang="ts">
|
2023-03-27 10:28:13 -04:00
|
|
|
import { storeToRefs } from 'pinia'
|
|
|
|
|
2023-01-11 04:54:25 -05:00
|
|
|
const authStore = useAuth()
|
|
|
|
const configStore = useConfig()
|
|
|
|
const indexStore = useIndex()
|
|
|
|
const mediaStore = useMedia()
|
2023-03-27 10:28:13 -04:00
|
|
|
const { toMin, mediaType } = stringFormatter()
|
2023-01-11 04:54:25 -05:00
|
|
|
const contentType = { 'content-type': 'application/json;charset=UTF-8' }
|
|
|
|
|
2023-03-27 10:28:13 -04:00
|
|
|
const { configID } = storeToRefs(useConfig())
|
|
|
|
|
2023-01-11 04:54:25 -05:00
|
|
|
useHead({
|
2023-03-27 10:28:13 -04:00
|
|
|
title: 'Media | ffplayout',
|
2023-01-11 04:54:25 -05:00
|
|
|
})
|
|
|
|
|
2023-03-27 10:28:13 -04:00
|
|
|
const browserIsLoading = ref(false)
|
|
|
|
const deleteName = ref('')
|
|
|
|
const renameOldName = ref('')
|
|
|
|
const renameNewName = ref('')
|
|
|
|
const previewName = ref('')
|
|
|
|
const previewUrl = ref('')
|
|
|
|
const previewOpt = ref()
|
|
|
|
const isVideo = ref(false)
|
2024-04-07 09:45:26 -04:00
|
|
|
const showDeleteModal = ref(false)
|
|
|
|
const showPreviewModal = ref(false)
|
|
|
|
const showRenameModal = ref(false)
|
|
|
|
const showCreateModal = ref(false)
|
|
|
|
const showUploadModal = ref(false)
|
2023-01-11 04:54:25 -05:00
|
|
|
const extensions = ref('')
|
2023-09-08 04:16:34 -04:00
|
|
|
const folderName = ref({} as Folder)
|
2023-01-11 04:54:25 -05:00
|
|
|
const inputFiles = ref([] as File[])
|
2023-04-06 05:05:15 -04:00
|
|
|
const fileInputName = ref()
|
2023-01-11 04:54:25 -05:00
|
|
|
const currentNumber = ref(0)
|
|
|
|
const uploadTask = ref('')
|
|
|
|
const overallProgress = ref(0)
|
|
|
|
const currentProgress = ref(0)
|
|
|
|
const lastPath = ref('')
|
|
|
|
const xhr = ref(new XMLHttpRequest())
|
|
|
|
|
|
|
|
onMounted(async () => {
|
2023-07-14 07:45:48 -04:00
|
|
|
let config_extensions = configStore.configPlayout.storage.extensions
|
|
|
|
let extra_extensions = configStore.configGui[configStore.configID].extra_extensions
|
|
|
|
|
|
|
|
if (typeof config_extensions === 'string') {
|
|
|
|
config_extensions = config_extensions.split(',')
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof extra_extensions === 'string') {
|
|
|
|
extra_extensions = extra_extensions.split(',')
|
|
|
|
}
|
|
|
|
|
2023-12-07 16:00:05 -05:00
|
|
|
const exts = [...config_extensions, ...extra_extensions].map((ext) => {
|
2023-01-11 04:54:25 -05:00
|
|
|
return `.${ext}`
|
|
|
|
})
|
|
|
|
|
|
|
|
extensions.value = exts.join(', ')
|
2023-03-27 10:28:13 -04:00
|
|
|
|
|
|
|
if (!mediaStore.folderTree.parent) {
|
|
|
|
getPath('')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
watch([configID], () => {
|
|
|
|
getPath('')
|
2023-01-11 04:54:25 -05:00
|
|
|
})
|
|
|
|
|
2023-03-27 10:28:13 -04:00
|
|
|
async function getPath(path: string) {
|
|
|
|
browserIsLoading.value = true
|
|
|
|
await mediaStore.getTree(path)
|
|
|
|
browserIsLoading.value = false
|
|
|
|
}
|
|
|
|
|
|
|
|
function setPreviewData(path: string) {
|
|
|
|
/*
|
|
|
|
Set path and player options for video preview.
|
|
|
|
*/
|
|
|
|
let fullPath = path
|
|
|
|
if (!path.includes('/')) {
|
|
|
|
fullPath = `/${mediaStore.folderTree.parent}/${mediaStore.folderTree.source}/${path}`.replace(/\/[/]+/g, '/')
|
|
|
|
}
|
|
|
|
|
|
|
|
previewName.value = fullPath.split('/').slice(-1)[0]
|
2023-12-07 16:00:05 -05:00
|
|
|
previewUrl.value = encodeURIComponent(`/file/${configStore.configGui[configStore.configID].id}${fullPath}`).replace(
|
|
|
|
/%2F/g,
|
|
|
|
'/'
|
|
|
|
)
|
2023-03-27 10:28:13 -04:00
|
|
|
|
|
|
|
const ext = previewName.value.split('.').slice(-1)[0].toLowerCase()
|
2023-12-07 16:00:05 -05:00
|
|
|
const fileType =
|
|
|
|
mediaType(previewName.value) === 'audio'
|
|
|
|
? `audio/${ext}`
|
|
|
|
: mediaType(previewName.value) === 'live'
|
|
|
|
? 'application/x-mpegURL'
|
|
|
|
: `video/${ext}`
|
2023-03-27 10:28:13 -04:00
|
|
|
|
|
|
|
if (configStore.configPlayout.storage.extensions.includes(`${ext}`)) {
|
|
|
|
isVideo.value = true
|
|
|
|
previewOpt.value = {
|
|
|
|
liveui: false,
|
|
|
|
controls: true,
|
|
|
|
suppressNotSupportedError: true,
|
|
|
|
autoplay: false,
|
|
|
|
preload: 'auto',
|
|
|
|
sources: [
|
|
|
|
{
|
|
|
|
type: fileType,
|
|
|
|
src: previewUrl.value,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
isVideo.value = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-07 09:45:26 -04:00
|
|
|
async function deleteFileOrFolder(del: boolean) {
|
2023-03-27 10:28:13 -04:00
|
|
|
/*
|
|
|
|
Delete function, works for files and folders.
|
|
|
|
*/
|
2024-04-07 09:45:26 -04:00
|
|
|
showDeleteModal.value = false
|
|
|
|
|
|
|
|
if (del) {
|
|
|
|
await fetch(`/api/file/${configStore.configGui[configStore.configID].id}/remove/`, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: { ...contentType, ...authStore.authHeader },
|
|
|
|
body: JSON.stringify({ source: deleteName.value }),
|
2023-03-27 10:28:13 -04:00
|
|
|
})
|
2024-04-07 09:45:26 -04:00
|
|
|
.then(async (response) => {
|
|
|
|
if (response.status !== 200) {
|
|
|
|
indexStore.msgAlert('alert-error', `${await response.text()}`, 5)
|
|
|
|
}
|
|
|
|
getPath(mediaStore.folderTree.source)
|
|
|
|
})
|
|
|
|
.catch((e) => {
|
|
|
|
indexStore.msgAlert('alert-error', `Delete error: ${e}`, 5)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteName.value = ''
|
2023-03-27 10:28:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function setRenameValues(path: string) {
|
|
|
|
renameNewName.value = path
|
|
|
|
renameOldName.value = path
|
|
|
|
}
|
|
|
|
|
2024-04-07 09:45:26 -04:00
|
|
|
async function renameFile(ren: boolean) {
|
2023-03-27 10:28:13 -04:00
|
|
|
/*
|
|
|
|
Form submit for file rename request.
|
|
|
|
*/
|
2024-04-07 09:45:26 -04:00
|
|
|
showRenameModal.value = false
|
2023-03-27 10:28:13 -04:00
|
|
|
|
2024-04-07 09:45:26 -04:00
|
|
|
if (ren) {
|
|
|
|
await fetch(`/api/file/${configStore.configGui[configStore.configID].id}/rename/`, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: { ...contentType, ...authStore.authHeader },
|
|
|
|
body: JSON.stringify({ source: renameOldName.value, target: renameNewName.value }),
|
2023-03-27 10:28:13 -04:00
|
|
|
})
|
2024-04-07 09:45:26 -04:00
|
|
|
.then(() => {
|
|
|
|
getPath(mediaStore.folderTree.source)
|
|
|
|
})
|
|
|
|
.catch((e) => {
|
|
|
|
indexStore.msgAlert('alert-error', `Delete error: ${e}`, 3)
|
|
|
|
})
|
|
|
|
}
|
2023-03-27 10:28:13 -04:00
|
|
|
|
|
|
|
renameOldName.value = ''
|
|
|
|
renameNewName.value = ''
|
|
|
|
}
|
|
|
|
|
|
|
|
function closePlayer() {
|
2024-04-07 09:45:26 -04:00
|
|
|
showPreviewModal.value = false
|
2023-03-27 10:28:13 -04:00
|
|
|
isVideo.value = false
|
|
|
|
}
|
|
|
|
|
2024-04-07 09:45:26 -04:00
|
|
|
async function createFolder(create: boolean) {
|
|
|
|
showCreateModal.value = false
|
2023-01-11 04:54:25 -05:00
|
|
|
|
2024-04-07 09:45:26 -04:00
|
|
|
if (create) {
|
|
|
|
const path = `${mediaStore.folderTree.source}/${folderName.value.name}`.replace(/\/[/]+/g, '/')
|
|
|
|
lastPath.value = mediaStore.folderTree.source
|
2023-01-11 04:54:25 -05:00
|
|
|
|
2024-04-07 09:45:26 -04:00
|
|
|
if (mediaStore.folderTree.folders.includes(folderName.value)) {
|
|
|
|
indexStore.msgAlert('alert-warning', `Folder "${folderName.value.name}" exists already!`, 2)
|
2020-04-13 15:35:24 -04:00
|
|
|
|
2024-04-07 09:45:26 -04:00
|
|
|
return
|
|
|
|
}
|
2020-01-31 07:45:56 -05:00
|
|
|
|
2024-04-07 09:45:26 -04:00
|
|
|
await $fetch(`/api/file/${configStore.configGui[configStore.configID].id}/create-folder/`, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: { ...contentType, ...authStore.authHeader },
|
|
|
|
body: JSON.stringify({ source: path }),
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
indexStore.msgAlert('alert-success', 'Folder create done...', 2)
|
|
|
|
})
|
|
|
|
.catch((e: string) => {
|
|
|
|
indexStore.msgAlert('alert-error', `Folder create error: ${e}`, 3)
|
|
|
|
indexStore.alertVariant = 'alert-error'
|
|
|
|
})
|
|
|
|
|
|
|
|
getPath(lastPath.value)
|
|
|
|
}
|
2020-01-30 15:25:10 -05:00
|
|
|
|
2023-09-08 04:16:34 -04:00
|
|
|
folderName.value = {} as Folder
|
2020-04-20 12:07:12 -04:00
|
|
|
}
|
|
|
|
|
2023-01-11 04:54:25 -05:00
|
|
|
function onFileChange(evt: any) {
|
|
|
|
const files = evt.target.files || evt.dataTransfer.files
|
2020-05-04 06:16:35 -04:00
|
|
|
|
2023-01-11 04:54:25 -05:00
|
|
|
if (!files.length) {
|
|
|
|
return
|
|
|
|
}
|
2020-05-04 06:16:35 -04:00
|
|
|
|
2023-01-11 04:54:25 -05:00
|
|
|
inputFiles.value = files
|
2020-05-04 06:16:35 -04:00
|
|
|
}
|
|
|
|
|
2023-12-20 06:55:24 -05:00
|
|
|
async function upload(file: any): Promise<null | undefined> {
|
2023-04-06 05:05:15 -04:00
|
|
|
const formData = new FormData()
|
|
|
|
formData.append(file.name, file)
|
|
|
|
xhr.value = new XMLHttpRequest()
|
2023-06-28 05:01:17 -04:00
|
|
|
|
2023-12-07 16:00:05 -05:00
|
|
|
return new Promise((resolve) => {
|
2023-01-11 04:54:25 -05:00
|
|
|
xhr.value.open(
|
|
|
|
'PUT',
|
2023-01-11 07:41:22 -05:00
|
|
|
`/api/file/${configStore.configGui[configStore.configID].id}/upload/?path=${encodeURIComponent(
|
2023-01-11 04:54:25 -05:00
|
|
|
mediaStore.crumbs[mediaStore.crumbs.length - 1].path
|
|
|
|
)}`
|
|
|
|
)
|
2020-04-20 12:07:12 -04:00
|
|
|
|
2023-01-11 04:54:25 -05:00
|
|
|
xhr.value.setRequestHeader('Authorization', `Bearer ${authStore.jwtToken}`)
|
2020-04-20 12:07:12 -04:00
|
|
|
|
2023-06-28 05:01:17 -04:00
|
|
|
xhr.value.upload.onprogress = (event: any) => {
|
2023-01-11 04:54:25 -05:00
|
|
|
currentProgress.value = Math.round((100 * event.loaded) / event.total)
|
|
|
|
}
|
2020-01-31 07:45:56 -05:00
|
|
|
|
2023-06-28 05:01:17 -04:00
|
|
|
xhr.value.upload.onerror = () => {
|
2024-04-04 17:28:25 -04:00
|
|
|
indexStore.msgAlert('alert-error', `Upload error: ${xhr.value.status}`, 3)
|
2024-02-21 08:23:20 -05:00
|
|
|
|
2023-04-06 05:05:15 -04:00
|
|
|
resolve(undefined)
|
2023-01-11 04:54:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// upload completed successfully
|
2023-06-28 05:01:17 -04:00
|
|
|
xhr.value.onload = () => {
|
2023-01-11 04:54:25 -05:00
|
|
|
currentProgress.value = 100
|
2023-06-28 05:01:17 -04:00
|
|
|
resolve(xhr.value.response)
|
2023-01-11 04:54:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
xhr.value.send(formData)
|
2023-12-07 16:00:05 -05:00
|
|
|
})
|
2023-04-06 05:05:15 -04:00
|
|
|
}
|
|
|
|
|
2024-04-07 09:45:26 -04:00
|
|
|
async function uploadFiles(upl: boolean) {
|
|
|
|
if (upl) {
|
2024-04-07 09:48:55 -04:00
|
|
|
authStore.inspectToken()
|
2024-04-07 09:45:26 -04:00
|
|
|
lastPath.value = mediaStore.folderTree.source
|
2023-04-06 05:05:15 -04:00
|
|
|
|
2024-04-07 09:45:26 -04:00
|
|
|
for (let i = 0; i < inputFiles.value.length; i++) {
|
|
|
|
const file = inputFiles.value[i]
|
|
|
|
uploadTask.value = file.name
|
|
|
|
currentProgress.value = 0
|
|
|
|
currentNumber.value = i + 1
|
2023-04-06 05:05:15 -04:00
|
|
|
|
2024-04-07 09:45:26 -04:00
|
|
|
if (mediaStore.folderTree.files.find((f) => f.name === file.name)) {
|
|
|
|
indexStore.msgAlert('alert-warning', 'File exists already!', 3)
|
|
|
|
} else {
|
|
|
|
await upload(file)
|
|
|
|
}
|
2023-04-06 05:05:15 -04:00
|
|
|
|
2024-04-07 09:45:26 -04:00
|
|
|
overallProgress.value = (currentNumber.value * 100) / inputFiles.value.length
|
2024-02-21 08:23:20 -05:00
|
|
|
}
|
2023-04-06 05:05:15 -04:00
|
|
|
|
2024-04-07 09:45:26 -04:00
|
|
|
uploadTask.value = 'Done...'
|
|
|
|
getPath(lastPath.value)
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
fileInputName.value = null
|
|
|
|
currentNumber.value = 0
|
|
|
|
currentProgress.value = 0
|
|
|
|
overallProgress.value = 0
|
|
|
|
inputFiles.value = []
|
|
|
|
uploadTask.value = ''
|
|
|
|
showUploadModal.value = false
|
|
|
|
}, 1500)
|
|
|
|
} else {
|
|
|
|
fileInputName.value = null
|
2023-01-11 04:54:25 -05:00
|
|
|
inputFiles.value = []
|
2024-04-07 09:45:26 -04:00
|
|
|
overallProgress.value = 0
|
|
|
|
currentProgress.value = 0
|
2023-04-06 05:05:15 -04:00
|
|
|
uploadTask.value = ''
|
2024-04-07 09:45:26 -04:00
|
|
|
xhr.value.abort()
|
|
|
|
showUploadModal.value = false
|
2023-03-27 10:28:13 -04:00
|
|
|
}
|
|
|
|
}
|
2024-04-07 09:45:26 -04:00
|
|
|
</script>
|