Skip to content

Commit

Permalink
fix: error when special char in file/dir name
Browse files Browse the repository at this point in the history
  • Loading branch information
imzlh committed Oct 1, 2024
1 parent 22eef01 commit 515c32b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/opener/markdown.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts" setup>
import type { AlertOpts, MessageOpinion, vFile } from '@/env';
import Upload from '@/module/upload.vue';
import { alert, FILE_PROXY_SERVER, FS, message, splitPath } from '@/utils';
import { alert, encodePath, FILE_PROXY_SERVER, FS, message, splitPath } from '@/utils';
import {
CodeBlockLanguageSelector,
EmojiSelector,
Expand Down Expand Up @@ -214,10 +214,10 @@
prefix = '!';
if(cur) muya.editor.activeContentBlock.text =
data.substring(0, cur.start.offset) +
prefix + `[ ${data.substring(cur.start.offset, cur.end.offset +1) || meta.fname} ](${FILE_PROXY_SERVER + file} "${meta.fname}")` +
prefix + `[ ${data.substring(cur.start.offset, cur.end.offset +1) || meta.fname} ](${FILE_PROXY_SERVER + encodePath(file)} "${meta.fname}")` +
data.substring(cur.end.offset +1);
else muya.editor.activeContentBlock.text =
prefix + `[ ${data || meta.fname} ](${FILE_PROXY_SERVER + file} "${meta.fname}")`;
prefix + `[ ${data || meta.fname} ](${FILE_PROXY_SERVER + encodePath(file)} "${meta.fname}")`;
muya.editor.activeContentBlock.focusHandler();
muya.focus();
}
Expand Down
4 changes: 2 additions & 2 deletions src/opener/vlite.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { vFile } from '@/env';
import { regSelf } from '@/opener';
import parseCue from './media/cue';
import { acceptDrag, FILE_PROXY_SERVER, FS, message, splitPath } from '@/utils';
import { acceptDrag, encodePath, FILE_PROXY_SERVER, FS, message, splitPath } from '@/utils';
import { Lrc, Runner, type Lyric } from 'lrc-kit';
import MediaSession, { updateMediaSession } from './media/mediaSession';
import { computed, nextTick, onMounted, onUnmounted, ref, shallowReactive, watch } from 'vue';
Expand Down Expand Up @@ -423,7 +423,7 @@
"album": element.album,
"composer": element.performer,
"path": item.path,
"url": FILE_PROXY_SERVER + finfo.dir + '/' + element.file,
"url": FILE_PROXY_SERVER + encodePath(finfo.dir + '/' + element.file),
"start": element.start,
"match_name": splitPath({path: element.file}).name
}));
Expand Down
11 changes: 7 additions & 4 deletions src/utils/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ async function upload(file: Blob, refl: vFile, option?: {
}
const upload_ = upload;

export const encodePath = (path: string) =>
encodeURI(path).replace('#', '%23').replace('?', '%3F');

namespace Tree{
/**
* 加载文件夹
Expand Down Expand Up @@ -364,7 +367,7 @@ namespace Tree{
function compileObject(obj: FileOrDir, parent: vDir){
obj.parent = parent;
obj.path = parent.path + obj.name + (obj.type == 'dir' ? '/' : '');
obj.url = FILE_PROXY_SERVER + obj.path;
obj.url = FILE_PROXY_SERVER + encodePath(obj.path);
obj.parent = parent;
obj.type == 'dir' && (obj.active = new Map());
obj.icon = getIcon(obj.name, obj.type == 'file');
Expand Down Expand Up @@ -426,7 +429,7 @@ namespace Tree{
const path = preset.path ?? (preset.parent
? preset.parent.path + preset.name + (preset.type == 'dir' ? '/' : '')
: ''),
url = path ? FILE_PROXY_SERVER + path : '';
url = path ? FILE_PROXY_SERVER + encodePath(path) : '';
if(preset.type == 'dir'){
var node: FileOrDir = reactive<vDir>({
ctime: 0,
Expand Down Expand Up @@ -814,8 +817,8 @@ export namespace FS{
: tarobj.parent.child!.unshift(node);

// 修改目标
node.path = target;
node.url = FILE_PROXY_SERVER + clearPath(target);
node.path = clearPath(target);
node.url = FILE_PROXY_SERVER + encodePath(node.path);
node.parent = tarobj.parent;
node.type == 'file' && (node.icon = getIcon(node.name, true));
node.type == 'dir' && (node.active = new Map(), node.child = []);
Expand Down

0 comments on commit 515c32b

Please sign in to comment.