Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use the on-disk filename in the content-disposition header when downl…
…oading recordings in the webui. The old behaviour was to just take the episode title, and would generate a ".bin" extension for passthrough (TS) recordings.
  • Loading branch information
linuxstb committed Aug 27, 2014
1 parent 99ed831 commit 6e4a22a
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/webui/webui.c
Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 6e4a22a

Please sign in to comment.