diff --git a/package.json b/package.json index 773f364..4b34f23 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "aes-js": "^3.1.2", "axios": "^1.7.3", "codemirror": "^6.0.1", + "copy-to-clipboard": "^3.3.3", "lodash": "^4.17.21", "markdown-it": "^14.1.0", "naive-ui": "^2.39.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3c8726e..1e8a8c2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -53,6 +53,9 @@ importers: codemirror: specifier: ^6.0.1 version: 6.0.1(@lezer/common@1.2.1) + copy-to-clipboard: + specifier: ^3.3.3 + version: 3.3.3 lodash: specifier: ^4.17.21 version: 4.17.21 @@ -672,6 +675,9 @@ packages: console-control-strings@1.1.0: resolution: {integrity: sha512-ty/fTekppD2fIwRvnZAVdeOiGd1c7YXEixbgJTNzqcxJWKQnjJ/V1bNEEE6hygpM3WjwHFUVK6HTjWSzV4a8sQ==} + copy-to-clipboard@3.3.3: + resolution: {integrity: sha512-2KV8NhB5JqC3ky0r9PMCAZKbUHSwtEo4CwCs0KXgruG43gX5PMqDEBbVU4OUzw2MuAWUfsuFmWvEKG5QRfSnJA==} + core-js@3.38.1: resolution: {integrity: sha512-OP35aUorbU3Zvlx7pjsFdu1rGNnD4pgw/CWoYzRY3t2EzoVT7shKHY1dlAy3f41cGIO7ZDPQimhGFTlEYkG/Hw==} @@ -1103,6 +1109,9 @@ packages: resolution: {integrity: sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==} engines: {node: '>=8.0'} + toggle-selection@1.0.6: + resolution: {integrity: sha512-BiZS+C1OS8g/q2RRbJmy59xpyghNBqrr6k5L/uKBGRsTfxmu3ffiRnd8mlGPUVayg8pvfi5urfnu8TU7DVOkLQ==} + tr46@0.0.3: resolution: {integrity: sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==} @@ -1877,6 +1886,10 @@ snapshots: console-control-strings@1.1.0: optional: true + copy-to-clipboard@3.3.3: + dependencies: + toggle-selection: 1.0.6 + core-js@3.38.1: {} crelt@1.0.6: {} @@ -2371,6 +2384,8 @@ snapshots: dependencies: is-number: 7.0.0 + toggle-selection@1.0.6: {} + tr46@0.0.3: optional: true diff --git a/src/class/PluginCenter.ts b/src/class/PluginCenter.ts index 499a4ee..b8f05d0 100644 --- a/src/class/PluginCenter.ts +++ b/src/class/PluginCenter.ts @@ -1,7 +1,7 @@ import useVirtualPages from "@/hooks/useVirtualPages"; import VirtualDirectory, { VirtualFile } from "./VirtualDirectory"; import { ShallowRef, shallowRef } from "vue"; -import { alertTipType } from "@/types/type"; +import { alertTipType, usePluginHooksType } from "@/types/type"; export enum PluginGroup { default = "default", @@ -19,7 +19,7 @@ export interface registerComponentOption { exitConfirm?: boolean; } -type Plugin = { +export type Plugin = { // 用于显示的名字 name: string; // 代表插件的icon @@ -31,7 +31,12 @@ type Plugin = { // 判断在未禁用时是否可以使用这个组件 // 使用组件即调用下面的func filter: (VDirectories: VirtualDirectory[], VFiles: VirtualFile[]) => boolean; - func: (VDirectories: VirtualDirectory[], VFiles: VirtualFile[], ...args: any[]) => void; + func: ( + VDirectories: VirtualDirectory[], + VFiles: VirtualFile[], + hooks: usePluginHooksType, + ...args: any[] + ) => void; }; export default class PluginCenter { @@ -107,6 +112,8 @@ export default class PluginCenter { } usePlugin(key: string, VDirectories?: VirtualDirectory[], VFiles?: VirtualFile[], ...args: any[]) { - this.pluginsMap[key].func(VDirectories ?? [], VFiles ?? [], ...args); + this.pluginsMap[key].func(VDirectories ?? [], VFiles ?? [], { + globalAlertTip: this.globalAlertTip + }, ...args); } } diff --git a/src/hooks/init/initPlugin.ts b/src/hooks/init/initPlugin.ts index 64f8f7f..ee7c274 100644 --- a/src/hooks/init/initPlugin.ts +++ b/src/hooks/init/initPlugin.ts @@ -1,6 +1,6 @@ import usePluginCenter, { initPluginCenter } from "@/hooks/usePluginCenter"; -import { registerComponentOption } from "@/class/PluginCenter"; -import { alertTipType } from "@/types/type"; +import { Plugin, registerComponentOption } from "@/class/PluginCenter"; +import { alertTipType, PluginExportType } from "@/types/type"; const initPlugin = async (globalAlertTip: alertTipType) => { initPluginCenter(globalAlertTip) @@ -11,9 +11,18 @@ const initPlugin = async (globalAlertTip: alertTipType) => { promiseArray.push( new Promise(async resolve => { const _config = pluginConfig as () => Promise<{ - default: registerComponentOption; + default: registerComponentOption | Plugin; + type: PluginExportType + key?: string }>; - resolve(pluginCenter.registerComponent((await _config()).default)); + const {type, key} = await _config() + if(type === PluginExportType.component) { + // @ts-ignore + resolve(pluginCenter.registerComponent((await _config()).default)); + } else if (type === PluginExportType.default) { + // @ts-ignore + resolve(pluginCenter.register(key as string, (await _config()).default)); + } }) ); } diff --git a/src/plugins/copyFileUrl2Clipboard/copy.ts b/src/plugins/copyFileUrl2Clipboard/copy.ts new file mode 100644 index 0000000..bf6916d --- /dev/null +++ b/src/plugins/copyFileUrl2Clipboard/copy.ts @@ -0,0 +1,16 @@ +import { VirtualFile } from "@/class/VirtualDirectory" +import config from "@/config" +import { usePluginHooksType } from "@/types/type" +import copy2Clipboard from 'copy-to-clipboard' + +const copy = (__: any, vFiles: VirtualFile[], hooks: usePluginHooksType) => { + const { globalAlertTip } = hooks + const vFile = vFiles[0] + console.log(vFile.url) + copy2Clipboard(`${config.baseUrl}${vFile.url}`) + globalAlertTip(`${vFile.name}的链接已复制至剪切板`, { + type: 'info', + timeout: 2000 + }) +} +export default copy \ No newline at end of file diff --git a/src/plugins/copyFileUrl2Clipboard/export.ts b/src/plugins/copyFileUrl2Clipboard/export.ts new file mode 100644 index 0000000..a5f0fb0 --- /dev/null +++ b/src/plugins/copyFileUrl2Clipboard/export.ts @@ -0,0 +1,26 @@ +import { Plugin, PluginGroup } from "@/class/PluginCenter"; +import Copy from "./copy"; +import { CopyOutline } from "@vicons/ionicons5"; +import { PluginExportType } from "@/types/type"; +import { shallowRef } from "vue"; + +const pluginConfig: Plugin = { + name: "复制链接", + icon: shallowRef(CopyOutline), + filter: (vDirs, vFiles) => { + if (vDirs.length !== 0) { + return false; + } + if (vFiles.length !== 1) { + return false; + } + return true; + }, + disable: false, + group: [PluginGroup.default], + func: Copy +}; + +export default pluginConfig; + +export const type = PluginExportType.default; diff --git a/src/plugins/miaoCodeMirror/export.ts b/src/plugins/miaoCodeMirror/export.ts index b58e0a6..5cb254f 100644 --- a/src/plugins/miaoCodeMirror/export.ts +++ b/src/plugins/miaoCodeMirror/export.ts @@ -1,5 +1,6 @@ import { registerComponentOption } from '@/class/PluginCenter' import { CodeOutline } from '@vicons/ionicons5' +import { PluginExportType } from '@/types/type' const pluginConfig: registerComponentOption = { key: 'miaoCodeMirror', @@ -40,3 +41,5 @@ const pluginConfig: registerComponentOption = { } export default pluginConfig + +export const type = PluginExportType.component \ No newline at end of file diff --git a/src/plugins/miaoCrypto/export.ts b/src/plugins/miaoCrypto/export.ts index a8685cc..477b74e 100644 --- a/src/plugins/miaoCrypto/export.ts +++ b/src/plugins/miaoCrypto/export.ts @@ -1,5 +1,6 @@ // @ts-nocheck import { registerComponentOption } from '@/class/PluginCenter' +import { PluginExportType } from '@/types/type' const pluginConfig: registerComponentOption = { key: 'miaoCrypto', @@ -16,6 +17,9 @@ const pluginConfig: registerComponentOption = { } return vFiles[0].name.endsWith('txt') }, + disable: true, } export default pluginConfig + +export const type = PluginExportType.component \ No newline at end of file diff --git a/src/plugins/miaoCrypto/miaoCrypto.vue b/src/plugins/miaoCrypto/miaoCrypto.vue index df7249b..6140fa3 100644 --- a/src/plugins/miaoCrypto/miaoCrypto.vue +++ b/src/plugins/miaoCrypto/miaoCrypto.vue @@ -2,6 +2,7 @@
+
+
@@ -38,7 +39,7 @@ const miaoFetchApi = useMiaoFetchApi() interface workItem { id: number - status: 'wait' | 'process' | 'finish' + status: 'wait' | 'process' | 'finish' | 'error' buffer?: Uint8Array getBuffer: () => Promise getBufferProgress: number @@ -68,8 +69,12 @@ class Work { return } currentItem.status = 'process' - currentItem.buffer = await this.func(key.value, currentItem.buffer) - currentItem.status = 'finish' + try { + currentItem.buffer = await this.func(key.value, currentItem.buffer) + currentItem.status = 'finish' + } catch (e) { + currentItem.status = 'error' + } this.funcLoop() } async getBufferLoop() { @@ -81,7 +86,11 @@ class Work { } const item = _list[0] item.isGettingBuffer = true - item.buffer = await item.getBuffer() + try { + item.buffer = await item.getBuffer() + } catch(e) { + item.status = 'error' + } item.isGettingBuffer = false this.funcLoop() this.getBufferLoop() @@ -139,7 +148,7 @@ onMounted(() => { onUnmounted(() => { encryptWork.abortLoop = true - encryptWork.queue.forEach(item=>{ + encryptWork.queue.forEach(item => { item.getBufferAbort && item.getBufferAbort() }) }) diff --git a/src/plugins/miaoDirectory/export.ts b/src/plugins/miaoDirectory/export.ts index eb0cb02..5563d08 100644 --- a/src/plugins/miaoDirectory/export.ts +++ b/src/plugins/miaoDirectory/export.ts @@ -17,3 +17,7 @@ const pluginConfig: registerComponentOption = { } export default pluginConfig + + +import { PluginExportType } from '@/types/type' +export const type = PluginExportType.component \ No newline at end of file diff --git a/src/plugins/miaoIframe/export.ts b/src/plugins/miaoIframe/export.ts index b0beef6..df12505 100644 --- a/src/plugins/miaoIframe/export.ts +++ b/src/plugins/miaoIframe/export.ts @@ -18,4 +18,8 @@ const pluginConfig: registerComponentOption = { } } -export default pluginConfig \ No newline at end of file +export default pluginConfig + + +import { PluginExportType } from '@/types/type' +export const type = PluginExportType.component \ No newline at end of file diff --git a/src/plugins/miaoImages/export.ts b/src/plugins/miaoImages/export.ts index 7d9dd04..ad1ae1c 100644 --- a/src/plugins/miaoImages/export.ts +++ b/src/plugins/miaoImages/export.ts @@ -43,3 +43,7 @@ const pluginConfig: registerComponentOption = { } export default pluginConfig + + +import { PluginExportType } from '@/types/type' +export const type = PluginExportType.component \ No newline at end of file diff --git a/src/plugins/miaoMarkdown/export.ts b/src/plugins/miaoMarkdown/export.ts index f5df472..51f358f 100644 --- a/src/plugins/miaoMarkdown/export.ts +++ b/src/plugins/miaoMarkdown/export.ts @@ -19,3 +19,7 @@ const pluginConfig: registerComponentOption = { } export default pluginConfig + + +import { PluginExportType } from '@/types/type' +export const type = PluginExportType.component \ No newline at end of file diff --git a/src/plugins/miaoPDF/export.ts b/src/plugins/miaoPDF/export.ts index 0325a88..a5cdfb6 100644 --- a/src/plugins/miaoPDF/export.ts +++ b/src/plugins/miaoPDF/export.ts @@ -19,3 +19,7 @@ const pluginConfig: registerComponentOption = { } export default pluginConfig + + +import { PluginExportType } from '@/types/type' +export const type = PluginExportType.component \ No newline at end of file diff --git a/src/plugins/miaoPluginTemplate/_export.ts b/src/plugins/miaoPluginTemplate/_export.ts index dc57b94..b0715e6 100644 --- a/src/plugins/miaoPluginTemplate/_export.ts +++ b/src/plugins/miaoPluginTemplate/_export.ts @@ -20,3 +20,7 @@ const pluginConfig: registerComponentOption = { } export default pluginConfig + + +import { PluginExportType } from '@/types/type' +export const type = PluginExportType.component \ No newline at end of file diff --git a/src/plugins/miaoVideoPlayer/export.ts b/src/plugins/miaoVideoPlayer/export.ts index e24d4e5..e6b27c4 100644 --- a/src/plugins/miaoVideoPlayer/export.ts +++ b/src/plugins/miaoVideoPlayer/export.ts @@ -26,3 +26,7 @@ const pluginConfig: registerComponentOption = { } export default pluginConfig + + +import { PluginExportType } from '@/types/type' +export const type = PluginExportType.component \ No newline at end of file diff --git a/src/types/type.ts b/src/types/type.ts index 2934764..fcc08fa 100644 --- a/src/types/type.ts +++ b/src/types/type.ts @@ -27,4 +27,13 @@ export interface AlertTipMessageOptions { type?: 'info' | 'success' | 'error' timeout?: number id?: number +} + +export enum PluginExportType { + default = 'default', + component = 'component' +} + +export interface usePluginHooksType { + globalAlertTip: alertTipType; } \ No newline at end of file