mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-08-02 18:41:35 +08:00
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:
@@ -254,8 +254,18 @@ fn build_provider_meta(request: &DeepLinkImportRequest) -> Result<Option<Provide
|
||||
String::new()
|
||||
};
|
||||
|
||||
// Determine enabled state: explicit param > has code > false
|
||||
let enabled = request.usage_enabled.unwrap_or(!code.is_empty());
|
||||
// Determine enabled state: explicit param only, defaulting to disabled.
|
||||
//
|
||||
// 「携带了代码」不构成用户的启用决定。此处的输入来自 deeplink——即第三方
|
||||
// 构造、经浏览器抵达的不可信载荷——而 `code` 是一段会在查询用量时执行的
|
||||
// JavaScript。若以 `!code.is_empty()` 作默认,一条链接就能让脚本在用户
|
||||
// 从未勾选过的情况下进入启用态。
|
||||
//
|
||||
// 要启用,链接必须显式携带 `usageEnabled=true`。注意该参数是**链接作者**的
|
||||
// 请求,不构成用户的同意;用户的同意体现在确认框展示了完整脚本正文与启用
|
||||
// 徽章之后仍点了导入——所以那两处展示是本设计的承重部分,不可省略。
|
||||
// 用户在应用内手动配置的脚本不走这条路径。
|
||||
let enabled = request.usage_enabled.unwrap_or(false);
|
||||
|
||||
let usage_script = UsageScript {
|
||||
enabled,
|
||||
|
||||
Reference in New Issue
Block a user