From 6e4a22a52ddf9c3ed63e343d31b356698018ace5 Mon Sep 17 00:00:00 2001 From: Dave Chapman Date: Wed, 27 Aug 2014 22:30:07 +0100 Subject: [PATCH] Use the on-disk filename in the content-disposition header when downloading recordings in the webui. The old behaviour was to just take the episode title, and would generate a ".bin" extension for passthrough (TS) recordings. --- src/webui/webui.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/webui/webui.c b/src/webui/webui.c index 8266de95..9c96cac8 100644 --- a/src/webui/webui.c +++ b/src/webui/webui.c @@ -1103,9 +1103,10 @@ page_dvrfile(http_connection_t *hc, const char *remain, void *opaque) { int fd, i; struct stat st; - const char *content = NULL, *postfix, *range; + const char *content = NULL, *range; dvr_entry_t *de; char *fname; + char *basename; char range_buf[255]; char disposition[256]; off_t content_len, chunk; @@ -1129,10 +1130,23 @@ page_dvrfile(http_connection_t *hc, const char *remain, void *opaque) fname = strdup(de->de_filename); content = muxer_container_type2mime(de->de_mc, 1); - postfix = muxer_container_suffix(de->de_mc, 1); pthread_mutex_unlock(&global_lock); + basename = strrchr(fname, '/'); + if (basename) { + basename++; /* Skip '/' */ + snprintf(disposition, sizeof(disposition), "attachment; filename=\"%s\"", basename); + // Ensure there are no " characters in the filename. + i = strlen(disposition)-2; + while (i > 21) { + if (disposition[i] == '"') { disposition[i] = '_'; } + i--; + } + } else { + disposition[0] = 0; + } + fd = tvh_open(fname, O_RDONLY, 0); free(fname); if(fd < 0) @@ -1173,20 +1187,6 @@ page_dvrfile(http_connection_t *hc, const char *remain, void *opaque) if(file_start > 0) lseek(fd, file_start, SEEK_SET); - if(de->de_title != NULL) { - snprintf(disposition, sizeof(disposition), - "attachment; filename=%s.%s", lang_str_get(de->de_title, NULL), postfix); - i = 20; - while(disposition[i]) { - if(disposition[i] == ' ') - disposition[i] = '_'; - i++; - } - - } else { - disposition[0] = 0; - } - http_send_header(hc, range ? HTTP_STATUS_PARTIAL_CONTENT : HTTP_STATUS_OK, content, content_len, NULL, NULL, 10, range ? range_buf : NULL,