mirror of
https://github.com/asdlokj1qpi233/subconverter.git
synced 2026-11-03 18:24:58 +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)
|
||||
{
|
||||
case CURLINFO_TEXT:
|
||||
prefix = "CURL_INFO";
|
||||
prefix = "CURL_INFO: ";
|
||||
break;
|
||||
case CURLINFO_HEADER_IN:
|
||||
prefix = "CURL_HEADER: < ";
|
||||
break;
|
||||
case CURLINFO_HEADER_OUT:
|
||||
prefix = "CURL_HEADER";
|
||||
prefix = "CURL_HEADER: > ";
|
||||
break;
|
||||
case CURLINFO_DATA_IN:
|
||||
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)
|
||||
{
|
||||
std::string log_content = prefix;
|
||||
log_content += ": ";
|
||||
log_content += x;
|
||||
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
|
||||
{
|
||||
std::string log_content = prefix;
|
||||
log_content += ": ";
|
||||
log_content += trimWhitespace(content);
|
||||
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)
|
||||
{
|
||||
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"))
|
||||
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, user_agent_str);
|
||||
@@ -233,7 +234,7 @@ static int curlGet(const FetchArgument &argument, FetchResult &result)
|
||||
while(true)
|
||||
{
|
||||
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;
|
||||
else
|
||||
fail_count++;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
#include <quickjspp.hpp>
|
||||
#include <utility>
|
||||
#include <quickjs/quickjs-libc.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
@@ -226,7 +227,7 @@ public:
|
||||
qjs_fetch_Headers headers;
|
||||
std::string cookies;
|
||||
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
|
||||
@@ -389,7 +390,7 @@ void script_runtime_init(qjs::Runtime &runtime)
|
||||
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
|
||||
if(!type)
|
||||
@@ -424,7 +425,7 @@ struct Lambda {
|
||||
|
||||
uint32_t currentTime()
|
||||
{
|
||||
return time(NULL);
|
||||
return time(nullptr);
|
||||
}
|
||||
|
||||
int script_context_init(qjs::Context &context)
|
||||
@@ -525,7 +526,7 @@ int script_context_init(qjs::Context &context)
|
||||
)", "<import>", JS_EVAL_TYPE_MODULE);
|
||||
return 0;
|
||||
}
|
||||
catch(qjs::exception)
|
||||
catch(qjs::exception&)
|
||||
{
|
||||
script_print_stack(context);
|
||||
return 1;
|
||||
|
||||
@@ -26,7 +26,8 @@ std::string getTime(int type)
|
||||
format = "%Y%m%d-%H%M%S";
|
||||
break;
|
||||
case 2:
|
||||
format = "%Y/%m/%d %a %H:%M:%S." + std::string(cMillis);
|
||||
format = "%Y/%m/%d %a %H:%M:%S.";
|
||||
format += cMillis;
|
||||
break;
|
||||
case 3:
|
||||
default:
|
||||
|
||||
Reference in new issue
Block a user