mirror of
https://github.com/asdlokj1qpi233/subconverter.git
synced 2026-11-05 11:12:12 +00:00
Enhancements
Refine libcurl logs. Do not retry web request on API mode. Optimize codes.
This commit is contained in:
3 files changed
+14
-11
No files matched your search
@@ -87,11 +87,13 @@ static int logger(CURL *handle, curl_infotype type, char *data, size_t size, voi
|
|||||||
switch(type)
|
switch(type)
|
||||||
{
|
{
|
||||||
case CURLINFO_TEXT:
|
case CURLINFO_TEXT:
|
||||||
prefix = "CURL_INFO";
|
prefix = "CURL_INFO: ";
|
||||||
break;
|
break;
|
||||||
case CURLINFO_HEADER_IN:
|
case CURLINFO_HEADER_IN:
|
||||||
|
prefix = "CURL_HEADER: < ";
|
||||||
|
break;
|
||||||
case CURLINFO_HEADER_OUT:
|
case CURLINFO_HEADER_OUT:
|
||||||
prefix = "CURL_HEADER";
|
prefix = "CURL_HEADER: > ";
|
||||||
break;
|
break;
|
||||||
case CURLINFO_DATA_IN:
|
case CURLINFO_DATA_IN:
|
||||||
case CURLINFO_DATA_OUT:
|
case CURLINFO_DATA_OUT:
|
||||||
@@ -105,7 +107,6 @@ static int logger(CURL *handle, curl_infotype type, char *data, size_t size, voi
|
|||||||
for(auto &x : lines)
|
for(auto &x : lines)
|
||||||
{
|
{
|
||||||
std::string log_content = prefix;
|
std::string log_content = prefix;
|
||||||
log_content += ": ";
|
|
||||||
log_content += x;
|
log_content += x;
|
||||||
writeLog(0, log_content, LOG_LEVEL_VERBOSE);
|
writeLog(0, log_content, LOG_LEVEL_VERBOSE);
|
||||||
}
|
}
|
||||||
@@ -113,7 +114,6 @@ static int logger(CURL *handle, curl_infotype type, char *data, size_t size, voi
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::string log_content = prefix;
|
std::string log_content = prefix;
|
||||||
log_content += ": ";
|
|
||||||
log_content += trimWhitespace(content);
|
log_content += trimWhitespace(content);
|
||||||
writeLog(0, log_content, LOG_LEVEL_VERBOSE);
|
writeLog(0, log_content, LOG_LEVEL_VERBOSE);
|
||||||
}
|
}
|
||||||
@@ -172,7 +172,8 @@ static int curlGet(const FetchArgument &argument, FetchResult &result)
|
|||||||
{
|
{
|
||||||
for(auto &x : *argument.request_headers)
|
for(auto &x : *argument.request_headers)
|
||||||
{
|
{
|
||||||
header_list = curl_slist_append(header_list, (x.first + ": " + x.second).data());
|
auto header = x.first + ": " + x.second;
|
||||||
|
header_list = curl_slist_append(header_list, header.data());
|
||||||
}
|
}
|
||||||
if(!argument.request_headers->contains("User-Agent"))
|
if(!argument.request_headers->contains("User-Agent"))
|
||||||
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, user_agent_str);
|
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, user_agent_str);
|
||||||
@@ -233,7 +234,7 @@ static int curlGet(const FetchArgument &argument, FetchResult &result)
|
|||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
retVal = curl_easy_perform(curl_handle);
|
retVal = curl_easy_perform(curl_handle);
|
||||||
if(retVal == CURLE_OK || max_fails <= fail_count)
|
if(retVal == CURLE_OK || max_fails <= fail_count || global.APIMode)
|
||||||
break;
|
break;
|
||||||
else
|
else
|
||||||
fail_count++;
|
fail_count++;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <quickjspp.hpp>
|
#include <quickjspp.hpp>
|
||||||
|
#include <utility>
|
||||||
#include <quickjs/quickjs-libc.h>
|
#include <quickjs/quickjs-libc.h>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@@ -226,7 +227,7 @@ public:
|
|||||||
qjs_fetch_Headers headers;
|
qjs_fetch_Headers headers;
|
||||||
std::string cookies;
|
std::string cookies;
|
||||||
std::string postdata;
|
std::string postdata;
|
||||||
explicit qjs_fetch_Request(const std::string &url) : url(url) {}
|
explicit qjs_fetch_Request(std::string url) : url(std::move(url)) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class qjs_fetch_Response
|
class qjs_fetch_Response
|
||||||
@@ -389,7 +390,7 @@ void script_runtime_init(qjs::Runtime &runtime)
|
|||||||
js_std_init_handlers(runtime.rt);
|
js_std_init_handlers(runtime.rt);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ShowMsgbox(const std::string &title, std::string content, uint16_t type = 0)
|
int ShowMsgbox(const std::string &title, const std::string &content, uint16_t type = 0)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if(!type)
|
if(!type)
|
||||||
@@ -424,7 +425,7 @@ struct Lambda {
|
|||||||
|
|
||||||
uint32_t currentTime()
|
uint32_t currentTime()
|
||||||
{
|
{
|
||||||
return time(NULL);
|
return time(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
int script_context_init(qjs::Context &context)
|
int script_context_init(qjs::Context &context)
|
||||||
@@ -525,7 +526,7 @@ int script_context_init(qjs::Context &context)
|
|||||||
)", "<import>", JS_EVAL_TYPE_MODULE);
|
)", "<import>", JS_EVAL_TYPE_MODULE);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
catch(qjs::exception)
|
catch(qjs::exception&)
|
||||||
{
|
{
|
||||||
script_print_stack(context);
|
script_print_stack(context);
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ std::string getTime(int type)
|
|||||||
format = "%Y%m%d-%H%M%S";
|
format = "%Y%m%d-%H%M%S";
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
format = "%Y/%m/%d %a %H:%M:%S." + std::string(cMillis);
|
format = "%Y/%m/%d %a %H:%M:%S.";
|
||||||
|
format += cMillis;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in new issue
Block a user