Skip to content

Commit c6250c8

Browse files
committed
feat: Console
Update arguments-builder.config.ts Update response.dev.js Update request.dev.js Update database.mjs Update response.js Update setENV.mjs Update request.js
1 parent c00de16 commit c6250c8

File tree

7 files changed

+50
-20
lines changed

7 files changed

+50
-20
lines changed

arguments-builder.config.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,20 @@ export default defineConfig({
130130
placeholder: "123456789123456789abcdefghijklmnopqrstuv",
131131
description: "WAQI API 令牌,填写此字段将自动使用WAQI高级API",
132132
},
133+
{
134+
key: "LogLevel",
135+
name: "[调试] 日志等级",
136+
type: "string",
137+
defaultValue: "WARN",
138+
description: "选择脚本日志的输出等级,低于所选等级的日志将全部输出。",
139+
options: [
140+
{ key: "OFF", label: "关闭" },
141+
{ key: "ERROR", label: "❌ 错误" },
142+
{ key: "WARN", label: "⚠️ 警告" },
143+
{ key: "INFO", label: "ℹ️ 信息" },
144+
{ key: "DEBUG", label: "🅱️ 调试" },
145+
{ key: "ALL", label: "全部" },
146+
],
147+
},
133148
],
134149
});

src/function/database.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ export default {
3434
v1: ["currentWeather", "dailyForecast", "hourlyForecast", "minuteForecast", "weatherAlerts"],
3535
v2: ["airQuality", "currentWeather", "forecastDaily", "forecastHourly", "forecastPeriodic", "historicalComparisons", "weatherChanges", "forecastNextHour", "weatherAlerts", "weatherAlertNotifications", "news"],
3636
},
37+
},
38+
},
39+
Default: {
40+
Settings: {
41+
LogLevel: "WARN",
42+
},
43+
Configs: {
3744
Storefront: {
3845
AE: "143481",
3946
AF: "143610",

src/function/setENV.mjs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,12 @@ export default function setENV(name, platforms, database) {
1212
Console.log("☑️ Set Environment Variables");
1313
const { Settings, Caches, Configs } = getStorage(name, platforms, database);
1414
/***************** Settings *****************/
15-
switch (platforms) {
16-
case "WeatherKit":
17-
if (!Array.isArray(Settings?.AQI?.ReplaceProviders)) _.set(Settings, "AQI.ReplaceProviders", (Settings?.AQI?.ReplaceProviders) ? [Settings.AQI.ReplaceProviders.toString()] : []);
18-
if (Settings.AQI.ReplaceProviders.includes("TWC")) Settings.AQI.ReplaceProviders.push("The Weather Channel");
19-
if (Settings.AQI.ReplaceProviders.includes("QWeather")) Settings.AQI.ReplaceProviders.push("和风天气");
20-
Settings.AQI.ReplaceProviders.push(undefined);
21-
if (!Array.isArray(Settings?.AQI?.Local?.ReplaceScales)) _.set(Settings, "AQI.Local.ReplaceScales", (Settings?.AQI?.Local?.ReplaceScales) ? [Settings.AQI.Local.ReplaceScales.toString()] : []);
22-
break;
23-
case "Siri":
24-
if (!Array.isArray(Settings?.Domains)) _.set(Settings, "Domains", (Settings?.Domains) ? [Settings.Domains.toString()] : []);
25-
if (!Array.isArray(Settings?.Functions)) _.set(Settings, "Functions", (Settings?.Functions) ? [Settings.Functions.toString()] : []);
26-
break;
27-
case "TV":
28-
if (!Array.isArray(Settings?.Tabs)) _.set(Settings, "Tabs", (Settings?.Tabs) ? [Settings.Tabs.toString()] : []);
29-
break;
30-
};
31-
Console.debug(`typeof Settings: ${typeof Settings}`, `Settings: ${JSON.stringify(Settings, null, 2)}`);
15+
if (!Array.isArray(Settings?.AQI?.ReplaceProviders)) _.set(Settings, "AQI.ReplaceProviders", Settings?.AQI?.ReplaceProviders ? [Settings.AQI.ReplaceProviders.toString()] : []);
16+
if (Settings.AQI.ReplaceProviders.includes("TWC")) Settings.AQI.ReplaceProviders.push("The Weather Channel");
17+
if (Settings.AQI.ReplaceProviders.includes("QWeather")) Settings.AQI.ReplaceProviders.push("和风天气");
18+
Settings.AQI.ReplaceProviders.push(undefined);
19+
if (!Array.isArray(Settings?.AQI?.Local?.ReplaceScales)) _.set(Settings, "AQI.Local.ReplaceScales", Settings?.AQI?.Local?.ReplaceScales ? [Settings.AQI.Local.ReplaceScales.toString()] : []);
20+
Console.info(`typeof Settings: ${typeof Settings}`, `Settings: ${JSON.stringify(Settings, null, 2)}`);
3221
/***************** Caches *****************/
3322
//Console.debug(`typeof Caches: ${typeof Caches}`, `Caches: ${JSON.stringify(Caches)}`);
3423
/***************** Configs *****************/
@@ -37,4 +26,4 @@ export default function setENV(name, platforms, database) {
3726
if (Configs.i18n) for (const type in Configs.i18n) Configs.i18n[type] = new Map(Configs.i18n[type]);
3827
Console.log("✅ Set Environment Variables");
3928
return { Settings, Caches, Configs };
40-
};
29+
}

src/response.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import ColorfulClouds from "./class/ColorfulClouds.mjs";
88
import QWeather from "./class/QWeather.mjs";
99
import AirQuality from "./class/AirQuality.mjs";
1010
import * as flatbuffers from "flatbuffers";
11-
Console.logLevel = "DEBUG";
1211
/***************** Processing *****************/
1312
// 解构URL
1413
const url = new URL($request.url);
@@ -25,6 +24,7 @@ Console.info(`FORMAT: ${FORMAT}`);
2524
* @type {{Settings: import('./types').Settings}}
2625
*/
2726
const { Settings, Caches, Configs } = setENV("iRingo", "WeatherKit", database);
27+
Console.logLevel = Settings.LogLevel;
2828
// 创建空数据
2929
let body = {};
3030
// 格式判断

src/response.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Console.info(`FORMAT: ${FORMAT}`);
2424
* @type {{Settings: import('./types').Settings}}
2525
*/
2626
const { Settings, Caches, Configs } = setENV("iRingo", "WeatherKit", database);
27+
Console.logLevel = Settings.LogLevel;
2728
// 创建空数据
2829
let body = {};
2930
// 格式判断

src/types.d.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,22 @@ export interface Settings {
132132
Token?: string;
133133
};
134134
};
135+
/**
136+
* [调试] 日志等级
137+
*
138+
* 选择脚本日志的输出等级,低于所选等级的日志将全部输出。
139+
*
140+
* @remarks
141+
*
142+
* Possible values:
143+
* - `'OFF'` - 关闭
144+
* - `'ERROR'` - ❌ 错误
145+
* - `'WARN'` - ⚠️ 警告
146+
* - `'INFO'` - ℹ️ 信息
147+
* - `'DEBUG'` - 🅱️ 调试
148+
* - `'ALL'` - 全部
149+
*
150+
* @defaultValue "WARN"
151+
*/
152+
LogLevel?: 'OFF' | 'ERROR' | 'WARN' | 'INFO' | 'DEBUG' | 'ALL';
135153
}

template/boxjs.settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[{"id":"@iRingo.WeatherKit.Settings.NextHour.Provider","name":"[未来一小时降水强度] 数据源","type":"selects","val":"ColorfulClouds","items":[{"key":"WeatherKit","label":"WeatherKit (不进行替换)"},{"key":"ColorfulClouds","label":"彩云天气"},{"key":"QWeather","label":"和风天气"}],"desc":"始终会使用选定的数据源,填补无降水监测地区的数据。"},{"id":"@iRingo.WeatherKit.Settings.AQI.Provider","name":"[空气质量] 数据源","type":"selects","val":"ColorfulClouds","items":[{"key":"WeatherKit","label":"WeatherKit (不进行替换)"},{"key":"ColorfulClouds","label":"彩云天气"},{"key":"QWeather","label":"和风天气"},{"key":"WAQI","label":"The World Air Quality Project"}],"desc":"始终会使用选定的数据源,填补无空气质量监测地区的数据。"},{"id":"@iRingo.WeatherKit.Settings.AQI.ReplaceProviders","name":"[空气质量] 需要替换的供应商","type":"checkboxes","val":["QWeather"],"items":[{"key":"QWeather","label":"和风天气"},{"key":"BreezoMeter","label":"BreezoMeter"},{"key":"TWC","label":"The Weather Channel"}],"desc":"选中的空气质量数据源会被替换。"},{"id":"@iRingo.WeatherKit.Settings.AQI.Local.Scale","name":"[空气质量] 本地替换算法","type":"selects","val":"WAQI_InstantCast","items":[{"key":"NONE","label":"None (不进行替换)"},{"key":"WAQI_InstantCast","label":"WAQI InstantCast"}],"desc":"本地替换时使用的算法"},{"id":"@iRingo.WeatherKit.Settings.AQI.Local.ReplaceScales","name":"[空气质量] 需要修改的标准","type":"checkboxes","val":["HJ6332012"],"items":[{"key":"HJ6332012","label":"中国 (HJ 633—2012)"}],"desc":"选中的空气质量标准会被替换。请注意各国监测的污染物种类可能有所不同,转换算法或API未必适合当地。"},{"id":"@iRingo.WeatherKit.Settings.AQI.Local.ConvertUnits","name":"[空气质量] 转换污染物计量单位","type":"boolean","val":false,"desc":"将污染物数据替换为转换单位后的数据,方便对照转换后的标准。(不推荐。不同单位互转可能会损失精度,导致数值偏大)"},{"id":"@iRingo.WeatherKit.Settings.API.ColorfulClouds.Token","name":"[API] 彩云天气令牌","type":"text","val":"","desc":"彩云天气 API 令牌","placeholder":"123456789123456789abcdefghijklmnopqrstuv"},{"id":"@iRingo.WeatherKit.Settings.API.QWeather.Host","name":"[API] 和风天气主机","type":"selects","val":"devapi.qweather.com","items":[{"key":"devapi.qweather.com","label":"免费订阅 (devapi.qweather.com)"},{"key":"api.qweather.com","label":"付费订阅 (api.qweather.com)"}],"desc":"和风天气 API 使用的主机名"},{"id":"@iRingo.WeatherKit.Settings.API.QWeather.Token","name":"[API] 和风天气令牌","type":"text","val":"","desc":"和风天气 API 令牌","placeholder":"123456789123456789abcdefghijklmnopqrstuv"},{"id":"@iRingo.WeatherKit.Settings.API.WAQI.Token","name":"[API] WAQI 令牌","type":"text","val":"","desc":"WAQI API 令牌,填写此字段将自动使用WAQI高级API","placeholder":"123456789123456789abcdefghijklmnopqrstuv"}]
1+
[{"id":"@iRingo.WeatherKit.Settings.NextHour.Provider","name":"[未来一小时降水强度] 数据源","type":"selects","val":"ColorfulClouds","items":[{"key":"WeatherKit","label":"WeatherKit (不进行替换)"},{"key":"ColorfulClouds","label":"彩云天气"},{"key":"QWeather","label":"和风天气"}],"desc":"始终会使用选定的数据源,填补无降水监测地区的数据。"},{"id":"@iRingo.WeatherKit.Settings.AQI.Provider","name":"[空气质量] 数据源","type":"selects","val":"ColorfulClouds","items":[{"key":"WeatherKit","label":"WeatherKit (不进行替换)"},{"key":"ColorfulClouds","label":"彩云天气"},{"key":"QWeather","label":"和风天气"},{"key":"WAQI","label":"The World Air Quality Project"}],"desc":"始终会使用选定的数据源,填补无空气质量监测地区的数据。"},{"id":"@iRingo.WeatherKit.Settings.AQI.ReplaceProviders","name":"[空气质量] 需要替换的供应商","type":"checkboxes","val":["QWeather"],"items":[{"key":"QWeather","label":"和风天气"},{"key":"BreezoMeter","label":"BreezoMeter"},{"key":"TWC","label":"The Weather Channel"}],"desc":"选中的空气质量数据源会被替换。"},{"id":"@iRingo.WeatherKit.Settings.AQI.Local.Scale","name":"[空气质量] 本地替换算法","type":"selects","val":"WAQI_InstantCast","items":[{"key":"NONE","label":"None (不进行替换)"},{"key":"WAQI_InstantCast","label":"WAQI InstantCast"}],"desc":"本地替换时使用的算法"},{"id":"@iRingo.WeatherKit.Settings.AQI.Local.ReplaceScales","name":"[空气质量] 需要修改的标准","type":"checkboxes","val":["HJ6332012"],"items":[{"key":"HJ6332012","label":"中国 (HJ 633—2012)"}],"desc":"选中的空气质量标准会被替换。请注意各国监测的污染物种类可能有所不同,转换算法或API未必适合当地。"},{"id":"@iRingo.WeatherKit.Settings.AQI.Local.ConvertUnits","name":"[空气质量] 转换污染物计量单位","type":"boolean","val":false,"desc":"将污染物数据替换为转换单位后的数据,方便对照转换后的标准。(不推荐。不同单位互转可能会损失精度,导致数值偏大)"},{"id":"@iRingo.WeatherKit.Settings.API.ColorfulClouds.Token","name":"[API] 彩云天气令牌","type":"text","val":"","desc":"彩云天气 API 令牌","placeholder":"123456789123456789abcdefghijklmnopqrstuv"},{"id":"@iRingo.WeatherKit.Settings.API.QWeather.Host","name":"[API] 和风天气主机","type":"selects","val":"devapi.qweather.com","items":[{"key":"devapi.qweather.com","label":"免费订阅 (devapi.qweather.com)"},{"key":"api.qweather.com","label":"付费订阅 (api.qweather.com)"}],"desc":"和风天气 API 使用的主机名"},{"id":"@iRingo.WeatherKit.Settings.API.QWeather.Token","name":"[API] 和风天气令牌","type":"text","val":"","desc":"和风天气 API 令牌","placeholder":"123456789123456789abcdefghijklmnopqrstuv"},{"id":"@iRingo.WeatherKit.Settings.API.WAQI.Token","name":"[API] WAQI 令牌","type":"text","val":"","desc":"WAQI API 令牌,填写此字段将自动使用WAQI高级API","placeholder":"123456789123456789abcdefghijklmnopqrstuv"},{"id":"@iRingo.WeatherKit.Settings.LogLevel","name":"[调试] 日志等级","type":"selects","val":"WARN","items":[{"key":"OFF","label":"关闭"},{"key":"ERROR","label":"❌ 错误"},{"key":"WARN","label":"⚠️ 警告"},{"key":"INFO","label":"ℹ️ 信息"},{"key":"DEBUG","label":"🅱️ 调试"},{"key":"ALL","label":"全部"}],"desc":"选择脚本日志的输出等级,低于所选等级的日志将全部输出。"}]

0 commit comments

Comments
 (0)