Merge pull request #219 from gnh1201/dev

Change the remote blob server to localhost
This commit is contained in:
Namhyeon Go 2025-04-05 17:47:25 +09:00 committed by GitHub
commit 231e6a56bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 78 additions and 36 deletions

View File

@ -78,6 +78,15 @@ namespace WelsonJS.Launcher.Properties {
} }
} }
/// <summary>
/// https://catswords.blob.core.windows.net/welsonjs/과(와) 유사한 지역화된 문자열을 찾습니다.
/// </summary>
internal static string BlobServerPrefix {
get {
return ResourceManager.GetString("BlobServerPrefix", resourceCulture);
}
}
/// <summary> /// <summary>
/// https://copilot.microsoft.com/과(와) 유사한 지역화된 문자열을 찾습니다. /// https://copilot.microsoft.com/과(와) 유사한 지역화된 문자열을 찾습니다.
/// </summary> /// </summary>
@ -249,14 +258,5 @@ namespace WelsonJS.Launcher.Properties {
return ResourceManager.GetString("WhoisServerUrl", resourceCulture); return ResourceManager.GetString("WhoisServerUrl", resourceCulture);
} }
} }
/// <summary>
/// Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.3124.77과(와) 유사한 지역화된 문자열을 찾습니다.
/// </summary>
internal static string WhoisUserAgent {
get {
return ResourceManager.GetString("WhoisUserAgent", resourceCulture);
}
}
} }
} }

View File

@ -178,7 +178,7 @@
<data name="WhoisServerUrl" xml:space="preserve"> <data name="WhoisServerUrl" xml:space="preserve">
<value>https://xn--c79as89aj0e29b77z.xn--3e0b707e/kor/whois.jsc</value> <value>https://xn--c79as89aj0e29b77z.xn--3e0b707e/kor/whois.jsc</value>
</data> </data>
<data name="WhoisUserAgent" xml:space="preserve"> <data name="BlobServerPrefix" xml:space="preserve">
<value>Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.3124.77</value> <value>https://catswords.blob.core.windows.net/welsonjs/</value>
</data> </data>
</root> </root>

View File

@ -1,7 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Reflection; using System.Reflection;
@ -9,7 +9,6 @@ using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using System.Xml.Linq;
namespace WelsonJS.Launcher namespace WelsonJS.Launcher
{ {
@ -21,7 +20,9 @@ namespace WelsonJS.Launcher
private bool _isRunning; private bool _isRunning;
private string _prefix; private string _prefix;
private string _resourceName; private string _resourceName;
private List<IResourceTool> _resourceTools = new List<IResourceTool>(); private List<IResourceTool> _tools = new List<IResourceTool>();
private const int _blobTimeout = 5000;
private readonly HttpClient _blobClient = new HttpClient();
public ResourceServer(string prefix, string resourceName) public ResourceServer(string prefix, string resourceName)
{ {
@ -29,14 +30,15 @@ namespace WelsonJS.Launcher
_listener = new HttpListener(); _listener = new HttpListener();
_listener.Prefixes.Add(prefix); _listener.Prefixes.Add(prefix);
_resourceName = resourceName; _resourceName = resourceName;
_blobClient.Timeout = TimeSpan.FromMilliseconds(_blobTimeout);
// Add resource tools // Add resource tools
_resourceTools.Add(new ResourceTools.Completion(this)); _tools.Add(new ResourceTools.Completion(this));
_resourceTools.Add(new ResourceTools.Config(this)); _tools.Add(new ResourceTools.Config(this));
_resourceTools.Add(new ResourceTools.DevTools(this)); _tools.Add(new ResourceTools.DevTools(this));
_resourceTools.Add(new ResourceTools.DnsQuery(this)); _tools.Add(new ResourceTools.DnsQuery(this));
_resourceTools.Add(new ResourceTools.Tfa(this)); _tools.Add(new ResourceTools.Tfa(this));
_resourceTools.Add(new ResourceTools.Whois(this)); _tools.Add(new ResourceTools.Whois(this));
} }
public string GetPrefix() public string GetPrefix()
@ -93,6 +95,13 @@ namespace WelsonJS.Launcher
{ {
string path = context.Request.Url.AbsolutePath.TrimStart('/'); string path = context.Request.Url.AbsolutePath.TrimStart('/');
// Serve from a resource name
if (String.IsNullOrEmpty(path))
{
ServeResource(context, GetResource(_resourceName), "text/html");
return;
}
// Serve the favicon.ico file // Serve the favicon.ico file
if ("favicon.ico".Equals(path, StringComparison.OrdinalIgnoreCase)) if ("favicon.ico".Equals(path, StringComparison.OrdinalIgnoreCase))
{ {
@ -101,9 +110,8 @@ namespace WelsonJS.Launcher
} }
// Serve from a resource tool // Serve from a resource tool
foreach(var tool in _resourceTools) foreach (var tool in _tools)
{ {
if (tool.CanHandle(path)) if (tool.CanHandle(path))
{ {
await tool.HandleAsync(context, path); await tool.HandleAsync(context, path);
@ -111,10 +119,44 @@ namespace WelsonJS.Launcher
} }
} }
// Serve from a resource name // Serve from the blob server
if (await ServeBlob(context, path)) return;
// Fallback to serve from a resource name
ServeResource(context, GetResource(_resourceName), "text/html"); ServeResource(context, GetResource(_resourceName), "text/html");
} }
private async Task<bool> ServeBlob(HttpListenerContext context, string path)
{
try
{
string blobServerPrefix = Program.GetAppConfig("BlobServerPrefix");
string url = $"{blobServerPrefix}{path}";
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.UserAgent.ParseAdd(context.Request.UserAgent);
HttpResponseMessage response = await _blobClient.SendAsync(request);
if (!response.IsSuccessStatusCode)
{
Trace.TraceError($"Failed to serve blob. Status: {response.StatusCode}");
return false;
}
byte[] data = await response.Content.ReadAsByteArrayAsync();
string mimeType = response.Content.Headers.ContentType?.MediaType ?? "application/octet-stream";
ServeResource(context, data, mimeType);
return true;
}
catch (Exception ex)
{
Trace.TraceError($"Failed to serve blob. Exception: {ex.ToString()}");
return false;
}
}
public void ServeResource(HttpListenerContext context) public void ServeResource(HttpListenerContext context)
{ {
ServeResource(context, "<error>Not Found</error>", "application/xml", 404); ServeResource(context, "<error>Not Found</error>", "application/xml", 404);

View File

@ -44,7 +44,7 @@ namespace WelsonJS.Launcher.ResourceTools
}; };
request.Headers.Add("Accept", "*/*"); request.Headers.Add("Accept", "*/*");
request.Headers.Add("User-Agent", Program.GetAppConfig("WhoisUserAgent")); request.Headers.Add("User-Agent", context.Request.UserAgent);
client.DefaultRequestHeaders.Referrer = new Uri(Program.GetAppConfig("WhoisReferrerUrl")); client.DefaultRequestHeaders.Referrer = new Uri(Program.GetAppConfig("WhoisReferrerUrl"));
try try

View File

@ -9,9 +9,9 @@
<add key="AzureAiServiceApiKey" value=""/> <add key="AzureAiServiceApiKey" value=""/>
<add key="WhoisServerUrl" value="https://xn--c79as89aj0e29b77z.xn--3e0b707e/kor/whois.jsc"/> <add key="WhoisServerUrl" value="https://xn--c79as89aj0e29b77z.xn--3e0b707e/kor/whois.jsc"/>
<add key="WhoisReferrerUrl" value="https://xn--c79as89aj0e29b77z.xn--3e0b707e/kor/whois/whois.jsp"/> <add key="WhoisReferrerUrl" value="https://xn--c79as89aj0e29b77z.xn--3e0b707e/kor/whois/whois.jsp"/>
<add key="WhoisUserAgent" value="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.3124.77"/>
<add key="WhoisClientAddress" value="141.101.82.1"/> <add key="WhoisClientAddress" value="141.101.82.1"/>
<add key="DnsServerAddress" value="1.1.1.1"/> <add key="DnsServerAddress" value="1.1.1.1"/>
<add key="BlobServerPrefix" value="https://catswords.blob.core.windows.net/welsonjs/"/>
</appSettings> </appSettings>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>

View File

@ -3,9 +3,9 @@
<head> <head>
<title>WelsonJS Editor</title> <title>WelsonJS Editor</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"> <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<link rel="stylesheet" href="https://catswords.blob.core.windows.net/welsonjs/ajax/libs/metroui/dev/lib/metro.css" integrity="sha384-4XgOiXH2ZMaWt5s5B35yKi7EAOabhZvx7wO8Jr71q2vZ+uONdRza/6CsK2kpyocd" crossorigin="anonymous"> <link rel="stylesheet" href="http://localhost:3000/ajax/libs/metroui/dev/lib/metro.css" integrity="sha384-4XgOiXH2ZMaWt5s5B35yKi7EAOabhZvx7wO8Jr71q2vZ+uONdRza/6CsK2kpyocd" crossorigin="anonymous">
<link rel="stylesheet" href="https://catswords.blob.core.windows.net/welsonjs/ajax/libs/metroui/dev/lib/icons.css" integrity="sha384-FuLND994etg+RtnpPSPMyNBvL+fEz+xGhbN61WUWuDEeZ+wJzcQ8SGqAMuI5hWrt" crossorigin="anonymous"> <link rel="stylesheet" href="http://localhost:3000/ajax/libs/metroui/dev/lib/icons.css" integrity="sha384-FuLND994etg+RtnpPSPMyNBvL+fEz+xGhbN61WUWuDEeZ+wJzcQ8SGqAMuI5hWrt" crossorigin="anonymous">
<link rel="stylesheet" href="https://catswords.blob.core.windows.net/welsonjs/ajax/libs/monaco-editor/0.52.2/min/vs/editor/editor.main.css" integrity="sha384-06yHXpYRlHEPaR4AS0fB/W+lMN09Zh5e1XMtfkNQdHV38OlhfkOEW5M+pCj3QskC" crossorigin="anonymous"> <link rel="stylesheet" href="http://localhost:3000/ajax/libs/monaco-editor/0.52.2/min/vs/editor/editor.main.css" integrity="sha384-06yHXpYRlHEPaR4AS0fB/W+lMN09Zh5e1XMtfkNQdHV38OlhfkOEW5M+pCj3QskC" crossorigin="anonymous">
<style> <style>
html, body { html, body {
margin: 0; margin: 0;
@ -85,16 +85,16 @@
<script> <script>
var require = { var require = {
paths: { paths: {
vs: 'https://catswords.blob.core.windows.net/welsonjs/ajax/libs/monaco-editor/0.52.2/min/vs' vs: 'http://localhost:3000/ajax/libs/monaco-editor/0.52.2/min/vs'
} }
}; };
</script> </script>
<script src="https://catswords.blob.core.windows.net/welsonjs/ajax/libs/axios/1.8.4/axios.min.js" integrity="sha384-06w+raHvkSL3+E7mbQ2X6DZwI5A3veU8Ba+NLrAPxxRGw4Xy78sihHDHQMustMM4" crossorigin="anonymous"></script> <script src="http://localhost:3000/ajax/libs/axios/1.8.4/axios.min.js" integrity="sha384-06w+raHvkSL3+E7mbQ2X6DZwI5A3veU8Ba+NLrAPxxRGw4Xy78sihHDHQMustMM4" crossorigin="anonymous"></script>
<script src="https://catswords.blob.core.windows.net/welsonjs/ajax/libs/fast-xml-parser/4.5.1/fxparser.min.js" integrity="sha384-ae/HepOQ8hiJ/VA6yGwPMGXQXOkT/lJpjlcQ7EUgibUcfnBltuozgNj4IgOZ9QLc" crossorigin="anonymous"></script> <script src="http://localhost:3000/ajax/libs/fast-xml-parser/4.5.1/fxparser.min.js" integrity="sha384-ae/HepOQ8hiJ/VA6yGwPMGXQXOkT/lJpjlcQ7EUgibUcfnBltuozgNj4IgOZ9QLc" crossorigin="anonymous"></script>
<script src="https://catswords.blob.core.windows.net/welsonjs/ajax/libs/dompurify/3.2.4/purify.min.js" integrity="sha384-eEu5CTj3qGvu9PdJuS+YlkNi7d2XxQROAFYOr59zgObtlcux1ae1Il3u7jvdCSWu" crossorigin="anonymous"></script> <script src="http://localhost:3000/ajax/libs/dompurify/3.2.4/purify.min.js" integrity="sha384-eEu5CTj3qGvu9PdJuS+YlkNi7d2XxQROAFYOr59zgObtlcux1ae1Il3u7jvdCSWu" crossorigin="anonymous"></script>
<script src="https://catswords.blob.core.windows.net/welsonjs/ajax/libs/metroui/dev/lib/metro.js" integrity="sha384-grz4KlnFmdCd5ELenGIdPkUL/l+44UC4SniSke/OZQyRYXaQ1EDlGigacn6z4hGB" crossorigin="anonymous"></script> <script src="http://localhost:3000/ajax/libs/metroui/dev/lib/metro.js" integrity="sha384-grz4KlnFmdCd5ELenGIdPkUL/l+44UC4SniSke/OZQyRYXaQ1EDlGigacn6z4hGB" crossorigin="anonymous"></script>
<script src="https://catswords.blob.core.windows.net/welsonjs/ajax/libs/monaco-editor/0.52.2/min/vs/loader.js" integrity="sha384-pHG02SG8pId94Np3AbPmBEJ1yPqaH0IkJGLSNGXYmuGhkazT8Lr/57WYpbkGjJtu" crossorigin="anonymous"></script> <script src="http://localhost:3000/ajax/libs/monaco-editor/0.52.2/min/vs/loader.js" integrity="sha384-pHG02SG8pId94Np3AbPmBEJ1yPqaH0IkJGLSNGXYmuGhkazT8Lr/57WYpbkGjJtu" crossorigin="anonymous"></script>
<script src="https://catswords.blob.core.windows.net/welsonjs/ajax/libs/monaco-editor/0.52.2/min/vs/editor/editor.main.js" integrity="sha384-fj9z+NUc93I3woCCy5IRQfrQ8Amu1E27tllwgb5gz3d9Vr1ymS13xcF6two3e4KH" crossorigin="anonymous"></script> <script src="http://localhost:3000/ajax/libs/monaco-editor/0.52.2/min/vs/editor/editor.main.js" integrity="sha384-fj9z+NUc93I3woCCy5IRQfrQ8Amu1E27tllwgb5gz3d9Vr1ymS13xcF6two3e4KH" crossorigin="anonymous"></script>
<script> <script>
var editor; var editor;
var currentFileName = "sayhello.js"; var currentFileName = "sayhello.js";