Skip to content
This repository was archived by the owner on Apr 25, 2022. It is now read-only.

Commit 69c02a4

Browse files
committed
优化配置页面
1 parent 59c4bb1 commit 69c02a4

17 files changed

+425
-387
lines changed

build/cxmooc-tools/manifest.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,6 @@
5555
"web_accessible_resources": [
5656
"src/mooc.js"
5757
],
58-
"homepage_url": "https://cx.icodef.com"
58+
"homepage_url": "https://cx.icodef.com",
59+
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
5960
}

package-lock.json

+26-27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"minimist": ">=1.2.2",
5050
"mongodb": "^3.1.10",
5151
"node-telegram-bot-api": "^0.30.0",
52-
"redis": "^2.8.0"
52+
"redis": "^2.8.0",
53+
"vue": "^2.6.12"
5354
}
5455
}

src/background.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,11 @@ class background implements Launcher {
169169
}
170170
}
171171

172-
let component = new Map<string, any>().set("logger", new ConsoleLog()).set("config", new ChromeConfigItems(NewBackendConfig(false)));
172+
async function init() {
173+
let component = new Map<string, any>().set("logger", new ConsoleLog()).set("config", new ChromeConfigItems(await NewBackendConfig(false)));
173174

174-
let application = new Application(Backend, new background(), component);
175-
application.run();
175+
let application = new Application(Backend, new background(), component);
176+
application.run();
177+
}
178+
179+
init();

src/internal/app/question.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ export class ToolsQuestionBankFacade implements QuestionBankFacade {
287287
callback(status);
288288
return resolve();
289289
}
290-
let t = Application.App.config.topic_interval * 60 * 1000;
290+
let t = Application.App.config.topic_interval * 1000;
291291
for (let i = 0; i < ret.answer.length; i++) {
292292
let answer = ret.answer[i];
293293
let question = this.question[answer.index];

src/internal/utils/config.ts

+31-15
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import {Application} from "../application";
44
export interface ConfigItems extends Config {
55
SetNamespace(namespace: string): void
66

7+
SetNamespaceConfig(namespace: string, key: string, val: string): Promise<any>
8+
9+
GetNamespaceConfig(namespace: string, key: string, defaultVal?: string): string
10+
711
vtoken: string
812
rand_answer: boolean
913
auto: boolean
@@ -40,7 +44,15 @@ export class ChromeConfigItems implements ConfigItems {
4044
return this.config.ConfigList();
4145
}
4246

43-
public GetConfig(key: string, defaultVal?: string): any {
47+
public SetNamespaceConfig(namespace: string, key: string, val: string): Promise<any> {
48+
return this.config.SetConfig(namespace + key, val);
49+
}
50+
51+
public GetNamespaceConfig(namespace: string, key: string, defaultVal?: string): string {
52+
return this.config.GetConfig(namespace + key, defaultVal);
53+
}
54+
55+
public GetConfig(key: string, defaultVal?: string): string {
4456
let val = this.config.GetConfig(this.Namespace + key);
4557
if (val == undefined && this.Namespace != "") {
4658
return this.config.GetConfig(key, defaultVal);
@@ -81,7 +93,11 @@ export class ChromeConfigItems implements ConfigItems {
8193
}
8294

8395
public get video_cdn() {
84-
return this.GetConfig("video_cdn");
96+
let val = this.GetConfig("video_cdn");
97+
if (val == "默认") {
98+
return ""
99+
}
100+
return val;
85101
}
86102

87103
public get video_multiple() {
@@ -125,8 +141,12 @@ export interface ConfigWatchCallback {
125141
}
126142

127143
// 后台环境中使用
128-
export function NewBackendConfig(onlyRead: boolean): backendConfig {
129-
return new backendConfig(onlyRead);
144+
export function NewBackendConfig(onlyRead: boolean): Promise<backendConfig> {
145+
return new Promise(async resolve => {
146+
let ret = new backendConfig(onlyRead);
147+
await ret.updateCache();
148+
resolve(ret);
149+
});
130150
}
131151

132152
class configWatch {
@@ -182,7 +202,6 @@ class backendConfig implements Config {
182202
constructor(onlyRead: boolean) {
183203
this.onlyRead = onlyRead;
184204
this.watch = new configWatch();
185-
this.updateCache();
186205
chrome.runtime.onMessage.addListener((request) => {
187206
if (request.type && request.type == "cxconfig") {
188207
this.cache[request.key] = request.value;
@@ -200,7 +219,7 @@ class backendConfig implements Config {
200219
chrome.storage.sync.set({"config_storage": txt});
201220
}
202221

203-
protected updateCache(): Promise<any> {
222+
public updateCache(): Promise<any> {
204223
return new Promise(resolve => {
205224
let configDefaultValue = new Map<string, any>()
206225
.set("vtoken", "").set("rand_answer", false).set("auto", true)
@@ -224,15 +243,12 @@ class backendConfig implements Config {
224243
});
225244
}
226245

227-
public GetConfig(key: string, defaultVal?: string): any {
228-
return new Promise<any>(async resolve => {
229-
if (this.cache == undefined) {
230-
await this.updateCache();
231-
resolve(this.cache[key] || defaultVal);
232-
return;
233-
}
234-
resolve(this.cache[key] || defaultVal);
235-
});
246+
public GetConfig(key: string, defaultVal?: string): string {
247+
if (this.cache == undefined) {
248+
Application.App.log.Fatal("缓存失败!!!");
249+
return "";
250+
}
251+
return this.cache[key] || defaultVal;
236252
}
237253

238254
public Watch(key: Array<string> | string, callback: ConfigWatchCallback): void {

src/mooc/course163/question.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class CourseQuestion implements Question {
106106
this.fill(options[n], answer.correct[i].content);
107107
if (this.GetType() == 2 && i != answer.correct.length - 1) {
108108
//多选
109-
await Sleep(Application.App.config.topic_interval * 60 * 1000);
109+
await Sleep(Application.App.config.topic_interval * 1000);
110110
}
111111
flag = true;
112112
}

0 commit comments

Comments
 (0)