@xiaou66/picture-plugin 0.0.53 → 0.0.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +31 -22
- package/dist/index.es.js.map +1 -1
- package/dist/src/flowNode/FlowNodePlugin.d.ts +63 -3
- package/dist/src/utils/FlowUtils.d.ts +11 -0
- package/dist/src/utils/index.d.ts +2 -0
- package/dist/src/utils/utils.d.ts +10 -0
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(e){let t=e;return t.pluginInfo.pluginType=`storage`,t}const t=[{label:`年`,value:`{YY}`,demo:()=>new Date().getFullYear().toString(),format:e=>new Date().getFullYear().toString()},{label:`年`,value:`{Y}`,demo:()=>new Date().getFullYear().toString().substring(2),format:e=>new Date().getFullYear().toString().substring(2)},{label:`月`,value:`{M}`,demo:()=>(new Date().getMonth()+1).toString().padStart(2,`0`),format:e=>(new Date().getMonth()+1).toString().padStart(2,`0`)},{label:`日`,value:`{D}`,demo:()=>new Date().getDate().toString().padStart(2,`0`),format:e=>new Date().getDate().toString().padStart(2,`0`)},{label:`时`,value:`{h}`,demo:()=>new Date().getHours().toString().padStart(2,`0`),format:e=>new Date().getHours().toString().padStart(2,`0`)},{label:`分`,value:`{m}`,demo:()=>new Date().getMinutes().toString().padStart(2,`0`),format:e=>new Date().getMinutes().toString().padStart(2,`0`)},{label:`秒`,value:`{s}`,demo:()=>new Date().getSeconds().toString().padStart(2,`0`),format:()=>new Date().getSeconds().toString().padStart(2,`0`)},{label:`毫秒`,value:`{ss}`,demo:()=>new Date().getMilliseconds().toString().padStart(3,`0`),format:e=>new Date().getMilliseconds().toString().padStart(3,`0`)},{label:`时间戳`,value:`{timestamp}`,width:300,demo:()=>Date.now(),format:e=>Date.now().toString()},{label:`文件名称`,value:`{filename}`,width:200,demo:()=>`文本`,format:e=>e.fileName},{label:`后缀`,value:`{suffix}`,width:200,demo:()=>`txt`,format:e=>e.suffix},{label:`全文件名`,value:`{allFilename}`,width:300,demo:()=>`文本.txt`,format:e=>e.allFileName},{label:`场景名称`,value:`{sceneName}`,width:300,demo:()=>`测试场景`,format:e=>e.sceneName||``},{label:`随机字符串`,value:`{rand(5)}`,width:300,demo:()=>n(5),format:e=>n(5)}];function n(e){let t=``;for(let n=0;n<e;n++)t+=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`.charAt(Math.floor(Math.random()*62));return t}function r(e,r){return console.log(`filePathFormat`,e,r),t.forEach(t=>{let n=t.format(r)||``,i=new RegExp(t.value,`g`);e=e.replace(i,n)}),e=e.replace(/\{rand\((\d+)\)\}/g,(e,t)=>n(parseInt(t,10))),e}
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(e){let t=e;return t.pluginInfo.pluginType=`storage`,t}const t=[{label:`年`,value:`{YY}`,demo:()=>new Date().getFullYear().toString(),format:e=>new Date().getFullYear().toString()},{label:`年`,value:`{Y}`,demo:()=>new Date().getFullYear().toString().substring(2),format:e=>new Date().getFullYear().toString().substring(2)},{label:`月`,value:`{M}`,demo:()=>(new Date().getMonth()+1).toString().padStart(2,`0`),format:e=>(new Date().getMonth()+1).toString().padStart(2,`0`)},{label:`日`,value:`{D}`,demo:()=>new Date().getDate().toString().padStart(2,`0`),format:e=>new Date().getDate().toString().padStart(2,`0`)},{label:`时`,value:`{h}`,demo:()=>new Date().getHours().toString().padStart(2,`0`),format:e=>new Date().getHours().toString().padStart(2,`0`)},{label:`分`,value:`{m}`,demo:()=>new Date().getMinutes().toString().padStart(2,`0`),format:e=>new Date().getMinutes().toString().padStart(2,`0`)},{label:`秒`,value:`{s}`,demo:()=>new Date().getSeconds().toString().padStart(2,`0`),format:()=>new Date().getSeconds().toString().padStart(2,`0`)},{label:`毫秒`,value:`{ss}`,demo:()=>new Date().getMilliseconds().toString().padStart(3,`0`),format:e=>new Date().getMilliseconds().toString().padStart(3,`0`)},{label:`时间戳`,value:`{timestamp}`,width:300,demo:()=>Date.now(),format:e=>Date.now().toString()},{label:`文件名称`,value:`{filename}`,width:200,demo:()=>`文本`,format:e=>e.fileName},{label:`后缀`,value:`{suffix}`,width:200,demo:()=>`txt`,format:e=>e.suffix},{label:`全文件名`,value:`{allFilename}`,width:300,demo:()=>`文本.txt`,format:e=>e.allFileName},{label:`场景名称`,value:`{sceneName}`,width:300,demo:()=>`测试场景`,format:e=>e.sceneName||``},{label:`随机字符串`,value:`{rand(5)}`,width:300,demo:()=>n(5),format:e=>n(5)}];function n(e){let t=``;for(let n=0;n<e;n++)t+=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`.charAt(Math.floor(Math.random()*62));return t}function r(e,r){return console.log(`filePathFormat`,e,r),t.forEach(t=>{let n=t.format(r)||``,i=new RegExp(t.value,`g`);e=e.replace(i,n)}),e=e.replace(/\{rand\((\d+)\)\}/g,(e,t)=>n(parseInt(t,10))),e}function i(e,t){let n=e.uploadFile;if(!window.fs.existsSync(tempPath))throw Error(`replaceUploadFile--文件不存在--`+t);n.tempFile=!0,n.filePath=window.path.join(utools.getPath(`downloads`),`test.webp`),n.fileName=window.path.basename(tempPath),n.fileSize=window.fs.statSync(tempPath).size}function a(){return utools.dbStorage.getItem(`settingUserStore/localAppData/${utools.getNativeId()}`)||window.path.join(utools.getPath(`userData`),`app`,`picture-bed-plus`,`temps`)}var o=class{init(){this.doInit()}destroy(){this.doDestroy()}deleteFile(e){return Promise.resolve(!1)}formatUploadPath(e,t){return r(e,t)}extractImagePath(e){try{return new URL(e).pathname}catch{let t=e.match(/https?:\/\/[^\/]+(\/.*)/);return t?t[1]:``}}verifyConfig(e){return Promise.resolve(void 0)}readConfig(e){let t=`storageSource/${e}`;return utools.dbCryptoStorage.getItem(t)}saveConfig(e,t){let n=`storageSource/${e}`;utools.dbCryptoStorage.setItem(n,t)}uninstall(){}};const s={storage:{name:`存储`,icon:`i-u-cloud-storage`},flowNode:{name:`流程`,icon:`i-u-flow`}};function c(e){let t=e;return t.pluginInfo.pluginType=`flowNode`,t}var l=class{};function u(e){return e}exports.FlowNodePlugin=l,exports.StoragePlugin=o,exports.createFlowNodeActions=u,exports.createFlowNodePluginConfig=c,exports.createStoragePluginConfig=e,exports.filePathFormat=r,exports.getDataTempSavePath=a,exports.pluginTypeDict=s,exports.replaceUploadFile=i,exports.stringVariable=t;
|
|
2
2
|
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","names":["pluginTypeDict: Record<PluginType, Record<string, string>>"],"sources":["../src/storage/StoragePluginConfig.ts","../src/utils/StrTemplateUtils.ts","../src/storage/StoragePlugin.ts","../src/core/PluginInfo.ts","../src/flowNode/FlowNodePlugin.ts"],"sourcesContent":["// 从 types 包导入并重新导出\nexport type {\n StorageUIFormElement,\n StorageUIConfig,\n StoragePluginInfo,\n StoragePluginConfig,\n} from '@xiaou66/picture-types'\n\nimport type { StoragePluginConfig, StoragePluginInfo } from '@xiaou66/picture-types'\n\n/**\n * 存储插件配置\n * @param config\n */\nexport function createStoragePluginConfig(config: Omit<StoragePluginConfig, 'pluginInfo'> & { pluginInfo: Omit<StoragePluginInfo, 'pluginType'> }): StoragePluginConfig {\n const newConfig = config as StoragePluginConfig\n newConfig.pluginInfo.pluginType = 'storage';\n return newConfig;\n}\n","import { IUploadFileParams } from '../storage'\n\n\nexport const stringVariable = [\n {\n label: '年',\n value: '{YY}',\n demo: () => {\n return new Date().getFullYear().toString();\n },\n format: (obj: IUploadFileParams) => {\n return new Date().getFullYear().toString();\n }\n },\n {\n label: '年',\n value: '{Y}',\n demo: () => {\n return new Date().getFullYear().toString().substring(2);\n },\n format: (obj: IUploadFileParams) => {\n return new Date().getFullYear().toString().substring(2);\n }\n },\n {\n label: '月',\n value: '{M}',\n demo: () => {\n return (new Date().getMonth() + 1).toString().padStart(2, '0');\n },\n format: (obj: IUploadFileParams) => {\n return (new Date().getMonth() + 1).toString().padStart(2, '0');\n }\n },\n {\n label: '日',\n value: '{D}',\n demo: () => {\n return (new Date().getDate()).toString().padStart(2, '0');\n },\n format: (obj: IUploadFileParams) => {\n return (new Date().getDate()).toString().padStart(2, '0');\n }\n },\n {\n label: '时',\n value: '{h}',\n demo: () => {\n return new Date().getHours().toString().padStart(2, '0');\n },\n format: (obj: IUploadFileParams) => {\n return new Date().getHours().toString().padStart(2, '0');\n }\n },\n {\n label: '分',\n value: '{m}',\n demo: () => {\n return new Date().getMinutes().toString().padStart(2, '0');\n },\n format: (obj: IUploadFileParams) => {\n return new Date().getMinutes().toString().padStart(2, '0');\n }\n },\n {\n label: '秒',\n value: '{s}',\n demo: () => {\n return new Date().getSeconds().toString().padStart(2, '0');\n },\n format: () => {\n return new Date().getSeconds().toString().padStart(2, '0');\n }\n },\n {\n label: '毫秒',\n value: '{ss}',\n demo: () => {\n return new Date().getMilliseconds().toString().padStart(3, '0');\n },\n format: (obj: IUploadFileParams) => {\n return new Date().getMilliseconds().toString().padStart(3, '0');\n }\n },\n {\n label: '时间戳',\n value: '{timestamp}',\n width: 300,\n demo: () => {\n return Date.now();\n },\n format: (obj: IUploadFileParams) => {\n return Date.now().toString();\n }\n },\n {\n label: '文件名称',\n value: '{filename}',\n width: 200,\n demo: () => {\n return '文本';\n },\n format: (obj: IUploadFileParams) => {\n return obj.fileName;\n }\n },\n {\n label: '后缀',\n value: '{suffix}',\n width: 200,\n demo: () => {\n return 'txt';\n },\n format: (obj: IUploadFileParams) => {\n return obj.suffix;\n }\n },\n {\n label: '全文件名',\n value: '{allFilename}',\n width: 300,\n demo: () => {\n return '文本.txt';\n },\n format: (obj: IUploadFileParams) => {\n return obj.allFileName;\n }\n },\n {\n label: '场景名称',\n value: '{sceneName}',\n width: 300,\n demo: () => {\n return '测试场景';\n },\n format: (obj: IUploadFileParams) => {\n return obj.sceneName || '';\n }\n },\n {\n label: '随机字符串',\n value: '{rand(5)}',\n width: 300,\n demo: () => {\n return generateRandomString(5);\n },\n format: (obj: IUploadFileParams) => {\n return generateRandomString(5);\n }\n },\n];\n\n// 生成指定长度的随机字符串\nfunction generateRandomString(length: number): string {\n const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';\n let result = '';\n for (let i = 0; i < length; i++) {\n result += chars.charAt(Math.floor(Math.random() * chars.length));\n }\n return result;\n}\nexport function filePathFormat(str: string, obj: IUploadFileParams): string {\n console.log('filePathFormat', str, obj)\n stringVariable.forEach(variable => {\n // 获取变量的值\n const value = variable.format(obj) || '';\n // 使用正则表达式替换所有匹配的变量\n const regex = new RegExp(variable.value, 'g'); // 'g' 标志表示全局替换\n str = str.replace(regex, value);\n });\n\n // 处理动态变量 {rand(n)}\n const randRegex = /\\{rand\\((\\d+)\\)\\}/g;\n str = str.replace(randRegex, (match, p1) => {\n const length = parseInt(p1, 10);\n return generateRandomString(length);\n });\n\n return str;\n}\n","import type { IDeleteFileParams, IUploadFileParams, IUploadFileResult, UploadFileOptions } from '@xiaou66/picture-types'\nimport { filePathFormat } from '../utils'\n\n// 重新导出 UploadFileOptions\nexport type { UploadFileOptions } from '@xiaou66/picture-types'\n\n\n/**\n * 插件接口\n */\ninterface IStoragePlugin {\n\n /**\n * 插件初始化调用\n */\n init(errorCallback: ErrorCallbackType): void;\n\n /**\n * 插件销毁调用\n */\n destroy(): void;\n}\n\n\ntype ErrorCallbackType = (name: string, action: string, error: Error) => void;\n\n\n/**\n * 存储插件\n */\nexport abstract class StoragePlugin<C = any, E = any> implements IStoragePlugin {\n\n init(): void {\n this.doInit()\n }\n\n /**\n * 初始化使用 <br/>\n * constructor 方法之后调用, 在第一次使用前调用\n * @protected\n */\n protected abstract doInit(): void\n\n destroy() {\n this.doDestroy()\n }\n\n /**\n * 插件销毁调用, 用于销毁资源\n * @protected\n */\n protected abstract doDestroy(): void\n\n\n /**\n * 上传文件\n * @param params 参数\n * @param options 上传可选参数\n */\n abstract uploadFile(params: IUploadFileParams, options?: UploadFileOptions): Promise<IUploadFileResult<E>>\n\n\n /**\n * 删除文件 <br/>\n * 如果要实现删除文件请实现这个接口\n * @param params 参数\n */\n public deleteFile(params: IDeleteFileParams<E>): Promise<boolean> {\n return Promise.resolve(false);\n }\n\n /**\n * 格式化上传路径\n * @param templateStr 模版路径\n * @param params 上传参数\n * @protected\n */\n protected formatUploadPath(templateStr: string, params: IUploadFileParams) {\n return filePathFormat(templateStr, params);\n }\n\n /**\n * 从 URL 中提取路径\n * @param url 完整的图片 URL\n * @returns 图片路径\n */\n protected extractImagePath(url: string): string {\n try {\n const urlObj = new URL(url);\n return urlObj.pathname;\n } catch (error) {\n // 如果 URL 解析失败,尝试使用正则表达式\n const matches = url.match(/https?:\\/\\/[^\\/]+(\\/.*)/);\n return matches ? matches[1] : '';\n }\n }\n\n\n /**\n * 校验配置 <br/>\n * 如果不通过抛出异常\n * @param config\n * @protected\n */\n public verifyConfig(config: C): Promise<void> {\n return Promise.resolve(undefined);\n }\n\n protected readConfig(storageId: string): C {\n const key = `storageSource/${storageId}`\n return utools.dbCryptoStorage.getItem(key)\n }\n\n protected saveConfig(storageId: string, config: C): void {\n const key = `storageSource/${storageId}`;\n utools.dbCryptoStorage.setItem(key, config);\n }\n\n /**\n * 插件被卸载\n */\n uninstall() {\n\n }\n}\n","// 从 types 包导入并重新导出\nexport type { PluginType, PluginInfo, PluginConfig } from '@xiaou66/picture-types'\nimport type { PluginType } from '@xiaou66/picture-types'\n\n// @unocss-include\nexport const pluginTypeDict: Record<PluginType, Record<string, string>> = {\n 'storage': {\n name: '存储',\n icon: 'i-u-cloud-storage',\n },\n 'flowNode': {\n name: '流程',\n icon: 'i-u-flow'\n },\n}\n","// 从 types 包导入并重新导出\nexport type {\n FlowNodePluginInfo,\n FlowNodePluginConfig,\n IFlowContext,\n IFlowNodeActions,\n // 以下类型在 types 包的其他文件中定义,这里也重新导出以保持兼容\n FileUpdateInfoItem,\n SceneInfoItem,\n FileUploadInfo,\n FileLibraryInfo,\n FileLibraryItem,\n IFlowNode,\n IFlowItem,\n} from '@xiaou66/picture-types'\n\nimport type { FlowNodePluginConfig, FlowNodePluginInfo, IFlowNodeActions } from '@xiaou66/picture-types'\n\n/**\n * 流程节点插件配置\n * @param config\n */\nexport function createFlowNodePluginConfig(config: Omit<FlowNodePluginConfig, 'pluginInfo'> & { pluginInfo: Omit<FlowNodePluginInfo, 'pluginType'> }): FlowNodePluginConfig {\n const newConfig = config as FlowNodePluginConfig\n newConfig.pluginInfo.pluginType = 'flowNode';\n return newConfig;\n}\n\n/**\n * 创建流程节点动作配置\n * @param actions 流程节点动作配置\n */\nexport function createFlowNodeActions<T>(actions: IFlowNodeActions<T>): IFlowNodeActions<T> {\n return actions;\n}\n\n"],"mappings":"mEAcA,SAAgB,EAA0B,EAA8H,CACtK,IAAM,EAAY,EAElB,MADA,GAAU,WAAW,WAAa,UAC3B,ECdT,MAAa,EAAiB,CAC5B,CACE,MAAO,IACP,MAAO,OACP,SACS,IAAI,MAAM,CAAC,aAAa,CAAC,UAAU,CAE5C,OAAS,GACA,IAAI,MAAM,CAAC,aAAa,CAAC,UAAU,CAE7C,CACD,CACE,MAAO,IACP,MAAO,MACP,SACS,IAAI,MAAM,CAAC,aAAa,CAAC,UAAU,CAAC,UAAU,EAAE,CAEzD,OAAS,GACA,IAAI,MAAM,CAAC,aAAa,CAAC,UAAU,CAAC,UAAU,EAAE,CAE1D,CACD,CACE,MAAO,IACP,MAAO,MACP,UACU,IAAI,MAAM,CAAC,UAAU,CAAG,GAAG,UAAU,CAAC,SAAS,EAAG,IAAI,CAEhE,OAAS,IACC,IAAI,MAAM,CAAC,UAAU,CAAG,GAAG,UAAU,CAAC,SAAS,EAAG,IAAI,CAEjE,CACD,CACE,MAAO,IACP,MAAO,M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B,QAAQ,EAAK,EAAO,CAM7C,WAAY,ICpHd,MAAaA,EAA6D,CACxE,QAAW,CACT,KAAM,KACN,KAAM,oBACP,CACD,SAAY,CACV,KAAM,KACN,KAAM,WACP,CACF,CCQD,SAAgB,EAA2B,EAAiI,CAC1K,IAAM,EAAY,EAElB,MADA,GAAU,WAAW,WAAa,WAC3B,EAOT,SAAgB,EAAyB,EAAmD,CAC1F,OAAO"}
|
|
1
|
+
{"version":3,"file":"index.cjs.js","names":["pluginTypeDict: Record<PluginType, Record<string, string>>"],"sources":["../src/storage/StoragePluginConfig.ts","../src/utils/StrTemplateUtils.ts","../src/utils/FlowUtils.ts","../src/utils/utils.ts","../src/storage/StoragePlugin.ts","../src/core/PluginInfo.ts","../src/flowNode/FlowNodePlugin.ts"],"sourcesContent":["// 从 types 包导入并重新导出\nexport type {\n StorageUIFormElement,\n StorageUIConfig,\n StoragePluginInfo,\n StoragePluginConfig,\n} from '@xiaou66/picture-types'\n\nimport type { StoragePluginConfig, StoragePluginInfo } from '@xiaou66/picture-types'\n\n/**\n * 存储插件配置\n * @param config\n */\nexport function createStoragePluginConfig(config: Omit<StoragePluginConfig, 'pluginInfo'> & { pluginInfo: Omit<StoragePluginInfo, 'pluginType'> }): StoragePluginConfig {\n const newConfig = config as StoragePluginConfig\n newConfig.pluginInfo.pluginType = 'storage';\n return newConfig;\n}\n","import { IUploadFileParams } from '../storage'\n\n\nexport const stringVariable = [\n {\n label: '年',\n value: '{YY}',\n demo: () => {\n return new Date().getFullYear().toString();\n },\n format: (obj: IUploadFileParams) => {\n return new Date().getFullYear().toString();\n }\n },\n {\n label: '年',\n value: '{Y}',\n demo: () => {\n return new Date().getFullYear().toString().substring(2);\n },\n format: (obj: IUploadFileParams) => {\n return new Date().getFullYear().toString().substring(2);\n }\n },\n {\n label: '月',\n value: '{M}',\n demo: () => {\n return (new Date().getMonth() + 1).toString().padStart(2, '0');\n },\n format: (obj: IUploadFileParams) => {\n return (new Date().getMonth() + 1).toString().padStart(2, '0');\n }\n },\n {\n label: '日',\n value: '{D}',\n demo: () => {\n return (new Date().getDate()).toString().padStart(2, '0');\n },\n format: (obj: IUploadFileParams) => {\n return (new Date().getDate()).toString().padStart(2, '0');\n }\n },\n {\n label: '时',\n value: '{h}',\n demo: () => {\n return new Date().getHours().toString().padStart(2, '0');\n },\n format: (obj: IUploadFileParams) => {\n return new Date().getHours().toString().padStart(2, '0');\n }\n },\n {\n label: '分',\n value: '{m}',\n demo: () => {\n return new Date().getMinutes().toString().padStart(2, '0');\n },\n format: (obj: IUploadFileParams) => {\n return new Date().getMinutes().toString().padStart(2, '0');\n }\n },\n {\n label: '秒',\n value: '{s}',\n demo: () => {\n return new Date().getSeconds().toString().padStart(2, '0');\n },\n format: () => {\n return new Date().getSeconds().toString().padStart(2, '0');\n }\n },\n {\n label: '毫秒',\n value: '{ss}',\n demo: () => {\n return new Date().getMilliseconds().toString().padStart(3, '0');\n },\n format: (obj: IUploadFileParams) => {\n return new Date().getMilliseconds().toString().padStart(3, '0');\n }\n },\n {\n label: '时间戳',\n value: '{timestamp}',\n width: 300,\n demo: () => {\n return Date.now();\n },\n format: (obj: IUploadFileParams) => {\n return Date.now().toString();\n }\n },\n {\n label: '文件名称',\n value: '{filename}',\n width: 200,\n demo: () => {\n return '文本';\n },\n format: (obj: IUploadFileParams) => {\n return obj.fileName;\n }\n },\n {\n label: '后缀',\n value: '{suffix}',\n width: 200,\n demo: () => {\n return 'txt';\n },\n format: (obj: IUploadFileParams) => {\n return obj.suffix;\n }\n },\n {\n label: '全文件名',\n value: '{allFilename}',\n width: 300,\n demo: () => {\n return '文本.txt';\n },\n format: (obj: IUploadFileParams) => {\n return obj.allFileName;\n }\n },\n {\n label: '场景名称',\n value: '{sceneName}',\n width: 300,\n demo: () => {\n return '测试场景';\n },\n format: (obj: IUploadFileParams) => {\n return obj.sceneName || '';\n }\n },\n {\n label: '随机字符串',\n value: '{rand(5)}',\n width: 300,\n demo: () => {\n return generateRandomString(5);\n },\n format: (obj: IUploadFileParams) => {\n return generateRandomString(5);\n }\n },\n];\n\n// 生成指定长度的随机字符串\nfunction generateRandomString(length: number): string {\n const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';\n let result = '';\n for (let i = 0; i < length; i++) {\n result += chars.charAt(Math.floor(Math.random() * chars.length));\n }\n return result;\n}\nexport function filePathFormat(str: string, obj: IUploadFileParams): string {\n console.log('filePathFormat', str, obj)\n stringVariable.forEach(variable => {\n // 获取变量的值\n const value = variable.format(obj) || '';\n // 使用正则表达式替换所有匹配的变量\n const regex = new RegExp(variable.value, 'g'); // 'g' 标志表示全局替换\n str = str.replace(regex, value);\n });\n\n // 处理动态变量 {rand(n)}\n const randRegex = /\\{rand\\((\\d+)\\)\\}/g;\n str = str.replace(randRegex, (match, p1) => {\n const length = parseInt(p1, 10);\n return generateRandomString(length);\n });\n\n return str;\n}\n","import { IFlowContext } from '@xiaou66/picture-types'\n\n/**\n * 替换上传文件\n * @param ctx 流程上下文\n * @param filePath 替换的文件路径\n */\nexport function replaceUploadFile(ctx: IFlowContext, filePath: string) {\n const uploadFile = ctx.uploadFile\n //@ts-ignore;\n const existsSync = window.fs.existsSync(tempPath)\n if (!existsSync) {\n throw new Error('replaceUploadFile--文件不存在--' + filePath);\n }\n uploadFile.tempFile = true\n //@ts-ignore;\n uploadFile.filePath = window.path.join(utools.getPath('downloads'), 'test.webp')\n // @ts-ignore\n uploadFile.fileName = window.path.basename(tempPath)\n // @ts-ignore\n const stats = window.fs.statSync(tempPath)\n uploadFile.fileSize = stats.size\n}\n\nexport default {\n replaceUploadFile,\n}\n","/**\n * 获取临时存储路径\n * 用于保存上传前的临时文件\n * @returns {string} 临时存储路径\n */\nexport function getDataTempSavePath(): string {\n return (\n utools.dbStorage.getItem(`settingUserStore/localAppData/${utools.getNativeId()}`) ||\n // @ts-ignore\n window.path.join(utools.getPath('userData'), 'app', 'picture-bed-plus', 'temps')\n )\n}\n\nexport default {\n getDataTempSavePath,\n}\n","import type { IDeleteFileParams, IUploadFileParams, IUploadFileResult, UploadFileOptions } from '@xiaou66/picture-types'\nimport { filePathFormat } from '../utils'\nimport { createFlowNodeActions } from '../flowNode'\n\n// 重新导出 UploadFileOptions\nexport type { UploadFileOptions } from '@xiaou66/picture-types'\n\n\n/**\n * 插件接口\n */\ninterface IStoragePlugin {\n\n /**\n * 插件初始化调用\n */\n init(errorCallback: ErrorCallbackType): void;\n\n /**\n * 插件销毁调用\n */\n destroy(): void;\n}\n\n\ntype ErrorCallbackType = (name: string, action: string, error: Error) => void;\n\n\n/**\n * 存储插件\n */\nexport abstract class StoragePlugin<C = any, E = any> implements IStoragePlugin {\n\n init(): void {\n this.doInit()\n }\n\n /**\n * 初始化使用 <br/>\n * constructor 方法之后调用, 在第一次使用前调用\n * @protected\n */\n protected abstract doInit(): void\n\n destroy() {\n this.doDestroy()\n }\n\n /**\n * 插件销毁调用, 用于销毁资源\n * @protected\n */\n protected abstract doDestroy(): void\n\n\n /**\n * 上传文件\n * @param params 参数\n * @param options 上传可选参数\n */\n abstract uploadFile(params: IUploadFileParams, options?: UploadFileOptions): Promise<IUploadFileResult<E>>\n\n\n /**\n * 删除文件 <br/>\n * 如果要实现删除文件请实现这个接口\n * @param params 参数\n */\n public deleteFile(params: IDeleteFileParams<E>): Promise<boolean> {\n return Promise.resolve(false);\n }\n\n /**\n * 格式化上传路径\n * @param templateStr 模版路径\n * @param params 上传参数\n * @protected\n */\n protected formatUploadPath(templateStr: string, params: IUploadFileParams) {\n return filePathFormat(templateStr, params);\n }\n\n /**\n * 从 URL 中提取路径\n * @param url 完整的图片 URL\n * @returns 图片路径\n */\n protected extractImagePath(url: string): string {\n try {\n const urlObj = new URL(url);\n return urlObj.pathname;\n } catch (error) {\n // 如果 URL 解析失败,尝试使用正则表达式\n const matches = url.match(/https?:\\/\\/[^\\/]+(\\/.*)/);\n return matches ? matches[1] : '';\n }\n }\n\n\n /**\n * 校验配置 <br/>\n * 如果不通过抛出异常\n * @param config\n * @protected\n */\n public verifyConfig(config: C): Promise<void> {\n return Promise.resolve(undefined);\n }\n\n protected readConfig(storageId: string): C {\n const key = `storageSource/${storageId}`\n return utools.dbCryptoStorage.getItem(key)\n }\n\n protected saveConfig(storageId: string, config: C): void {\n const key = `storageSource/${storageId}`;\n utools.dbCryptoStorage.setItem(key, config);\n }\n\n /**\n * 插件被卸载\n */\n uninstall() {\n\n }\n}\n","// 从 types 包导入并重新导出\nexport type { PluginType, PluginInfo, PluginConfig } from '@xiaou66/picture-types'\nimport type { PluginType } from '@xiaou66/picture-types'\n\n// @unocss-include\nexport const pluginTypeDict: Record<PluginType, Record<string, string>> = {\n 'storage': {\n name: '存储',\n icon: 'i-u-cloud-storage',\n },\n 'flowNode': {\n name: '流程',\n icon: 'i-u-flow'\n },\n}\n","// 从 types 包导入并重新导出\nexport type {\n FlowNodePluginInfo,\n FlowNodePluginConfig,\n IFlowContext,\n IFlowNodeActions,\n // 以下类型在 types 包的其他文件中定义,这里也重新导出以保持兼容\n FileUpdateInfoItem,\n SceneInfoItem,\n FileUploadInfo,\n FileLibraryInfo,\n FileLibraryItem,\n IFlowNode,\n IFlowItem,\n} from '@xiaou66/picture-types'\n\nimport type {\n FlowNodePluginConfig,\n FlowNodePluginInfo,\n IFlowNodeActions,\n IFlowItem,\n IFlowNode,\n IFlowContext\n} from '@xiaou66/picture-types'\n\n/**\n * 流程节点插件配置\n * @param config\n */\nexport function createFlowNodePluginConfig(config: Omit<FlowNodePluginConfig, 'pluginInfo'> & { pluginInfo: Omit<FlowNodePluginInfo, 'pluginType'> }): FlowNodePluginConfig {\n const newConfig = config as FlowNodePluginConfig\n newConfig.pluginInfo.pluginType = 'flowNode';\n return newConfig;\n}\n\n\n/**\n * 流程节点插件抽象基类\n * @template T 节点数据类型\n *\n * @example\n * ```typescript\n * class ImageCompressPlugin extends FlowNodePlugin<{ quality: number }> {\n * readonly info = {\n * pluginCode: 'image-compress',\n * pluginName: '图片压缩',\n * pluginGroup: 'image',\n * // ...其他插件信息\n * }\n *\n * async onExecute(flow, flowData, data) {\n * const { quality } = flowData.nodeData\n * // 压缩逻辑\n * }\n *\n * onDestroy(flow, flowData) {\n * // 清理资源\n * }\n * }\n *\n * const actions = createFlowNodeActions(new ImageCompressPlugin())\n * ```\n */\nexport abstract class FlowNodePlugin<T = any> implements IFlowNodeActions<T> {\n /**\n * 执行节点核心逻辑\n * @param flow 流程项\n * @param flowData 流程节点数据\n * @param data 流程上下文\n */\n abstract onExecute(flow: IFlowItem, flowData: IFlowNode<T>, data: IFlowContext): Promise<void>\n\n /**\n * 保存数据后的钩子(可选)\n * @param flow 流程项\n * @param flowData 流程节点数据\n */\n onAfterSave?(flow: IFlowItem, flowData: IFlowNode<T>): void\n\n /**\n * 节点销毁时的清理钩子(可选)\n * @param flow 流程项\n * @param flowData 流程节点数据\n */\n onDestroy?(flow: IFlowItem, flowData: IFlowNode<T>): void\n}\n\n\n/**\n * 创建流程节点动作配置\n * @param input 流程节点动作配置或 FlowNodePlugin 实例\n *\n * @example\n * // 方式1: 函数式配置(保持兼容)\n * const actions = createFlowNodeActions({\n * onExecute: async (flow, flowData, data) => {\n * // 逻辑\n * }\n * })\n *\n * @example\n * // 方式2: 类实例\n * const actions = createFlowNodeActions(new MyFlowNodePlugin())\n */\nexport function createFlowNodeActions<T>(input: IFlowNodeActions<T> | FlowNodePlugin<T>): IFlowNodeActions<T> {\n // FlowNodePlugin 实现了 IFlowNodeActions,可直接返回\n return input\n}\n"],"mappings":"mEAcA,SAAgB,EAA0B,EAA8H,CACtK,IAAM,EAAY,EAElB,MADA,GAAU,WAAW,WAAa,UAC3B,ECdT,MAAa,EAAiB,CAC5B,CACE,MAAO,IACP,MAAO,OACP,SACS,IAAI,MAAM,CAAC,aAAa,CAAC,UAAU,CAE5C,OAAS,GACA,IAAI,MAAM,CAAC,aAAa,CAAC,UAAU,CAE7C,CACD,CACE,MAAO,IACP,MAAO,MACP,SACS,IAAI,MAAM,CAAC,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
|
+
return s.pluginInfo.pluginType = "storage", s;
|
|
4
4
|
}
|
|
5
5
|
const stringVariable = [
|
|
6
6
|
{
|
|
@@ -95,15 +95,23 @@ const stringVariable = [
|
|
|
95
95
|
}
|
|
96
96
|
];
|
|
97
97
|
function generateRandomString(e) {
|
|
98
|
-
let
|
|
99
|
-
for (let
|
|
100
|
-
return
|
|
98
|
+
let s = "";
|
|
99
|
+
for (let c = 0; c < e; c++) s += "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(Math.random() * 62));
|
|
100
|
+
return s;
|
|
101
101
|
}
|
|
102
|
-
function filePathFormat(e,
|
|
103
|
-
return console.log("filePathFormat", e,
|
|
104
|
-
let
|
|
105
|
-
e = e.replace(
|
|
106
|
-
}), e = e.replace(/\{rand\((\d+)\)\}/g, (e,
|
|
102
|
+
function filePathFormat(e, l) {
|
|
103
|
+
return console.log("filePathFormat", e, l), stringVariable.forEach((s) => {
|
|
104
|
+
let c = s.format(l) || "", u = new RegExp(s.value, "g");
|
|
105
|
+
e = e.replace(u, c);
|
|
106
|
+
}), e = e.replace(/\{rand\((\d+)\)\}/g, (e, s) => generateRandomString(parseInt(s, 10))), e;
|
|
107
|
+
}
|
|
108
|
+
function replaceUploadFile(e, s) {
|
|
109
|
+
let c = e.uploadFile;
|
|
110
|
+
if (!window.fs.existsSync(tempPath)) throw Error("replaceUploadFile--文件不存在--" + s);
|
|
111
|
+
c.tempFile = !0, c.filePath = window.path.join(utools.getPath("downloads"), "test.webp"), c.fileName = window.path.basename(tempPath), c.fileSize = window.fs.statSync(tempPath).size;
|
|
112
|
+
}
|
|
113
|
+
function getDataTempSavePath() {
|
|
114
|
+
return utools.dbStorage.getItem(`settingUserStore/localAppData/${utools.getNativeId()}`) || window.path.join(utools.getPath("userData"), "app", "picture-bed-plus", "temps");
|
|
107
115
|
}
|
|
108
116
|
var StoragePlugin = class {
|
|
109
117
|
init() {
|
|
@@ -115,27 +123,27 @@ var StoragePlugin = class {
|
|
|
115
123
|
deleteFile(e) {
|
|
116
124
|
return Promise.resolve(!1);
|
|
117
125
|
}
|
|
118
|
-
formatUploadPath(e,
|
|
119
|
-
return filePathFormat(e,
|
|
126
|
+
formatUploadPath(e, s) {
|
|
127
|
+
return filePathFormat(e, s);
|
|
120
128
|
}
|
|
121
129
|
extractImagePath(e) {
|
|
122
130
|
try {
|
|
123
131
|
return new URL(e).pathname;
|
|
124
132
|
} catch {
|
|
125
|
-
let
|
|
126
|
-
return
|
|
133
|
+
let s = e.match(/https?:\/\/[^\/]+(\/.*)/);
|
|
134
|
+
return s ? s[1] : "";
|
|
127
135
|
}
|
|
128
136
|
}
|
|
129
137
|
verifyConfig(e) {
|
|
130
138
|
return Promise.resolve(void 0);
|
|
131
139
|
}
|
|
132
140
|
readConfig(e) {
|
|
133
|
-
let
|
|
134
|
-
return utools.dbCryptoStorage.getItem(
|
|
141
|
+
let s = `storageSource/${e}`;
|
|
142
|
+
return utools.dbCryptoStorage.getItem(s);
|
|
135
143
|
}
|
|
136
|
-
saveConfig(e,
|
|
137
|
-
let
|
|
138
|
-
utools.dbCryptoStorage.setItem(
|
|
144
|
+
saveConfig(e, s) {
|
|
145
|
+
let c = `storageSource/${e}`;
|
|
146
|
+
utools.dbCryptoStorage.setItem(c, s);
|
|
139
147
|
}
|
|
140
148
|
uninstall() {}
|
|
141
149
|
};
|
|
@@ -150,12 +158,13 @@ const pluginTypeDict = {
|
|
|
150
158
|
}
|
|
151
159
|
};
|
|
152
160
|
function createFlowNodePluginConfig(e) {
|
|
153
|
-
let
|
|
154
|
-
return
|
|
161
|
+
let s = e;
|
|
162
|
+
return s.pluginInfo.pluginType = "flowNode", s;
|
|
155
163
|
}
|
|
164
|
+
var FlowNodePlugin = class {};
|
|
156
165
|
function createFlowNodeActions(e) {
|
|
157
166
|
return e;
|
|
158
167
|
}
|
|
159
|
-
export { StoragePlugin, createFlowNodeActions, createFlowNodePluginConfig, createStoragePluginConfig, filePathFormat, pluginTypeDict, stringVariable };
|
|
168
|
+
export { FlowNodePlugin, StoragePlugin, createFlowNodeActions, createFlowNodePluginConfig, createStoragePluginConfig, filePathFormat, getDataTempSavePath, pluginTypeDict, replaceUploadFile, stringVariable };
|
|
160
169
|
|
|
161
170
|
//# sourceMappingURL=index.es.js.map
|
package/dist/index.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es.js","names":["pluginTypeDict: Record<PluginType, Record<string, string>>"],"sources":["../src/storage/StoragePluginConfig.ts","../src/utils/StrTemplateUtils.ts","../src/storage/StoragePlugin.ts","../src/core/PluginInfo.ts","../src/flowNode/FlowNodePlugin.ts"],"sourcesContent":["// 从 types 包导入并重新导出\nexport type {\n StorageUIFormElement,\n StorageUIConfig,\n StoragePluginInfo,\n StoragePluginConfig,\n} from '@xiaou66/picture-types'\n\nimport type { StoragePluginConfig, StoragePluginInfo } from '@xiaou66/picture-types'\n\n/**\n * 存储插件配置\n * @param config\n */\nexport function createStoragePluginConfig(config: Omit<StoragePluginConfig, 'pluginInfo'> & { pluginInfo: Omit<StoragePluginInfo, 'pluginType'> }): StoragePluginConfig {\n const newConfig = config as StoragePluginConfig\n newConfig.pluginInfo.pluginType = 'storage';\n return newConfig;\n}\n","import { IUploadFileParams } from '../storage'\n\n\nexport const stringVariable = [\n {\n label: '年',\n value: '{YY}',\n demo: () => {\n return new Date().getFullYear().toString();\n },\n format: (obj: IUploadFileParams) => {\n return new Date().getFullYear().toString();\n }\n },\n {\n label: '年',\n value: '{Y}',\n demo: () => {\n return new Date().getFullYear().toString().substring(2);\n },\n format: (obj: IUploadFileParams) => {\n return new Date().getFullYear().toString().substring(2);\n }\n },\n {\n label: '月',\n value: '{M}',\n demo: () => {\n return (new Date().getMonth() + 1).toString().padStart(2, '0');\n },\n format: (obj: IUploadFileParams) => {\n return (new Date().getMonth() + 1).toString().padStart(2, '0');\n }\n },\n {\n label: '日',\n value: '{D}',\n demo: () => {\n return (new Date().getDate()).toString().padStart(2, '0');\n },\n format: (obj: IUploadFileParams) => {\n return (new Date().getDate()).toString().padStart(2, '0');\n }\n },\n {\n label: '时',\n value: '{h}',\n demo: () => {\n return new Date().getHours().toString().padStart(2, '0');\n },\n format: (obj: IUploadFileParams) => {\n return new Date().getHours().toString().padStart(2, '0');\n }\n },\n {\n label: '分',\n value: '{m}',\n demo: () => {\n return new Date().getMinutes().toString().padStart(2, '0');\n },\n format: (obj: IUploadFileParams) => {\n return new Date().getMinutes().toString().padStart(2, '0');\n }\n },\n {\n label: '秒',\n value: '{s}',\n demo: () => {\n return new Date().getSeconds().toString().padStart(2, '0');\n },\n format: () => {\n return new Date().getSeconds().toString().padStart(2, '0');\n }\n },\n {\n label: '毫秒',\n value: '{ss}',\n demo: () => {\n return new Date().getMilliseconds().toString().padStart(3, '0');\n },\n format: (obj: IUploadFileParams) => {\n return new Date().getMilliseconds().toString().padStart(3, '0');\n }\n },\n {\n label: '时间戳',\n value: '{timestamp}',\n width: 300,\n demo: () => {\n return Date.now();\n },\n format: (obj: IUploadFileParams) => {\n return Date.now().toString();\n }\n },\n {\n label: '文件名称',\n value: '{filename}',\n width: 200,\n demo: () => {\n return '文本';\n },\n format: (obj: IUploadFileParams) => {\n return obj.fileName;\n }\n },\n {\n label: '后缀',\n value: '{suffix}',\n width: 200,\n demo: () => {\n return 'txt';\n },\n format: (obj: IUploadFileParams) => {\n return obj.suffix;\n }\n },\n {\n label: '全文件名',\n value: '{allFilename}',\n width: 300,\n demo: () => {\n return '文本.txt';\n },\n format: (obj: IUploadFileParams) => {\n return obj.allFileName;\n }\n },\n {\n label: '场景名称',\n value: '{sceneName}',\n width: 300,\n demo: () => {\n return '测试场景';\n },\n format: (obj: IUploadFileParams) => {\n return obj.sceneName || '';\n }\n },\n {\n label: '随机字符串',\n value: '{rand(5)}',\n width: 300,\n demo: () => {\n return generateRandomString(5);\n },\n format: (obj: IUploadFileParams) => {\n return generateRandomString(5);\n }\n },\n];\n\n// 生成指定长度的随机字符串\nfunction generateRandomString(length: number): string {\n const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';\n let result = '';\n for (let i = 0; i < length; i++) {\n result += chars.charAt(Math.floor(Math.random() * chars.length));\n }\n return result;\n}\nexport function filePathFormat(str: string, obj: IUploadFileParams): string {\n console.log('filePathFormat', str, obj)\n stringVariable.forEach(variable => {\n // 获取变量的值\n const value = variable.format(obj) || '';\n // 使用正则表达式替换所有匹配的变量\n const regex = new RegExp(variable.value, 'g'); // 'g' 标志表示全局替换\n str = str.replace(regex, value);\n });\n\n // 处理动态变量 {rand(n)}\n const randRegex = /\\{rand\\((\\d+)\\)\\}/g;\n str = str.replace(randRegex, (match, p1) => {\n const length = parseInt(p1, 10);\n return generateRandomString(length);\n });\n\n return str;\n}\n","import type { IDeleteFileParams, IUploadFileParams, IUploadFileResult, UploadFileOptions } from '@xiaou66/picture-types'\nimport { filePathFormat } from '../utils'\n\n// 重新导出 UploadFileOptions\nexport type { UploadFileOptions } from '@xiaou66/picture-types'\n\n\n/**\n * 插件接口\n */\ninterface IStoragePlugin {\n\n /**\n * 插件初始化调用\n */\n init(errorCallback: ErrorCallbackType): void;\n\n /**\n * 插件销毁调用\n */\n destroy(): void;\n}\n\n\ntype ErrorCallbackType = (name: string, action: string, error: Error) => void;\n\n\n/**\n * 存储插件\n */\nexport abstract class StoragePlugin<C = any, E = any> implements IStoragePlugin {\n\n init(): void {\n this.doInit()\n }\n\n /**\n * 初始化使用 <br/>\n * constructor 方法之后调用, 在第一次使用前调用\n * @protected\n */\n protected abstract doInit(): void\n\n destroy() {\n this.doDestroy()\n }\n\n /**\n * 插件销毁调用, 用于销毁资源\n * @protected\n */\n protected abstract doDestroy(): void\n\n\n /**\n * 上传文件\n * @param params 参数\n * @param options 上传可选参数\n */\n abstract uploadFile(params: IUploadFileParams, options?: UploadFileOptions): Promise<IUploadFileResult<E>>\n\n\n /**\n * 删除文件 <br/>\n * 如果要实现删除文件请实现这个接口\n * @param params 参数\n */\n public deleteFile(params: IDeleteFileParams<E>): Promise<boolean> {\n return Promise.resolve(false);\n }\n\n /**\n * 格式化上传路径\n * @param templateStr 模版路径\n * @param params 上传参数\n * @protected\n */\n protected formatUploadPath(templateStr: string, params: IUploadFileParams) {\n return filePathFormat(templateStr, params);\n }\n\n /**\n * 从 URL 中提取路径\n * @param url 完整的图片 URL\n * @returns 图片路径\n */\n protected extractImagePath(url: string): string {\n try {\n const urlObj = new URL(url);\n return urlObj.pathname;\n } catch (error) {\n // 如果 URL 解析失败,尝试使用正则表达式\n const matches = url.match(/https?:\\/\\/[^\\/]+(\\/.*)/);\n return matches ? matches[1] : '';\n }\n }\n\n\n /**\n * 校验配置 <br/>\n * 如果不通过抛出异常\n * @param config\n * @protected\n */\n public verifyConfig(config: C): Promise<void> {\n return Promise.resolve(undefined);\n }\n\n protected readConfig(storageId: string): C {\n const key = `storageSource/${storageId}`\n return utools.dbCryptoStorage.getItem(key)\n }\n\n protected saveConfig(storageId: string, config: C): void {\n const key = `storageSource/${storageId}`;\n utools.dbCryptoStorage.setItem(key, config);\n }\n\n /**\n * 插件被卸载\n */\n uninstall() {\n\n }\n}\n","// 从 types 包导入并重新导出\nexport type { PluginType, PluginInfo, PluginConfig } from '@xiaou66/picture-types'\nimport type { PluginType } from '@xiaou66/picture-types'\n\n// @unocss-include\nexport const pluginTypeDict: Record<PluginType, Record<string, string>> = {\n 'storage': {\n name: '存储',\n icon: 'i-u-cloud-storage',\n },\n 'flowNode': {\n name: '流程',\n icon: 'i-u-flow'\n },\n}\n","// 从 types 包导入并重新导出\nexport type {\n FlowNodePluginInfo,\n FlowNodePluginConfig,\n IFlowContext,\n IFlowNodeActions,\n // 以下类型在 types 包的其他文件中定义,这里也重新导出以保持兼容\n FileUpdateInfoItem,\n SceneInfoItem,\n FileUploadInfo,\n FileLibraryInfo,\n FileLibraryItem,\n IFlowNode,\n IFlowItem,\n} from '@xiaou66/picture-types'\n\nimport type { FlowNodePluginConfig, FlowNodePluginInfo, IFlowNodeActions } from '@xiaou66/picture-types'\n\n/**\n * 流程节点插件配置\n * @param config\n */\nexport function createFlowNodePluginConfig(config: Omit<FlowNodePluginConfig, 'pluginInfo'> & { pluginInfo: Omit<FlowNodePluginInfo, 'pluginType'> }): FlowNodePluginConfig {\n const newConfig = config as FlowNodePluginConfig\n newConfig.pluginInfo.pluginType = 'flowNode';\n return newConfig;\n}\n\n/**\n * 创建流程节点动作配置\n * @param actions 流程节点动作配置\n */\nexport function createFlowNodeActions<T>(actions: IFlowNodeActions<T>): IFlowNodeActions<T> {\n return actions;\n}\n\n"],"mappings":"AAcA,SAAgB,0BAA0B,GAA8H;CACtK,IAAM,IAAY;AAElB,QADA,EAAU,WAAW,aAAa,WAC3B;;ACdT,MAAa,iBAAiB;CAC5B;EACE,OAAO;EACP,OAAO;EACP,6BACS,IAAI,MAAM,EAAC,aAAa,CAAC,UAAU;EAE5C,SAAS,uBACA,IAAI,MAAM,EAAC,aAAa,CAAC,UAAU;EAE7C;CACD;EACE,OAAO;EACP,OAAO;EACP,6BACS,IAAI,MAAM,EAAC,aAAa,CAAC,UAAU,CAAC,UAAU,EAAE;EAEzD,SAAS,uBACA,IAAI,MAAM,EAAC,aAAa,CAAC,UAAU,CAAC,UAAU,EAAE;EAE1D;CACD;EACE,OAAO;EACP,OAAO;EACP,YACE,kCAAQ,IAAI,MAAM,EAAC,UAAU,GAAG,GAAG,UAAU,CAAC,SAAS,GAAG,IAAI;EAEhE,SAAS,MACP,kCAAQ,IAAI,MAAM,EAAC,UAAU,GAAG,GAAG,UAAU,CAAC,SAAS,GAAG,IAAI;EAEjE;CACD;EACE,OAAO;EACP,OAAO;EACP,6BACU,IAAI,MAAM,EAAC,SAAS,CAAE,UAAU,CAAC,SAAS,GAAG,IAAI;EAE3D,SAAS,uBACC,IAAI,MAAM,EAAC,SAAS,CAAE,UAAU,CAAC,SAAS,GAAG,IAAI;EAE5D;CACD;EACE,OAAO;EACP,OAAO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,2BAA2B,GAAiI;CAC1K,IAAM,IAAY;AAElB,QADA,EAAU,WAAW,aAAa,YAC3B;;AAOT,SAAgB,sBAAyB,GAAmD;AAC1F,QAAO"}
|
|
1
|
+
{"version":3,"file":"index.es.js","names":["pluginTypeDict: Record<PluginType, Record<string, string>>"],"sources":["../src/storage/StoragePluginConfig.ts","../src/utils/StrTemplateUtils.ts","../src/utils/FlowUtils.ts","../src/utils/utils.ts","../src/storage/StoragePlugin.ts","../src/core/PluginInfo.ts","../src/flowNode/FlowNodePlugin.ts"],"sourcesContent":["// 从 types 包导入并重新导出\nexport type {\n StorageUIFormElement,\n StorageUIConfig,\n StoragePluginInfo,\n StoragePluginConfig,\n} from '@xiaou66/picture-types'\n\nimport type { StoragePluginConfig, StoragePluginInfo } from '@xiaou66/picture-types'\n\n/**\n * 存储插件配置\n * @param config\n */\nexport function createStoragePluginConfig(config: Omit<StoragePluginConfig, 'pluginInfo'> & { pluginInfo: Omit<StoragePluginInfo, 'pluginType'> }): StoragePluginConfig {\n const newConfig = config as StoragePluginConfig\n newConfig.pluginInfo.pluginType = 'storage';\n return newConfig;\n}\n","import { IUploadFileParams } from '../storage'\n\n\nexport const stringVariable = [\n {\n label: '年',\n value: '{YY}',\n demo: () => {\n return new Date().getFullYear().toString();\n },\n format: (obj: IUploadFileParams) => {\n return new Date().getFullYear().toString();\n }\n },\n {\n label: '年',\n value: '{Y}',\n demo: () => {\n return new Date().getFullYear().toString().substring(2);\n },\n format: (obj: IUploadFileParams) => {\n return new Date().getFullYear().toString().substring(2);\n }\n },\n {\n label: '月',\n value: '{M}',\n demo: () => {\n return (new Date().getMonth() + 1).toString().padStart(2, '0');\n },\n format: (obj: IUploadFileParams) => {\n return (new Date().getMonth() + 1).toString().padStart(2, '0');\n }\n },\n {\n label: '日',\n value: '{D}',\n demo: () => {\n return (new Date().getDate()).toString().padStart(2, '0');\n },\n format: (obj: IUploadFileParams) => {\n return (new Date().getDate()).toString().padStart(2, '0');\n }\n },\n {\n label: '时',\n value: '{h}',\n demo: () => {\n return new Date().getHours().toString().padStart(2, '0');\n },\n format: (obj: IUploadFileParams) => {\n return new Date().getHours().toString().padStart(2, '0');\n }\n },\n {\n label: '分',\n value: '{m}',\n demo: () => {\n return new Date().getMinutes().toString().padStart(2, '0');\n },\n format: (obj: IUploadFileParams) => {\n return new Date().getMinutes().toString().padStart(2, '0');\n }\n },\n {\n label: '秒',\n value: '{s}',\n demo: () => {\n return new Date().getSeconds().toString().padStart(2, '0');\n },\n format: () => {\n return new Date().getSeconds().toString().padStart(2, '0');\n }\n },\n {\n label: '毫秒',\n value: '{ss}',\n demo: () => {\n return new Date().getMilliseconds().toString().padStart(3, '0');\n },\n format: (obj: IUploadFileParams) => {\n return new Date().getMilliseconds().toString().padStart(3, '0');\n }\n },\n {\n label: '时间戳',\n value: '{timestamp}',\n width: 300,\n demo: () => {\n return Date.now();\n },\n format: (obj: IUploadFileParams) => {\n return Date.now().toString();\n }\n },\n {\n label: '文件名称',\n value: '{filename}',\n width: 200,\n demo: () => {\n return '文本';\n },\n format: (obj: IUploadFileParams) => {\n return obj.fileName;\n }\n },\n {\n label: '后缀',\n value: '{suffix}',\n width: 200,\n demo: () => {\n return 'txt';\n },\n format: (obj: IUploadFileParams) => {\n return obj.suffix;\n }\n },\n {\n label: '全文件名',\n value: '{allFilename}',\n width: 300,\n demo: () => {\n return '文本.txt';\n },\n format: (obj: IUploadFileParams) => {\n return obj.allFileName;\n }\n },\n {\n label: '场景名称',\n value: '{sceneName}',\n width: 300,\n demo: () => {\n return '测试场景';\n },\n format: (obj: IUploadFileParams) => {\n return obj.sceneName || '';\n }\n },\n {\n label: '随机字符串',\n value: '{rand(5)}',\n width: 300,\n demo: () => {\n return generateRandomString(5);\n },\n format: (obj: IUploadFileParams) => {\n return generateRandomString(5);\n }\n },\n];\n\n// 生成指定长度的随机字符串\nfunction generateRandomString(length: number): string {\n const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';\n let result = '';\n for (let i = 0; i < length; i++) {\n result += chars.charAt(Math.floor(Math.random() * chars.length));\n }\n return result;\n}\nexport function filePathFormat(str: string, obj: IUploadFileParams): string {\n console.log('filePathFormat', str, obj)\n stringVariable.forEach(variable => {\n // 获取变量的值\n const value = variable.format(obj) || '';\n // 使用正则表达式替换所有匹配的变量\n const regex = new RegExp(variable.value, 'g'); // 'g' 标志表示全局替换\n str = str.replace(regex, value);\n });\n\n // 处理动态变量 {rand(n)}\n const randRegex = /\\{rand\\((\\d+)\\)\\}/g;\n str = str.replace(randRegex, (match, p1) => {\n const length = parseInt(p1, 10);\n return generateRandomString(length);\n });\n\n return str;\n}\n","import { IFlowContext } from '@xiaou66/picture-types'\n\n/**\n * 替换上传文件\n * @param ctx 流程上下文\n * @param filePath 替换的文件路径\n */\nexport function replaceUploadFile(ctx: IFlowContext, filePath: string) {\n const uploadFile = ctx.uploadFile\n //@ts-ignore;\n const existsSync = window.fs.existsSync(tempPath)\n if (!existsSync) {\n throw new Error('replaceUploadFile--文件不存在--' + filePath);\n }\n uploadFile.tempFile = true\n //@ts-ignore;\n uploadFile.filePath = window.path.join(utools.getPath('downloads'), 'test.webp')\n // @ts-ignore\n uploadFile.fileName = window.path.basename(tempPath)\n // @ts-ignore\n const stats = window.fs.statSync(tempPath)\n uploadFile.fileSize = stats.size\n}\n\nexport default {\n replaceUploadFile,\n}\n","/**\n * 获取临时存储路径\n * 用于保存上传前的临时文件\n * @returns {string} 临时存储路径\n */\nexport function getDataTempSavePath(): string {\n return (\n utools.dbStorage.getItem(`settingUserStore/localAppData/${utools.getNativeId()}`) ||\n // @ts-ignore\n window.path.join(utools.getPath('userData'), 'app', 'picture-bed-plus', 'temps')\n )\n}\n\nexport default {\n getDataTempSavePath,\n}\n","import type { IDeleteFileParams, IUploadFileParams, IUploadFileResult, UploadFileOptions } from '@xiaou66/picture-types'\nimport { filePathFormat } from '../utils'\nimport { createFlowNodeActions } from '../flowNode'\n\n// 重新导出 UploadFileOptions\nexport type { UploadFileOptions } from '@xiaou66/picture-types'\n\n\n/**\n * 插件接口\n */\ninterface IStoragePlugin {\n\n /**\n * 插件初始化调用\n */\n init(errorCallback: ErrorCallbackType): void;\n\n /**\n * 插件销毁调用\n */\n destroy(): void;\n}\n\n\ntype ErrorCallbackType = (name: string, action: string, error: Error) => void;\n\n\n/**\n * 存储插件\n */\nexport abstract class StoragePlugin<C = any, E = any> implements IStoragePlugin {\n\n init(): void {\n this.doInit()\n }\n\n /**\n * 初始化使用 <br/>\n * constructor 方法之后调用, 在第一次使用前调用\n * @protected\n */\n protected abstract doInit(): void\n\n destroy() {\n this.doDestroy()\n }\n\n /**\n * 插件销毁调用, 用于销毁资源\n * @protected\n */\n protected abstract doDestroy(): void\n\n\n /**\n * 上传文件\n * @param params 参数\n * @param options 上传可选参数\n */\n abstract uploadFile(params: IUploadFileParams, options?: UploadFileOptions): Promise<IUploadFileResult<E>>\n\n\n /**\n * 删除文件 <br/>\n * 如果要实现删除文件请实现这个接口\n * @param params 参数\n */\n public deleteFile(params: IDeleteFileParams<E>): Promise<boolean> {\n return Promise.resolve(false);\n }\n\n /**\n * 格式化上传路径\n * @param templateStr 模版路径\n * @param params 上传参数\n * @protected\n */\n protected formatUploadPath(templateStr: string, params: IUploadFileParams) {\n return filePathFormat(templateStr, params);\n }\n\n /**\n * 从 URL 中提取路径\n * @param url 完整的图片 URL\n * @returns 图片路径\n */\n protected extractImagePath(url: string): string {\n try {\n const urlObj = new URL(url);\n return urlObj.pathname;\n } catch (error) {\n // 如果 URL 解析失败,尝试使用正则表达式\n const matches = url.match(/https?:\\/\\/[^\\/]+(\\/.*)/);\n return matches ? matches[1] : '';\n }\n }\n\n\n /**\n * 校验配置 <br/>\n * 如果不通过抛出异常\n * @param config\n * @protected\n */\n public verifyConfig(config: C): Promise<void> {\n return Promise.resolve(undefined);\n }\n\n protected readConfig(storageId: string): C {\n const key = `storageSource/${storageId}`\n return utools.dbCryptoStorage.getItem(key)\n }\n\n protected saveConfig(storageId: string, config: C): void {\n const key = `storageSource/${storageId}`;\n utools.dbCryptoStorage.setItem(key, config);\n }\n\n /**\n * 插件被卸载\n */\n uninstall() {\n\n }\n}\n","// 从 types 包导入并重新导出\nexport type { PluginType, PluginInfo, PluginConfig } from '@xiaou66/picture-types'\nimport type { PluginType } from '@xiaou66/picture-types'\n\n// @unocss-include\nexport const pluginTypeDict: Record<PluginType, Record<string, string>> = {\n 'storage': {\n name: '存储',\n icon: 'i-u-cloud-storage',\n },\n 'flowNode': {\n name: '流程',\n icon: 'i-u-flow'\n },\n}\n","// 从 types 包导入并重新导出\nexport type {\n FlowNodePluginInfo,\n FlowNodePluginConfig,\n IFlowContext,\n IFlowNodeActions,\n // 以下类型在 types 包的其他文件中定义,这里也重新导出以保持兼容\n FileUpdateInfoItem,\n SceneInfoItem,\n FileUploadInfo,\n FileLibraryInfo,\n FileLibraryItem,\n IFlowNode,\n IFlowItem,\n} from '@xiaou66/picture-types'\n\nimport type {\n FlowNodePluginConfig,\n FlowNodePluginInfo,\n IFlowNodeActions,\n IFlowItem,\n IFlowNode,\n IFlowContext\n} from '@xiaou66/picture-types'\n\n/**\n * 流程节点插件配置\n * @param config\n */\nexport function createFlowNodePluginConfig(config: Omit<FlowNodePluginConfig, 'pluginInfo'> & { pluginInfo: Omit<FlowNodePluginInfo, 'pluginType'> }): FlowNodePluginConfig {\n const newConfig = config as FlowNodePluginConfig\n newConfig.pluginInfo.pluginType = 'flowNode';\n return newConfig;\n}\n\n\n/**\n * 流程节点插件抽象基类\n * @template T 节点数据类型\n *\n * @example\n * ```typescript\n * class ImageCompressPlugin extends FlowNodePlugin<{ quality: number }> {\n * readonly info = {\n * pluginCode: 'image-compress',\n * pluginName: '图片压缩',\n * pluginGroup: 'image',\n * // ...其他插件信息\n * }\n *\n * async onExecute(flow, flowData, data) {\n * const { quality } = flowData.nodeData\n * // 压缩逻辑\n * }\n *\n * onDestroy(flow, flowData) {\n * // 清理资源\n * }\n * }\n *\n * const actions = createFlowNodeActions(new ImageCompressPlugin())\n * ```\n */\nexport abstract class FlowNodePlugin<T = any> implements IFlowNodeActions<T> {\n /**\n * 执行节点核心逻辑\n * @param flow 流程项\n * @param flowData 流程节点数据\n * @param data 流程上下文\n */\n abstract onExecute(flow: IFlowItem, flowData: IFlowNode<T>, data: IFlowContext): Promise<void>\n\n /**\n * 保存数据后的钩子(可选)\n * @param flow 流程项\n * @param flowData 流程节点数据\n */\n onAfterSave?(flow: IFlowItem, flowData: IFlowNode<T>): void\n\n /**\n * 节点销毁时的清理钩子(可选)\n * @param flow 流程项\n * @param flowData 流程节点数据\n */\n onDestroy?(flow: IFlowItem, flowData: IFlowNode<T>): void\n}\n\n\n/**\n * 创建流程节点动作配置\n * @param input 流程节点动作配置或 FlowNodePlugin 实例\n *\n * @example\n * // 方式1: 函数式配置(保持兼容)\n * const actions = createFlowNodeActions({\n * onExecute: async (flow, flowData, data) => {\n * // 逻辑\n * }\n * })\n *\n * @example\n * // 方式2: 类实例\n * const actions = createFlowNodeActions(new MyFlowNodePlugin())\n */\nexport function createFlowNodeActions<T>(input: IFlowNodeActions<T> | FlowNodePlugin<T>): IFlowNodeActions<T> {\n // FlowNodePlugin 实现了 IFlowNodeActions,可直接返回\n return input\n}\n"],"mappings":"AAcA,SAAgB,0BAA0B,GAA8H;CACtK,IAAM,IAAY;AAElB,QADA,EAAU,WAAW,aAAa,WAC3B;;ACdT,MAAa,iBAAiB;CAC5B;EACE,OAAO;EACP,OAAO;EACP,6BACS,IAAI,MAAM,EAAC,aAAa,CAAC,UAAU;EAE5C,SAAS,uBACA,IAAI,MAAM,EAAC,aAAa,CAAC,UAAU;EAE7C;CACD;EACE,OAAO;EACP,OAAO;EACP,6BACS,IAAI,MAAM,EAAC,aAAa,CAAC,UAAU,CAAC,UAAU,EAAE;EAEzD,SAAS,uBACA,IAAI,MAAM,EAAC,aAAa,CAAC,UAAU,CAAC,UAAU,EAAE;EAE1D;CACD;EACE,OAAO;EACP,OAAO;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AAC5C,QACE,OAAO,UAAU,QAAQ,iCAAiC,OAAO,aAAa,GAAG,IAEjF,OAAO,KAAK,KAAK,OAAO,QAAQ,WAAW,EAAE,OAAO,oBAAoB,QAAQ;;ACsBpF,IAAsB,gBAAtB,MAAgF;CAE9E,OAAa;AACX,OAAK,QAAQ;;CAUf,UAAU;AACR,OAAK,WAAW;;CAuBlB,WAAkB,GAAgD;AAChE,SAAO,QAAQ,QAAQ,GAAM;;CAS/B,iBAA2B,GAAqB,GAA2B;AACzE,SAAO,eAAe,GAAa,EAAO;;CAQ5C,iBAA2B,GAAqB;AAC9C,MAAI;AAEF,UADe,IAAI,IAAI,EAAI,CACb;UACA;GAEd,IAAM,IAAU,EAAI,MAAM,0BAA0B;AACpD,UAAO,IAAU,EAAQ,KAAK;;;CAWlC,aAAoB,GAA0B;AAC5C,SAAO,QAAQ,QAAQ,KAAA,EAAU;;CAGnC,WAAqB,GAAsB;EACzC,IAAM,IAAM,iBAAiB;AAC7B,SAAO,OAAO,gBAAgB,QAAQ,EAAI;;CAG5C,WAAqB,GAAmB,GAAiB;EACvD,IAAM,IAAM,iBAAiB;AAC7B,SAAO,gBAAgB,QAAQ,GAAK,EAAO;;CAM7C,YAAY;;ACrHd,MAAaA,iBAA6D;CACxE,SAAW;EACT,MAAM;EACN,MAAM;EACP;CACD,UAAY;EACV,MAAM;EACN,MAAM;EACP;CACF;ACeD,SAAgB,2BAA2B,GAAiI;CAC1K,IAAM,IAAY;AAElB,QADA,EAAU,WAAW,aAAa,YAC3B;;AA+BT,IAAsB,iBAAtB,MAA6E;AAyC7E,SAAgB,sBAAyB,GAAqE;AAE5G,QAAO"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FlowNodePluginConfig, FlowNodePluginInfo, IFlowNodeActions } from '@xiaou66/picture-types';
|
|
1
|
+
import { FlowNodePluginConfig, FlowNodePluginInfo, IFlowNodeActions, IFlowItem, IFlowNode, IFlowContext } from '@xiaou66/picture-types';
|
|
2
2
|
export type { FlowNodePluginInfo, FlowNodePluginConfig, IFlowContext, IFlowNodeActions, FileUpdateInfoItem, SceneInfoItem, FileUploadInfo, FileLibraryInfo, FileLibraryItem, IFlowNode, IFlowItem, } from '@xiaou66/picture-types';
|
|
3
3
|
/**
|
|
4
4
|
* 流程节点插件配置
|
|
@@ -7,8 +7,68 @@ export type { FlowNodePluginInfo, FlowNodePluginConfig, IFlowContext, IFlowNodeA
|
|
|
7
7
|
export declare function createFlowNodePluginConfig(config: Omit<FlowNodePluginConfig, 'pluginInfo'> & {
|
|
8
8
|
pluginInfo: Omit<FlowNodePluginInfo, 'pluginType'>;
|
|
9
9
|
}): FlowNodePluginConfig;
|
|
10
|
+
/**
|
|
11
|
+
* 流程节点插件抽象基类
|
|
12
|
+
* @template T 节点数据类型
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* class ImageCompressPlugin extends FlowNodePlugin<{ quality: number }> {
|
|
17
|
+
* readonly info = {
|
|
18
|
+
* pluginCode: 'image-compress',
|
|
19
|
+
* pluginName: '图片压缩',
|
|
20
|
+
* pluginGroup: 'image',
|
|
21
|
+
* // ...其他插件信息
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* async onExecute(flow, flowData, data) {
|
|
25
|
+
* const { quality } = flowData.nodeData
|
|
26
|
+
* // 压缩逻辑
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* onDestroy(flow, flowData) {
|
|
30
|
+
* // 清理资源
|
|
31
|
+
* }
|
|
32
|
+
* }
|
|
33
|
+
*
|
|
34
|
+
* const actions = createFlowNodeActions(new ImageCompressPlugin())
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare abstract class FlowNodePlugin<T = any> implements IFlowNodeActions<T> {
|
|
38
|
+
/**
|
|
39
|
+
* 执行节点核心逻辑
|
|
40
|
+
* @param flow 流程项
|
|
41
|
+
* @param flowData 流程节点数据
|
|
42
|
+
* @param data 流程上下文
|
|
43
|
+
*/
|
|
44
|
+
abstract onExecute(flow: IFlowItem, flowData: IFlowNode<T>, data: IFlowContext): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* 保存数据后的钩子(可选)
|
|
47
|
+
* @param flow 流程项
|
|
48
|
+
* @param flowData 流程节点数据
|
|
49
|
+
*/
|
|
50
|
+
onAfterSave?(flow: IFlowItem, flowData: IFlowNode<T>): void;
|
|
51
|
+
/**
|
|
52
|
+
* 节点销毁时的清理钩子(可选)
|
|
53
|
+
* @param flow 流程项
|
|
54
|
+
* @param flowData 流程节点数据
|
|
55
|
+
*/
|
|
56
|
+
onDestroy?(flow: IFlowItem, flowData: IFlowNode<T>): void;
|
|
57
|
+
}
|
|
10
58
|
/**
|
|
11
59
|
* 创建流程节点动作配置
|
|
12
|
-
* @param
|
|
60
|
+
* @param input 流程节点动作配置或 FlowNodePlugin 实例
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* // 方式1: 函数式配置(保持兼容)
|
|
64
|
+
* const actions = createFlowNodeActions({
|
|
65
|
+
* onExecute: async (flow, flowData, data) => {
|
|
66
|
+
* // 逻辑
|
|
67
|
+
* }
|
|
68
|
+
* })
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* // 方式2: 类实例
|
|
72
|
+
* const actions = createFlowNodeActions(new MyFlowNodePlugin())
|
|
13
73
|
*/
|
|
14
|
-
export declare function createFlowNodeActions<T>(
|
|
74
|
+
export declare function createFlowNodeActions<T>(input: IFlowNodeActions<T> | FlowNodePlugin<T>): IFlowNodeActions<T>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IFlowContext } from '@xiaou66/picture-types';
|
|
2
|
+
/**
|
|
3
|
+
* 替换上传文件
|
|
4
|
+
* @param ctx 流程上下文
|
|
5
|
+
* @param filePath 替换的文件路径
|
|
6
|
+
*/
|
|
7
|
+
export declare function replaceUploadFile(ctx: IFlowContext, filePath: string): void;
|
|
8
|
+
declare const _default: {
|
|
9
|
+
replaceUploadFile: typeof replaceUploadFile;
|
|
10
|
+
};
|
|
11
|
+
export default _default;
|