diff --git a/plugins/explorer/client/file-picker.vue b/plugins/explorer/client/file-picker.vue index e1bda9fd..b1dfa891 100644 --- a/plugins/explorer/client/file-picker.vue +++ b/plugins/explorer/client/file-picker.vue @@ -88,7 +88,7 @@ const entries = computed(() => { const { filters } = options.value return children.filter((entry) => { if (entry.type === 'directory') return true - if (entry.type === 'file') { + if (entry.type === 'file' || entry.type === 'symlink') { if (filters.includes('file')) return true return filters.some((filter) => { const index = entry.name.lastIndexOf('.') diff --git a/plugins/explorer/client/icons/directory.vue b/plugins/explorer/client/icons/directory.vue index 502fcef5..d0dddc5f 100644 --- a/plugins/explorer/client/icons/directory.vue +++ b/plugins/explorer/client/icons/directory.vue @@ -1,5 +1,5 @@ diff --git a/plugins/explorer/client/icons/file.vue b/plugins/explorer/client/icons/file.vue index c923bd4e..bd5caf15 100644 --- a/plugins/explorer/client/icons/file.vue +++ b/plugins/explorer/client/icons/file.vue @@ -1,5 +1,5 @@ diff --git a/plugins/explorer/client/icons/index.ts b/plugins/explorer/client/icons/index.ts index 5394af51..657acea1 100644 --- a/plugins/explorer/client/icons/index.ts +++ b/plugins/explorer/client/icons/index.ts @@ -4,9 +4,11 @@ import Directory from './directory.vue' import File from './file.vue' import Refresh from './refresh.vue' import Save from './save.vue' +import Symlink from './symlink.vue' icons.register('activity:explorer', Activity) icons.register('directory', Directory) icons.register('file', File) icons.register('refresh', Refresh) icons.register('save', Save) +icons.register('symlink', Symlink) diff --git a/plugins/explorer/client/icons/symlink.vue b/plugins/explorer/client/icons/symlink.vue new file mode 100644 index 00000000..7259187e --- /dev/null +++ b/plugins/explorer/client/icons/symlink.vue @@ -0,0 +1,5 @@ + diff --git a/plugins/explorer/client/index.vue b/plugins/explorer/client/index.vue index d55fd47d..0d7436ec 100644 --- a/plugins/explorer/client/index.vue +++ b/plugins/explorer/client/index.vue @@ -46,7 +46,7 @@ - 在左侧栏选择要查看的文件 + 在左侧栏选择要查看的文件
@@ -130,7 +130,7 @@ ctx.action('explorer.tree.upload', { }) ctx.action('explorer.tree.download', { - disabled: ({ explorer }) => explorer.tree.type !== 'file', + disabled: ({ explorer }) => explorer.tree.type === 'directory', action: ({ explorer }) => downloadFile(explorer.tree.filename), }) @@ -224,7 +224,7 @@ function filterNode(value: string, data: TreeEntry) { return data.name.toLowerCase().includes(keyword.value.toLowerCase()) } -function createEntry(entry: TreeEntry, type: 'file' | 'directory') { +function createEntry(entry: TreeEntry, type: 'file' | 'symlink' | 'directory') { cancelRename() renaming.value = entry.filename + '/' files[renaming.value] = { @@ -311,7 +311,7 @@ function getLanguage(filename: string) { } watch(() => files[active.value], async (entry) => { - if (entry?.type !== 'file') return + if (!entry || entry.type === 'directory') return if (typeof entry.oldValue !== 'string') { entry.loading = send('explorer/read', entry.filename) const { base64, mime } = await entry.loading @@ -334,7 +334,7 @@ model.onDidChangeContent((e) => { }) async function handleClick(data: TreeEntry) { - if (data.type !== 'file') return + if (data.type === 'directory') return active.value = data.filename } diff --git a/plugins/explorer/src/index.ts b/plugins/explorer/src/index.ts index 7a400f05..340563fe 100644 --- a/plugins/explorer/src/index.ts +++ b/plugins/explorer/src/index.ts @@ -1,7 +1,7 @@ import { Context, Schema } from 'koishi' import { DataService } from '@koishijs/console' import { join, relative, resolve } from 'path' -import { mkdir, readdir, readFile, rename, rm, writeFile } from 'fs/promises' +import { mkdir, readdir, readFile, readlink, rename, rm, writeFile } from 'fs/promises' import { FSWatcher, watch } from 'chokidar' import { detect } from 'chardet' import FileType from 'file-type' @@ -32,9 +32,10 @@ export interface File { } export interface Entry { - type: 'file' | 'directory' + type: 'file' | 'directory' | 'symlink' name: string mime?: string + target?: string filename?: string children?: this[] oldValue?: string @@ -128,6 +129,8 @@ class Explorer extends DataService { return { type: 'file', name: dirent.name } } else if (dirent.isDirectory()) { return { type: 'directory', name: dirent.name, children: await this.traverse(filename) } + } else if (dirent.isSymbolicLink()) { + return { type: 'symlink', name: dirent.name, target: await readlink(filename) } } })).then((entries) => entries .filter(Boolean) @@ -158,7 +161,7 @@ namespace Explorer { ignored: Schema .array(String) .role('table') - .default(['**/node_modules', '**/.*', 'data/accounts/*/data', 'cache']), + .default(['**/node_modules', '**/.*', 'cache']), }).i18n({ 'zh-CN': zhCN, })