|
@@ -1,5 +1,4 @@
|
|
|
-import { createWriteStream } from 'fs';
|
|
|
-import { Stream } from 'stream';
|
|
|
+import { writeFileSync } from 'fs';
|
|
|
|
|
|
import axios from 'axios';
|
|
|
import * as CallableInstance from 'callable-instance';
|
|
@@ -35,12 +34,12 @@ class Webshot extends CallableInstance<[FullUser, Fleets, (...args) => void, num
|
|
|
onready();
|
|
|
}
|
|
|
|
|
|
- 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) {
|
|
@@ -56,8 +55,8 @@ class Webshot extends CallableInstance<[FullUser, Fleets, (...args) => void, num
|
|
|
});
|
|
|
}).then(data =>
|
|
|
(ext => {
|
|
|
- const mediaTempFilePath = temp.path({suffix: ext});
|
|
|
- data.pipe(createWriteStream(mediaTempFilePath));
|
|
|
+ const mediaTempFilePath = temp.path({suffix: `.${ext}`});
|
|
|
+ writeFileSync(mediaTempFilePath, Buffer.from(data));
|
|
|
const path = `file://${mediaTempFilePath}`;
|
|
|
switch (ext) {
|
|
|
case 'jpg':
|
|
@@ -84,7 +83,7 @@ class Webshot extends CallableInstance<[FullUser, Fleets, (...args) => void, num
|
|
|
promise = promise.then(() => {
|
|
|
logger.info(`working on ${user.screen_name}/${fleet.fleet_id}`);
|
|
|
});
|
|
|
- let messageChain: '';
|
|
|
+ let messageChain = '';
|
|
|
|
|
|
// text processing
|
|
|
const author = `${user.name} (@${user.screen_name}):\n`;
|