fix(deeplink): import usage scripts disabled and show their code

An imported usage script is JavaScript that runs whenever usage is
queried. Two things made it possible to acquire one without seeing it:

  - `usage_enabled.unwrap_or(!code.is_empty())` treated the presence of
    code as a decision to run it, so a link that simply carried a script
    got it enabled
  - the confirmation dialog rendered only an enabled/disabled badge; the
    script body was never displayed

Default to disabled. Enabling now requires `usageEnabled=true` in the
link -- which is the link author's request, not the user's consent. The
consent is the user pressing Import after seeing the full script body
and the badge, which is why both displays are load-bearing rather than
decorative.

The badge predicate moves from `!== false` to `=== true` to match the
new backend default. Left alone it would have started rendering "did not
say" as a green "Enabled" -- more optimistic than what would actually
happen.

Extracts the payload decode into `decodeDeeplinkPayload`, which falls
back to the raw string when decoding fails or yields empty. A dialog
whose job is to show what is about to be written must not let a payload
vanish just because it is malformed; empty reads as "there is no
script", which is exactly the wrong impression.
This commit is contained in:
Jason
2026-07-29 00:04:20 +08:00
parent 19bf236e58
commit cfa90f396a
10 changed files with 193 additions and 5 deletions
+2
View File
@@ -2509,6 +2509,8 @@
"usageScript": "Usage Query",
"usageScriptEnabled": "Enabled",
"usageScriptDisabled": "Disabled",
"usageScriptCode": "Script code",
"usageScriptWarning": "This is JavaScript that runs when usage is queried, once enabled. Import it only if you trust the source.",
"usageApiKey": "Usage API Key",
"usageBaseUrl": "Usage Query URL",
"usageAutoInterval": "Auto Query",
+2
View File
@@ -2509,6 +2509,8 @@
"usageScript": "使用量クエリ",
"usageScriptEnabled": "有効",
"usageScriptDisabled": "無効",
"usageScriptCode": "スクリプトコード",
"usageScriptWarning": "これは有効化すると使用量クエリ時に実行される JavaScript です。提供元が信頼できる場合のみインポートしてください。",
"usageApiKey": "使用量 API キー",
"usageBaseUrl": "使用量クエリ URL",
"usageAutoInterval": "自動クエリ",
+2
View File
@@ -2480,6 +2480,8 @@
"usageScript": "用量查詢",
"usageScriptEnabled": "已啟用",
"usageScriptDisabled": "未啟用",
"usageScriptCode": "指令碼程式碼",
"usageScriptWarning": "這是一段 JavaScript 程式碼,啟用後會在查詢用量時執行。請確認來源可信後再匯入。",
"usageApiKey": "用量 API Key",
"usageBaseUrl": "用量查詢位址",
"usageAutoInterval": "自動查詢",
+2
View File
@@ -2509,6 +2509,8 @@
"usageScript": "用量查询",
"usageScriptEnabled": "已启用",
"usageScriptDisabled": "未启用",
"usageScriptCode": "脚本代码",
"usageScriptWarning": "这是一段 JavaScript 代码,启用后会在查询用量时执行。请确认来源可信后再导入。",
"usageApiKey": "用量 API Key",
"usageBaseUrl": "用量查询地址",
"usageAutoInterval": "自动查询",