mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-09-12 05:53:31 +08:00
quickcommand.loadRemoteScript添加是否使用缓存的选项,支持将脚本缓存到本地,不必每次重复下载
This commit is contained in:
parent
abcb672d70
commit
32f8fad362
@ -14,7 +14,10 @@ window.getModelsFromAiApi = getModels;
|
|||||||
|
|
||||||
const systemDialog = require("./dialog/service");
|
const systemDialog = require("./dialog/service");
|
||||||
|
|
||||||
const { getQuickcommandTempFile } = require("./getQuickcommandFile");
|
const {
|
||||||
|
getQuickcommandTempFile,
|
||||||
|
getQuickcommandFolderFile,
|
||||||
|
} = require("./getQuickcommandFile");
|
||||||
|
|
||||||
const createTerminalCommand = require("./createTerminalCommand");
|
const createTerminalCommand = require("./createTerminalCommand");
|
||||||
|
|
||||||
@ -153,18 +156,26 @@ const quickcommand = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 载入在线资源
|
// 载入在线资源
|
||||||
loadRemoteScript: async function (url) {
|
loadRemoteScript: async function (url, options) {
|
||||||
if (
|
const urlReg =
|
||||||
!/^((ht|f)tps?):\/\/([\w\-]+(\.[\w\-]+)*\/)*[\w\-]+(\.[\w\-]+)*\/?(\?([\w\-\.,@?^=%&:\/~\+#]*)+)?/.test(
|
/^((ht|f)tps?):\/\/([\w\-]+(\.[\w\-]+)*\/)*[\w\-]+(\.[\w\-]+)*\/?(\?([\w\-\.,@?^=%&:\/~\+#]*)+)?/;
|
||||||
url
|
if (!urlReg.test(url)) throw "url 不合法";
|
||||||
)
|
const { useCache = false } = options;
|
||||||
)
|
if (useCache) {
|
||||||
throw "url 不合法";
|
const urlHash = quickcomposer.coding.md5Hash(url);
|
||||||
let local = getQuickcommandTempFile("js");
|
const fileName = path.basename(url, ".js") + "." + urlHash.slice(8, -8);
|
||||||
await this.downloadFile(url, local);
|
const local = getQuickcommandFolderFile(fileName, "js");
|
||||||
let source = require(local);
|
if (!fs.existsSync(local)) {
|
||||||
fs.unlinkSync(local);
|
await this.downloadFile(url, local);
|
||||||
return source;
|
}
|
||||||
|
return require(local);
|
||||||
|
} else {
|
||||||
|
const local = getQuickcommandTempFile("js");
|
||||||
|
await this.downloadFile(url, local);
|
||||||
|
let source = require(local);
|
||||||
|
fs.unlinkSync(local);
|
||||||
|
return source;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 唤醒 uTools
|
// 唤醒 uTools
|
||||||
|
@ -346,8 +346,10 @@ interface quickcommandApi {
|
|||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @param url 脚本地址
|
* @param url 脚本地址
|
||||||
|
* @param options 选项
|
||||||
|
* @param options.useCache 使用缓存,默认为假。为真时会将远程脚本缓存到本地的utools.getPath("userData")/quickcommand目录,否则每次都会下载脚本
|
||||||
*/
|
*/
|
||||||
loadRemoteScript(url: string): Promise<object>;
|
loadRemoteScript(url: string, options?: { useCache?: boolean }): Promise<object>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将 signal 发送给 pid 标识的进程 , 默认为关闭进程
|
* 将 signal 发送给 pid 标识的进程 , 默认为关闭进程
|
||||||
|
Loading…
x
Reference in New Issue
Block a user