@xyo-network/image-thumbnail-plugin 2.72.8 → 2.73.0

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 +1 @@
1
- {"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../../src/Diviner/Diviner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAC/D,OAAO,EAAE,iBAAiB,EAAuB,MAAM,8BAA8B,CAAA;AAErF,OAAO,EAA0C,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAEpG,OAAO,EAAE,cAAc,EAAwB,MAAM,6CAA6C,CAAA;AAClG,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAA;AAI5D,OAAO,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAA;AAEtD,qBAAa,qBAAqB,CAAC,OAAO,SAAS,2BAA2B,GAAG,2BAA2B,CAAE,SAAQ,eAAe,CAAC,OAAO,CAAC;IAC5I,OAAgB,aAAa,kFAA2D;IAExF,OAAO,CAAC,kBAAkB,CAAwC;IAClE,OAAO,CAAC,6CAA6C,CAA2B;IAChF,OAAO,CAAC,IAAI,CAAoC;IAChD,OAAO,CAAC,uBAAuB,CAAsC;IACrE,OAAO,CAAC,OAAO,CAAC,CAAkC;IAElD,IAAI,SAAS,kKAEZ;IAED,IAAI,cAAc,uBAEjB;IAED,IAAI,mBAAmB,WAEtB;IAED,IAAI,aAAa,uBAEhB;IAGK,oBAAoB,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAelD,yBAAyB,IAAI,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC;cAkB9C,aAAa,CAAC,QAAQ,GAAE,UAAU,EAAO,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAU9F,SAAS,CAAC,qCAAqC;cAc/B,OAAO;cAQP,cAAc;cAiBd,yBAAyB;cAgChB,WAAW,CAAC,QAAQ,CAAC,EAAE,MAAM,G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U,EAAO,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;YAsCjF,sBAAsB;IAiBpC;;;;OAIG;YACW,wBAAwB;YAKxB,QAAQ;CA4HvB"}
@@ -1 +1 @@
1
- {"version":3,"file":"getVideoFrameAsImageFluent.d.ts","sourceRoot":"","sources":["../../../../../src/Witness/ffmpeg/fluent/getVideoFrameAsImageFluent.ts"],"names":[],"mappings":";AAGA;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,gBAAuB,MAAM,oBA4CnE,CAAA"}
1
+ {"version":3,"file":"getVideoFrameAsImageFluent.d.ts","sourceRoot":"","sources":["../../../../../src/Witness/ffmpeg/fluent/getVideoFrameAsImageFluent.ts"],"names":[],"mappings":";AA6BA;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,gBAAuB,MAAM,oBAoCnE,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"executeFfmpeg.d.ts","sourceRoot":"","sources":["../../../../../src/Witness/ffmpeg/spawn/executeFfmpeg.ts"],"names":[],"mappings":";AAGA;;;;;GAKG;AACH,eAAO,MAAM,aAAa,gBAAiB,MAAM,cAAc,MAAM,EAAE,KAAG,QAAQ,MAAM,CAqBvF,CAAA"}
1
+ {"version":3,"file":"executeFfmpeg.d.ts","sourceRoot":"","sources":["../../../../../src/Witness/ffmpeg/spawn/executeFfmpeg.ts"],"names":[],"mappings":";AAEA;;;;;GAKG;AACH,eAAO,MAAM,aAAa,gBAAiB,MAAM,cAAc,MAAM,EAAE,KAAG,QAAQ,MAAM,CAkBvF,CAAA"}
package/package.json CHANGED
@@ -10,28 +10,28 @@
10
10
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
11
11
  },
12
12
  "dependencies": {
13
- "@xylabs/assert": "^2.9.3",
14
- "@xylabs/delay": "^2.9.3",
15
- "@xylabs/url": "^2.9.3",
16
- "@xyo-network/abstract-diviner": "~2.72.8",
17
- "@xyo-network/archivist-model": "~2.72.8",
18
- "@xyo-network/axios": "~2.72.8",
19
- "@xyo-network/core": "~2.72.8",
20
- "@xyo-network/diviner-model": "~2.72.8",
21
- "@xyo-network/diviner-payload-model": "~2.72.8",
22
- "@xyo-network/image-thumbnail-payload-plugin": "~2.72.8",
23
- "@xyo-network/module": "~2.72.8",
24
- "@xyo-network/payload-model": "~2.72.8",
25
- "@xyo-network/payloadset-plugin": "~2.72.8",
26
- "@xyo-network/url-payload-plugin": "~2.72.8",
27
- "@xyo-network/witness": "~2.72.8",
13
+ "@xylabs/assert": "^2.10.7",
14
+ "@xylabs/delay": "^2.10.7",
15
+ "@xylabs/lodash": "^2.10.7",
16
+ "@xylabs/url": "^2.10.7",
17
+ "@xyo-network/abstract-diviner": "~2.73.0",
18
+ "@xyo-network/archivist-model": "~2.73.0",
19
+ "@xyo-network/axios": "~2.73.0",
20
+ "@xyo-network/core": "~2.73.0",
21
+ "@xyo-network/diviner-model": "~2.73.0",
22
+ "@xyo-network/diviner-payload-model": "~2.73.0",
23
+ "@xyo-network/image-thumbnail-payload-plugin": "~2.73.0",
24
+ "@xyo-network/module": "~2.73.0",
25
+ "@xyo-network/payload-model": "~2.73.0",
26
+ "@xyo-network/payloadset-plugin": "~2.73.0",
27
+ "@xyo-network/url-payload-plugin": "~2.73.0",
28
+ "@xyo-network/witness": "~2.73.0",
28
29
  "async-mutex": "^0.4.0",
29
30
  "file-type": "^16.5.4",
30
31
  "fluent-ffmpeg": "^2.1.2",
31
32
  "gm": "^1.25.0",
32
33
  "hasbin": "^1.2.3",
33
34
  "hash-wasm": "^4.9.0",
34
- "lodash": "^4.17.21",
35
35
  "lru-cache": "^10.0.1",
36
36
  "sha.js": "^2.4.11",
37
37
  "url-parse": "^1.5.10"
@@ -41,8 +41,8 @@
41
41
  "@types/gm": "^1.25.1",
42
42
  "@types/hasbin": "^1.2.0",
43
43
  "@types/lodash": "^4.14.198",
44
- "@xylabs/ts-scripts-yarn3": "^2.19.3",
45
- "@xylabs/tsconfig": "^2.19.3",
44
+ "@xylabs/ts-scripts-yarn3": "^2.19.5",
45
+ "@xylabs/tsconfig": "^2.19.5",
46
46
  "typescript": "^5.2.2"
47
47
  },
48
48
  "description": "Primary SDK for using XYO Protocol 2.0",
@@ -78,5 +78,5 @@
78
78
  },
79
79
  "sideEffects": false,
80
80
  "types": "dist/types/index.d.ts",
81
- "version": "2.72.8"
81
+ "version": "2.73.0"
82
82
  }
@@ -1,5 +1,6 @@
1
1
  import { assertEx } from '@xylabs/assert'
2
2
  import { delay } from '@xylabs/delay'
3
+ import { compact } from '@xylabs/lodash'
3
4
  import { AbstractDiviner } from '@xyo-network/abstract-diviner'
4
5
  import { ArchivistInstance, asArchivistInstance } from '@xyo-network/archivist-model'
5
6
  import { PayloadHasher } from '@xyo-network/core'
@@ -7,7 +8,6 @@ import { asDivinerInstance, DivinerConfigSchema, DivinerInstance } from '@xyo-ne
7
8
  import { PayloadDivinerQueryPayload, PayloadDivinerQuerySchema } from '@xyo-network/diviner-payload-model'
8
9
  import { ImageThumbnail, ImageThumbnailSchema } from '@xyo-network/image-thumbnail-payload-plugin'
9
10
  import { UrlPayload } from '@xyo-network/url-payload-plugin'
10
- import compact from 'lodash/compact'
11
11
 
12
12
  import { ImageThumbnailDivinerConfigSchema } from './Config'
13
13
  import { ImageThumbnailDivinerParams } from './Params'
@@ -1,6 +1,7 @@
1
1
  /* eslint-disable max-statements */
2
2
  import { promises as dnsPromises } from 'node:dns'
3
3
 
4
+ import { compact } from '@xylabs/lodash'
4
5
  import { URL } from '@xylabs/url'
5
6
  import { axios, AxiosError, AxiosResponse } from '@xyo-network/axios'
6
7
  import { PayloadHasher } from '@xyo-network/core'
@@ -12,7 +13,6 @@ import FileType from 'file-type'
12
13
  import { subClass } from 'gm'
13
14
  import { sync as hasbin } from 'hasbin'
14
15
  import { sha256 } from 'hash-wasm'
15
- import compact from 'lodash/compact'
16
16
  import { LRUCache } from 'lru-cache'
17
17
  import shajs from 'sha.js'
18
18
  import Url from 'url-parse'
@@ -103,9 +103,7 @@ export class ImageThumbnailWitness<TParams extends ImageThumbnailWitnessParams =
103
103
  if (url.startsWith('data:image')) {
104
104
  const data = url.split(',')[1]
105
105
  if (data) {
106
- const buffer = Buffer.from(Uint8Array.from(atob(data), (c) => c.charCodeAt(0)))
107
- console.log(`data buffer: ${buffer.length}`)
108
- return buffer
106
+ return Buffer.from(Uint8Array.from(atob(data), (c) => c.charCodeAt(0)))
109
107
  } else {
110
108
  const error: ImageThumbnailWitnessError = {
111
109
  message: 'Invalid data Url',
@@ -1,5 +1,31 @@
1
+ import { uuid } from '@xyo-network/core'
1
2
  import ffmpeg from 'fluent-ffmpeg'
2
- import { Readable, Writable } from 'stream'
3
+ import { unlink, writeFile } from 'fs/promises'
4
+ import { tmpdir } from 'os'
5
+ import { Writable, WritableOptions } from 'stream'
6
+
7
+ /**
8
+ * A Writable stream that collects output from ffmpeg.
9
+ */
10
+ class FfmpegOutputStream extends Writable {
11
+ private readonly chunks: Uint8Array[] = []
12
+
13
+ constructor(options?: WritableOptions) {
14
+ super(options)
15
+ }
16
+
17
+ override _write(chunk: never, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void {
18
+ this.chunks.push(chunk)
19
+ callback()
20
+ }
21
+
22
+ /**
23
+ * Collects the output from ffmpeg into a buffer.
24
+ * @returns A buffer containing the concatenated
25
+ * output from ffmpeg.
26
+ */
27
+ toBuffer = () => Buffer.concat(this.chunks)
28
+ }
3
29
 
4
30
  /**
5
31
  * Execute FFmpeg using fluent API with provided input buffer and video thumbnail image.
@@ -7,47 +33,39 @@ import { Readable, Writable } from 'stream'
7
33
  * @returns Output buffer containing the video thumbnail image.
8
34
  */
9
35
  export const getVideoFrameAsImageFluent = async (videoBuffer: Buffer) => {
10
- const imageBuffer = await new Promise<Buffer>((resolve, reject) => {
11
- // const videoStream = new PassThrough()
12
- // videoStream.end(videoBuffer)
13
-
14
- const videoStream = new Readable()
15
- videoStream._read = () => {} // _read is required but you can noop it
16
- videoStream.push(videoBuffer)
17
- videoStream.push(null)
18
-
19
- // Initialize empty array to collect PNG chunks
20
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
- const pngChunks: any[] = []
22
-
23
- // Create a Writable stream to collect PNG output from ffmpeg
24
- const writableStream = new Writable({
25
- write(chunk, encoding, callback) {
26
- pngChunks.push(chunk)
27
- callback()
28
- },
36
+ // Get a temp file name
37
+ const tmpFile = `/${tmpdir()}/${uuid()}`
38
+ try {
39
+ // Write videoBuffer to temp file for use as input to ffmpeg to
40
+ // avoid issues with ffmpeg inferring premature EOF from buffer
41
+ // passed via stdin (happens when ffmpeg is trying to infer
42
+ // input video format)
43
+ await writeFile(tmpFile, videoBuffer, { encoding: 'binary' })
44
+ const imageBuffer = await new Promise<Buffer>((resolve, reject) => {
45
+ // Create a Writable stream to collect PNG output from ffmpeg
46
+ const ffmpegOutput = new FfmpegOutputStream()
47
+ // Execute ffmpeg using fluent API
48
+ ffmpeg()
49
+ // NOTE: Uncomment to debug CLI args to ffmpeg
50
+ // .on('start', (commandLine) => console.log('Spawned Ffmpeg with command: ' + commandLine))
51
+ .on('error', (err) => reject(err.message))
52
+ // Listen for the 'end' event to combine the output into a buffer holding the PNG image
53
+ .on('end', () => resolve(ffmpegOutput.toBuffer()))
54
+ .input(tmpFile) // Use temp file as input
55
+ .takeFrames(1) // Only take 1st video frame
56
+ .withNoAudio() // Don't include audio
57
+ .outputOptions('-f image2pipe') // Write output to stdout
58
+ .videoCodec('png') // Force PNG output
59
+ // Start processing and direct ffmpeg stdout to writable stream
60
+ .pipe(ffmpegOutput)
29
61
  })
30
-
31
- const command = ffmpeg()
32
- // Uncomment to debug CLI args to ffmpeg
33
- // .on('start', (commandLine) => console.log('Spawned Ffmpeg with command: ' + commandLine))
34
- .input(videoStream)
35
- .takeFrames(1)
36
- .withNoAudio()
37
- // Exactly as their docs but does not work
38
- // .setStartTime('00:00:00')
39
- // .seekInput(0)
40
- .on('error', (err) => reject(err.message))
41
- // Listen for the 'end' event to combine the chunks and create a PNG buffer
42
- .on('end', () => resolve(Buffer.concat(pngChunks)))
43
- .on('data', (chunk) => pngChunks.push(chunk))
44
- // .toFormat('png')
45
- .outputOptions('-f image2pipe')
46
- // .outputOptions('-vcodec png')
47
- // .output(writableStream, { end: true })
48
-
49
- // Start processing
50
- command.pipe(writableStream)
51
- })
52
- return imageBuffer
62
+ return imageBuffer
63
+ } finally {
64
+ // Cleanup temp file
65
+ try {
66
+ await unlink(tmpFile)
67
+ } catch {
68
+ // No error here since file doesn't exist
69
+ }
70
+ }
53
71
  }
@@ -1,5 +1,4 @@
1
1
  import { spawn } from 'child_process'
2
- import { PassThrough } from 'stream'
3
2
 
4
3
  /**
5
4
  * Execute FFmpeg with the provided arguments.
@@ -9,23 +8,20 @@ import { PassThrough } from 'stream'
9
8
  */
10
9
  export const executeFFmpeg = (videoBuffer: Buffer, ffmpegArgs: string[]): Promise<Buffer> => {
11
10
  return new Promise((resolve, reject) => {
11
+ const imageData: Buffer[] = []
12
12
  const ffmpeg = spawn('ffmpeg', ffmpegArgs)
13
-
14
- // Create a readable stream from the input buffer
15
- const videoStream = new PassThrough().end(videoBuffer)
16
-
17
- // Pipe the input stream to ffmpeg's stdin
18
- videoStream.pipe(ffmpeg.stdin)
19
- const chunks: Buffer[] = []
20
- ffmpeg.stdout.on('data', (chunk: Buffer) => chunks.push(chunk))
13
+ ffmpeg.stdout.on('data', (data: Buffer) => imageData.push(data))
21
14
  // TODO: This is required as we're seeing errors thrown due to
22
15
  // how we're piping the data to ffmpeg. Works perfectly though.
23
16
  ffmpeg.stdin.on('error', () => {})
24
17
  ffmpeg.on('close', (code) => {
25
18
  if (code !== 0) {
26
- return reject(new Error(`FFmpeg exited with code ${code}`))
19
+ reject(new Error(`FFmpeg exited with code ${code}`))
20
+ } else {
21
+ resolve(Buffer.concat(imageData))
27
22
  }
28
- resolve(Buffer.concat(chunks))
29
23
  })
24
+ // Pipe the input stream to ffmpeg's stdin
25
+ ffmpeg.stdin.end(videoBuffer)
30
26
  })
31
27
  }