fix preview
This commit is contained in:
parent
852c0e2803
commit
3e400cea39
11
src/bot.js
11
src/bot.js
@ -78,7 +78,9 @@ class TgBotSender {
|
|||||||
async sendVideo (chatId, data, settings = {}, apiOptions = {}) {
|
async sendVideo (chatId, data, settings = {}, apiOptions = {}) {
|
||||||
if (this.parent.mtproto !== null) {
|
if (this.parent.mtproto !== null) {
|
||||||
const mtprotoMID = await this.parent.mtproto.saveMedia(
|
const mtprotoMID = await this.parent.mtproto.saveMedia(
|
||||||
data, settings.caption ?? ""
|
data, settings.caption ?? "", {
|
||||||
|
thumb: settings.thumb,
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return await this.bot.copyMessage(
|
return await this.bot.copyMessage(
|
||||||
@ -157,6 +159,7 @@ class TgBotSender {
|
|||||||
.then(async (downloaded) => {
|
.then(async (downloaded) => {
|
||||||
//console.debug("downloaded:", downloaded);
|
//console.debug("downloaded:", downloaded);
|
||||||
try {
|
try {
|
||||||
|
const videoInfo = await video.getVideoInfo();
|
||||||
if (downloaded.format.type === "video") {
|
if (downloaded.format.type === "video") {
|
||||||
const filesize = (typeof isStream !== "string" || this.parent.mtproto !== null) ?
|
const filesize = (typeof isStream !== "string" || this.parent.mtproto !== null) ?
|
||||||
0 : await getFileSize(downloaded.data);
|
0 : await getFileSize(downloaded.data);
|
||||||
@ -170,7 +173,10 @@ class TgBotSender {
|
|||||||
await this.sendVideo(
|
await this.sendVideo(
|
||||||
msg.chat.id,
|
msg.chat.id,
|
||||||
downloaded.data,
|
downloaded.data,
|
||||||
{ caption: info.title },
|
{
|
||||||
|
caption: info.title,
|
||||||
|
thumb: await downloadFile(videoInfo.thumbnail),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
filename,
|
filename,
|
||||||
contentType: isStream === true ? "application/octet-stream" : downloaded.format.mime,
|
contentType: isStream === true ? "application/octet-stream" : downloaded.format.mime,
|
||||||
@ -193,7 +199,6 @@ class TgBotSender {
|
|||||||
} MB)`);
|
} MB)`);
|
||||||
}
|
}
|
||||||
} else if (downloaded.format.type === "audio") {
|
} else if (downloaded.format.type === "audio") {
|
||||||
const videoInfo = await video.getVideoInfo();
|
|
||||||
await this.sendAudio(
|
await this.sendAudio(
|
||||||
msg.chat.id,
|
msg.chat.id,
|
||||||
downloaded.data,
|
downloaded.data,
|
||||||
|
|||||||
@ -32,7 +32,6 @@ class MTProtoUser {
|
|||||||
writeStream.on("error", reject);
|
writeStream.on("error", reject);
|
||||||
writeStream.on("finish", resolve);
|
writeStream.on("finish", resolve);
|
||||||
});
|
});
|
||||||
//fs.writeFileSync();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const msg = await this.client.sendFile(config.mtproto.chatId, {
|
const msg = await this.client.sendFile(config.mtproto.chatId, {
|
||||||
@ -41,6 +40,14 @@ class MTProtoUser {
|
|||||||
thumb: options.thumb,
|
thumb: options.thumb,
|
||||||
//filename: options.filename,
|
//filename: options.filename,
|
||||||
supportsStreaming: true,
|
supportsStreaming: true,
|
||||||
|
attributes: [
|
||||||
|
new Api.DocumentAttributeVideo({
|
||||||
|
duration: options.duration || 0,
|
||||||
|
w: options.width || 1280,
|
||||||
|
h: options.height || 720,
|
||||||
|
supportsStreaming: true
|
||||||
|
}),
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
return msg.id;
|
return msg.id;
|
||||||
|
|||||||
@ -21,18 +21,15 @@ async function downloadFile (fileUrl) {
|
|||||||
|
|
||||||
protocol.get(fileUrl, (response) => {
|
protocol.get(fileUrl, (response) => {
|
||||||
if (response.statusCode !== 200) {
|
if (response.statusCode !== 200) {
|
||||||
return reject(
|
return reject(
|
||||||
new Error(`Failed to get '${fileUrl}' (${response.statusCode})`)
|
new Error(`Failed to get '${fileUrl}' (${response.statusCode})`)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
response.pipe(file);
|
response.pipe(file);
|
||||||
|
|
||||||
file.on("finish", () => {
|
file.on("finish", () => {
|
||||||
file.close();
|
file.close();
|
||||||
/*setTimeout(() => {
|
|
||||||
fs.rm(savePath, () => {});
|
|
||||||
}, 60000);*/
|
|
||||||
resolve(savePath);
|
resolve(savePath);
|
||||||
});
|
});
|
||||||
}).on("error", (err) => {
|
}).on("error", (err) => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user