mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-07 12:16:04 +00:00
Improve initial start time, and Add WHOIS request
This commit is contained in:
parent
07991329fc
commit
1f859c75c6
|
@ -5,6 +5,7 @@ using System.Diagnostics;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WelsonJS.Launcher
|
||||
{
|
||||
|
@ -14,9 +15,12 @@ namespace WelsonJS.Launcher
|
|||
|
||||
public ExecutablesCollector()
|
||||
{
|
||||
executables.AddRange(GetInstalledSoftwareExecutables());
|
||||
executables.AddRange(GetExecutablesFromPath());
|
||||
executables.AddRange(GetExecutablesFromNetFx());
|
||||
new Task(() =>
|
||||
{
|
||||
executables.AddRange(GetInstalledSoftwareExecutables());
|
||||
executables.AddRange(GetExecutablesFromPath());
|
||||
executables.AddRange(GetExecutablesFromNetFx());
|
||||
}).Start();
|
||||
}
|
||||
|
||||
public List<string> GetExecutables()
|
||||
|
|
|
@ -110,6 +110,14 @@ namespace WelsonJS.Launcher
|
|||
return;
|
||||
}
|
||||
|
||||
// Serve WHOIS request (use KRNIC server)
|
||||
const string whoisPrefix = "whois/";
|
||||
if (path.StartsWith(whoisPrefix, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
ServeWhoisRequest(context, path.Substring(whoisPrefix.Length)).Wait();
|
||||
return;
|
||||
}
|
||||
|
||||
// Serve a resource
|
||||
ServeResource(context, GetResource(_resourceName), "text/html");
|
||||
}
|
||||
|
@ -167,6 +175,35 @@ namespace WelsonJS.Launcher
|
|||
}
|
||||
}
|
||||
|
||||
private async Task ServeWhoisRequest(HttpListenerContext context, string query)
|
||||
{
|
||||
string whoisServerUrl = "https://xn--c79as89aj0e29b77z.xn--3e0b707e";
|
||||
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, $"{whoisServerUrl}/kor/whois.jsc")
|
||||
{
|
||||
Content = new StringContent($"query={query}&ip=141.101.82.1", Encoding.UTF8, "application/x-www-form-urlencoded")
|
||||
};
|
||||
|
||||
request.Headers.Add("Accept", "*/*");
|
||||
request.Headers.Add("User-Agent", "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");
|
||||
client.DefaultRequestHeaders.Referrer = new Uri($"{whoisServerUrl}/kor/whois/whois.jsp");
|
||||
|
||||
try
|
||||
{
|
||||
HttpResponseMessage response = await client.SendAsync(request);
|
||||
string responseBody = await response.Content.ReadAsStringAsync();
|
||||
|
||||
ServeResource(context, responseBody, "text/html", (int)response.StatusCode);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ServeResource(context, $"<error>Failed to process WHOIS request. {ex.Message}</error>", "application/xml", 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ServeResource(HttpListenerContext context, byte[] data, string mimeType = "text/html", int statusCode = 200)
|
||||
{
|
||||
string xmlHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>WelsonJS Code Editor</title>
|
||||
<title>WelsonJS Editor</title>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
||||
<link rel="stylesheet" href="https://cdn.metroui.org.ua/dev/metro.css">
|
||||
<link rel="stylesheet" href="https://cdn.metroui.org.ua/dev/icons.css">
|
||||
|
@ -36,27 +36,39 @@
|
|||
<body>
|
||||
<nav data-role="ribbonmenu">
|
||||
<ul class="tabs-holder">
|
||||
<li class="static"><a href="#">File</a></li>
|
||||
<li class="static"><a href="#">WelsonJS</a></li>
|
||||
<li><a href="#editor-tab">Editor</a></li>
|
||||
</ul>
|
||||
<div class="content-holder">
|
||||
<div class="section" id="editor-tab">
|
||||
<button id="btnOpenFile" class="ribbon-button">
|
||||
<span class="icon mif-folder-open"></span>
|
||||
<span class="caption">Open File</span>
|
||||
</button>
|
||||
<button id="btnSaveFile" class="ribbon-button">
|
||||
<span class="icon mif-floppy-disks"></span>
|
||||
<span class="caption">Save File</span>
|
||||
</button>
|
||||
<button id="btnGenerate" class="ribbon-button">
|
||||
<span class="icon mif-rocket"></span>
|
||||
<span class="caption">Generate</span>
|
||||
</button>
|
||||
<button id="btnSponsor" class="ribbon-button">
|
||||
<span class="icon mif-heart"></span>
|
||||
<span class="caption">Sponsor</span>
|
||||
</button>
|
||||
<div class="group">
|
||||
<button id="btnOpenFile" class="ribbon-button">
|
||||
<span class="icon mif-folder-open"></span>
|
||||
<span class="caption">Open File</span>
|
||||
</button>
|
||||
<button id="btnSaveFile" class="ribbon-button">
|
||||
<span class="icon mif-floppy-disks"></span>
|
||||
<span class="caption">Save File</span>
|
||||
</button>
|
||||
<button id="btnGenerate" class="ribbon-button">
|
||||
<span class="icon mif-rocket"></span>
|
||||
<span class="caption">Generate</span>
|
||||
</button>
|
||||
<button id="btnSponsor" class="ribbon-button">
|
||||
<span class="icon mif-heart"></span>
|
||||
<span class="caption">Sponsor</span>
|
||||
</button>
|
||||
|
||||
<span class="title">Common</span>
|
||||
</div>
|
||||
<div class="group">
|
||||
<button id="btnWhois" class="ribbon-button">
|
||||
<span class="icon mif-earth"></span>
|
||||
<span class="caption">Whois</span>
|
||||
</button>
|
||||
|
||||
<span class="title">Specific</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
@ -94,7 +106,7 @@
|
|||
}
|
||||
|
||||
function getSuggestions(word, range) {
|
||||
return axios.get(serverBaseUrl + "/completion/" + encodeURIComponent(word))
|
||||
return axios.get(`${serverBaseUrl}/completion/${encodeURIComponent(word)}`)
|
||||
.then(function (response) {
|
||||
var parser = new XMLParser();
|
||||
var result = parser.parse(response.data);
|
||||
|
@ -234,7 +246,7 @@
|
|||
return;
|
||||
}
|
||||
|
||||
appendTextToEditor("\n// " + promptMessage + "... Thinking with Generative AI...");
|
||||
appendTextToEditor(`\n//${promptMessage}... Thinking with Generative AI...`);
|
||||
|
||||
(async function () {
|
||||
const targetWsUrl = await getTargetByUrl('copilot.microsoft.com');
|
||||
|
@ -246,8 +258,27 @@
|
|||
})();
|
||||
};
|
||||
|
||||
document.getElementById("btnWhois").onclick = function () {
|
||||
const hostname = prompt("Enter a hostname or IP address:", '');
|
||||
if (!hostname || hostname.trim() == '') {
|
||||
alert("A hostname or IP address is required.");
|
||||
return;
|
||||
}
|
||||
|
||||
axios.get(`${serverBaseUrl}/whois/${hostname}`).then(response => {
|
||||
const responseText = response.data
|
||||
.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '')
|
||||
.replace(/<\/?[^>]+(>|$)/g, '')
|
||||
.replace(/^[\r\n]+|[\r\n]+$/g, '');
|
||||
|
||||
appendTextToEditor(`/*\n${responseText}\n*/`);
|
||||
}).catch(error => {
|
||||
console.error(error);
|
||||
});
|
||||
};
|
||||
|
||||
async function getTargetByUrl(urlPart) {
|
||||
const response = await fetch(serverBaseUrl + "/devtools/json");
|
||||
const response = await fetch(`${serverBaseUrl}/devtools/json`);
|
||||
const targets = await response.json();
|
||||
|
||||
const target = targets.find(target => target.url.includes(urlPart));
|
||||
|
@ -303,7 +334,7 @@
|
|||
|
||||
socket.onmessage = (event) => {
|
||||
const response = JSON.parse(event.data);
|
||||
console.log('Sent successfully:', response.result);
|
||||
console.log("Sent successfully:", response.result);
|
||||
|
||||
if (response.id == 3) {
|
||||
appendTextToEditor(response.result.result.value);
|
||||
|
|
Loading…
Reference in New Issue
Block a user