Skip to content

Commit

Permalink
fix: upload
Browse files Browse the repository at this point in the history
  • Loading branch information
imzlh committed Oct 1, 2024
1 parent fdcc71c commit 22eef01
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 26 deletions.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@imzlh/vlist",
"version": "5.7.3",
"version": "5.8.0",
"displayName": "vList",
"description": "一个全能的现代化的文件管理UI,使用vue3",
"license": "MIT",
Expand All @@ -11,6 +11,10 @@
"file-sharing",
"media-player"
],
"repository": {
"type": "git",
"url": "https://github.com/imzlh/vList5.git"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
Expand Down
17 changes: 10 additions & 7 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,16 @@
if(locked) return;
const target = e.target as HTMLElement;
// 切换活动ID
if((target.classList.contains('item') || target.classList.contains('parent')) && target.dataset.position){
const index = target.dataset.position.lastIndexOf(':'),
tree = await FS.stat(target.dataset.position!.substring(0, index)),
id = parseInt(target.dataset.position.substring(index + 1));
current_tree = tree.type == 'dir' ? tree : tree.parent!,
current_index = id, handleUpdate(true);
}
if(target.classList.contains('item') || target.classList.contains('parent'))
if(target.dataset.position){
const index = target.dataset.position.lastIndexOf(':'),
tree = await FS.stat(target.dataset.position!.substring(0, index)),
id = parseInt(target.dataset.position.substring(index + 1));
current_tree = tree.type == 'dir' ? tree : tree.parent!,
current_index = id, handleUpdate(true);
}else{
current_tree = TREE.parent!, current_index = 0, handleUpdate(true);
}
})));
const tree_active = ref(false),
Expand Down
2 changes: 1 addition & 1 deletion src/module/tree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
@dragleave.stop="($event.currentTarget as HTMLElement).classList.remove('moving')"
@click="data.active = new Map()"
>
<template v-for="(child, id) in data.child" :key="child.path">
<template v-for="(child, id) in data.child" :key="child.path + ',' + child.ctime">

<tree v-if="child.type == 'dir'" :data="child" :data-position="data.path + ':' + id" />

Expand Down
34 changes: 17 additions & 17 deletions src/utils/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,15 @@ async function request(method: string,body: Object, json = false){
}
await request(method, body, json);
}else if(Math.floor(xhr.status / 100) != 2){
throw new Error(await xhr.text());
throw new APIError(await xhr.text(), xhr.status);
}

// 处理返回值
try{
if(json) return await xhr.json();
else return await xhr.text();
}catch{
throw new TypeError('Server Error');
throw new APIError('Server Error', 500);
}
}

Expand Down Expand Up @@ -453,11 +453,7 @@ namespace Tree{
throw new Error('Invalid object type (should be file or dir)');
}

if(preset.parent){
// 加入父节点
if(!preset.parent.child) load(preset.parent).then(() => preset.parent!.child!.push(node));
else preset.parent.child!.push(node);
}else if(import.meta.env.DEV)
if(import.meta.env.DEV && !node.parent)
console.warn('Parent node is required');
return node;
}
Expand All @@ -473,15 +469,16 @@ namespace Tree{
await request('mkdir', { files: name.map(n => parent.path + n) });
// 添加文件夹
const exports: Array<vDir> = [];
name.forEach(n => {
for(const n of name){
const obj = createObject({
type: 'dir',
name: n,
parent: parent
});
exports.push(obj);
if(!parent.child) await Tree.load(parent);
parent.child!.push(obj);
});
}
return exports;
}

Expand Down Expand Up @@ -511,7 +508,7 @@ namespace Tree{
if(!node.child) try{
await load(node);
}catch(e){
if(e instanceof APIError && e.code == 404)
if(e instanceof APIError && (e.code == 404 || e.code == 403))
throw new Error(`Directory "${path}" not found. Please refresh the cache`);
else throw e;
}
Expand All @@ -524,7 +521,7 @@ namespace Tree{
node.child!.push(nd);
node = nd;
}catch(e){
if(e instanceof APIError && e.code == 404){
if(e instanceof APIError && (e.code == 404 || e.code == 403)){
// --CODE1
if(create_on_miss)
node = (await createDir([part], node))[0];
Expand Down Expand Up @@ -584,6 +581,7 @@ async function uploadArray(files: IUploadArray, option?: IUploadOption){
size: file.size,
ctime: Date.now()
});
if(!parent.child) await Tree.load(parent);
parent.child!.push(newobj);
option?.created && option.created(newobj);
await upload(file, newobj, option);
Expand All @@ -593,7 +591,7 @@ async function uploadArray(files: IUploadArray, option?: IUploadOption){
for(const { file, path, name } of files){
try{
var node = await Tree.find(path, true, 'file', true);
}catch{
}catch(e){
failed.push({ file, path, name });
continue;
}
Expand All @@ -607,10 +605,10 @@ async function uploadArray(files: IUploadArray, option?: IUploadOption){

// 开始上传
try{
if(promises.length == option?.thread_pool || 1)
if(promises.length == (option?.thread_pool || 1))
await Promise.race(promises);
promises.push(up(file, name, node.parent));
}catch{
}catch(e){
failed.push({ file, path, name });
}
}
Expand Down Expand Up @@ -801,6 +799,7 @@ export namespace FS{
for(const [source, target] of generator()){
// 删除源
const { parent, index } = await Tree.find(source, true, 'file');
if(!parent.child) await Tree.load(parent);
const node = parent.child!.splice(index, 1)[0];

// 获取目标
Expand Down Expand Up @@ -862,6 +861,7 @@ export namespace FS{
// 删除节点
for(const each of files){
const { parent, index } = await Tree.find(each, true, 'file');
if(!parent.child) await Tree.load(parent);
parent.child!.splice(index, 1);
}
}
Expand All @@ -879,7 +879,7 @@ export namespace FS{
parent,
path: dir
});
parent.child || (Tree.load(parent))
parent.child || (await Tree.load(parent))
parent.child!.push(node);
}
}
Expand All @@ -902,7 +902,7 @@ export namespace FS{
size: 0,
ctime: Date.now()
});
parent.child || (Tree.load(parent))
parent.child || (await Tree.load(parent))
parent.child!.push(node);
}
}
Expand All @@ -922,7 +922,7 @@ export namespace FS{
size: file.type == 'file' ? file.size : undefined,
ctime: file.ctime
});
parent.child || (Tree.load(parent))
parent.child || (await Tree.load(parent))
parent.child!.push(node);
}
}
Expand Down

0 comments on commit 22eef01

Please sign in to comment.