mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-05-07 00:15:53 +08:00
feat: 改进http,返回header和status_code,并实现url级别细粒度控制和ui提示 (#2332)
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Media;
|
||||
using BetterGenshinImpact.Core.Script.Group;
|
||||
using BetterGenshinImpact.GameTask;
|
||||
using BetterGenshinImpact.Service.Notification;
|
||||
@@ -37,13 +39,76 @@ public class ScriptGroupProjectEditorViewModel : ObservableObject
|
||||
|
||||
public bool? AllowJsHTTP
|
||||
{
|
||||
get => _project.AllowJsHTTP;
|
||||
get
|
||||
{
|
||||
return _project.AllowJsHTTP;
|
||||
}
|
||||
set
|
||||
{
|
||||
_project.AllowJsHTTP = value;
|
||||
// 为了避免误用,AllowJsHTTP禁止set,通过更新Hash来控制
|
||||
// 脚本作者更新时,如果Hash变更会自动禁用http权限,避免安全风险
|
||||
if (value == null || value == false)
|
||||
{
|
||||
_project.AllowJsHTTPHash = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
_project.AllowJsHTTPHash = _project.GetHttpAllowedUrlsHash();
|
||||
}
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public record JsText(string Text, Brush Color);
|
||||
public List<JsText> JsHTTPInfoText
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_project.Project == null)
|
||||
{
|
||||
_project.BuildScriptProjectRelation();
|
||||
}
|
||||
if (_project.Project == null)
|
||||
{
|
||||
return new List<JsText>
|
||||
{
|
||||
new JsText("当前脚本项目未加载", Brushes.Red)
|
||||
};
|
||||
}
|
||||
var urls = _project.Project.Manifest?.HttpAllowedUrls ?? [];
|
||||
if (urls.Length == 0)
|
||||
{
|
||||
return new List<JsText>
|
||||
{
|
||||
new JsText("当前脚本无需使用HTTP资源", Brushes.Green)
|
||||
};
|
||||
}
|
||||
return new List<JsText>
|
||||
{
|
||||
new JsText($"当前脚本使用 {urls.Length} 个HTTP资源", Brushes.OrangeRed)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public record JsLine(string Text, Brush Color);
|
||||
|
||||
public List<JsLine> JsHTTPInfo
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_project.Project == null)
|
||||
{
|
||||
_project.BuildScriptProjectRelation();
|
||||
}
|
||||
var urls = _project.Project?.Manifest?.HttpAllowedUrls ?? [];
|
||||
var blocks = new List<JsLine>();
|
||||
foreach (var url in urls)
|
||||
{
|
||||
blocks.Add(new JsLine(url, Brushes.OrangeRed));
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
}
|
||||
|
||||
public string Status
|
||||
{
|
||||
@@ -68,7 +133,7 @@ public class ScriptGroupProjectEditorViewModel : ObservableObject
|
||||
{
|
||||
OnPropertyChanged(nameof(AllowJsNotification));
|
||||
}
|
||||
if (e.PropertyName == nameof(ScriptGroupProject.AllowJsHTTP))
|
||||
if (e.PropertyName == nameof(ScriptGroupProject.AllowJsHTTPHash))
|
||||
{
|
||||
OnPropertyChanged(nameof(AllowJsHTTP));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user