Skip to content

Commit

Permalink
feat: Console
Browse files Browse the repository at this point in the history
Update arguments-builder.config.ts
Update boxjs.settings.json
Update response.dev.js
Update request.dev.js
Update database.mjs
Update response.js
Update request.js
Update setENV.mjs
Update types.d.ts
  • Loading branch information
VirgilClyne committed Dec 9, 2024
1 parent c00de16 commit 4c69457
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 20 deletions.
15 changes: 15 additions & 0 deletions arguments-builder.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,20 @@ export default defineConfig({
placeholder: "123456789123456789abcdefghijklmnopqrstuv",
description: "WAQI API 令牌,填写此字段将自动使用WAQI高级API",
},
{
key: "LogLevel",
name: "[调试] 日志等级",
type: "string",
defaultValue: "WARN",
description: "选择脚本日志的输出等级,低于所选等级的日志将全部输出。",
options: [
{ key: "OFF", label: "关闭" },
{ key: "ERROR", label: "❌ 错误" },
{ key: "WARN", label: "⚠️ 警告" },
{ key: "INFO", label: "ℹ️ 信息" },
{ key: "DEBUG", label: "🅱️ 调试" },
{ key: "ALL", label: "全部" },
],
},
],
});
7 changes: 7 additions & 0 deletions src/function/database.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ export default {
v1: ["currentWeather", "dailyForecast", "hourlyForecast", "minuteForecast", "weatherAlerts"],
v2: ["airQuality", "currentWeather", "forecastDaily", "forecastHourly", "forecastPeriodic", "historicalComparisons", "weatherChanges", "forecastNextHour", "weatherAlerts", "weatherAlertNotifications", "news"],
},
},
},
Default: {
Settings: {
LogLevel: "WARN",
},
Configs: {
Storefront: {
AE: "143481",
AF: "143610",
Expand Down
25 changes: 7 additions & 18 deletions src/function/setENV.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,12 @@ export default function setENV(name, platforms, database) {
Console.log("☑️ Set Environment Variables");
const { Settings, Caches, Configs } = getStorage(name, platforms, database);
/***************** Settings *****************/
switch (platforms) {
case "WeatherKit":
if (!Array.isArray(Settings?.AQI?.ReplaceProviders)) _.set(Settings, "AQI.ReplaceProviders", (Settings?.AQI?.ReplaceProviders) ? [Settings.AQI.ReplaceProviders.toString()] : []);
if (Settings.AQI.ReplaceProviders.includes("TWC")) Settings.AQI.ReplaceProviders.push("The Weather Channel");
if (Settings.AQI.ReplaceProviders.includes("QWeather")) Settings.AQI.ReplaceProviders.push("和风天气");
Settings.AQI.ReplaceProviders.push(undefined);
if (!Array.isArray(Settings?.AQI?.Local?.ReplaceScales)) _.set(Settings, "AQI.Local.ReplaceScales", (Settings?.AQI?.Local?.ReplaceScales) ? [Settings.AQI.Local.ReplaceScales.toString()] : []);
break;
case "Siri":
if (!Array.isArray(Settings?.Domains)) _.set(Settings, "Domains", (Settings?.Domains) ? [Settings.Domains.toString()] : []);
if (!Array.isArray(Settings?.Functions)) _.set(Settings, "Functions", (Settings?.Functions) ? [Settings.Functions.toString()] : []);
break;
case "TV":
if (!Array.isArray(Settings?.Tabs)) _.set(Settings, "Tabs", (Settings?.Tabs) ? [Settings.Tabs.toString()] : []);
break;
};
Console.debug(`typeof Settings: ${typeof Settings}`, `Settings: ${JSON.stringify(Settings, null, 2)}`);
if (!Array.isArray(Settings?.AQI?.ReplaceProviders)) _.set(Settings, "AQI.ReplaceProviders", Settings?.AQI?.ReplaceProviders ? [Settings.AQI.ReplaceProviders.toString()] : []);
if (Settings.AQI.ReplaceProviders.includes("TWC")) Settings.AQI.ReplaceProviders.push("The Weather Channel");
if (Settings.AQI.ReplaceProviders.includes("QWeather")) Settings.AQI.ReplaceProviders.push("和风天气");
Settings.AQI.ReplaceProviders.push(undefined);
if (!Array.isArray(Settings?.AQI?.Local?.ReplaceScales)) _.set(Settings, "AQI.Local.ReplaceScales", Settings?.AQI?.Local?.ReplaceScales ? [Settings.AQI.Local.ReplaceScales.toString()] : []);
Console.info(`typeof Settings: ${typeof Settings}`, `Settings: ${JSON.stringify(Settings, null, 2)}`);
/***************** Caches *****************/
//Console.debug(`typeof Caches: ${typeof Caches}`, `Caches: ${JSON.stringify(Caches)}`);
/***************** Configs *****************/
Expand All @@ -37,4 +26,4 @@ export default function setENV(name, platforms, database) {
if (Configs.i18n) for (const type in Configs.i18n) Configs.i18n[type] = new Map(Configs.i18n[type]);
Console.log("✅ Set Environment Variables");
return { Settings, Caches, Configs };
};
}
2 changes: 1 addition & 1 deletion src/response.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import ColorfulClouds from "./class/ColorfulClouds.mjs";
import QWeather from "./class/QWeather.mjs";
import AirQuality from "./class/AirQuality.mjs";
import * as flatbuffers from "flatbuffers";
Console.logLevel = "DEBUG";
/***************** Processing *****************/
// 解构URL
const url = new URL($request.url);
Expand All @@ -25,6 +24,7 @@ Console.info(`FORMAT: ${FORMAT}`);
* @type {{Settings: import('./types').Settings}}
*/
const { Settings, Caches, Configs } = setENV("iRingo", "WeatherKit", database);
Console.logLevel = Settings.LogLevel;
// 创建空数据
let body = {};
// 格式判断
Expand Down
1 change: 1 addition & 0 deletions src/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Console.info(`FORMAT: ${FORMAT}`);
* @type {{Settings: import('./types').Settings}}
*/
const { Settings, Caches, Configs } = setENV("iRingo", "WeatherKit", database);
Console.logLevel = Settings.LogLevel;
// 创建空数据
let body = {};
// 格式判断
Expand Down
18 changes: 18 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,22 @@ export interface Settings {
Token?: string;
};
};
/**
* [调试] 日志等级
*
* 选择脚本日志的输出等级,低于所选等级的日志将全部输出。
*
* @remarks
*
* Possible values:
* - `'OFF'` - 关闭
* - `'ERROR'` - ❌ 错误
* - `'WARN'` - ⚠️ 警告
* - `'INFO'` - ℹ️ 信息
* - `'DEBUG'` - 🅱️ 调试
* - `'ALL'` - 全部
*
* @defaultValue "WARN"
*/
LogLevel?: 'OFF' | 'ERROR' | 'WARN' | 'INFO' | 'DEBUG' | 'ALL';
}
2 changes: 1 addition & 1 deletion template/boxjs.settings.json
Original file line number Diff line number Diff line change
@@ -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"}]
[{"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 comments on commit 4c69457

Please sign in to comment.