@ryuu-reinzz/haruka-lib 2.2.1 → 2.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,7 +1,17 @@
|
|
|
1
|
-
import fs from 'fs-extra'
|
|
2
|
-
import ffmpeg from 'fluent-ffmpeg'
|
|
3
|
-
import { stickerVid } from './video-to-webp.js'
|
|
4
|
-
import { stickerImg } from './image-to-webp.js'
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import ffmpeg from 'fluent-ffmpeg';
|
|
3
|
+
import { stickerVid } from './video-to-webp.js';
|
|
4
|
+
import { stickerImg } from './image-to-webp.js';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
|
|
7
|
+
async function bufferToTmp(buffer, ext = '.bin') {
|
|
8
|
+
const tmp = path.join(
|
|
9
|
+
tmpdir(),
|
|
10
|
+
Crypto.randomBytes(6).toString('hex') + ext
|
|
11
|
+
)
|
|
12
|
+
await fs.writeFile(tmp, buffer)
|
|
13
|
+
return tmp
|
|
14
|
+
}
|
|
5
15
|
|
|
6
16
|
class Sticker {
|
|
7
17
|
constructor(media, options = {}) {
|
|
@@ -30,19 +40,21 @@ class Sticker {
|
|
|
30
40
|
}
|
|
31
41
|
|
|
32
42
|
async build() {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
43
|
+
const tmpPath = await bufferToTmp(this.media)
|
|
44
|
+
|
|
45
|
+
const isVideo = await new Promise(resolve => {
|
|
46
|
+
ffmpeg.ffprobe(tmpPath, (err, meta) => {
|
|
47
|
+
if (err) return resolve(false)
|
|
48
|
+
resolve(meta.streams.some(
|
|
49
|
+
s => s.codec_type === 'video' && s.duration > 0
|
|
50
|
+
))
|
|
38
51
|
})
|
|
52
|
+
})
|
|
39
53
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
}
|
|
54
|
+
return isVideo
|
|
55
|
+
? await this.toStickerVid()
|
|
56
|
+
: await this.toStickerImg()
|
|
57
|
+
}
|
|
46
58
|
}
|
|
47
59
|
|
|
48
60
|
export default Sticker
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ryuu-reinzz/haruka-lib",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.3",
|
|
4
4
|
"description": "Library extra for bot WhatsApp",
|
|
5
5
|
"main": "main/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"file-type": "^16.5.3",
|
|
21
21
|
"fluent-ffmpeg": "^2.1.3",
|
|
22
22
|
"fs-extra": "^11.2.0",
|
|
23
|
+
"path": "^0.12.7",
|
|
23
24
|
"node-fetch": "^3.3.2",
|
|
24
25
|
"node-webpmux": "^3.2.1",
|
|
25
26
|
"node-fetch": "^2.6.1",
|