Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c70ab48

Browse files
committed
改进OpenAPI日志输出样式,区分Log, Info和Error类型, 持久化格式美化
1 parent 17765c7 commit c70ab48

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

Tools/OpenAPI/API.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* OpenAPI
3+
* @author: Peng-YM
4+
* https://github.com/Peng-YM/QuanX/blob/master/Tools/OpenAPI/README.md
5+
*/
16
function ENV() {
27
const isQX = typeof $task !== "undefined";
38
const isLoon = typeof $loon !== "undefined";
@@ -134,8 +139,7 @@ function API(name = "untitled", debug = false) {
134139
};
135140
}
136141

137-
// persistance
138-
142+
// persistence
139143
// initialize cache
140144
initCache() {
141145
if (isQX) this.cache = JSON.parse($prefs.valueForKey(this.name) || "{}");
@@ -175,7 +179,7 @@ function API(name = "untitled", debug = false) {
175179

176180
// store cache
177181
persistCache() {
178-
const data = JSON.stringify(this.cache);
182+
const data = JSON.stringify(this.cache, null, 2);
179183
if (isQX) $prefs.setValueForKey(data, this.name);
180184
if (isLoon || isSurge) $persistentStore.write(data, this.name);
181185
if (isNode) {
@@ -187,7 +191,7 @@ function API(name = "untitled", debug = false) {
187191
);
188192
this.node.fs.writeFileSync(
189193
"root.json",
190-
JSON.stringify(this.root),
194+
JSON.stringify(this.root, null, 2),
191195
{flag: "w"},
192196
(err) => console.log(err)
193197
);
@@ -270,7 +274,7 @@ function API(name = "untitled", debug = false) {
270274
let opts = {};
271275
if (openURL) opts["openUrl"] = openURL;
272276
if (mediaURL) opts["mediaUrl"] = mediaURL;
273-
if (JSON.stringify(opts) == "{}") {
277+
if (JSON.stringify(opts) === "{}") {
274278
$notification.post(title, subtitle, content);
275279
} else {
276280
$notification.post(title, subtitle, content, opts);
@@ -295,15 +299,15 @@ function API(name = "untitled", debug = false) {
295299

296300
// other helper functions
297301
log(msg) {
298-
if (this.debug) console.log(msg);
302+
if (this.debug) console.log(`[${this.name}] LOG: ${msg}`);
299303
}
300304

301305
info(msg) {
302-
console.log(msg);
306+
console.log(`[${this.name}] INFO: ${msg}`);
303307
}
304308

305309
error(msg) {
306-
console.log("ERROR: " + msg);
310+
console.log(`[${this.name}] ERROR: ${msg}`);
307311
}
308312

309313
wait(millisec) {
@@ -322,4 +326,4 @@ function API(name = "untitled", debug = false) {
322326
}
323327
}
324328
})(name, debug);
325-
}
329+
}

Tools/OpenAPI/api-minified.js

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

0 commit comments

Comments
 (0)