mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-15 04:39:58 +00:00
api: return correct extension for gif downloads in api response
This commit is contained in:
parent
29f967a3ec
commit
d560c0d34a
3 changed files with 18 additions and 5 deletions
|
@ -65,3 +65,14 @@ export function merge(a, b) {
|
|||
|
||||
return a;
|
||||
}
|
||||
|
||||
export function splitFilenameExtension(filename) {
|
||||
const parts = filename.split('.');
|
||||
const ext = parts.pop();
|
||||
|
||||
if (!parts.length) {
|
||||
return [ ext, "" ]
|
||||
} else {
|
||||
return [ parts.join('.'), ext ]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ import createFilename from "./create-filename.js";
|
|||
import { createResponse } from "./request.js";
|
||||
import { audioIgnore } from "./service-config.js";
|
||||
import { createStream } from "../stream/manage.js";
|
||||
import { splitFilenameExtension } from "../misc/utils.js";
|
||||
|
||||
export default function({ r, host, audioFormat, isAudioOnly, isAudioMuted, disableMetadata, filenameStyle, twitterGif, requestIP, audioBitrate, alwaysProxy }) {
|
||||
let action,
|
||||
|
@ -32,10 +33,11 @@ export default function({ r, host, audioFormat, isAudioOnly, isAudioMuted, disab
|
|||
}
|
||||
|
||||
if (action === "muteVideo" && isAudioMuted && !r.filenameAttributes) {
|
||||
const parts = r.filename.split(".");
|
||||
const ext = parts.pop();
|
||||
|
||||
defaultParams.filename = `${parts.join(".")}_mute.${ext}`;
|
||||
const [ name, ext ] = splitFilenameExtension(r.filename);
|
||||
defaultParams.filename = `${name}_mute.${ext}`;
|
||||
} else if (action === "gif") {
|
||||
const [ name ] = splitFilenameExtension(r.filename);
|
||||
defaultParams.filename = `${name}.gif`;
|
||||
}
|
||||
|
||||
switch (action) {
|
||||
|
|
|
@ -291,7 +291,7 @@ const convertGif = (streamInfo, res) => {
|
|||
const [,,, muxOutput] = process.stdio;
|
||||
|
||||
res.setHeader('Connection', 'keep-alive');
|
||||
res.setHeader('Content-Disposition', contentDisposition(streamInfo.filename.split('.')[0] + ".gif"));
|
||||
res.setHeader('Content-Disposition', contentDisposition(streamInfo.filename));
|
||||
|
||||
pipe(muxOutput, res, shutdown);
|
||||
|
||||
|
|
Loading…
Reference in a new issue