parent
05c207daae
commit
0d5ca44316
@ -42,6 +42,8 @@ const std::unordered_map<std::string, std::string> mime_type_map = {
|
|||||||
{ ".mkv" , "video/x-matroska" },
|
{ ".mkv" , "video/x-matroska" },
|
||||||
{ ".mk3d" , "video/x-matroska" },
|
{ ".mk3d" , "video/x-matroska" },
|
||||||
{ ".mks" , "video/x-matroska" },
|
{ ".mks" , "video/x-matroska" },
|
||||||
|
|
||||||
|
{ ".pdf" , "application/pdf" }
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename InputIt>
|
template<typename InputIt>
|
||||||
@ -170,7 +172,9 @@ namespace api {
|
|||||||
try {
|
try {
|
||||||
if (file.fileLength() > 100 * 1024 * 1024) throw std::exception();
|
if (file.fileLength() > 100 * 1024 * 1024) throw std::exception();
|
||||||
std::filesystem::path filename(inode->getValueOfName());
|
std::filesystem::path filename(inode->getValueOfName());
|
||||||
const std::string& mime = mime_type_map.at(filename.extension().string());
|
std::string ext = filename.extension().string();
|
||||||
|
std::transform(ext.begin(), ext.end(), ext.begin(), tolower);
|
||||||
|
const std::string& mime = mime_type_map.at(ext);
|
||||||
if (!mime.starts_with("image")) throw std::exception();
|
if (!mime.starts_with("image")) throw std::exception();
|
||||||
|
|
||||||
cv::_InputArray image_arr(file.fileData(), (int) file.fileLength());
|
cv::_InputArray image_arr(file.fileData(), (int) file.fileLength());
|
||||||
@ -332,12 +336,12 @@ namespace api {
|
|||||||
if (!inode.has_value())
|
if (!inode.has_value())
|
||||||
return cbk(dto::Responses::get_badreq_res("Unknown node"));
|
return cbk(dto::Responses::get_badreq_res("Unknown node"));
|
||||||
|
|
||||||
|
std::filesystem::path name(inode->getValueOfName());
|
||||||
std::filesystem::path p("./files"), name(inode->getValueOfName());
|
std::string ext = name.extension().string();
|
||||||
p /= std::to_string(inode->getValueOfId());
|
std::transform(ext.begin(), ext.end(), ext.begin(), tolower);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cbk(dto::Responses::get_type_res(mime_type_map.at(name.extension().string())));
|
cbk(dto::Responses::get_type_res(mime_type_map.at(ext)));
|
||||||
} catch (const std::exception&) {
|
} catch (const std::exception&) {
|
||||||
cbk(dto::Responses::get_badreq_res("Invalid file type"));
|
cbk(dto::Responses::get_badreq_res("Invalid file type"));
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
import { NProgress } from 'naive-ui';
|
import { NProgress } from 'naive-ui';
|
||||||
import filesize from 'filesize';
|
import filesize from 'filesize';
|
||||||
import { Music, Video, Image } from '@vicons/carbon';
|
import { Music, Video, Image, Document } from '@vicons/carbon';
|
||||||
import type { DialogApiInjection } from 'naive-ui/es/dialog/src/DialogProvider';
|
import type { DialogApiInjection } from 'naive-ui/es/dialog/src/DialogProvider';
|
||||||
|
|
||||||
export default function createBlobDialog(
|
export default function createBlobDialog(
|
||||||
dialog: DialogApiInjection,
|
dialog: DialogApiInjection,
|
||||||
|
image: boolean,
|
||||||
audio: boolean,
|
audio: boolean,
|
||||||
video: boolean
|
video: boolean
|
||||||
) {
|
) {
|
||||||
@ -14,11 +15,22 @@ export default function createBlobDialog(
|
|||||||
const percentage = ref(0);
|
const percentage = ref(0);
|
||||||
const dia = dialog.create({
|
const dia = dialog.create({
|
||||||
title:
|
title:
|
||||||
'Loading ' + (video ? 'video' : audio ? 'audio' : 'image') + '...',
|
'Loading ' +
|
||||||
|
(video ? 'video' : audio ? 'audio' : image ? 'image' : 'content') +
|
||||||
|
'...',
|
||||||
closable: false,
|
closable: false,
|
||||||
closeOnEsc: false,
|
closeOnEsc: false,
|
||||||
maskClosable: false,
|
maskClosable: false,
|
||||||
icon: () => (video ? <Video /> : audio ? <Music /> : <Image />),
|
icon: () =>
|
||||||
|
video ? (
|
||||||
|
<Video />
|
||||||
|
) : audio ? (
|
||||||
|
<Music />
|
||||||
|
) : image ? (
|
||||||
|
<Image />
|
||||||
|
) : (
|
||||||
|
<Document />
|
||||||
|
),
|
||||||
content: () => (
|
content: () => (
|
||||||
<NProgress
|
<NProgress
|
||||||
type="line"
|
type="line"
|
||||||
|
@ -19,7 +19,8 @@ enum fileTypes {
|
|||||||
LOADING,
|
LOADING,
|
||||||
IMAGE,
|
IMAGE,
|
||||||
AUDIO,
|
AUDIO,
|
||||||
VIDEO
|
VIDEO,
|
||||||
|
IFRAME
|
||||||
}
|
}
|
||||||
|
|
||||||
const fileType = ref<fileTypes>(fileTypes.UNKNOWN);
|
const fileType = ref<fileTypes>(fileTypes.UNKNOWN);
|
||||||
@ -36,6 +37,7 @@ async function loadContent() {
|
|||||||
if (!token) return;
|
if (!token) return;
|
||||||
const { progress, total, percentage, dia } = createBlobDialog(
|
const { progress, total, percentage, dia } = createBlobDialog(
|
||||||
dialog,
|
dialog,
|
||||||
|
fileType.value === fileTypes.IMAGE,
|
||||||
fileType.value === fileTypes.AUDIO,
|
fileType.value === fileTypes.AUDIO,
|
||||||
fileType.value === fileTypes.VIDEO
|
fileType.value === fileTypes.VIDEO
|
||||||
);
|
);
|
||||||
@ -66,9 +68,11 @@ async function getType(node: Responses.GetNode) {
|
|||||||
if (resp.type.startsWith('image')) {
|
if (resp.type.startsWith('image')) {
|
||||||
fileType.value = fileTypes.IMAGE;
|
fileType.value = fileTypes.IMAGE;
|
||||||
await loadContent();
|
await loadContent();
|
||||||
}
|
} else if (resp.type.startsWith('application/pdf')) {
|
||||||
if (resp.type.startsWith('audio')) fileType.value = fileTypes.AUDIO;
|
fileType.value = fileTypes.IFRAME;
|
||||||
if (resp.type.startsWith('video')) fileType.value = fileTypes.VIDEO;
|
await loadContent();
|
||||||
|
} else if (resp.type.startsWith('audio')) fileType.value = fileTypes.AUDIO;
|
||||||
|
else if (resp.type.startsWith('video')) fileType.value = fileTypes.VIDEO;
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
@ -112,7 +116,17 @@ watch(
|
|||||||
:src="src"
|
:src="src"
|
||||||
:alt="node.name"
|
:alt="node.name"
|
||||||
/>
|
/>
|
||||||
<n-button v-else-if="fileType !== fileTypes.IMAGE" @click="loadContent">
|
<iframe
|
||||||
|
v-else-if="fileType === fileTypes.IFRAME && src !== ''"
|
||||||
|
:src="src"
|
||||||
|
width="800"
|
||||||
|
height="1000"
|
||||||
|
>
|
||||||
|
</iframe>
|
||||||
|
<n-button
|
||||||
|
v-else-if="fileType !== fileTypes.IMAGE"
|
||||||
|
@click="loadContent"
|
||||||
|
>
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<n-icon><Play /></n-icon>
|
<n-icon><Play /></n-icon>
|
||||||
</template>
|
</template>
|
||||||
|
Loading…
Reference in New Issue
Block a user