mirror of
https://github.com/asdlokj1qpi233/subconverter.git
synced 2026-11-05 03:02:06 +00:00
Optimize codes
This commit is contained in:
9 files changed
+808
-293
No files matched your search
@@ -2,6 +2,7 @@
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
#include <quickjspp.hpp>
|
||||
#include <quickjs/quickjs-libc.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
@@ -291,9 +292,7 @@ namespace qjs
|
||||
static qjs_fetch_Headers unwrap(JSContext *ctx, JSValueConst v)
|
||||
{
|
||||
qjs_fetch_Headers result;
|
||||
auto headers = JS_GetPropertyStr(ctx, v, "headers");
|
||||
result.headers = js_traits<detail::string_icase_map>::unwrap(ctx, headers);
|
||||
JS_FreeValue(ctx, headers);
|
||||
result.headers = unwrap_free<detail::string_icase_map>(ctx, v, "headers");
|
||||
return result;
|
||||
}
|
||||
static JSValue wrap(JSContext *ctx, const qjs_fetch_Headers &h)
|
||||
@@ -310,14 +309,12 @@ namespace qjs
|
||||
static qjs_fetch_Request unwrap(JSContext *ctx, JSValueConst v)
|
||||
{
|
||||
qjs_fetch_Request request;
|
||||
auto headers = JS_GetPropertyStr(ctx, v, "headers");
|
||||
request.method = JS_GetPropertyToString(ctx, v, "method");
|
||||
request.url = JS_GetPropertyToString(ctx, v, "url");
|
||||
request.postdata = JS_GetPropertyToString(ctx, v, "data");
|
||||
request.proxy = JS_GetPropertyToString(ctx, v, "proxy");
|
||||
request.cookies = JS_GetPropertyToString(ctx, v, "cookies");
|
||||
request.headers = js_traits<qjs_fetch_Headers>::unwrap(ctx, headers);
|
||||
JS_FreeValue(ctx, headers);
|
||||
request.method = unwrap_free<std::string>(ctx, v, "method");
|
||||
request.url = unwrap_free<std::string>(ctx, v, "url");
|
||||
request.postdata = unwrap_free<std::string>(ctx, v, "data");
|
||||
request.proxy = unwrap_free<std::string>(ctx, v, "proxy");
|
||||
request.cookies = unwrap_free<std::string>(ctx, v, "cookies");
|
||||
request.headers = unwrap_free<qjs_fetch_Headers>(ctx, v, "headers");
|
||||
return request;
|
||||
}
|
||||
};
|
||||
@@ -390,7 +387,6 @@ std::string getGeoIP(const std::string &address, const std::string &proxy)
|
||||
void script_runtime_init(qjs::Runtime &runtime)
|
||||
{
|
||||
js_std_init_handlers(runtime.rt);
|
||||
JS_SetModuleLoaderFunc(runtime.rt, nullptr, js_module_loader, nullptr);
|
||||
}
|
||||
|
||||
int ShowMsgbox(const std::string &title, std::string content, uint16_t type = 0)
|
||||
@@ -459,18 +455,6 @@ int script_context_init(qjs::Context &context)
|
||||
.fun<&qjs_fetch_Response::content>("data")
|
||||
.fun<&qjs_fetch_Response::cookies>("cookies")
|
||||
.fun<&qjs_fetch_Response::headers>("headers");
|
||||
/*
|
||||
module.class_<nodeInfo>("NodeInfo")
|
||||
.constructor<>()
|
||||
.fun<&nodeInfo::linkType>("LinkType")
|
||||
.fun<&nodeInfo::id>("ID")
|
||||
.fun<&nodeInfo::groupID>("GroupID")
|
||||
.fun<&nodeInfo::group>("Group")
|
||||
.fun<&nodeInfo::remarks>("Remark")
|
||||
.fun<&nodeInfo::server>("Hostname")
|
||||
.fun<&nodeInfo::port>("Port")
|
||||
.fun<&nodeInfo::proxyStr>("ProxyInfo");
|
||||
*/
|
||||
module.class_<Proxy>("Proxy")
|
||||
.constructor<>()
|
||||
.fun<&Proxy::Type>("Type")
|
||||
@@ -502,7 +486,20 @@ int script_context_init(qjs::Context &context)
|
||||
.fun<&Proxy::UDP>("UDP")
|
||||
.fun<&Proxy::TCPFastOpen>("TCPFastOpen")
|
||||
.fun<&Proxy::AllowInsecure>("AllowInsecure")
|
||||
.fun<&Proxy::TLS13>("TLS13");
|
||||
.fun<&Proxy::TLS13>("TLS13")
|
||||
.fun<&Proxy::SnellVersion>("SnellVersion")
|
||||
.fun<&Proxy::ServerName>("ServerName")
|
||||
.fun<&Proxy::SelfIP>("SelfIP")
|
||||
.fun<&Proxy::SelfIPv6>("SelfIPv6")
|
||||
.fun<&Proxy::PublicKey>("PublicKey")
|
||||
.fun<&Proxy::PrivateKey>("PrivateKey")
|
||||
.fun<&Proxy::PreSharedKey>("PreSharedKey")
|
||||
.fun<&Proxy::DnsServers>("DnsServers")
|
||||
.fun<&Proxy::Mtu>("Mtu")
|
||||
.fun<&Proxy::AllowedIPs>("AllowedIPs")
|
||||
.fun<&Proxy::KeepAlive>("KeepAlive")
|
||||
.fun<&Proxy::TestUrl>("TestUrl")
|
||||
.fun<&Proxy::ClientId>("ClientId");
|
||||
context.global().add<&makeDataURI>("makeDataURI")
|
||||
.add<&qjs_fetch>("fetch")
|
||||
.add<&base64Encode>("atob")
|
||||
@@ -518,7 +515,7 @@ int script_context_init(qjs::Context &context)
|
||||
globalThis.Request = interUtils.Request
|
||||
globalThis.Response = interUtils.Response
|
||||
globalThis.Headers = interUtils.Headers
|
||||
globalThis.NodeInfo = interUtils.NodeInfo
|
||||
globalThis.Proxy = interUtils.Proxy
|
||||
import * as std from 'std'
|
||||
import * as os from 'os'
|
||||
globalThis.std = std
|
||||
|
||||
Reference in new issue
Block a user