|
@@ -1,5 +1,5 @@
|
|
|
-import { createWriteStream } from 'fs';
|
|
|
-import { Readable, Stream } from 'stream';
|
|
|
+import { writeFileSync } from 'fs';
|
|
|
+import { Readable } from 'stream';
|
|
|
import { promisify } from 'util';
|
|
|
|
|
|
import axios from 'axios';
|
|
@@ -257,12 +257,12 @@ class Webshot extends CallableInstance<[Tweets, (...args) => void, number], Prom
|
|
|
);
|
|
|
};
|
|
|
|
|
|
- private fetchMedia = (url: string): Promise<string> => new Promise<Stream>((resolve, reject) => {
|
|
|
+ private fetchMedia = (url: string): Promise<string> => new Promise<ArrayBuffer>((resolve, reject) => {
|
|
|
logger.info(`fetching ${url}`);
|
|
|
axios({
|
|
|
method: 'get',
|
|
|
url,
|
|
|
- responseType: 'stream',
|
|
|
+ responseType: 'arraybuffer',
|
|
|
timeout: 150000,
|
|
|
}).then(res => {
|
|
|
if (res.status === 200) {
|
|
@@ -279,7 +279,7 @@ class Webshot extends CallableInstance<[Tweets, (...args) => void, number], Prom
|
|
|
}).then(data =>
|
|
|
(ext => {
|
|
|
const mediaTempFilePath = temp.path({suffix: `.${ext}`});
|
|
|
- data.pipe(createWriteStream(mediaTempFilePath));
|
|
|
+ writeFileSync(mediaTempFilePath, Buffer.from(data));
|
|
|
const path = `file://${mediaTempFilePath}`;
|
|
|
switch (ext) {
|
|
|
case 'jpg':
|
|
@@ -390,7 +390,9 @@ class Webshot extends CallableInstance<[Tweets, (...args) => void, number], Prom
|
|
|
// refer to quoted tweet, if any
|
|
|
if (originTwi.is_quote_status) {
|
|
|
promise = promise.then(() => {
|
|
|
- messageChain += `\n回复此命令查看引用的推文:\n/twitter_view ${originTwi.quoted_status.id_str}`;
|
|
|
+ const match = /\/status\/(\d+)/.exec(originTwi.quoted_status_permalink?.expanded);
|
|
|
+ const blockQuoteIdStr = match ? match[1] : originTwi.quoted_status?.id_str;
|
|
|
+ if (blockQuoteIdStr) messageChain += `\n回复此命令查看引用的推文:\n/twitter_view ${blockQuoteIdStr}`;
|
|
|
});
|
|
|
}
|
|
|
promise.then(() => {
|