From 758246ef90ca5da4131b9f169f16fb0dfa866db7 Mon Sep 17 00:00:00 2001 From: Zijian Zhang Date: Wed, 17 Jan 2024 22:30:35 +0800 Subject: [PATCH] refactor: remove useless stuff --- lipui.sln | 62 ++--- src/LipNETWrapper/Class/LipPackage.cs | 64 ----- src/LipNETWrapper/Class/LipPackageItem.cs | 19 -- src/LipNETWrapper/Class/LipRegistry.cs | 39 --- src/LipNETWrapper/Class/Tooth/ToothJson.cs | 49 ---- src/LipNETWrapper/ILipWrapper.cs | 23 -- src/LipNETWrapper/LipConsoleLoader.cs | 238 ------------------ src/LipNETWrapper/LipConsoleWrapper.cs | 106 -------- src/LipNETWrapper/LipNETWrapper.csproj | 11 - src/LipNETWrapper/LipPInvokeWrapper.cs | 9 - src/LipNETWrapper/Utils.cs | 132 ---------- .../LipNETWrapperTest.csproj | 23 -- src/LipNETWrapperTest/UnitTest.cs | 140 ----------- src/LipNETWrapperTest/Usings.cs | 1 - src/LipWebApi/AuthManager.cs | 122 --------- src/LipWebApi/Global.cs | 10 - src/LipWebApi/Launcher.cs | 4 - src/LipWebApi/LipWebApi.csproj | 28 --- src/LipWebApi/Models/AuthData.cs | 17 -- src/LipWebApi/Program.cs | 44 ---- src/LipWebApi/WebApi/LocalTooth.cs | 7 - src/LipWebApi/WebApi/Main.cs | 57 ----- 22 files changed, 27 insertions(+), 1178 deletions(-) delete mode 100644 src/LipNETWrapper/Class/LipPackage.cs delete mode 100644 src/LipNETWrapper/Class/LipPackageItem.cs delete mode 100644 src/LipNETWrapper/Class/LipRegistry.cs delete mode 100644 src/LipNETWrapper/Class/Tooth/ToothJson.cs delete mode 100644 src/LipNETWrapper/ILipWrapper.cs delete mode 100644 src/LipNETWrapper/LipConsoleLoader.cs delete mode 100644 src/LipNETWrapper/LipConsoleWrapper.cs delete mode 100644 src/LipNETWrapper/LipNETWrapper.csproj delete mode 100644 src/LipNETWrapper/LipPInvokeWrapper.cs delete mode 100644 src/LipNETWrapper/Utils.cs delete mode 100644 src/LipNETWrapperTest/LipNETWrapperTest.csproj delete mode 100644 src/LipNETWrapperTest/UnitTest.cs delete mode 100644 src/LipNETWrapperTest/Usings.cs delete mode 100644 src/LipWebApi/AuthManager.cs delete mode 100644 src/LipWebApi/Global.cs delete mode 100644 src/LipWebApi/Launcher.cs delete mode 100644 src/LipWebApi/LipWebApi.csproj delete mode 100644 src/LipWebApi/Models/AuthData.cs delete mode 100644 src/LipWebApi/Program.cs delete mode 100644 src/LipWebApi/WebApi/LocalTooth.cs delete mode 100644 src/LipWebApi/WebApi/Main.cs diff --git a/lipui.sln b/lipui.sln index ef88680..0912a81 100644 --- a/lipui.sln +++ b/lipui.sln @@ -1,51 +1,43 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 -VisualStudioVersion = 17.5.002.0 +VisualStudioVersion = 17.8.34408.163 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{0CADAFD8-0753-4869-BA72-59B6FC6B79FC}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LipNETWrapper", "src\LipNETWrapper\LipNETWrapper.csproj", "{485A0991-74A5-4A3A-90A6-B4E7CDBC00CA}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LipNETWrapperTest", "src\LipNETWrapperTest\LipNETWrapperTest.csproj", "{8165CB1E-1A2C-46EA-A3CD-DE46A3CDC1AE}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LipUI", "src\LipUI\LipUI.csproj", "{D72F9B3E-0D4C-4BA7-A436-13E3B94D54DC}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LipWebApi", "src\LipWebApi\LipWebApi.csproj", "{03F83CBD-D38F-42A2-9D08-0A3221F04746}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LipUI", "src\LipUI\LipUI.csproj", "{E0A3F349-6972-4266-8730-9E983EEFCA0D}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU + Debug|ARM64 = Debug|ARM64 + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|ARM64 = Release|ARM64 + Release|x64 = Release|x64 + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {485A0991-74A5-4A3A-90A6-B4E7CDBC00CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {485A0991-74A5-4A3A-90A6-B4E7CDBC00CA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {485A0991-74A5-4A3A-90A6-B4E7CDBC00CA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {485A0991-74A5-4A3A-90A6-B4E7CDBC00CA}.Release|Any CPU.Build.0 = Release|Any CPU - {8165CB1E-1A2C-46EA-A3CD-DE46A3CDC1AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8165CB1E-1A2C-46EA-A3CD-DE46A3CDC1AE}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8165CB1E-1A2C-46EA-A3CD-DE46A3CDC1AE}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8165CB1E-1A2C-46EA-A3CD-DE46A3CDC1AE}.Release|Any CPU.Build.0 = Release|Any CPU - {D72F9B3E-0D4C-4BA7-A436-13E3B94D54DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D72F9B3E-0D4C-4BA7-A436-13E3B94D54DC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D72F9B3E-0D4C-4BA7-A436-13E3B94D54DC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D72F9B3E-0D4C-4BA7-A436-13E3B94D54DC}.Release|Any CPU.Build.0 = Release|Any CPU - {03F83CBD-D38F-42A2-9D08-0A3221F04746}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {03F83CBD-D38F-42A2-9D08-0A3221F04746}.Debug|Any CPU.Build.0 = Debug|Any CPU - {03F83CBD-D38F-42A2-9D08-0A3221F04746}.Release|Any CPU.ActiveCfg = Release|Any CPU - {03F83CBD-D38F-42A2-9D08-0A3221F04746}.Release|Any CPU.Build.0 = Release|Any CPU + {E0A3F349-6972-4266-8730-9E983EEFCA0D}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {E0A3F349-6972-4266-8730-9E983EEFCA0D}.Debug|ARM64.Build.0 = Debug|ARM64 + {E0A3F349-6972-4266-8730-9E983EEFCA0D}.Debug|ARM64.Deploy.0 = Debug|ARM64 + {E0A3F349-6972-4266-8730-9E983EEFCA0D}.Debug|x64.ActiveCfg = Debug|x64 + {E0A3F349-6972-4266-8730-9E983EEFCA0D}.Debug|x64.Build.0 = Debug|x64 + {E0A3F349-6972-4266-8730-9E983EEFCA0D}.Debug|x64.Deploy.0 = Debug|x64 + {E0A3F349-6972-4266-8730-9E983EEFCA0D}.Debug|x86.ActiveCfg = Debug|x86 + {E0A3F349-6972-4266-8730-9E983EEFCA0D}.Debug|x86.Build.0 = Debug|x86 + {E0A3F349-6972-4266-8730-9E983EEFCA0D}.Debug|x86.Deploy.0 = Debug|x86 + {E0A3F349-6972-4266-8730-9E983EEFCA0D}.Release|ARM64.ActiveCfg = Release|ARM64 + {E0A3F349-6972-4266-8730-9E983EEFCA0D}.Release|ARM64.Build.0 = Release|ARM64 + {E0A3F349-6972-4266-8730-9E983EEFCA0D}.Release|ARM64.Deploy.0 = Release|ARM64 + {E0A3F349-6972-4266-8730-9E983EEFCA0D}.Release|x64.ActiveCfg = Release|x64 + {E0A3F349-6972-4266-8730-9E983EEFCA0D}.Release|x64.Build.0 = Release|x64 + {E0A3F349-6972-4266-8730-9E983EEFCA0D}.Release|x64.Deploy.0 = Release|x64 + {E0A3F349-6972-4266-8730-9E983EEFCA0D}.Release|x86.ActiveCfg = Release|x86 + {E0A3F349-6972-4266-8730-9E983EEFCA0D}.Release|x86.Build.0 = Release|x86 + {E0A3F349-6972-4266-8730-9E983EEFCA0D}.Release|x86.Deploy.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {485A0991-74A5-4A3A-90A6-B4E7CDBC00CA} = {0CADAFD8-0753-4869-BA72-59B6FC6B79FC} - {8165CB1E-1A2C-46EA-A3CD-DE46A3CDC1AE} = {0CADAFD8-0753-4869-BA72-59B6FC6B79FC} - {D72F9B3E-0D4C-4BA7-A436-13E3B94D54DC} = {0CADAFD8-0753-4869-BA72-59B6FC6B79FC} - {03F83CBD-D38F-42A2-9D08-0A3221F04746} = {0CADAFD8-0753-4869-BA72-59B6FC6B79FC} - EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {4BDECB42-58DC-4BCC-B2D3-E6B2E4DEA7E3} + SolutionGuid = {19C83D64-AA9C-4A55-9A1F-D035A212D14F} EndGlobalSection EndGlobal diff --git a/src/LipNETWrapper/Class/LipPackage.cs b/src/LipNETWrapper/Class/LipPackage.cs deleted file mode 100644 index b35f99b..0000000 --- a/src/LipNETWrapper/Class/LipPackage.cs +++ /dev/null @@ -1,64 +0,0 @@ -#nullable disable -using System.Collections.Generic; -using Newtonsoft.Json; - -namespace LipNETWrapper.Class; - -public partial class LipPackage -{ - [JsonProperty("format_version")] - public long FormatVersion { get; set; } - - [JsonProperty("tooth")] - public string Tooth { get; set; } - - [JsonProperty("version")] - public string Version { get; set; } - - [JsonProperty("info")] - public Info Info { get; set; } - - [JsonProperty("commands")] - public Commands Commands { get; set; } - - [JsonProperty("dependencies")] - public Dictionary Dependencies { get; set; } - - [JsonProperty("files")] - public Files Files { get; set; } -} - -public partial class Commands -{ - [JsonProperty("post_install")] - public string[] PostInstall { get; set; } -} -public partial class Files -{ - [JsonProperty("place")] - public Place[] Place { get; set; } - - [JsonProperty("remove")] - public string[] Remove { get; set; } -} - -public partial class Place -{ - [JsonProperty("src")] - public string Src { get; set; } - - [JsonProperty("dest")] - public string Dest { get; set; } -} - -public partial class Info -{ - [JsonProperty("name")] - public string Name { get; set; } - - [JsonProperty("description")] - public string Description { get; set; } - - [JsonProperty("author")] - public string Author { get; set; } -} \ No newline at end of file diff --git a/src/LipNETWrapper/Class/LipPackageItem.cs b/src/LipNETWrapper/Class/LipPackageItem.cs deleted file mode 100644 index c0f06b8..0000000 --- a/src/LipNETWrapper/Class/LipPackageItem.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json; -#nullable disable -namespace LipNETWrapper.Class; - -public class LipPackageItem -{ - [JsonProperty("available_versions")] public LipPackageVersions AvailableVersions { get; set; } - [JsonProperty("metadata")] public LipPackage Package { get; set; } -} - -public class LipPackageVersions : List -{ - -} \ No newline at end of file diff --git a/src/LipNETWrapper/Class/LipRegistry.cs b/src/LipNETWrapper/Class/LipRegistry.cs deleted file mode 100644 index 32bce59..0000000 --- a/src/LipNETWrapper/Class/LipRegistry.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; -using System.Collections.Generic; -using Newtonsoft.Json; - -namespace LipNETWrapper.Class; -public class LipRegistry -{ - /* - * { - "format_version": 1, - "index": { - "adaptationprotocols": { - "author": "QingYu", - "description": "Let 1.19.60/62 client into 1.19.63 server or 1.19.63 client into 1.19.61/62 server", - "homepage": "", - "license": "", - "name": "AdaptationProtocols", - "repository": "github.com/Tooth-Hub/AdaptationProtocols", - "tags": ["plugin", "ll"], - "tooth": "github.com/Tooth-Hub/AdaptationProtocols" - } - } - } */ - [JsonProperty("format_version")] public int FormatVersion; -#pragma warning disable CS8618 - [JsonProperty("index")] public IReadOnlyDictionary Index; -#pragma warning restore CS8618 - public class LipRegistryItem - { - [JsonProperty("author")] public string Author { get; set; } = string.Empty; - [JsonProperty("description")] public string Description { get; set; } = string.Empty; - [JsonProperty("homepage")] public string Homepage { get; set; } = string.Empty; - [JsonProperty("license")] public string License { get; set; } = string.Empty; - [JsonProperty("name")] public string Name { get; set; } = string.Empty; - [JsonProperty("repository")] public string Repository { get; set; } = string.Empty; - [JsonProperty("tags")] public IReadOnlyList Tags { get; set; } = Array.Empty(); - [JsonProperty("tooth")] public string Tooth { get; set; } = string.Empty; - } -} \ No newline at end of file diff --git a/src/LipNETWrapper/Class/Tooth/ToothJson.cs b/src/LipNETWrapper/Class/Tooth/ToothJson.cs deleted file mode 100644 index 38e4c12..0000000 --- a/src/LipNETWrapper/Class/Tooth/ToothJson.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System.Collections.Generic; -using System.Collections.ObjectModel; -using Newtonsoft.Json; - -namespace LipNETWrapper.Class.Tooth; -public class ToothJson -{ - [JsonProperty("format_version")] public int FormatVersion { get; set; } - - [JsonProperty("tooth")] public string Tooth { get; set; } = ""; - [JsonProperty("version")] public string Version { get; set; } = ""; - [JsonProperty("dependencies")] public Dictionary>> Dependencies { get; set; } = new(); - [JsonProperty("information")] public Information Information { get; set; } = new(); - [JsonProperty("placement")] public ObservableCollection Placement { get; set; } = new(); - [JsonProperty("possession")] public ObservableCollection Possession { get; set; } = new(); - [JsonProperty("commands")] public ObservableCollection Commands { get; set; } = new(); - [JsonProperty("confirmation")] public ObservableCollection Confirmation { get; set; } = new(); -} - -public class Information -{ - [JsonProperty("name")] public string Name { get; set; } = ""; - [JsonProperty("description")] public string Description { get; set; } = ""; - [JsonProperty("author")] public string Author { get; set; } = ""; - [JsonProperty("license")] public string License { get; set; } = ""; - [JsonProperty("homepage")] public string Homepage { get; set; } = ""; -} - -public class Placement -{ - [JsonProperty("source")] public string Source { get; set; } = ""; - [JsonProperty("destination")] public string Destination { get; set; } = ""; -} -public class Command -{ - [JsonProperty("type")] public string Type { get; set; } = ""; - [JsonProperty("commands")] public ObservableCollection Commands { get; set; } = new(); - [JsonProperty("GOOS")] public string GOOS { get; set; } = ""; - [JsonProperty("GOARCH")] public string GOARCH { get; set; } = ""; -} - -public class Confirmation -{ - [JsonProperty("type")] public string Type { get; set; } = ""; - [JsonProperty("message")] public string Message { get; set; } = ""; - [JsonProperty("GOOS")] public string GOOS { get; set; } = ""; - - [JsonProperty("GOARCH")] public string GOARCH { get; set; } = ""; -} \ No newline at end of file diff --git a/src/LipNETWrapper/ILipWrapper.cs b/src/LipNETWrapper/ILipWrapper.cs deleted file mode 100644 index 8bc7941..0000000 --- a/src/LipNETWrapper/ILipWrapper.cs +++ /dev/null @@ -1,23 +0,0 @@ -#nullable enable -using System; -using System.Threading; -using System.Threading.Tasks; -using LipNETWrapper.Class; -namespace LipNETWrapper; -public interface ILipWrapper -{ - string ExecutablePath { get; set; } - string? WorkingPath { get; set; } - Task GetLipVersion(CancellationToken tk = default); - Task<(LipPackage[] packages, string message)> GetAllPackagesAsync(CancellationToken tk = default); - Task<(bool success, LipPackageVersions? package, string message)> GetPackageInfoAsync(string packageId, - CancellationToken tk = default, Action? onOutput = null); - Task<(bool success, LipPackage? package, string message)> GetLocalPackageInfoAsync(string packageId, - CancellationToken tk = default); - Task InstallPackageAsync(string packageId, bool upgrade = false, bool skipDependency = false, - CancellationToken tk = default, Action>? onOutput = null); - Task UninstallPackageAsync(string packageId, - CancellationToken tk = default, Action? onOutput = null); - Task GetLipRegistryAsync(string registry, CancellationToken tk = default); - Task CachePurge(); -} diff --git a/src/LipNETWrapper/LipConsoleLoader.cs b/src/LipNETWrapper/LipConsoleLoader.cs deleted file mode 100644 index 21c33a3..0000000 --- a/src/LipNETWrapper/LipConsoleLoader.cs +++ /dev/null @@ -1,238 +0,0 @@ -#nullable enable -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace LipNETWrapper -{ - public class LipCommand - { - private readonly List _commands = new(); - public static LipCommand Create() - { - return new LipCommand(); - } - public static LipCommand Create(string cmd, bool quiet = false) - { - var instance = new LipCommand(); - if (quiet) - { - //todo ? - //instance.Add("-q"); - } - return instance.Add(cmd); - } - public LipCommand Add(string cmd) - { - _commands.Add(cmd); - return this; - } - public LipCommand WithJson() - { - _commands.Add("--json"); - return this; - } - //public LipCommand Verbose() - //{ - // _commands.Add("--verbose"); - // return this; - //} - public static implicit operator string(LipCommand cmd) => string.Join(" ", cmd._commands); - public override string ToString() => this; - public static LipCommand operator +(LipCommand cmd, string s) => cmd.Add(s); - } - public class LipConsoleCommandInstance - { - private Process? _process; - public bool HasExited => _process?.HasExited ?? false; - public int ExitCode => _process?.ExitCode ?? -1; - private readonly CancellationToken _tk; - - public LipConsoleCommandInstance(string exe, string? workingDir, string cmd, CancellationToken tk, - Action output, Action outputErr, out Process process) : this(exe, workingDir, cmd, tk, output, outputErr) - { - process = _process!; - } - public LipConsoleCommandInstance(string exe, string? workingDir, string cmd, CancellationToken tk, - Action output, Action outputErr) - { - _tk = tk; - _process = new(); - _process.StartInfo = new(exe, cmd) - { - StandardOutputEncoding = Encoding.UTF8, - StandardErrorEncoding = Encoding.UTF8, - RedirectStandardOutput = true, - UseShellExecute = false, - CreateNoWindow = true, - RedirectStandardError = true, - RedirectStandardInput = true, - WorkingDirectory = workingDir ?? Path.GetDirectoryName(exe) - }; - _process.OutputDataReceived += (_, args) => - { - if (!_tk.IsCancellationRequested) - output(args.Data??""); - }; - _process.ErrorDataReceived += (_, args) => - { - if (!_tk.IsCancellationRequested) - outputErr(args.Data ?? ""); - }; - _process.Start(); - _process.BeginOutputReadLine(); - _process.BeginErrorReadLine(); - } - public void KillIfCanceled() - { - if (_tk.IsCancellationRequested) - { - try - { - _process?.Kill(); - _process = null; - } - catch - { - // ignored - } - _tk.ThrowIfCancellationRequested(); - } - } - ~LipConsoleCommandInstance() - { - try - { - if (_process is { HasExited: false }) - { - _process?.Kill(); - } - } - catch - { - // ignored - } - _process?.Dispose(); - } - } - public class LipConsoleLoader - { - public LipConsoleLoader(string executablePath = "lip.exe", string? workingDir = null) - { - ExecutablePath = executablePath; - WorkingPath = workingDir; - } - public string ExecutablePath { get; } - public string? WorkingPath { get; } - public async Task Run(string cmd, Action? output, CancellationToken tk = default) - { - var inst = new LipConsoleCommandInstance(ExecutablePath, WorkingPath, cmd, tk, s => output?.Invoke(s), s => output?.Invoke(s)); - while (!inst.HasExited) - { - await Task.Delay(100, tk); - } - tk.ThrowIfCancellationRequested(); - return inst.ExitCode; - } - public async Task RunWithInput(string cmd, Action>? output, CancellationToken tk = default) - { - Process? process = default; - var inst = new LipConsoleCommandInstance(ExecutablePath, WorkingPath, cmd, tk, - s => - { - output?.Invoke(s, s => - { - process?.StandardInput.WriteLine(s); - }); - }, s => - { - output?.Invoke(s, s => - { - process?.StandardInput.WriteLine(s); - }); - }, out process); - while (!inst.HasExited) - { - await Task.Delay(100, tk); - } - tk.ThrowIfCancellationRequested(); - return inst.ExitCode; - } - public async Task Run(string cmd, Action output, Action outputError, CancellationToken tk = default) - { - var inst = new LipConsoleCommandInstance(ExecutablePath, WorkingPath, cmd, tk, output, outputError); - while (!inst.HasExited) - { - await Task.Delay(100, tk); - } - tk.ThrowIfCancellationRequested(); - return inst.ExitCode; - } - public async Task RunString(string cmd, Action? output = null, CancellationToken tk = default) - { - var sb = new StringBuilder(); - var inst = new LipConsoleCommandInstance(ExecutablePath, WorkingPath, cmd, tk, - s => - { - sb.AppendLine(s); output?.Invoke(s); - }, s => - { - sb.AppendLine(s); output?.Invoke(s); - }); - while (!inst.HasExited) - { - try - { - await Task.Delay(100, tk); - } - catch - { - // ignored - } - inst.KillIfCanceled(); - } - tk.ThrowIfCancellationRequested(); - return sb.ToString(); - } - public async Task RunStringWithInput(string cmd, Action>? output = null, CancellationToken tk = default) - { - var sb = new StringBuilder(); - Process? process = default; - var inst = new LipConsoleCommandInstance(ExecutablePath, WorkingPath, cmd, tk, - s => - { - sb.AppendLine(s); - output?.Invoke(s, s => - { - process?.StandardInput.WriteLine(s); - }); - }, s => - { - sb.AppendLine(s); - output?.Invoke(s, s => - { - process?.StandardInput.WriteLine(s); - }); - }, out process); - while (!inst.HasExited) - { - try - { - await Task.Delay(100, tk); - } - catch - { - // ignored - } - inst.KillIfCanceled(); - } - tk.ThrowIfCancellationRequested(); - return sb.ToString(); - } - } -} diff --git a/src/LipNETWrapper/LipConsoleWrapper.cs b/src/LipNETWrapper/LipConsoleWrapper.cs deleted file mode 100644 index 52388fa..0000000 --- a/src/LipNETWrapper/LipConsoleWrapper.cs +++ /dev/null @@ -1,106 +0,0 @@ -#nullable enable -using System; -using System.Diagnostics; -using System.Text; -using System.Net; -using System.Threading; -using System.Threading.Tasks; -using LipNETWrapper.Class; -using Newtonsoft.Json; - -namespace LipNETWrapper; - -public class LipConsoleWrapper : ILipWrapper -{ - public LipConsoleWrapper(string executablePath = "lip.exe", string? workingDir = null) - { - ExecutablePath = executablePath; - WorkingPath = workingDir; - } - public string ExecutablePath { get; set; } - public string? WorkingPath { get; set; } - public async Task GetLipVersion(CancellationToken tk = default) - { - return (await new LipConsoleLoader(ExecutablePath, WorkingPath) - .RunString(LipCommand.Create("-V"), tk: tk)).Trim(); - } - public async Task<(LipPackage[] packages, string message)> GetAllPackagesAsync(CancellationToken tk = default) - { - async Task<(LipPackage[] packages, string message)> GetInternal() - { - var json = await new LipConsoleLoader(ExecutablePath, WorkingPath) - .RunString(LipCommand.Create("list", true).WithJson(), tk: tk); - Debug.WriteLine(json); - var arr = JsonConvert.DeserializeObject(json); - return (arr ?? Array.Empty(), json); - } - try - { - return await GetInternal(); - } - catch - { //retry once - return await GetInternal(); - } - } - public async Task<(bool success, LipPackageVersions? package, string message)> GetPackageInfoAsync(string packageId, CancellationToken tk = default, Action? onOutput = null) - { - var json = await new LipConsoleLoader(ExecutablePath, WorkingPath) - .RunString(LipCommand.Create("show", onOutput is null).WithJson() + "--available" + packageId, onOutput, tk); - var obj = JsonConvert.DeserializeObject(json)?.AvailableVersions; - return (obj is not null, obj, json); - } - public async Task<(bool success, LipPackage? package, string message)> GetLocalPackageInfoAsync(string packageId, CancellationToken tk = default) - { - var json = await new LipConsoleLoader(ExecutablePath, WorkingPath) - .RunString(LipCommand.Create("show", true).WithJson() + packageId, tk: tk); - var obj = JsonConvert.DeserializeObject(json)?.Package; - return (obj is not null, obj, json); - } - public Task InstallPackageAsync(string packageId, bool upgrade = false, bool skipDependency = false, CancellationToken tk = default, Action>? onOutput = null) - { - var cmd = LipCommand.Create("install")/* + "-y"*/ /*+ "--numeric-progress"*/; - if (upgrade) - cmd += "--upgrade"; - if (skipDependency) - cmd += "--no-dependencies"; - //todo 强制重装 - //if (forceReinstall) - // cmd += "--force-reinstall"; - return new LipConsoleLoader(ExecutablePath, WorkingPath) - .RunWithInput(cmd + packageId, onOutput, tk); - } - - public Task UninstallPackageAsync(string packageId, CancellationToken tk = default, Action? onOutput = null) - { - return new LipConsoleLoader(ExecutablePath, WorkingPath) - .Run(LipCommand.Create("uninstall") + "-y" + packageId, onOutput, tk); - } - public async Task GetLipRegistryAsync(string registry, CancellationToken tk = default) - { -#if NET7_0 || NETCOREAPP - var client = new System.Net.Http.HttpClient() { }; - var response = await client.GetAsync(registry, tk); - - if (!response.IsSuccessStatusCode) - { - throw new Exception("Failed to get registry: " + response.StatusCode); - } - var content = await response.Content.ReadAsStringAsync(tk); - return JsonConvert.DeserializeObject(content)!; -#else - using var client = new WebClient() { Encoding = Encoding.UTF8 }; - var text = await client.DownloadStringTaskAsync(registry); - if (text is null) - { - throw new NullReferenceException("Failed to get registry : " + registry); - } - return JsonConvert.DeserializeObject(text)!; -#endif - } - public Task CachePurge() - { - return new LipConsoleLoader(ExecutablePath, WorkingPath) - .Run(LipCommand.Create("cache") + "purge", null, CancellationToken.None); - } -} \ No newline at end of file diff --git a/src/LipNETWrapper/LipNETWrapper.csproj b/src/LipNETWrapper/LipNETWrapper.csproj deleted file mode 100644 index 0b7c21c..0000000 --- a/src/LipNETWrapper/LipNETWrapper.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - net462;net7.0;netstandard2.0 - 10.0 - enable - - - - - - diff --git a/src/LipNETWrapper/LipPInvokeWrapper.cs b/src/LipNETWrapper/LipPInvokeWrapper.cs deleted file mode 100644 index 59bebc5..0000000 --- a/src/LipNETWrapper/LipPInvokeWrapper.cs +++ /dev/null @@ -1,9 +0,0 @@ -//using System; -//using System.Collections.Generic; -//using System.Text; -//namespace LipNETWrapper -//{ -// internal class LipPInvokeWrapper : ILipWrapper -// { -// } -//} diff --git a/src/LipNETWrapper/Utils.cs b/src/LipNETWrapper/Utils.cs deleted file mode 100644 index 046e90f..0000000 --- a/src/LipNETWrapper/Utils.cs +++ /dev/null @@ -1,132 +0,0 @@ -using Newtonsoft.Json.Linq; -using System; -using System.IO; -using System.Net; -using System.Threading.Tasks; - -namespace LipNETWrapper -{ - public static class Utils - { - /// - /// Get lip.exe Path - /// - /// - public static (bool success, string? path) TryGetLipFromPath() - { - var lipPath = Environment.GetEnvironmentVariable("PATH"); - if (lipPath != null) - { - var lipPaths = lipPath.Split(';'); - foreach (var lip in lipPaths) - { - var file = Path.Combine(lip, "lip.exe"); - if (File.Exists(file)) - { - return (true, file); - } - } - } - return (false, null); - } - public static async Task DownloadLipPortable(Action progress) - { - using var client = new WebClient(); - void ClientDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { progress(e); } - client.DownloadProgressChanged += ClientDownloadProgressChanged; - // Fetch latest release from GitHub API - var apiUrl = "https://api.github.com/repos/LiteLDev/Lip/releases/latest"; - client.Headers.Add("Accept", "application/vnd.github.v3+json"); - client.Headers.Add("User-Agent", "request"); // GitHub requires a User-Agent header - var response = await client.DownloadStringTaskAsync(apiUrl); - var data = JObject.Parse(response); - // Find asset with filename ending with "-windows-amd64-setup.exe" - var targetFilename = "-windows-amd64.zip"; - var assetUrl = ""; - foreach (var asset in data["assets"]!.Value()!) - { - var assetFilename = asset["name"]!.Value()!; - if (assetFilename.EndsWith(targetFilename)) - { - assetUrl = asset["browser_download_url"]!.Value(); - break; - } - } - // Download release asset - try - { - return await client.DownloadDataTaskAsync(assetUrl!); - } - catch - { - //try to download via mirror - var mirrorUrl = "https://ghproxy.com/" + assetUrl!; - return await client.DownloadDataTaskAsync(mirrorUrl); - } - } - /* public static class HttpClientExtensions - { - public static async Task DownloadAsync(this HttpClient client, string requestUri, Stream destination, IProgress progress = null, CancellationToken cancellationToken = default) - { - // Get the http headers first to examine the content length - using (var response = await client.GetAsync(requestUri, HttpCompletionOption.ResponseHeadersRead)) - { - var contentLength = response.Content.Headers.ContentLength; - - using (var download = await response.Content.ReadAsStreamAsync()) - { - - // Ignore progress reporting when no progress reporter was - // passed or when the content length is unknown - if (progress == null || !contentLength.HasValue) - { - await download.CopyToAsync(destination); - return; - } - - // Convert absolute progress (bytes downloaded) into relative progress (0% - 100%) - var relativeProgress = new Progress(totalBytes => progress.Report((float)totalBytes / contentLength.Value)); - // Use extension method to report progress while downloading - await download.CopyToAsync(destination, 81920, relativeProgress, cancellationToken); - progress.Report(1); - } - } - } - }*/ - public static async Task DownloadLipInstaller(Action progress) - { - using var client = new WebClient(); - void ClientDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { progress(e); } - client.DownloadProgressChanged += ClientDownloadProgressChanged; - // Fetch latest release from GitHub API - var apiUrl = "https://api.github.com/repos/LiteLDev/Lip/releases/latest"; - client.Headers.Add("Accept", "application/vnd.github.v3+json"); - client.Headers.Add("User-Agent", "request"); // GitHub requires a User-Agent header - var response = await client.DownloadStringTaskAsync(apiUrl); - var data = JObject.Parse(response); - // Find asset with filename ending with "-windows-amd64-setup.exe" - var targetFilename = "-windows-amd64-setup.exe"; - var assetUrl = ""; - foreach (var asset in data["assets"]!.Value()!) - { - var assetFilename = asset["name"]!.Value()!; - if (assetFilename.EndsWith(targetFilename)) - { - assetUrl = asset["browser_download_url"]!.Value(); - break; - } - } - // Download release asset - try - { - return await client.DownloadDataTaskAsync(assetUrl!); - } - catch - { - //try to download via mirror - var mirrorUrl = "https://ghproxy.com/" + assetUrl!; - return await client.DownloadDataTaskAsync(mirrorUrl); - } - } - } -} diff --git a/src/LipNETWrapperTest/LipNETWrapperTest.csproj b/src/LipNETWrapperTest/LipNETWrapperTest.csproj deleted file mode 100644 index 1324561..0000000 --- a/src/LipNETWrapperTest/LipNETWrapperTest.csproj +++ /dev/null @@ -1,23 +0,0 @@ - - - - net7.0 - enable - enable - - false - - - - - - - - - - - - - - - diff --git a/src/LipNETWrapperTest/UnitTest.cs b/src/LipNETWrapperTest/UnitTest.cs deleted file mode 100644 index 3d92e01..0000000 --- a/src/LipNETWrapperTest/UnitTest.cs +++ /dev/null @@ -1,140 +0,0 @@ -using System.Diagnostics; -using System.Runtime.CompilerServices; -using System.Text; -using LipNETWrapper; -using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; -using Newtonsoft.Json; -using NUnit.Framework.Internal; - -namespace LipNETWrapperTest -{ - public class Tests - { - private void Sep() - { - Console.WriteLine("---"); - } - private void OutPut(object? obj, [CallerArgumentExpression(nameof(obj))] string? expression = null) - { - if (obj is null) - { - Console.WriteLine(expression + " = [null]"); - } - else - { - Console.WriteLine(expression + " = " + obj); - - } - } - [SetUp] - public void Setup() - { - var (success, path) = Utils.TryGetLipFromPath(); - //if (!success) - //{ - // path= - //} - foreach (var workingDir in new[] - { - "A:\\Documents\\GitHub\\LipUI\\src\\LipUI\\bin\\Debug\\net462", - //put your path here - }) - { - if (Directory.Exists(workingDir)) - { - _loader = new LipNETWrapper.LipConsoleWrapper(success ? path! : - Path.Combine(workingDir, "lip.exe"), workingDir); - break; - } - } - if (_loader == null) - Assert.Fail("please put your lip.exe path"); - } - LipNETWrapper.LipConsoleWrapper Loader => _loader!; - LipNETWrapper.LipConsoleWrapper? _loader; - [Test] - public async Task TestLipVersion() - { - var result = await Loader.GetLipVersion(); - Assert.Pass(result); - } - [Test] - public async Task TestGetAllPackages() - { - var (packages, message) = await Loader.GetAllPackagesAsync(); - OutPut(packages.Length.ToString()); - foreach (var item in packages) - { - OutPut("Tooth = " + item.Tooth); - OutPut("Version = " + item.Version); - OutPut("-----"); - } - OutPut(message); - } - - [Test] - public async Task TestGetPackageInfo() - { - //github.com/tooth-hub/liteloaderbds - var (success, versions, message) = await Loader.GetPackageInfoAsync("github.com/tooth-hub/liteloaderbds"); - OutPut(success.ToString()); - if (success) - { - if (versions is not null) - foreach (var v in versions) - { - OutPut(v); - } - } - OutPut("----------"); - OutPut(message); - } - - [Test] - public async Task TestGetLocalPackageInfo() - { - //github.com/tooth-hub/liteloaderbds - var (success, package, message) = await Loader.GetLocalPackageInfoAsync("github.com/tooth-hub/liteloaderbds"); - OutPut(success.ToString()); - OutPut(package?.Info.Name); - OutPut(package?.Version); - OutPut("----------"); - OutPut(message); - } - [Test] - public async Task TestInstallPackage() - { - var result = await Loader.InstallPackageAsync("github.com/tooth-hub/liteloaderbds", onOutput: (s, input) => - { - OutPut(s); - }); - OutPut("exit code : " + result); - } - - [Test] - public async Task TestGetLipRegistry() - { - var registry = await Loader.GetLipRegistryAsync("https://registry.litebds.com/index.json"); - //output all info - OutPut(registry.FormatVersion); - foreach (var x in registry.Index) - { - Sep(); - OutPut(x.Key); - OutPut(JsonConvert.SerializeObject(x.Value)); - } - } - [Test] - public void TestLipPath() - { - //OutPut(Environment.GetEnvironmentVariable("PATH")); - OutPut(Utils.TryGetLipFromPath()); - } - [Test] - public void TestLipDownload() - { - //OutPut(Environment.GetEnvironmentVariable("PATH")); - OutPut(Utils.TryGetLipFromPath()); - } - } -} \ No newline at end of file diff --git a/src/LipNETWrapperTest/Usings.cs b/src/LipNETWrapperTest/Usings.cs deleted file mode 100644 index cefced4..0000000 --- a/src/LipNETWrapperTest/Usings.cs +++ /dev/null @@ -1 +0,0 @@ -global using NUnit.Framework; \ No newline at end of file diff --git a/src/LipWebApi/AuthManager.cs b/src/LipWebApi/AuthManager.cs deleted file mode 100644 index 32ab3a4..0000000 --- a/src/LipWebApi/AuthManager.cs +++ /dev/null @@ -1,122 +0,0 @@ -using HttpServerLite; -using Newtonsoft.Json.Linq; -using System; -using System.Collections.Concurrent; -using System.Linq; -using System.Security.Cryptography; -using System.Text; -using System.Threading.Tasks; -using static LipWebApi.WebApi.Main; -namespace LipWebApi; -internal static class AuthManager -{ - /// - /// key : token - /// value : expired time - /// - private static readonly ConcurrentDictionary _validTokens = new(); - /// - /// key : username - /// value : token - /// - private static readonly ConcurrentDictionary _userTokens = new(); - private static readonly RandomNumberGenerator _rng = RandomNumberGenerator.Create(); - private static void StoreToken(string token) - { - RemoveExpiredTokens(); - _validTokens[token] = DateTime.UtcNow.AddHours(1); - } - private static void RemoveExpiredTokens() - { - var expiredTokens = _validTokens.Where(x => x.Value < DateTime.UtcNow).Select(x => x.Key).ToArray(); - if (expiredTokens.Length > 0) - { - foreach (var token in expiredTokens) - { - _validTokens.TryRemove(token, out _); - } - var expiredUsers = _userTokens.Where(x => expiredTokens.Contains(x.Value)).Select(x => x.Key).ToArray(); - foreach (var user in expiredUsers) - { - _userTokens.TryRemove(user, out _); - } - } - } - private static string GenerateToken() - { - var bytes = new byte[16]; - _rng.GetBytes(bytes); - return new Guid(bytes).ToString(); - } - public static bool CheckToken(string token) - { - return _validTokens.TryGetValue(token, out DateTime expiration) && expiration > DateTime.UtcNow; - } - //sample: - // http://locolhost:9000/auth?username=admin&passwordMd5=pwd - //result(success): - // { - // "success": true, - // "token": "ba205422-20e0-4291-a97f-5536658df223" - // } - //result(fail): - // { - // "success": false, - // "message": "Invalid username or password" - // } - //{username: "a", passwordMd5: "03c7c0ace395d80182db07ae2c30f034"} - [StaticRoute(HttpMethod.POST, "/auth")] - public static async Task Auth(HttpContext ctx) - { - //string resp = "Hello from the dynamic route"; - //ctx.Response.StatusCode = 200; - //ctx.Response.ContentType = "text/plain"; - //ctx.Response.ContentLength = resp.Length; - //await ctx.Response.SendAsync(resp); - //return; - var raw = Encoding.UTF8.GetString(ctx.Request.DataAsBytes); - var jobj = JObject.Parse(raw); - var username = jobj.Value("username")!; - var passwordMd5 = jobj.Value("passwordMd5")!; - bool CheckUsernameAndPassword()//检查用户名和密码 - { - //if (_userTokens.TryGetValue(username, out string token))//已经登录 - //{ - // if (_validTokens.TryGetValue(token, out DateTime expiration) && expiration > DateTime.UtcNow) - // { - // //验证用户 - // return true; - // } - //} - //_userTokens.TryRemove(username, out _);//移除旧验证 - - return false; - } - bool isValid = CheckUsernameAndPassword(); - //bool isValid = true; - if (isValid) - { - string token = GenerateToken(); - StoreToken(token); - await SendResult(ctx.Response, new - { - success = true, - token - }); - } - else - { - await SendResult(ctx.Response, new - { - success = false, - message = "Invalid username or password" - }); - } - } - - [StaticRoute(HttpMethod.POST, "/verify")] - public static async Task VerifyToken(HttpContext ctx) - { - - } -} \ No newline at end of file diff --git a/src/LipWebApi/Global.cs b/src/LipWebApi/Global.cs deleted file mode 100644 index 279ae3d..0000000 --- a/src/LipWebApi/Global.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.IO; - -namespace LipWebApi -{ - internal class Global - { - internal static readonly string ConfigFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".lip", "config", "lipweb"); - } -} diff --git a/src/LipWebApi/Launcher.cs b/src/LipWebApi/Launcher.cs deleted file mode 100644 index e6375fd..0000000 --- a/src/LipWebApi/Launcher.cs +++ /dev/null @@ -1,4 +0,0 @@ -namespace LipWebApi; -internal class Launcher -{ -} diff --git a/src/LipWebApi/LipWebApi.csproj b/src/LipWebApi/LipWebApi.csproj deleted file mode 100644 index 09f605d..0000000 --- a/src/LipWebApi/LipWebApi.csproj +++ /dev/null @@ -1,28 +0,0 @@ - - - - Exe - enable - 11.0 - enable - - - net462; - - - net462;net7.0-windows - - - System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute;System.Diagnostics.CodeAnalysis.NotNullAttribute - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive; compile - - - - - - - diff --git a/src/LipWebApi/Models/AuthData.cs b/src/LipWebApi/Models/AuthData.cs deleted file mode 100644 index 0516619..0000000 --- a/src/LipWebApi/Models/AuthData.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Concurrent; -using System.IO; - -namespace LipWebApi.Models -{ - public class AuthData : ConcurrentDictionary - { - public static readonly Lazy _instance = new(() => - { - var authConfig = Path.Combine(Global.ConfigFolder, "auth.json"); - return JsonConvert.DeserializeObject(File.ReadAllText(authConfig))!; - }); - public static AuthData Instance => _instance.Value; - } -} diff --git a/src/LipWebApi/Program.cs b/src/LipWebApi/Program.cs deleted file mode 100644 index 4cd5797..0000000 --- a/src/LipWebApi/Program.cs +++ /dev/null @@ -1,44 +0,0 @@ -using HttpServerLite; -using System; -using System.Threading.Tasks; - -Webserver server = new Webserver("localhost", 9000, false, null, null, DefaultRoute); -server.Settings.Headers.Host = "https://localhost:3000"; -server.Events.Logger = Console.WriteLine; -server.Routes.Preflight = async (ctx) => -{ - ctx.Response.StatusCode = 200; - var headerValue = ctx.Request.Headers.GetValues("Access-Control-Request-Headers"); - if (headerValue?.Length > 0) - { - ctx.Response.Headers.Add("Access-Control-Allow-Headers", string.Join(", ", headerValue)); - } - await ctx.Response.SendAsync(0); -}; -//server.Settings.AccessControl.Mode = AccessControlMode.DefaultPermit; -server.Settings.Debug.Responses = true; -server.Settings.Debug.Routing = true; -server.Settings.Debug.Tcp = true; -server.Settings.Debug.AccessControl = true; -server.Settings.Debug.Connections = true; -//server.Events.Exception += Events_Exception; - -void Events_Exception(object sender, ExceptionEventArgs e) -{ - Console.WriteLine(e.Exception); -} - -//server.Settings.Headers.AccessControlAllowOrigin = "http://localhost:3000/"; -//server.Settings.Headers.AccessControlAllowHeaders = "http://localhost:3000/"; -server.Start(); -Console.WriteLine("HttpServerLite listening on http://localhost:9000"); -Console.WriteLine("ENTER to exit"); -Console.ReadLine(); -static async Task DefaultRoute(HttpContext ctx) -{ - string resp = "404 - NotFound"; - ctx.Response.StatusCode = 404; - ctx.Response.ContentLength = resp.Length; - ctx.Response.ContentType = "text/plain"; - await ctx.Response.SendAsync(resp); -} \ No newline at end of file diff --git a/src/LipWebApi/WebApi/LocalTooth.cs b/src/LipWebApi/WebApi/LocalTooth.cs deleted file mode 100644 index b3606b9..0000000 --- a/src/LipWebApi/WebApi/LocalTooth.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace LipWebApi.WebApi -{ - public class LocalTooth - { - - } -} diff --git a/src/LipWebApi/WebApi/Main.cs b/src/LipWebApi/WebApi/Main.cs deleted file mode 100644 index 44e0660..0000000 --- a/src/LipWebApi/WebApi/Main.cs +++ /dev/null @@ -1,57 +0,0 @@ -using HttpServerLite; -using System.Threading.Tasks; - -namespace LipWebApi.WebApi; -public class Main -{ - public static async Task SendResult(HttpResponse response, object item) - { - string result = BuildResult(item); - response.StatusCode = 200; - response.ContentLength = result.Length; - response.ContentType = "application/json"; - - //response.Headers["Access-Control-Allow-Origin"] = "*"; - //response.Headers["Access-Control-Allow-Methods"] = "GET, POST, PUT, DELETE, OPTIONS"; - //response.Headers["Access-Control-Allow-Headers"] = "Content-Type, Authorization"; - //response.Headers["Access-Control-Max-Age"] = "86400"; - - await response.SendAsync(result); - } - static string BuildResult(object item) - { -#if DEBUG - return Newtonsoft.Json.JsonConvert.SerializeObject(item, Newtonsoft.Json.Formatting.Indented); -#else - return Newtonsoft.Json.JsonConvert.SerializeObject(item); -#endif - } - /// - /// 验证服务端是否连接通畅 - /// - [StaticRoute(HttpMethod.GET, "/ping")] - public static async Task Ping(HttpContext ctx) - { - await SendResult(ctx.Response, new { success = true }); - } - //[ParameterRoute(HttpMethod.GET, "/{version}/api/{id}")] - //public static async Task MyParameterRoute(HttpContext ctx) - //{ - // string resp = "Hello from parameter route version " + ctx.Request.Url.Parameters["version"] + " for ID " + ctx.Request.Url.Parameters["id"]; - // ctx.Response.StatusCode = 200; - // ctx.Response.ContentType = "text/plain"; - // ctx.Response.ContentLength = resp.Length; - // await ctx.Response.SendAsync(resp); - // return; - //} - //[DynamicRoute(HttpMethod.GET, "^/dynamic/\\d+$")] - //public static async Task MyDynamicRoute(HttpContext ctx) - //{ - // string resp = "Hello from the dynamic route"; - // ctx.Response.StatusCode = 200; - // ctx.Response.ContentType = "text/plain"; - // ctx.Response.ContentLength = resp.Length; - // await ctx.Response.SendAsync(resp); - // return; - //} -}