upstream: fix: Improve status reporting and filename handling for /url save (a9ef00032)

This commit is contained in:
2026-03-31 19:57:35 +03:00
parent c67f716eb9
commit c1dd6b8b1a
5 changed files with 55 additions and 24 deletions

View File

@@ -106,9 +106,11 @@ aesgcm_file_get(void* userdata)
http_dl->worker = aesgcm_dl->worker;
http_dl->id = strdup(aesgcm_dl->id);
http_dl->url = strdup(https_url);
http_dl->display_url = strdup(aesgcm_dl->url);
http_dl->filename = strdup(tmpname);
http_dl->cmd_template = NULL;
http_dl->silent = FALSE;
http_dl->silent_done = TRUE;
http_dl->return_bytes_received = TRUE;
aesgcm_dl->http_dl = http_dl;
@@ -139,10 +141,12 @@ aesgcm_file_get(void* userdata)
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id,
"Downloading '%s' failed: Failed to decrypt "
"file (%s).",
https_url, gcry_strerror(crypt_res));
aesgcm_dl->url, gcry_strerror(crypt_res));
} else {
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id,
"Decrypted file saved to '%s'", aesgcm_dl->filename);
"Downloading '%s': done\nSaved to '%s'",
aesgcm_dl->url, aesgcm_dl->filename);
win_mark_received(aesgcm_dl->window, aesgcm_dl->id);
}
if (aesgcm_dl->cmd_template != NULL) {

View File

@@ -58,7 +58,6 @@
#include "common.h"
GSList* download_processes = NULL;
gboolean silent = FALSE;
static int
_xferinfo(void* userdata, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
@@ -84,9 +83,16 @@ _xferinfo(void* userdata, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultot
dlperc = (100 * dlnow) / dltotal;
}
if (!silent)
http_print_transfer_update(download->window, download->url,
"Downloading '%s': %d%%", download->url, dlperc);
if (!download->silent) {
const char* url = download->display_url ? download->display_url : download->url;
if (dlnow == dltotal && dltotal > 0) {
http_print_transfer_update(download->window, download->id,
"Downloading '%s': done", url);
} else {
http_print_transfer_update(download->window, download->id,
"Downloading '%s': %d%%", url, dlperc);
}
}
pthread_mutex_unlock(&lock);
@@ -111,15 +117,15 @@ http_file_get(void* userdata)
CURL* curl;
CURLcode res;
silent = download->silent;
download->cancel = 0;
download->bytes_received = 0;
pthread_mutex_lock(&lock);
if (!silent) {
const char* display_url = download->display_url ? download->display_url : download->url;
if (!download->silent) {
http_print_transfer(download->window, download->id,
"Downloading '%s': 0%%", download->url);
"Downloading '%s': 0%%", display_url);
}
FILE* outfh = fopen(download->filename, "wb");
@@ -198,18 +204,18 @@ http_file_get(void* userdata)
http_print_transfer_update(download->window, download->id,
"Downloading '%s' failed: "
"Download was canceled",
download->url);
display_url);
} else {
http_print_transfer_update(download->window, download->id,
"Downloading '%s' failed: %s",
download->url, err);
display_url, err);
}
free(err);
} else {
if (!download->cancel && !silent) {
if (!download->cancel && !download->silent && !download->silent_done) {
http_print_transfer_update(download->window, download->id,
"Downloading '%s': done\nSaved to '%s'",
download->url, download->filename);
display_url, download->filename);
win_mark_received(download->window, download->id);
if (download->return_bytes_received) {
ret = malloc(sizeof(*ret));
@@ -230,7 +236,7 @@ http_file_get(void* userdata)
http_print_transfer_update(download->window, download->id,
"Downloading '%s' failed: Unable to call "
"command '%s' with file at '%s' (%s).",
download->url,
display_url,
download->cmd_template,
download->filename,
"TODO: Log the error");
@@ -247,6 +253,7 @@ out:
free(download->filename);
free(download->url);
free(download->display_url);
free(download->id);
free(download);

View File

@@ -51,6 +51,7 @@ typedef struct http_download_t
{
char* id;
char* url;
char* display_url;
char* filename;
char* cmd_template;
curl_off_t bytes_received;
@@ -58,6 +59,7 @@ typedef struct http_download_t
pthread_t worker;
int cancel;
gboolean silent;
gboolean silent_done;
gboolean return_bytes_received;
} HTTPDownload;

View File

@@ -91,7 +91,13 @@ _xferinfo(void* userdata, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultot
ulperc = (100 * ulnow) / ultotal;
}
gchar* msg = g_strdup_printf("Uploading '%s': %d%%", upload->filename, ulperc);
gchar* msg = NULL;
if (ulnow == ultotal && ultotal > 0) {
msg = g_strdup_printf("Uploading '%s': done", upload->filename);
} else {
msg = g_strdup_printf("Uploading '%s': %d%%", upload->filename, ulperc);
}
if (!msg) {
msg = g_strdup(FALLBACK_MSG);
}
@@ -314,7 +320,7 @@ http_file_put(void* userdata)
cons_show_error("%s", err_msg);
} else {
if (!upload->cancel) {
auto_gchar gchar* status_msg = g_strdup_printf("Uploading '%s': 100%%", upload->filename);
auto_gchar gchar* status_msg = g_strdup_printf("Uploading '%s': done", upload->filename);
if (!status_msg) {
status_msg = g_strdup(FALLBACK_MSG);
}