@ryuu-reinzz/haruka-lib 2.2.1 → 2.2.2

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.
@@ -3,6 +3,15 @@ import ffmpeg from 'fluent-ffmpeg'
3
3
  import { stickerVid } from './video-to-webp.js'
4
4
  import { stickerImg } from './image-to-webp.js'
5
5
 
6
+ async function bufferToTmp(buffer, ext = '.bin') {
7
+ const tmp = path.join(
8
+ tmpdir(),
9
+ Crypto.randomBytes(6).toString('hex') + ext
10
+ )
11
+ await fs.writeFile(tmp, buffer)
12
+ return tmp
13
+ }
14
+
6
15
  class Sticker {
7
16
  constructor(media, options = {}) {
8
17
  this.media = media
@@ -30,19 +39,21 @@ class Sticker {
30
39
  }
31
40
 
32
41
  async build() {
33
- const isVideo = await new Promise(resolve => {
34
- ffmpeg.ffprobe(this.media, (err, meta) => {
35
- if (err) return resolve(false)
36
- resolve(meta.streams.some(s => s.codec_type === 'video'))
37
- })
42
+ const tmpPath = await bufferToTmp(this.media)
43
+
44
+ const isVideo = await new Promise(resolve => {
45
+ ffmpeg.ffprobe(tmpPath, (err, meta) => {
46
+ if (err) return resolve(false)
47
+ resolve(meta.streams.some(
48
+ s => s.codec_type === 'video' && s.duration > 0
49
+ ))
38
50
  })
51
+ })
39
52
 
40
- if (isVideo) {
41
- return await this.toStickerVid()
42
- } else {
43
- return await this.toStickerImg()
44
- }
45
- }
53
+ return isVideo
54
+ ? await this.toStickerVid()
55
+ : await this.toStickerImg()
56
+ }
46
57
  }
47
58
 
48
59
  export default Sticker
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ryuu-reinzz/haruka-lib",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "description": "Library extra for bot WhatsApp",
5
5
  "main": "main/index.js",
6
6
  "type": "module",