hopefully fixed filename preview on telegram
This commit is contained in:
parent
7e1afcb1b1
commit
4bef255fe0
12
src/main.js
12
src/main.js
|
@ -59,7 +59,7 @@ async function track_req(request, env) {
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'track':
|
case 'track':
|
||||||
return await track(env, id, format, tagging, request.headers.get('range'))
|
return await track(env, id, format, tagging, request.headers.get('range'), request.headers.get('user-agent'))
|
||||||
case 'album':
|
case 'album':
|
||||||
case 'playlist':
|
case 'playlist':
|
||||||
return await m3u8(type, id, format, tagging, request.headers.get('host'))
|
return await m3u8(type, id, format, tagging, request.headers.get('host'))
|
||||||
|
@ -148,7 +148,7 @@ async function auth_dzapi(env) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function track(env, id, format, tagging, range_header) {
|
async function track(env, id, format, tagging, range_header, user_agent) {
|
||||||
// other users' user-upped tracks cannot be downloaded with the gw-light API
|
// other users' user-upped tracks cannot be downloaded with the gw-light API
|
||||||
let json;
|
let json;
|
||||||
if (id >= 0) {
|
if (id >= 0) {
|
||||||
|
@ -258,13 +258,19 @@ async function track(env, id, format, tagging, range_header) {
|
||||||
if (json.VERSION) title += ` ${json.VERSION}`
|
if (json.VERSION) title += ` ${json.VERSION}`
|
||||||
|
|
||||||
const filename = `${title} [${id}].${formats[format].ext}`
|
const filename = `${title} [${id}].${formats[format].ext}`
|
||||||
|
let content_disposition
|
||||||
|
if (user_agent === null || !user_agent.startsWith('TelegramBot')) {
|
||||||
|
content_disposition = `inline; filename*=UTF-8''${encodeRFC5987ValueChars(filename)}`
|
||||||
|
} else {
|
||||||
|
content_disposition = `inline; filename="${filename.replace(/['\\]/g, (c) => `\\${c}`)}"`
|
||||||
|
}
|
||||||
|
|
||||||
let init = { method: 'GET', headers: {} }
|
let init = { method: 'GET', headers: {} }
|
||||||
let resp_init = {
|
let resp_init = {
|
||||||
status: 200,
|
status: 200,
|
||||||
headers: {
|
headers: {
|
||||||
'content-type': formats[format].mime,
|
'content-type': formats[format].mime,
|
||||||
'content-disposition': `inline; filename*=UTF-8''${encodeRFC5987ValueChars(filename)}`,
|
'content-disposition': content_disposition,
|
||||||
'accept-ranges': 'bytes'
|
'accept-ranges': 'bytes'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue