Skip to content

Commit

Permalink
🐛 修复订阅@connect错误的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed Jan 22, 2022
1 parent f5183bd commit 247db9c
Show file tree
Hide file tree
Showing 5 changed files with 223 additions and 190 deletions.
9 changes: 5 additions & 4 deletions src/apps/grant/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ export class BackgroundGrant {
const _this: BackgroundGrant = <BackgroundGrant>this;
return new Promise((resolve, reject) => {
const handler = async () => {
const script = <Script | undefined>await App.Cache.getOrSet('script:' + grant.id.toString(), () => {
return _this.scriptMgr.getScript(grant.id)
const script = <Script | undefined>await App.Cache.getOrSet('script:grant:' + grant.id.toString(), () => {
return _this.scriptMgr.getScriptSelfMeta(grant.id);
});
if (!script) {
return reject('permission denied');
Expand Down Expand Up @@ -530,6 +530,7 @@ export class BackgroundGrant {
@BackgroundGrant.GMFunction({
confirm: (grant: Grant, script: Script) => {
return new Promise(resolve => {
console.log(grant, script);
const config = <GM_Types.XHRDetails>grant.params[0];
const url = new URL(config.url);
if (script.metadata['connect']) {
Expand All @@ -542,11 +543,11 @@ export class BackgroundGrant {
}
const ret: ConfirmParam = {
permission: 'cors',
permissionValue: url.host,
permissionValue: url.hostname,
title: '脚本正在试图访问跨域资源',
metadata: {
'脚本名称': script.name,
'请求域名': url.host,
'请求域名': url.hostname,
'请求地址': config.url,
},
describe: '请您确认是否允许脚本进行此操作,脚本也可增加@connect标签跳过此选项',
Expand Down
39 changes: 21 additions & 18 deletions src/apps/script/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,31 +490,34 @@ export class ScriptController {
}

public buildScriptCache(script: Script): Promise<ScriptCache> {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
return new Promise(async resolve => {
const ret: ScriptCache = <ScriptCache>Object.assign({}, script);

// 自定义配置
for (const key in ret.metadata) {
if (ret.selfMetadata && ret.selfMetadata[key]) {
ret.metadata[key] = ret.selfMetadata[key];
return new Promise(resolve => {
const handler = async () => {
const ret: ScriptCache = <ScriptCache>Object.assign({}, script);

// 自定义配置
if (ret.selfMetadata) {
ret.metadata = Object.assign({}, ret.metadata);
for (const key in ret.selfMetadata) {
ret.metadata[key] = ret.selfMetadata[key];
}
}
}

ret.value = await this.getScriptValue(ret);
ret.value = await this.getScriptValue(ret);

ret.resource = await this.getResources(ret);
ret.resource = await this.getResources(ret);

ret.flag = randomString(16);
ret.code = compileScriptCode(ret);
ret.flag = randomString(16);
ret.code = compileScriptCode(ret);

ret.grantMap = {};
ret.grantMap = {};

ret.metadata['grant']?.forEach((val: string) => {
ret.grantMap[val] = 'ok';
});
ret.metadata['grant']?.forEach((val: string) => {
ret.grantMap[val] = 'ok';
});

resolve(ret);
resolve(ret);
}
void handler();
});
}

Expand Down
Loading

0 comments on commit 247db9c

Please sign in to comment.