migrate media, unify modal

This commit is contained in:
jb-alvarado 2024-04-07 15:45:26 +02:00
parent 8cec8683a5
commit ce99831023
8 changed files with 2929 additions and 3037 deletions

View File

@ -70,7 +70,7 @@
/>
</label>
<div class="join mt-4">
<div class="join my-4">
<button class="join-item btn btn-primary" type="submit">Save</button>
<button
class="join-item btn btn-primary"

View File

@ -72,68 +72,54 @@
</form>
</div>
<div
v-if="showUserModal"
class="z-50 fixed top-0 bottom-0 left-0 right-0 flex justify-center items-center bg-black/30"
>
<div class="flex flex-col bg-base-100 w-full max-w-[500px] h-[576px] rounded-md p-5 shadow-xl">
<div class="font-bold text-lg">Add user</div>
<form @reset="clearUser" @submit.prevent="addUser">
<label class="form-control w-full mt-7">
<div class="label">
<span class="label-text">Username</span>
</div>
<input type="text" placeholder="Name" class="input input-bordered w-full" v-model="user.username" />
</label>
<label class="form-control w-full mt-3">
<div class="label">
<span class="label-text">Mail</span>
</div>
<input type="email" placeholder="Mail" class="input input-bordered w-full" v-model="user.mail" />
</label>
<label class="form-control w-full mt-3">
<div class="label">
<span class="label-text">Password</span>
</div>
<input
type="password"
placeholder="Password"
class="input input-bordered w-full"
v-model="user.password"
/>
</label>
<label class="form-control w-full mt-3">
<div class="label">
<span class="label-text">Confirm Password</span>
</div>
<input
type="password"
placeholder="Password"
class="input input-bordered w-full"
v-model="user.confirm"
/>
</label>
<div class="form-control mt-3">
<label class="label cursor-pointer w-20">
<span class="label-text">Admin</span>
<input type="checkbox" class="checkbox" v-model.number="user.admin" />
</label>
<Modal :show="showUserModal" title="Add user" :modal-action="addUser">
<div class="w-full max-w-[500px] h-[420px]">
<label class="form-control w-full">
<div class="label">
<span class="label-text">Username</span>
</div>
<input type="text" placeholder="Name" class="input input-bordered w-full" v-model="user.username" />
</label>
<div class="flex justify-end mt-2">
<div class="join">
<button class="btn join-item" type="reset">Cancel</button>
<button class="btn join-item" type="submit">Ok</button>
</div>
<label class="form-control w-full mt-3">
<div class="label">
<span class="label-text">Mail</span>
</div>
</form>
<input type="email" placeholder="Mail" class="input input-bordered w-full" v-model="user.mail" />
</label>
<label class="form-control w-full mt-3">
<div class="label">
<span class="label-text">Password</span>
</div>
<input
type="password"
placeholder="Password"
class="input input-bordered w-full"
v-model="user.password"
/>
</label>
<label class="form-control w-full mt-3">
<div class="label">
<span class="label-text">Confirm Password</span>
</div>
<input
type="password"
placeholder="Password"
class="input input-bordered w-full"
v-model="user.confirm"
/>
</label>
<div class="form-control mt-3">
<label class="label cursor-pointer w-20">
<span class="label-text">Admin</span>
<input type="checkbox" class="checkbox" v-model.number="user.admin" />
</label>
</div>
</div>
</div>
</Modal>
</template>
<script setup lang="ts">
@ -215,44 +201,46 @@ async function deleteUser() {
}
}
async function clearUser() {
function clearUser() {
user.value.username = ''
user.value.mail = ''
user.value.password = ''
user.value.confirm = ''
user.value.admin = false
user.value.role_id = 2
showUserModal.value = false
}
async function addUser() {
if (user.value.admin) {
user.value.role_id = 1
} else {
user.value.role_id = 2
}
delete user.value.admin
if (user.value.password === user.value.confirm) {
showUserModal.value = false
authStore.inspectToken()
const update = await configStore.addNewUser(user.value)
if (update.status === 200) {
indexStore.msgAlert('alert-success', 'Add user success!', 2)
await getUsers()
await getUserConfig()
async function addUser(add: boolean) {
if (add) {
if (user.value.admin) {
user.value.role_id = 1
} else {
indexStore.msgAlert('alert-error', 'Add user failed!', 2)
user.value.role_id = 2
}
clearUser()
delete user.value.admin
if (user.value.password === user.value.confirm) {
authStore.inspectToken()
const update = await configStore.addNewUser(user.value)
showUserModal.value = false
if (update.status === 200) {
indexStore.msgAlert('alert-success', 'Add user success!', 2)
await getUsers()
await getUserConfig()
} else {
indexStore.msgAlert('alert-error', 'Add user failed!', 2)
}
clearUser()
} else {
indexStore.msgAlert('alert-error', 'Password mismatch!', 2)
}
} else {
indexStore.msgAlert('alert-error', 'Password mismatch!', 2)
showUserModal.value = false
clearUser()
}
}

View File

@ -1,10 +1,15 @@
<template>
<div v-if="show" class="z-50 fixed top-0 bottom-0 left-0 right-0 flex justify-center items-center bg-black/30">
<div class="flex flex-col bg-base-100 w-[400px] h-[200px] mt-[10%] rounded-md p-5 shadow-xl">
<div class="flex flex-col bg-base-100 min-w-[400px] max-w-[90%] h-auto rounded-md p-5 shadow-xl">
<div class="font-bold text-lg">{{ title }}</div>
<div class="grow mt-3" v-html="text" />
<div class="flex justify-end">
<div class="grow mt-3">
<slot>
<div v-html="text" />
</slot>
</div>
<div class="flex justify-end mt-3">
<div class="join">
<button class="btn btn-sm bg-base-300 hover:bg-base-300/50 join-item" @click="modalAction(false)">
Cancel

4980
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -24,7 +24,7 @@
"jwt-decode": "^4.0.0",
"lodash": "^4.17.21",
"mpegts.js": "^1.7.3",
"nuxt": "3.10.3",
"nuxt": "3.11.2",
"pinia": "^2.1.7",
"sortablejs-vue3": "^1.2.11",
"splitpanes": "^3.1.5",
@ -35,15 +35,14 @@
"devDependencies": {
"@nuxtjs/eslint-config": "^12.0.0",
"@nuxtjs/tailwindcss": "^6.11.4",
"@types/lodash": "^4.14.202",
"@types/splitpanes": "^2.2.6",
"@types/video.js": "^7.3.56",
"daisyui": "^4.9.0",
"@types/lodash": "^4.17.0",
"@types/video.js": "^7.3.57",
"daisyui": "^4.10.1",
"eslint": "^8.57.0",
"eslint-plugin-nuxt": "^4.0.0",
"postcss": "^8.4.35",
"postcss": "^8.4.38",
"postcss-loader": "^8.1.1",
"sass": "^1.71.1",
"sass": "^1.74.1",
"sass-loader": "^14.1.1"
}
}

View File

@ -1,380 +1,198 @@
<template>
<div class="container-fluid browser-container">
<div class="h-100">
<div>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li
class="breadcrumb-item"
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="#">
{{ crumb.text }}
</a>
<span v-else>{{ crumb.text }}</span>
</li>
</ol>
</nav>
</div>
<div class="browser-div">
<div v-if="browserIsLoading" class="d-flex justify-content-center loading-overlay">
<div class="spinner-border" role="status" />
</div>
<splitpanes
class="pane-row"
:class="$route.path === '/player' ? 'browser-splitter' : ''"
:horizontal="$route.path === '/player'"
<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)"
>
<pane
min-size="14"
max-size="80"
size="24"
:style="
$route.path === '/player'
? `height: ${mediaStore.folderTree.folders.length * 47 + 2}px`
: ''
"
>
<ul v-if="mediaStore.folderTree.parent" class="list-group media-browser-scroll m-1">
<li
class="list-group-item browser-item"
v-for="folder in mediaStore.folderTree.folders"
:key="folder.uid"
>
<div class="row">
<div class="col-1 browser-icons-col">
<i class="bi-folder-fill browser-icons" />
</div>
<div class="col browser-item-text">
<a
class="link-light"
href="#"
@click="getPath(`/${mediaStore.folderTree.source}/${folder.name}`)"
>
{{ folder.name }}
</a>
</div>
<div class="col-1 folder-delete">
<a
href="#"
class="btn-link"
data-bs-toggle="modal"
data-bs-target="#deleteModal"
@click="
deleteName = `/${mediaStore.folderTree.source}/${folder.name}`.replace(
/\/[/]+/g,
'/'
)
"
>
<i class="bi-x-circle-fill" />
</a>
</div>
</div>
</li>
</ul>
</pane>
<pane
:style="
$route.path === '/player' ? `height: ${mediaStore.folderTree.files.length * 26 + 2}px` : ''
"
>
<ul v-if="mediaStore.folderTree.parent" class="list-group media-browser-scroll m-1">
<li
v-for="(element, index) in mediaStore.folderTree.files"
:id="`file_${index}`"
class="draggable list-group-item browser-item"
:key="element.name"
>
<div class="row">
<div class="col-1 browser-icons-col">
<i
v-if="mediaType(element.name) === 'audio'"
class="bi-music-note-beamed browser-icons"
/>
<i
v-else-if="mediaType(element.name) === 'video'"
class="bi-film browser-icons"
/>
<i
v-else-if="mediaType(element.name) === 'image'"
class="bi-file-earmark-image browser-icons"
/>
<i v-else class="bi-file-binary browser-icons" />
</div>
<div class="col browser-item-text grabbing">
{{ element.name }}
</div>
<div class="col-1 browser-play-col">
<a
href="#"
class="btn-link"
data-bs-toggle="modal"
data-bs-target="#previewModal"
@click="setPreviewData(element.name)"
>
<i class="bi-play-fill" />
</a>
</div>
<div class="col-1 browser-dur-col">
<span class="duration">{{ toMin(element.duration) }}</span>
</div>
<div class="col-1 file-rename">
<a
href="#"
class="btn-link"
data-bs-toggle="modal"
data-bs-target="#renameModal"
@click="
setRenameValues(
`/${mediaStore.folderTree.source}/${element.name}`.replace(
/\/[/]+/g,
'/'
)
)
"
>
<i class="bi-pencil-square" />
</a>
</div>
<div class="col-1 file-delete">
<a
href="#"
class="btn-link"
data-bs-toggle="modal"
data-bs-target="#deleteModal"
@click="
deleteName = `/${mediaStore.folderTree.source}/${element.name}`.replace(
/\/[/]+/g,
'/'
)
"
>
<i class="bi-x-circle-fill" />
</a>
</div>
</div>
</li>
</ul>
</pane>
</splitpanes>
</div>
</div>
<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>
<div id="previewModal" class="modal" tabindex="-1" aria-labelledby="previewModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-xl">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="previewModalLabel">Preview: {{ previewName }}</h1>
<button
type="button"
class="btn-close"
data-bs-dismiss="modal"
aria-label="Cancel"
@click="closePlayer()"
></button>
</div>
<div class="modal-body">
<VideoPlayer v-if="isVideo && previewOpt" reference="previewPlayer" :options="previewOpt" />
<img v-else :src="previewUrl" class="img-fluid" :alt="previewName" />
</div>
</div>
<div class="h-[calc(100%-34px)]">
<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>
</div>
<div id="deleteModal" class="modal" tabindex="-1" aria-labelledby="deleteModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="deleteModalLabel">Delete File/Folder</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Cancel"></button>
</div>
<div class="modal-body">
<p>
Are you sure that you want to delete:<br />
<strong>{{ deleteName }}</strong>
</p>
</div>
<div class="modal-footer">
<button
type="reset"
class="btn btn-primary"
data-bs-dismiss="modal"
aria-label="Cancel"
@click="deleteName = ''"
<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">
<li
class="grid grid-cols-[auto_18px] gap-1"
v-for="folder in mediaStore.folderTree.folders"
:key="folder.uid"
>
Cancel
</button>
<button
type="submit"
class="btn btn-primary"
data-bs-dismiss="modal"
@click="deleteFileOrFolder"
>
Ok
</button>
</div>
</div>
</div>
</div>
<div id="renameModal" class="modal" tabindex="-1" aria-labelledby="renameModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="renameModalLabel">Rename File</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Cancel"></button>
</div>
<form @submit.prevent="onSubmitRenameFile" @reset="onCancelRenameFile">
<div class="modal-body">
<input type="text" class="form-control" v-model="renameNewName" />
</div>
<div class="modal-footer">
<button type="reset" class="btn btn-primary" data-bs-dismiss="modal" aria-label="Cancel">
Cancel
<button
class="truncate text-left"
@click="getPath(`/${mediaStore.folderTree.source}/${folder.name}`)"
>
<i class="bi-folder-fill" />
{{ folder.name }}
</button>
<button type="submit" class="btn btn-primary" data-bs-dismiss="modal">Ok</button>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="btn-group media-button">
<button
type="button"
class="btn btn-primary"
title="Create Folder"
data-bs-toggle="modal"
data-bs-target="#folderModal"
>
<i class="bi-folder-plus" />
</button>
<button
type="button"
class="btn btn-primary"
title="Upload File"
data-bs-toggle="modal"
data-bs-target="#uploadModal"
>
<i class="bi-upload" />
</button>
</div>
<button
class="opacity-30 hover:opacity-100"
@click="
;(showDeleteModal = true),
(deleteName = `/${mediaStore.folderTree.source}/${folder.name}`.replace(
/\/[/]+/g,
'/'
))
"
>
<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" />
<div id="folderModal" class="modal" tabindex="-1" aria-labelledby="folderModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="folderModalLabel">Create Folder</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Cancel"></button>
</div>
<form @submit.prevent="onSubmitCreateFolder" @reset="onCancelCreateFolder">
<div class="modal-body">
<input type="text" class="form-control" v-model="folderName.name" />
</div>
<div class="modal-footer">
<button type="reset" class="btn btn-primary" data-bs-dismiss="modal" aria-label="Cancel">
Cancel
</button>
<button type="submit" class="btn btn-primary" data-bs-dismiss="modal">Ok</button>
</div>
</form>
</div>
</div>
</div>
<div
id="uploadModal"
ref="uploadModal"
class="modal"
tabindex="-1"
aria-labelledby="uploadModalLabel"
data-bs-backdrop="static"
>
<div class="modal-dialog modal-dialog-centered modal-xl">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="uploadModalLabel">Upload Files</h1>
<button
type="button"
class="btn-close"
data-bs-dismiss="modal"
aria-label="Cancel"
@click.prevent="onResetUpload()"
></button>
</div>
<form @submit.prevent="onSubmitUpload" @reset.prevent="onResetUpload">
<div class="modal-body">
<input
class="form-control"
type="file"
ref="fileInputName"
:accept="extensions"
v-on:change="onFileChange"
multiple
/>
<div class="row">
<div class="col-10">
<div class="row progress-row">
<div class="col-1" style="min-width: 125px">Current:</div>
<div class="col-10">
<div class="progress">
<div
class="progress-bar bg-warning"
role="progressbar"
:aria-valuenow="currentProgress"
:style="`width: ${currentProgress}%`"
/>
</div>
</div>
<div class="w-100" />
<div class="col-1" style="min-width: 125px">
Overall ({{ currentNumber }}/{{ inputFiles.length }}):
</div>
<div class="col-10">
<div class="progress">
<div
class="progress-bar bg-warning"
role="progressbar"
:aria-valuenow="overallProgress"
:style="`width: ${overallProgress}%`"
/>
</div>
</div>
<div class="w-100" />
<div class="col-1" style="min-width: 125px">Uploading:</div>
<div class="col-10">
<strong>{{ uploadTask }}</strong>
</div>
</div>
{{ element.name }}
</div>
<div class="col-2">
<div class="media-button">
<button type="reset" class="btn btn-primary me-2" data-bs-dismiss="modal">
Cancel
</button>
<button type="submit" class="btn btn-primary">Upload</button>
</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(
/\/[/]+/g,
'/'
)
)
"
>
<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>
</div>
</div>
</form>
</div>
</li>
</ul>
</pane>
</splitpanes>
</div>
</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>
</div>
</div>
<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" />
</div>
</Modal>
<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>
</div>
<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>
</div>
<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>
<label class="form-control w-full mt-1">
<div class="label">
<span class="label-text">Overall ({{ currentNumber }}/{{ inputFiles.length }}):</span>
</div>
<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>
</div>
</Modal>
</template>
<script setup lang="ts">
import { storeToRefs } from 'pinia'
import { Splitpanes, Pane } from 'splitpanes'
import 'splitpanes/dist/splitpanes.css'
const { $bootstrap } = useNuxtApp()
const authStore = useAuth()
const configStore = useConfig()
const indexStore = useIndex()
@ -396,7 +214,11 @@ const previewName = ref('')
const previewUrl = ref('')
const previewOpt = ref()
const isVideo = ref(false)
const uploadModal = ref()
const showDeleteModal = ref(false)
const showPreviewModal = ref(false)
const showRenameModal = ref(false)
const showCreateModal = ref(false)
const showUploadModal = ref(false)
const extensions = ref('')
const folderName = ref({} as Folder)
const inputFiles = ref([] as File[])
@ -406,7 +228,6 @@ const uploadTask = ref('')
const overallProgress = ref(0)
const currentProgress = ref(0)
const lastPath = ref('')
const thisUploadModal = ref()
const xhr = ref(new XMLHttpRequest())
onMounted(async () => {
@ -426,8 +247,6 @@ onMounted(async () => {
})
extensions.value = exts.join(', ')
// @ts-ignore
thisUploadModal.value = $bootstrap.Modal.getOrCreateInstance(uploadModal.value)
if (!mediaStore.folderTree.parent) {
getPath('')
@ -487,24 +306,30 @@ function setPreviewData(path: string) {
}
}
async function deleteFileOrFolder() {
async function deleteFileOrFolder(del: boolean) {
/*
Delete function, works for files and folders.
*/
await fetch(`/api/file/${configStore.configGui[configStore.configID].id}/remove/`, {
method: 'POST',
headers: { ...contentType, ...authStore.authHeader },
body: JSON.stringify({ source: deleteName.value }),
})
.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)
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 }),
})
.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 = ''
}
function setRenameValues(path: string) {
@ -512,69 +337,64 @@ function setRenameValues(path: string) {
renameOldName.value = path
}
async function onSubmitRenameFile(evt: any) {
async function renameFile(ren: boolean) {
/*
Form submit for file rename request.
*/
evt.preventDefault()
showRenameModal.value = false
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 }),
})
.then(() => {
getPath(mediaStore.folderTree.source)
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 }),
})
.catch((e) => {
indexStore.msgAlert('alert-error', `Delete error: ${e}`, 3)
})
renameOldName.value = ''
renameNewName.value = ''
}
function onCancelRenameFile(evt: any) {
evt.preventDefault()
.then(() => {
getPath(mediaStore.folderTree.source)
})
.catch((e) => {
indexStore.msgAlert('alert-error', `Delete error: ${e}`, 3)
})
}
renameOldName.value = ''
renameNewName.value = ''
}
function closePlayer() {
showPreviewModal.value = false
isVideo.value = false
}
async function onSubmitCreateFolder(evt: any) {
evt.preventDefault()
const path = `${mediaStore.folderTree.source}/${folderName.value.name}`.replace(/\/[/]+/g, '/')
lastPath.value = mediaStore.folderTree.source
async function createFolder(create: boolean) {
showCreateModal.value = false
if (mediaStore.folderTree.folders.includes(folderName.value)) {
indexStore.msgAlert('alert-warning', `Folder "${folderName.value.name}" exists already!`, 2)
if (create) {
const path = `${mediaStore.folderTree.source}/${folderName.value.name}`.replace(/\/[/]+/g, '/')
lastPath.value = mediaStore.folderTree.source
return
if (mediaStore.folderTree.folders.includes(folderName.value)) {
indexStore.msgAlert('alert-warning', `Folder "${folderName.value.name}" exists already!`, 2)
return
}
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)
}
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'
})
folderName.value = {} as Folder
getPath(lastPath.value)
}
function onCancelCreateFolder(evt: any) {
evt.preventDefault()
folderName.value = {} as Folder
}
@ -623,108 +443,45 @@ async function upload(file: any): Promise<null | undefined> {
})
}
async function onSubmitUpload(evt: any) {
evt.preventDefault()
async function uploadFiles(upl: boolean) {
if (upl) {
lastPath.value = mediaStore.folderTree.source
lastPath.value = mediaStore.folderTree.source
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
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
if (mediaStore.folderTree.files.find((f) => f.name === file.name)) {
indexStore.msgAlert('alert-warning', 'File exists already!', 3)
} else {
await upload(file)
}
if (mediaStore.folderTree.files.find((f) => f.name === file.name)) {
indexStore.msgAlert('alert-warning', 'File exists already!', 3)
} else {
await upload(file)
overallProgress.value = (currentNumber.value * 100) / inputFiles.value.length
}
overallProgress.value = (currentNumber.value * 100) / inputFiles.value.length
}
uploadTask.value = 'Done...'
getPath(lastPath.value)
uploadTask.value = 'Done...'
getPath(lastPath.value)
setTimeout(() => {
fileInputName.value.value = null
thisUploadModal.value.hide()
currentNumber.value = 0
currentProgress.value = 0
overallProgress.value = 0
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
inputFiles.value = []
overallProgress.value = 0
currentProgress.value = 0
uploadTask.value = ''
}, 1500)
}
function onResetUpload() {
fileInputName.value.value = null
inputFiles.value = []
overallProgress.value = 0
currentProgress.value = 0
uploadTask.value = ''
xhr.value.abort()
xhr.value.abort()
showUploadModal.value = false
}
}
</script>
<style lang="scss">
.browser-container .browser-item:hover {
background-color: $item-hover;
div > .folder-delete {
display: inline;
}
}
.browser-div {
height: calc(100% - 34px);
}
.folder-delete {
margin-right: 0.8em;
display: none;
min-width: 30px;
}
#deleteModal strong {
display: inline-block;
width: 100%;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.file-delete,
.file-rename {
margin-right: 0.8em;
max-width: 35px !important;
min-width: 35px !important;
}
.browser-container {
position: relative;
width: 100%;
max-width: 100%;
height: calc(100% - 140px);
}
.browser-container > div {
height: 100%;
}
.progress-row {
margin-top: 1em;
}
.progress-row .col-1 {
min-width: 60px;
}
.progress-row .col-10 {
margin: auto 0 auto 0;
}
.progress {
padding: 0;
}
</style>

View File

@ -92,7 +92,7 @@
/>
</label>
</div>
<div class="grid grid-cols-[150px_150px_auto] gap-4">
<div class="grid grid-cols-[150px_150px_auto] gap-4 mt-2">
<div>
<label class="form-control w-full">
<div class="label">

View File

@ -0,0 +1,7 @@
import { Splitpanes, Pane } from 'splitpanes'
import 'splitpanes/dist/splitpanes.css'
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.component('Splitpanes', Splitpanes)
nuxtApp.vueApp.component('Pane', Pane)
})