Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
imzlh committed Jul 20, 2024
1 parent d35e9c1 commit 7295c9d
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 56 deletions.
2 changes: 1 addition & 1 deletion src/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface FileAndDir {
name: string,
dispName?:string,
ctime: number,
url: strings,
url: string,
path: string,
icon?:string
}
Expand Down
9 changes: 6 additions & 3 deletions src/module/tree.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import type { MessageOpinion } from '@/env';
import { DEFAULT_FILE_ICON, FS, Global, loadTree, UI, openFile, reloadTree, size2str, splitPath } from '@/utils';
import { DEFAULT_FILE_ICON, FS, Global, loadTree, UI, openFile, reloadTree, size2str, splitPath, clipFName } from '@/utils';
import { ref, shallowRef, toRaw, watch, type PropType } from 'vue';
import { upload, type iDir, type iFile, type iMixed } from '@/script/tree';
import { TREE_REG } from '@/action/tree';
Expand Down Expand Up @@ -74,7 +74,7 @@
e.dataTransfer.setData('application/json', JSON.stringify(toRaw(fd)));
e.dataTransfer.setData('text/vtoken', DRAG_TOKEN);
e.dataTransfer.setData('text/uri-list', fd.url);
e.dataTransfer.setData('text/plain', fd.name);
e.dataTransfer.setData('text/plain', `[ ${fd.name.replace(/[\[\]]/g, match => '\\' + match[0])} ](${encodeURI(fd.url)})`);
e.dataTransfer.dropEffect = 'copy';
if(fd.icon){
Expand Down Expand Up @@ -154,7 +154,10 @@
FS.rename({
[file.path]: val
}).then(() => (
file.name = val,file.rename = false
file.name = val ,
file.url = file.url.substring(0, file.url.lastIndexOf('/', file.url.length -2) +1) + file.name,
file.rename = false,
file.ctime = Date.now()
)).catch((e: Error) => (Global('ui.message').call({
'type': 'error',
'content': {
Expand Down
4 changes: 2 additions & 2 deletions src/module/upload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@

<template>
<div class="upload-wrapper" @dragover.prevent="drag.start" @drop.prevent="drag.end" @dragleave="mouse.show = false">
<div class="container" @click="upload(true, dir)">
<div v-for="item in eque" @click.stop="event('select', dir + '/' + item.name)">
<div class="container" @click="upload(true, dir, obj => eque.push(obj))">
<div v-for="item in eque" @click.stop="event('select', item.path)">
<img :src="getIcon(item.name)" :alt="item.icon">
<span class="name">{{ item.name }}</span>
<div :style="{
Expand Down
2 changes: 1 addition & 1 deletion src/opener/markdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
// this.obj.index = CFG.search_index;
// },
repAll(){
this.obj?.replace('next',{
this.obj?.replace(CFG.replace_text ,{
isSingle: false,
isRegexp: false
});
Expand Down
103 changes: 54 additions & 49 deletions src/script/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,65 +122,70 @@ export async function upload(e: FileList | Array<File> | DragEvent | boolean, to
uploaded = [] as Array<iFile>;
for (const file of e) {
// 相对的文件
if(file.webkitRelativePath || (file as xFile).fullpath){
if (file.webkitRelativePath || (file as xFile).fullpath) {
// 获取路径分层
const path = splitPath({ path:
file.webkitRelativePath
? file.webkitRelativePath
: (file as xFile).fullpath as string
}),
var path = splitPath({
path:
file.webkitRelativePath
? file.webkitRelativePath
: (file as xFile).fullpath as string
}),
parent = await loadPath(to_fd.path + path.dir);
} else {
var path = splitPath(to_fd),
parent = to_fd;
}

const matched = parent.child?.filter(item => item.name == path.fname)[0];
if(matched && matched.type == 'file')
repeated.push(matched),repeated_files.push(file);
else if(matched && matched.type == 'dir') Global('ui.message').call({
const matched = parent.child?.filter(item => item.name == path.fname)[0];
if (matched && matched.type == 'file') {
repeated.push(matched), repeated_files.push(file);
} else if (matched && matched.type == 'dir') {
Global('ui.message').call({
"title": "资源管理器",
"content": {
"title": "上传错误",
"content": "前提条件错误:目标是一个文件夹"
},
"type": "error",
"timeout": 10
} satisfies MessageOpinion);
} else {
// 创建一个元素
const file_element = reactive({
"ctime": Date.now(),
"icon": getIcon(file.name, true),
"name": file.name,
"path": to_fd.path + ((file as xFile).fullpath || file.webkitRelativePath || file.name),
"size": file.size,
"type": 'file',
"url": FILE_PROXY_SERVER + to_fd.path + ((file as xFile).fullpath || file.webkitRelativePath || file.name),
"status": 1
} as iFile);

// 直接开始上传
const id = (parent.child as Array<FileOrDir>).push(file_element);
try {
onCreate && onCreate(file_element);
await FS.write(
file_element.path,
file,
prog => file_element.status = prog.loaded / prog.total * 100
);
uploaded.push(file_element);
file_element.status = undefined;
} catch (e) {
// 删除对应元素
(parent.child as Array<FileOrDir>).splice(id - 1, 1);
// 抛出错误
Global('ui.message').call({
"title": "资源管理器",
"content": {
"title": "上传错误",
"content": "前提条件错误:目标是一个文件夹"
"content": (e as Error).message
},
"type": "error",
"timeout": 10
} satisfies MessageOpinion);
else {
// 创建一个元素
const file_element = reactive({
"ctime": Date.now(),
"icon": getIcon(file.name, true),
"name": file.name,
"path": to_fd.path + ((file as xFile).fullpath || file.webkitRelativePath),
"size": file.size,
"type": 'file',
"url": FILE_PROXY_SERVER + to_fd.path + ((file as xFile).fullpath || file.webkitRelativePath),
"status": 1
} as iFile);

// 直接开始上传
const id = (parent.child as Array<FileOrDir>).push(file_element);
try{
onCreate && onCreate(file_element);
await FS.write(
to_fd.path + ((file as xFile).fullpath || file.webkitRelativePath),
file,
prog => file_element.status = prog.loaded / prog.total * 100
);
uploaded.push(file_element);
file_element.status = undefined;
}catch(e){
// 删除对应元素
(parent.child as Array<FileOrDir>).splice(id -1, 1);
// 抛出错误
Global('ui.message').call({
"title": "资源管理器",
"content": {
"title": "上传错误",
"content": (e as Error).message
},
"type": "error",
"timeout": 10
} satisfies MessageOpinion);
}
}
}
}
Expand Down

0 comments on commit 7295c9d

Please sign in to comment.