Small fixes

This commit is contained in:
Mutzi 2022-10-14 13:22:01 +02:00
parent df361947cd
commit ffa3fc9a25
3 changed files with 71 additions and 15 deletions

View File

@ -39,7 +39,7 @@ fn handle_request(mut req: Request, db: db::DBPool) {
if !(path.contains('\\') || path.contains("..") || path.contains(':')) { if !(path.contains('\\') || path.contains("..") || path.contains(':')) {
let path_str = "./static".to_owned() + &path; let path_str = "./static".to_owned() + &path;
let path = std::path::Path::new(&path_str); let path = std::path::Path::new(&path_str);
if path.exists() { if path.is_file() {
let resp = Response::from_file(File::open(path).unwrap()); let resp = Response::from_file(File::open(path).unwrap());
match path.extension().map(|s| s.to_str()).unwrap_or(None) { match path.extension().map(|s| s.to_str()).unwrap_or(None) {
Some("html") => resp.with_header(header("content-type", "text/html; charset=utf-8")), Some("html") => resp.with_header(header("content-type", "text/html; charset=utf-8")),
@ -175,10 +175,12 @@ fn handle_api_request(span: &mut Span, req: &mut Request, pool: db::DBPool) -> R
} }
fn main() { fn main() {
println!("Loading config...");
let _ = config::CONFIG; let _ = config::CONFIG;
let db_pool: db::DBPool = db::build_pool(); let db_pool: db::DBPool = db::build_pool();
println!("Running migrations...");
db::run_migrations(&mut db_pool.get().unwrap()); db::run_migrations(&mut db_pool.get().unwrap());
if !std::path::Path::new("files").exists() { if !std::path::Path::new("files").exists() {
@ -188,11 +190,13 @@ fn main() {
if !std::path::Path::new("temp").is_dir() { if !std::path::Path::new("temp").is_dir() {
std::fs::create_dir("temp").expect("Failed to create temp dir"); std::fs::create_dir("temp").expect("Failed to create temp dir");
} }
println!("Cleaning up temp...");
std::fs::read_dir("temp").expect("Failed to iter temp dir").for_each(|dir| { std::fs::read_dir("temp").expect("Failed to iter temp dir").for_each(|dir| {
std::fs::remove_file(dir.expect("Failed to retrieve temp dir entry").path()) std::fs::remove_file(dir.expect("Failed to retrieve temp dir entry").path())
.expect("Failed to delete file in temp dir"); .expect("Failed to delete file in temp dir");
}); });
println!("Loading metrics...");
metrics::init(DBConnection::from(db_pool.get().unwrap())); metrics::init(DBConnection::from(db_pool.get().unwrap()));
let shutdown = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false)); let shutdown = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
@ -213,6 +217,7 @@ fn main() {
.build() .build()
.unwrap(); .unwrap();
println!("Listening on 0.0.0.0:2345");
'server: loop { 'server: loop {
match server.recv() { match server.recv() {
Ok(req) => { Ok(req) => {
@ -226,5 +231,5 @@ fn main() {
} }
} }
println!("Quitting"); println!("Goodbye");
} }

View File

@ -113,6 +113,7 @@ function createNewFolderDialog() {
</n-gi> </n-gi>
<n-gi span="2"> <n-gi span="2">
<DirViewerTable <DirViewerTable
:current-node="node"
:nodes="nodes" :nodes="nodes"
:show-preview="showPreview" :show-preview="showPreview"
@reloadNode="emit('reloadNode')" @reloadNode="emit('reloadNode')"

View File

@ -10,7 +10,7 @@ import type {
import type { SummaryCell } from 'naive-ui/es/data-table/src/interface'; import type { SummaryCell } from 'naive-ui/es/data-table/src/interface';
import { inject, ref, nextTick, Suspense } from 'vue'; import { inject, ref, nextTick, Suspense } from 'vue';
import filesize from 'filesize'; import filesize from 'filesize';
import { check_token, FS } from '@/api'; import { check_token, FS, isErrorResponse } from '@/api';
import { loadingMsgWrapper } from '@/utils'; import { loadingMsgWrapper } from '@/utils';
import { import {
useMessage, useMessage,
@ -31,7 +31,8 @@ import {
FolderParent, FolderParent,
DocumentBlank, DocumentBlank,
Delete, Delete,
Download Download,
Cut
} from '@vicons/carbon'; } from '@vicons/carbon';
import semaphore from 'semaphore'; import semaphore from 'semaphore';
import NLink from '@/components/NLink.vue'; import NLink from '@/components/NLink.vue';
@ -56,6 +57,7 @@ type DropdownOptionsType = Array<
>; >;
const props = defineProps<{ const props = defineProps<{
currentNode: Responses.GetNode;
nodes: Responses.GetNodeEntry[]; nodes: Responses.GetNodeEntry[];
showPreview: boolean; showPreview: boolean;
}>(); }>();
@ -65,6 +67,7 @@ const checkedRows = ref<number[]>([]);
const deleteNodes = ref<number[]>([]); const deleteNodes = ref<number[]>([]);
const deleteDialog = ref(); const deleteDialog = ref();
const deleteDialogShow = ref(false); const deleteDialogShow = ref(false);
const cutNodes = ref<number[]>([]);
const dropdownX = ref(0); const dropdownX = ref(0);
const dropdownY = ref(0); const dropdownY = ref(0);
@ -82,6 +85,15 @@ const dropdownOptionsFolder: DropdownOptionsType = [
</NIcon> </NIcon>
) )
}, },
{
label: () => <NText>Cut</NText>,
key: 'cut',
icon: () => (
<NIcon>
<Cut />
</NIcon>
)
},
{ {
label: () => <NText type="error">Delete</NText>, label: () => <NText type="error">Delete</NText>,
key: 'delete', key: 'delete',
@ -102,6 +114,15 @@ const dropdownOptionsFile: DropdownOptionsType = [
</NIcon> </NIcon>
) )
}, },
{
label: () => <NText>Cut</NText>,
key: 'cut',
icon: () => (
<NIcon>
<Cut />
</NIcon>
)
},
{ {
label: () => <NText type="error">Delete</NText>, label: () => <NText type="error">Delete</NText>,
key: 'delete', key: 'delete',
@ -124,6 +145,9 @@ const dropdownSelect = loadingMsgWrapper(message, async (key: string) => {
await FS.download_file(token, dropdownCurrentNode.id); await FS.download_file(token, dropdownCurrentNode.id);
else createZipDialog([dropdownCurrentNode.id], dialog, jwt); else createZipDialog([dropdownCurrentNode.id], dialog, jwt);
break; break;
case 'cut':
cutNodes.value = [dropdownCurrentNode.id];
break;
case 'delete': case 'delete':
dialog.warning({ dialog.warning({
title: 'Really delete?', title: 'Really delete?',
@ -269,19 +293,45 @@ const massDelete = loadingMsgWrapper(message, async () => {
}); });
}); });
function massCut() {
cutNodes.value = checkedRows.value;
checkedRows.value = [];
}
const pasteNodes = loadingMsgWrapper(message, async () => {
const token = await check_token(jwt);
if (!token) return;
const res = await FS.move(token, cutNodes.value, props.currentNode.id);
cutNodes.value = [];
if (isErrorResponse(res)) {
message.error(`Failed to move nodes: ${res.message}`);
return;
}
emit('reloadNode');
});
const selectionCell = (): SummaryCell => { const selectionCell = (): SummaryCell => {
return { return {
value: value: (
checkedRows.value.length != 0 ? ( <NButtonGroup>
<NButtonGroup> {cutNodes.value.length != 0 ? (
<NButton onClick={massDownload}>Download</NButton> <NButton onClick={pasteNodes}>Paste</NButton>
<NButton onClick={massDelete} type="error"> ) : (
Delete ''
</NButton> )}
</NButtonGroup> {checkedRows.value.length != 0 ? (
) : ( <>
'' <NButton onClick={massDownload}>Download</NButton>
), <NButton onClick={massCut}>Cut</NButton>
<NButton onClick={massDelete} type="error">
Delete
</NButton>
</>
) : (
''
)}
</NButtonGroup>
),
colSpan: props.showPreview ? 2 : 1 colSpan: props.showPreview ? 2 : 1
}; };
}; };