From b2eacb8cd42e1633741e749e3ff6e46d23e65e6c Mon Sep 17 00:00:00 2001 From: zdAnQi <131591012+zaodonganqi@users.noreply.github.com> Date: Wed, 23 Jul 2025 23:49:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9C=AC=E5=9C=B0=E4=BB=93?= =?UTF-8?q?=E5=BA=93readme=E4=B8=8Etxt=E8=8E=B7=E5=8F=96=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=20(#1915)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Core/Script/WebView/RepoWebBridge.cs | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/BetterGenshinImpact/Core/Script/WebView/RepoWebBridge.cs b/BetterGenshinImpact/Core/Script/WebView/RepoWebBridge.cs index f32c76d7..b8f68005 100644 --- a/BetterGenshinImpact/Core/Script/WebView/RepoWebBridge.cs +++ b/BetterGenshinImpact/Core/Script/WebView/RepoWebBridge.cs @@ -29,7 +29,8 @@ public class RepoWebBridge throw new Exception("仓库文件夹不存在,请至少成功更新一次仓库!"); } - var localRepoJsonPath = Directory.GetFiles(ScriptRepoUpdater.CenterRepoPath, "repo.json", SearchOption.AllDirectories).FirstOrDefault(); + var localRepoJsonPath = Directory + .GetFiles(ScriptRepoUpdater.CenterRepoPath, "repo.json", SearchOption.AllDirectories).FirstOrDefault(); if (localRepoJsonPath is null) { throw new Exception("repo.json 仓库索引文件不存在,请至少成功更新一次仓库!"); @@ -69,6 +70,7 @@ public class RepoWebBridge { throw new Exception("用户配置文件不存在: " + userConfigPath); } + return await File.ReadAllTextAsync(userConfigPath); } catch (Exception e) @@ -77,4 +79,37 @@ public class RepoWebBridge return ""; } } + + public async Task GetFile(string relPath) + { + try + { + string filePath = Path.Combine(ScriptRepoUpdater.CenterRepoPath, "repo", relPath) + .Replace('/', Path.DirectorySeparatorChar); + + if (!File.Exists(filePath)) + return "404"; + + // 允许返回内容的文本文件扩展名 + string[] allowedTextExtensions = { + ".txt", ".md", ".json", ".js", ".ts", + ".vue", ".css", ".html", ".csv", ".xml", + ".yaml", ".yml", ".ini", ".config" + }; + + string ext = Path.GetExtension(filePath).ToLower(); + + if (allowedTextExtensions.Contains(ext)) + { + return await File.ReadAllTextAsync(filePath); + } + + // 其他所有文件类型返回404 + return "404"; + } + catch + { + return "404"; + } + } }