Fix unsupported name of files

This commit is contained in:
FullGreaM 2026-01-30 18:53:11 +03:00
parent dc96a61358
commit 9e6c74fde7
3 changed files with 12 additions and 4 deletions

View File

@ -6,6 +6,7 @@ const https = require("https");
const config = require("./config");
const { DownloadVideo, YtdlUpdater, downloadFile } = require("./download");
const { MTProtoUser } = require("./mtproto");
const utils = require("./utils");
async function getImage(url) {
return new Promise((resolve, reject) => {
@ -212,9 +213,9 @@ class TgBotSender {
},
{
//filename: `downloaded.${downloaded.format.exc}`,
filename: `${
videoInfo.title
}.mp3`,
filename:
utils.setupCorrectFilename(videoInfo.title) +
".mp3",
contentType: downloaded.format.mime,
},
);

View File

@ -261,6 +261,9 @@ class DownloadVideo {
async download(cb, isStream = false) {
const signal = new EventEmitter();
const isPath = typeof isStream === "string";
if (isPath) {
console.debug({ isStream });
}
if (!this.parent.updater.lock(signal)) {
await new Promise((rs => {
this.parent.updater.once("finish", () => {

View File

@ -52,4 +52,8 @@ async function verifyThumbUrl (fileUrl) {
}
}
module.exports = { downloadFile, verifyThumbUrl };
function setupCorrectFilename (filename) {
return filename.replace(/[\/\\\s\.+]{1,}/g, "_");
}
module.exports = { downloadFile, verifyThumbUrl, setupCorrectFilename };