@xyo-network/image-thumbnail-plugin 2.73.3 → 2.73.4
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.
- package/dist/docs.json +567 -550
- package/dist/index.d.mts +245 -0
- package/dist/index.d.ts +245 -0
- package/dist/index.js +565 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +524 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +44 -31
- package/src/Diviner/Config.ts +1 -1
- package/src/Diviner/Diviner.ts +5 -1
- package/src/Witness/Witness.ts +8 -5
- package/tsup.config.ts +16 -0
- package/dist/cjs/Diviner/Config.js +0 -6
- package/dist/cjs/Diviner/Config.js.map +0 -1
- package/dist/cjs/Diviner/Diviner.js +0 -204
- package/dist/cjs/Diviner/Diviner.js.map +0 -1
- package/dist/cjs/Diviner/Params.js +0 -3
- package/dist/cjs/Diviner/Params.js.map +0 -1
- package/dist/cjs/Diviner/index.js +0 -7
- package/dist/cjs/Diviner/index.js.map +0 -1
- package/dist/cjs/Plugin.js +0 -21
- package/dist/cjs/Plugin.js.map +0 -1
- package/dist/cjs/Witness/Config.js +0 -6
- package/dist/cjs/Witness/Config.js.map +0 -1
- package/dist/cjs/Witness/Params.js +0 -3
- package/dist/cjs/Witness/Params.js.map +0 -1
- package/dist/cjs/Witness/Witness.js +0 -321
- package/dist/cjs/Witness/Witness.js.map +0 -1
- package/dist/cjs/Witness/ffmpeg/fluent/getVideoFrameAsImageFluent.js +0 -74
- package/dist/cjs/Witness/ffmpeg/fluent/getVideoFrameAsImageFluent.js.map +0 -1
- package/dist/cjs/Witness/ffmpeg/fluent/index.js +0 -5
- package/dist/cjs/Witness/ffmpeg/fluent/index.js.map +0 -1
- package/dist/cjs/Witness/ffmpeg/index.js +0 -6
- package/dist/cjs/Witness/ffmpeg/index.js.map +0 -1
- package/dist/cjs/Witness/ffmpeg/spawn/executeFfmpeg.js +0 -32
- package/dist/cjs/Witness/ffmpeg/spawn/executeFfmpeg.js.map +0 -1
- package/dist/cjs/Witness/ffmpeg/spawn/getVideoFrameAsImage.js +0 -16
- package/dist/cjs/Witness/ffmpeg/spawn/getVideoFrameAsImage.js.map +0 -1
- package/dist/cjs/Witness/ffmpeg/spawn/index.js +0 -6
- package/dist/cjs/Witness/ffmpeg/spawn/index.js.map +0 -1
- package/dist/cjs/Witness/index.js +0 -7
- package/dist/cjs/Witness/index.js.map +0 -1
- package/dist/cjs/index.js +0 -11
- package/dist/cjs/index.js.map +0 -1
- package/dist/esm/Diviner/Config.js +0 -3
- package/dist/esm/Diviner/Config.js.map +0 -1
- package/dist/esm/Diviner/Diviner.js +0 -179
- package/dist/esm/Diviner/Diviner.js.map +0 -1
- package/dist/esm/Diviner/Params.js +0 -2
- package/dist/esm/Diviner/Params.js.map +0 -1
- package/dist/esm/Diviner/index.js +0 -4
- package/dist/esm/Diviner/index.js.map +0 -1
- package/dist/esm/Plugin.js +0 -16
- package/dist/esm/Plugin.js.map +0 -1
- package/dist/esm/Witness/Config.js +0 -3
- package/dist/esm/Witness/Config.js.map +0 -1
- package/dist/esm/Witness/Params.js +0 -2
- package/dist/esm/Witness/Params.js.map +0 -1
- package/dist/esm/Witness/Witness.js +0 -292
- package/dist/esm/Witness/Witness.js.map +0 -1
- package/dist/esm/Witness/ffmpeg/fluent/getVideoFrameAsImageFluent.js +0 -69
- package/dist/esm/Witness/ffmpeg/fluent/getVideoFrameAsImageFluent.js.map +0 -1
- package/dist/esm/Witness/ffmpeg/fluent/index.js +0 -2
- package/dist/esm/Witness/ffmpeg/fluent/index.js.map +0 -1
- package/dist/esm/Witness/ffmpeg/index.js +0 -3
- package/dist/esm/Witness/ffmpeg/index.js.map +0 -1
- package/dist/esm/Witness/ffmpeg/spawn/executeFfmpeg.js +0 -28
- package/dist/esm/Witness/ffmpeg/spawn/executeFfmpeg.js.map +0 -1
- package/dist/esm/Witness/ffmpeg/spawn/getVideoFrameAsImage.js +0 -11
- package/dist/esm/Witness/ffmpeg/spawn/getVideoFrameAsImage.js.map +0 -1
- package/dist/esm/Witness/ffmpeg/spawn/index.js +0 -3
- package/dist/esm/Witness/ffmpeg/spawn/index.js.map +0 -1
- package/dist/esm/Witness/index.js +0 -4
- package/dist/esm/Witness/index.js.map +0 -1
- package/dist/esm/index.js +0 -7
- package/dist/esm/index.js.map +0 -1
- package/dist/types/Diviner/Config.d.ts +0 -11
- package/dist/types/Diviner/Config.d.ts.map +0 -1
- package/dist/types/Diviner/Diviner.d.ts +0 -30
- package/dist/types/Diviner/Diviner.d.ts.map +0 -1
- package/dist/types/Diviner/Params.d.ts +0 -5
- package/dist/types/Diviner/Params.d.ts.map +0 -1
- package/dist/types/Diviner/index.d.ts +0 -4
- package/dist/types/Diviner/index.d.ts.map +0 -1
- package/dist/types/Plugin.d.ts +0 -116
- package/dist/types/Plugin.d.ts.map +0 -1
- package/dist/types/Witness/Config.d.ts +0 -16
- package/dist/types/Witness/Config.d.ts.map +0 -1
- package/dist/types/Witness/Params.d.ts +0 -7
- package/dist/types/Witness/Params.d.ts.map +0 -1
- package/dist/types/Witness/Witness.d.ts +0 -66
- package/dist/types/Witness/Witness.d.ts.map +0 -1
- package/dist/types/Witness/ffmpeg/fluent/getVideoFrameAsImageFluent.d.ts +0 -8
- package/dist/types/Witness/ffmpeg/fluent/getVideoFrameAsImageFluent.d.ts.map +0 -1
- package/dist/types/Witness/ffmpeg/fluent/index.d.ts +0 -2
- package/dist/types/Witness/ffmpeg/fluent/index.d.ts.map +0 -1
- package/dist/types/Witness/ffmpeg/index.d.ts +0 -3
- package/dist/types/Witness/ffmpeg/index.d.ts.map +0 -1
- package/dist/types/Witness/ffmpeg/spawn/executeFfmpeg.d.ts +0 -9
- package/dist/types/Witness/ffmpeg/spawn/executeFfmpeg.d.ts.map +0 -1
- package/dist/types/Witness/ffmpeg/spawn/getVideoFrameAsImage.d.ts +0 -8
- package/dist/types/Witness/ffmpeg/spawn/getVideoFrameAsImage.d.ts.map +0 -1
- package/dist/types/Witness/ffmpeg/spawn/index.d.ts +0 -3
- package/dist/types/Witness/ffmpeg/spawn/index.d.ts.map +0 -1
- package/dist/types/Witness/index.d.ts +0 -4
- package/dist/types/Witness/index.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -6
- package/dist/types/index.d.ts.map +0 -1
|
@@ -1,321 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ImageThumbnailWitness = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
/* eslint-disable max-statements */
|
|
6
|
-
const node_dns_1 = require("node:dns");
|
|
7
|
-
const lodash_1 = require("@xylabs/lodash");
|
|
8
|
-
const url_1 = require("@xylabs/url");
|
|
9
|
-
const axios_1 = require("@xyo-network/axios");
|
|
10
|
-
const core_1 = require("@xyo-network/core");
|
|
11
|
-
const image_thumbnail_payload_plugin_1 = require("@xyo-network/image-thumbnail-payload-plugin");
|
|
12
|
-
const url_payload_plugin_1 = require("@xyo-network/url-payload-plugin");
|
|
13
|
-
const witness_1 = require("@xyo-network/witness");
|
|
14
|
-
const async_mutex_1 = require("async-mutex");
|
|
15
|
-
const file_type_1 = tslib_1.__importDefault(require("file-type"));
|
|
16
|
-
const gm_1 = require("gm");
|
|
17
|
-
const hasbin_1 = require("hasbin");
|
|
18
|
-
const hash_wasm_1 = require("hash-wasm");
|
|
19
|
-
const lru_cache_1 = require("lru-cache");
|
|
20
|
-
const sha_js_1 = tslib_1.__importDefault(require("sha.js"));
|
|
21
|
-
const url_parse_1 = tslib_1.__importDefault(require("url-parse"));
|
|
22
|
-
const Config_1 = require("./Config");
|
|
23
|
-
const ffmpeg_1 = require("./ffmpeg");
|
|
24
|
-
//TODO: Break this into two Witnesses?
|
|
25
|
-
// setFfmpegPath(ffmpegPath)
|
|
26
|
-
const gm = (0, gm_1.subClass)({ imageMagick: '7+' });
|
|
27
|
-
class ImageThumbnailWitness extends witness_1.AbstractWitness {
|
|
28
|
-
constructor() {
|
|
29
|
-
super(...arguments);
|
|
30
|
-
this._semaphore = new async_mutex_1.Semaphore(this.maxAsyncProcesses);
|
|
31
|
-
}
|
|
32
|
-
get cache() {
|
|
33
|
-
var _a;
|
|
34
|
-
this._cache =
|
|
35
|
-
(_a = this._cache) !== null && _a !== void 0 ? _a : new lru_cache_1.LRUCache({
|
|
36
|
-
max: this.maxCacheEntries,
|
|
37
|
-
maxSize: this.maxCacheBytes,
|
|
38
|
-
//just returning the size of the data
|
|
39
|
-
sizeCalculation: (value) => { var _a, _b; return (_b = (_a = value.url) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 1; },
|
|
40
|
-
});
|
|
41
|
-
return this._cache;
|
|
42
|
-
}
|
|
43
|
-
get encoding() {
|
|
44
|
-
var _a;
|
|
45
|
-
return (_a = this.config.encoding) !== null && _a !== void 0 ? _a : 'PNG';
|
|
46
|
-
}
|
|
47
|
-
get height() {
|
|
48
|
-
var _a;
|
|
49
|
-
return (_a = this.config.height) !== null && _a !== void 0 ? _a : 128;
|
|
50
|
-
}
|
|
51
|
-
get ipfGateway() {
|
|
52
|
-
var _a;
|
|
53
|
-
return (_a = this.config.ipfsGateway) !== null && _a !== void 0 ? _a : '5d7b6582.beta.decentralnetworkservices.com';
|
|
54
|
-
}
|
|
55
|
-
get maxAsyncProcesses() {
|
|
56
|
-
var _a;
|
|
57
|
-
return (_a = this.config.maxAsyncProcesses) !== null && _a !== void 0 ? _a : 2;
|
|
58
|
-
}
|
|
59
|
-
get maxCacheBytes() {
|
|
60
|
-
var _a;
|
|
61
|
-
return (_a = this.config.maxCacheBytes) !== null && _a !== void 0 ? _a : 1024 * 1024 * 16; //64MB max size
|
|
62
|
-
}
|
|
63
|
-
get maxCacheEntries() {
|
|
64
|
-
var _a;
|
|
65
|
-
return (_a = this.config.maxCacheEntries) !== null && _a !== void 0 ? _a : 500;
|
|
66
|
-
}
|
|
67
|
-
get quality() {
|
|
68
|
-
var _a;
|
|
69
|
-
return (_a = this.config.quality) !== null && _a !== void 0 ? _a : 50;
|
|
70
|
-
}
|
|
71
|
-
get width() {
|
|
72
|
-
var _a;
|
|
73
|
-
return (_a = this.config.width) !== null && _a !== void 0 ? _a : 128;
|
|
74
|
-
}
|
|
75
|
-
static binaryToSha256(data) {
|
|
76
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
77
|
-
yield core_1.PayloadHasher.wasmInitialized;
|
|
78
|
-
if (core_1.PayloadHasher.wasmSupport.canUseWasm) {
|
|
79
|
-
try {
|
|
80
|
-
return yield (0, hash_wasm_1.sha256)(data);
|
|
81
|
-
}
|
|
82
|
-
catch (ex) {
|
|
83
|
-
core_1.PayloadHasher.wasmSupport.allowWasm = false;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
87
|
-
return (0, sha_js_1.default)('sha256').update(data).digest().toString();
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
static bufferFromDataUrl(url) {
|
|
91
|
-
if (url.startsWith('data:image')) {
|
|
92
|
-
const data = url.split(',')[1];
|
|
93
|
-
if (data) {
|
|
94
|
-
return Buffer.from(Uint8Array.from(atob(data), (c) => c.charCodeAt(0)));
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
const error = {
|
|
98
|
-
message: 'Invalid data Url',
|
|
99
|
-
name: 'ImageThumbnailWitnessError',
|
|
100
|
-
url,
|
|
101
|
-
};
|
|
102
|
-
throw error;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Returns the equivalent IPFS gateway URL for the supplied URL.
|
|
108
|
-
* @param urlToCheck The URL to check
|
|
109
|
-
* @returns If the supplied URL is an IPFS URL, it converts the URL to the
|
|
110
|
-
* equivalent IPFS gateway URL. Otherwise, returns the original URL.
|
|
111
|
-
*/
|
|
112
|
-
checkIpfsUrl(urlToCheck) {
|
|
113
|
-
const url = new url_1.URL(urlToCheck);
|
|
114
|
-
let protocol = url.protocol;
|
|
115
|
-
let host = url.host;
|
|
116
|
-
let path = url.pathname;
|
|
117
|
-
const query = url.search;
|
|
118
|
-
if (protocol === 'ipfs:') {
|
|
119
|
-
protocol = 'https:';
|
|
120
|
-
host = this.ipfGateway;
|
|
121
|
-
path = url.host === 'ipfs' ? `ipfs${path}` : `ipfs/${url.host}${path}`;
|
|
122
|
-
const root = `${protocol}//${host}/${path}`;
|
|
123
|
-
return (query === null || query === void 0 ? void 0 : query.length) > 0 ? `${root}?${query}` : root;
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
return urlToCheck;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
observeHandler(payloads = []) {
|
|
130
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
131
|
-
if (!(0, hasbin_1.sync)('magick')) {
|
|
132
|
-
throw Error('ImageMagick is required for this witness');
|
|
133
|
-
}
|
|
134
|
-
const urlPayloads = payloads.filter((payload) => payload.schema === url_payload_plugin_1.UrlSchema);
|
|
135
|
-
return yield this._semaphore.runExclusive(() => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
136
|
-
return (0, lodash_1.compact)(yield Promise.all(urlPayloads.map(({ url }) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
137
|
-
const cachedResult = this.cache.get(url);
|
|
138
|
-
if (cachedResult) {
|
|
139
|
-
return cachedResult;
|
|
140
|
-
}
|
|
141
|
-
let result;
|
|
142
|
-
//if it is a data URL, return a Buffer
|
|
143
|
-
const dataBuffer = ImageThumbnailWitness.bufferFromDataUrl(url);
|
|
144
|
-
if (dataBuffer) {
|
|
145
|
-
result = {
|
|
146
|
-
schema: image_thumbnail_payload_plugin_1.ImageThumbnailSchema,
|
|
147
|
-
sourceHash: yield ImageThumbnailWitness.binaryToSha256(dataBuffer),
|
|
148
|
-
sourceUrl: url,
|
|
149
|
-
url,
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
//if it is ipfs, go through cloud flair
|
|
154
|
-
const mutatedUrl = this.checkIpfsUrl(url);
|
|
155
|
-
result = yield this.fromHttp(mutatedUrl, url);
|
|
156
|
-
}
|
|
157
|
-
this.cache.set(url, result);
|
|
158
|
-
return result;
|
|
159
|
-
}))));
|
|
160
|
-
}));
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
createThumbnailDataUrl(sourceBuffer, encoding) {
|
|
164
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
165
|
-
const thumb = yield new Promise((resolve, reject) => {
|
|
166
|
-
gm(sourceBuffer)
|
|
167
|
-
.quality(this.quality)
|
|
168
|
-
.resize(this.width, this.height)
|
|
169
|
-
.flatten()
|
|
170
|
-
.toBuffer(encoding !== null && encoding !== void 0 ? encoding : this.encoding, (error, buffer) => {
|
|
171
|
-
if (error) {
|
|
172
|
-
reject(error);
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
resolve(buffer);
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
return `data:image/png;base64,${thumb.toString('base64')}`;
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Creates an image thumbnail from a video.
|
|
184
|
-
* @param videoBuffer The input video buffer.
|
|
185
|
-
* @returns An buffer containing an image thumbnail for the video.
|
|
186
|
-
*/
|
|
187
|
-
createThumbnailFromVideo(videoBuffer) {
|
|
188
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
189
|
-
const imageBuffer = yield (0, ffmpeg_1.getVideoFrameAsImageFluent)(videoBuffer);
|
|
190
|
-
return this.createThumbnailDataUrl(imageBuffer);
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
fromHttp(url, sourceUrl) {
|
|
194
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
195
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
196
|
-
let response;
|
|
197
|
-
let dnsResult;
|
|
198
|
-
try {
|
|
199
|
-
const urlObj = new url_parse_1.default(url);
|
|
200
|
-
dnsResult = yield node_dns_1.promises.resolve(urlObj.host);
|
|
201
|
-
// console.log(`dnsResult: ${JSON.stringify(dnsResult, null, 2)}`)
|
|
202
|
-
}
|
|
203
|
-
catch (ex) {
|
|
204
|
-
const error = ex;
|
|
205
|
-
const result = {
|
|
206
|
-
http: {
|
|
207
|
-
dnsError: error.code,
|
|
208
|
-
},
|
|
209
|
-
schema: image_thumbnail_payload_plugin_1.ImageThumbnailSchema,
|
|
210
|
-
sourceUrl: sourceUrl !== null && sourceUrl !== void 0 ? sourceUrl : url,
|
|
211
|
-
};
|
|
212
|
-
return result;
|
|
213
|
-
}
|
|
214
|
-
try {
|
|
215
|
-
response = yield axios_1.axios.get(url, {
|
|
216
|
-
responseType: 'arraybuffer',
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
catch (ex) {
|
|
220
|
-
const axiosError = ex;
|
|
221
|
-
if (axiosError.isAxiosError) {
|
|
222
|
-
//selectively pick fields from AxiosError
|
|
223
|
-
const result = {
|
|
224
|
-
http: {
|
|
225
|
-
ipAddress: dnsResult[0],
|
|
226
|
-
status: (_a = axiosError === null || axiosError === void 0 ? void 0 : axiosError.response) === null || _a === void 0 ? void 0 : _a.status,
|
|
227
|
-
},
|
|
228
|
-
schema: image_thumbnail_payload_plugin_1.ImageThumbnailSchema,
|
|
229
|
-
sourceUrl: sourceUrl !== null && sourceUrl !== void 0 ? sourceUrl : url,
|
|
230
|
-
};
|
|
231
|
-
return result;
|
|
232
|
-
}
|
|
233
|
-
else {
|
|
234
|
-
throw ex;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
const result = {
|
|
238
|
-
http: {
|
|
239
|
-
status: response.status,
|
|
240
|
-
},
|
|
241
|
-
schema: image_thumbnail_payload_plugin_1.ImageThumbnailSchema,
|
|
242
|
-
sourceUrl: sourceUrl !== null && sourceUrl !== void 0 ? sourceUrl : url,
|
|
243
|
-
};
|
|
244
|
-
if (response.status >= 200 && response.status < 300) {
|
|
245
|
-
const contentType = (_b = response.headers['content-type']) === null || _b === void 0 ? void 0 : _b.toString();
|
|
246
|
-
const [mediaType, fileType] = contentType.split('/');
|
|
247
|
-
result.mime = (_c = result.mime) !== null && _c !== void 0 ? _c : {};
|
|
248
|
-
result.mime.returned = mediaType;
|
|
249
|
-
const sourceBuffer = Buffer.from(response.data, 'binary');
|
|
250
|
-
try {
|
|
251
|
-
result.mime.detected = yield file_type_1.default.fromBuffer(sourceBuffer);
|
|
252
|
-
}
|
|
253
|
-
catch (ex) {
|
|
254
|
-
const error = ex;
|
|
255
|
-
(_d = this.logger) === null || _d === void 0 ? void 0 : _d.error(`FileType error: ${error.message}`);
|
|
256
|
-
}
|
|
257
|
-
const processImage = (encoding) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
258
|
-
result.sourceHash = yield ImageThumbnailWitness.binaryToSha256(sourceBuffer);
|
|
259
|
-
result.url = yield this.createThumbnailDataUrl(sourceBuffer, encoding);
|
|
260
|
-
});
|
|
261
|
-
const processVideo = () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
262
|
-
var _h;
|
|
263
|
-
// Gracefully handle the case where ffmpeg is not installed.
|
|
264
|
-
if ((0, hasbin_1.sync)('ffmpeg')) {
|
|
265
|
-
result.sourceHash = yield ImageThumbnailWitness.binaryToSha256(sourceBuffer);
|
|
266
|
-
result.url = yield this.createThumbnailFromVideo(sourceBuffer);
|
|
267
|
-
}
|
|
268
|
-
else {
|
|
269
|
-
result.mime = (_h = result.mime) !== null && _h !== void 0 ? _h : {};
|
|
270
|
-
result.mime.invalid = true;
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
let encoding = 'PNG';
|
|
274
|
-
switch (fileType.toUpperCase()) {
|
|
275
|
-
case 'GIF':
|
|
276
|
-
encoding = 'GIF';
|
|
277
|
-
break;
|
|
278
|
-
case 'JPG':
|
|
279
|
-
case 'JPEG':
|
|
280
|
-
encoding = 'JPG';
|
|
281
|
-
break;
|
|
282
|
-
}
|
|
283
|
-
switch (mediaType) {
|
|
284
|
-
case 'image': {
|
|
285
|
-
yield processImage(encoding);
|
|
286
|
-
result.mime.type = mediaType;
|
|
287
|
-
break;
|
|
288
|
-
}
|
|
289
|
-
case 'video': {
|
|
290
|
-
yield processVideo();
|
|
291
|
-
result.mime.type = mediaType;
|
|
292
|
-
break;
|
|
293
|
-
}
|
|
294
|
-
default: {
|
|
295
|
-
switch ((_e = result.mime.detected) === null || _e === void 0 ? void 0 : _e.mime) {
|
|
296
|
-
case 'image': {
|
|
297
|
-
yield processImage();
|
|
298
|
-
result.mime.type = (_f = result.mime.detected) === null || _f === void 0 ? void 0 : _f.mime;
|
|
299
|
-
break;
|
|
300
|
-
}
|
|
301
|
-
case 'video': {
|
|
302
|
-
yield processVideo();
|
|
303
|
-
result.mime.type = (_g = result.mime.detected) === null || _g === void 0 ? void 0 : _g.mime;
|
|
304
|
-
break;
|
|
305
|
-
}
|
|
306
|
-
default: {
|
|
307
|
-
result.mime.invalid = true;
|
|
308
|
-
break;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
break;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
return result;
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
exports.ImageThumbnailWitness = ImageThumbnailWitness;
|
|
320
|
-
ImageThumbnailWitness.configSchemas = [Config_1.ImageThumbnailWitnessConfigSchema];
|
|
321
|
-
//# sourceMappingURL=Witness.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Witness.js","sourceRoot":"","sources":["../../../src/Witness/Witness.ts"],"names":[],"mappings":";;;;AAAA,mCAAmC;AACnC,uCAAkD;AAElD,2CAAwC;AACxC,qCAAiC;AACjC,8CAAqE;AACrE,4CAAiD;AACjD,gGAAkG;AAClG,wEAAuE;AACvE,kDAAsD;AACtD,6C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OAAO,CAAC,CAAC;wBACZ,MAAM,YAAY,CAAC,QAAQ,CAAC,CAAA;wBAC5B,MAAM,CAAC,IAAI,CAAC,IAAI,GAAG,SAAS,CAAA;wBAC5B,MAAK;qBACN;oBACD,KAAK,OAAO,CAAC,CAAC;wBACZ,MAAM,YAAY,EAAE,CAAA;wBACpB,MAAM,CAAC,IAAI,CAAC,IAAI,GAAG,SAAS,CAAA;wBAC5B,MAAK;qBACN;oBACD,OAAO,CAAC,CAAC;wBACP,QAAQ,MAAA,MAAM,CAAC,IAAI,CAAC,QAAQ,0CAAE,IAAI,EAAE;4BAClC,KAAK,OAAO,CAAC,CAAC;gCACZ,MAAM,YAAY,EAAE,CAAA;gCACpB,MAAM,CAAC,IAAI,CAAC,IAAI,GAAG,MAAA,MAAM,CAAC,IAAI,CAAC,QAAQ,0CAAE,IAAI,CAAA;gCAC7C,MAAK;6BACN;4BACD,KAAK,OAAO,CAAC,CAAC;gCACZ,MAAM,YAAY,EAAE,CAAA;gCACpB,MAAM,CAAC,IAAI,CAAC,IAAI,GAAG,MAAA,MAAM,CAAC,IAAI,CAAC,QAAQ,0CAAE,IAAI,CAAA;gCAC7C,MAAK;6BACN;4BACD,OAAO,CAAC,CAAC;gCACP,MAAM,CAAC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;gCAC1B,MAAK;6BACN;yBACF;wBACD,MAAK;qBACN;iBACF;aACF;YACD,OAAO,MAAM,CAAA;;KACd;;AAlSH,sDAmSC;AAlSiB,mCAAa,GAAG,CAAC,0CAAiC,CAAC,AAAtC,CAAsC"}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getVideoFrameAsImageFluent = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const core_1 = require("@xyo-network/core");
|
|
6
|
-
const fluent_ffmpeg_1 = tslib_1.__importDefault(require("fluent-ffmpeg"));
|
|
7
|
-
const promises_1 = require("fs/promises");
|
|
8
|
-
const os_1 = require("os");
|
|
9
|
-
const stream_1 = require("stream");
|
|
10
|
-
/**
|
|
11
|
-
* A Writable stream that collects output from ffmpeg.
|
|
12
|
-
*/
|
|
13
|
-
class FfmpegOutputStream extends stream_1.Writable {
|
|
14
|
-
constructor(options) {
|
|
15
|
-
super(options);
|
|
16
|
-
this.chunks = [];
|
|
17
|
-
/**
|
|
18
|
-
* Collects the output from ffmpeg into a buffer.
|
|
19
|
-
* @returns A buffer containing the concatenated
|
|
20
|
-
* output from ffmpeg.
|
|
21
|
-
*/
|
|
22
|
-
this.toBuffer = () => Buffer.concat(this.chunks);
|
|
23
|
-
}
|
|
24
|
-
_write(chunk, _encoding, callback) {
|
|
25
|
-
this.chunks.push(chunk);
|
|
26
|
-
callback();
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Execute FFmpeg using fluent API with provided input buffer and video thumbnail image.
|
|
31
|
-
* @param videoBuffer Input video buffer.
|
|
32
|
-
* @returns Output buffer containing the video thumbnail image.
|
|
33
|
-
*/
|
|
34
|
-
const getVideoFrameAsImageFluent = (videoBuffer) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
-
// Get a temp file name
|
|
36
|
-
const tmpFile = `/${(0, os_1.tmpdir)()}/${(0, core_1.uuid)()}`;
|
|
37
|
-
try {
|
|
38
|
-
// Write videoBuffer to temp file for use as input to ffmpeg to
|
|
39
|
-
// avoid issues with ffmpeg inferring premature EOF from buffer
|
|
40
|
-
// passed via stdin (happens when ffmpeg is trying to infer
|
|
41
|
-
// input video format)
|
|
42
|
-
yield (0, promises_1.writeFile)(tmpFile, videoBuffer, { encoding: 'binary' });
|
|
43
|
-
const imageBuffer = yield new Promise((resolve, reject) => {
|
|
44
|
-
// Create a Writable stream to collect PNG output from ffmpeg
|
|
45
|
-
const ffmpegOutput = new FfmpegOutputStream();
|
|
46
|
-
// Execute ffmpeg using fluent API
|
|
47
|
-
(0, fluent_ffmpeg_1.default)()
|
|
48
|
-
// NOTE: Uncomment to debug CLI args to ffmpeg
|
|
49
|
-
// .on('start', (commandLine) => console.log('Spawned Ffmpeg with command: ' + commandLine))
|
|
50
|
-
.on('error', (err) => reject(err.message))
|
|
51
|
-
// Listen for the 'end' event to combine the output into a buffer holding the PNG image
|
|
52
|
-
.on('end', () => resolve(ffmpegOutput.toBuffer()))
|
|
53
|
-
.input(tmpFile) // Use temp file as input
|
|
54
|
-
.takeFrames(1) // Only take 1st video frame
|
|
55
|
-
.withNoAudio() // Don't include audio
|
|
56
|
-
.outputOptions('-f image2pipe') // Write output to stdout
|
|
57
|
-
.videoCodec('png') // Force PNG output
|
|
58
|
-
// Start processing and direct ffmpeg stdout to writable stream
|
|
59
|
-
.pipe(ffmpegOutput);
|
|
60
|
-
});
|
|
61
|
-
return imageBuffer;
|
|
62
|
-
}
|
|
63
|
-
finally {
|
|
64
|
-
// Cleanup temp file
|
|
65
|
-
try {
|
|
66
|
-
yield (0, promises_1.unlink)(tmpFile);
|
|
67
|
-
}
|
|
68
|
-
catch (_a) {
|
|
69
|
-
// No error here since file doesn't exist
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
exports.getVideoFrameAsImageFluent = getVideoFrameAsImageFluent;
|
|
74
|
-
//# sourceMappingURL=getVideoFrameAsImageFluent.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getVideoFrameAsImageFluent.js","sourceRoot":"","sources":["../../../../../src/Witness/ffmpeg/fluent/getVideoFrameAsImageFluent.ts"],"names":[],"mappings":";;;;AAAA,4CAAwC;AACxC,0EAAkC;AAClC,0CAA+C;AAC/C,2BAA2B;AAC3B,mCAAkD;AAElD;;GAEG;AACH,MAAM,kBAAmB,SAAQ,iBAAQ;IAGvC,YAAY,OAAyB;QACnC,KAAK,CAAC,OAAO,CAAC,CAAA;QAHC,WAAM,GAAiB,EAAE,CAAA;QAW1C;;;;W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AAC,KAAK,CAAC,CAAC,mBAAmB;gBACtC,+DAA+D;iBAC9D,IAAI,CAAC,YAAY,CAAC,CAAA;QACvB,CAAC,CAAC,CAAA;QACF,OAAO,WAAW,CAAA;KACnB;YAAS;QACR,oBAAoB;QACpB,IAAI;YACF,MAAM,IAAA,iBAAM,EAAC,OAAO,CAAC,CAAA;SACtB;QAAC,WAAM;YACN,yCAAyC;SAC1C;KACF;AACH,CAAC,CAAA,CAAA;AApCY,QAAA,0BAA0B,8BAoCtC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/Witness/ffmpeg/fluent/index.ts"],"names":[],"mappings":";;;AAAA,uEAA4C"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/Witness/ffmpeg/index.ts"],"names":[],"mappings":";;;AAAA,mDAAwB;AACxB,kDAAuB"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.executeFFmpeg = void 0;
|
|
4
|
-
const child_process_1 = require("child_process");
|
|
5
|
-
/**
|
|
6
|
-
* Execute FFmpeg with the provided arguments.
|
|
7
|
-
* @param videoBuffer Input video buffer.
|
|
8
|
-
* @param ffmpegArgs FFmpeg arguments.
|
|
9
|
-
* @returns Output buffer containing the video thumbnail image.
|
|
10
|
-
*/
|
|
11
|
-
const executeFFmpeg = (videoBuffer, ffmpegArgs) => {
|
|
12
|
-
return new Promise((resolve, reject) => {
|
|
13
|
-
const imageData = [];
|
|
14
|
-
const ffmpeg = (0, child_process_1.spawn)('ffmpeg', ffmpegArgs);
|
|
15
|
-
ffmpeg.stdout.on('data', (data) => imageData.push(data));
|
|
16
|
-
// TODO: This is required as we're seeing errors thrown due to
|
|
17
|
-
// how we're piping the data to ffmpeg. Works perfectly though.
|
|
18
|
-
ffmpeg.stdin.on('error', () => { });
|
|
19
|
-
ffmpeg.on('close', (code) => {
|
|
20
|
-
if (code !== 0) {
|
|
21
|
-
reject(new Error(`FFmpeg exited with code ${code}`));
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
resolve(Buffer.concat(imageData));
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
// Pipe the input stream to ffmpeg's stdin
|
|
28
|
-
ffmpeg.stdin.end(videoBuffer);
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
exports.executeFFmpeg = executeFFmpeg;
|
|
32
|
-
//# sourceMappingURL=executeFfmpeg.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"executeFfmpeg.js","sourceRoot":"","sources":["../../../../../src/Witness/ffmpeg/spawn/executeFfmpeg.ts"],"names":[],"mappings":";;;AAAA,iDAAqC;AAErC;;;;;GAKG;AACI,MAAM,aAAa,GAAG,CAAC,WAAmB,EAAE,UAAoB,EAAmB,EAAE;IAC1F,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,SAAS,GAAa,EAAE,CAAA;QAC9B,MAAM,MAAM,GAAG,IAAA,qBAAK,EAAC,QAAQ,EAAE,UAAU,CAAC,CAAA;QAC1C,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;QAChE,8DAA8D;QAC9D,+DAA+D;QAC/D,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;QAClC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;YAC1B,IAAI,IAAI,KAAK,CAAC,EAAE;gBACd,MAAM,CAAC,IAAI,KAAK,CAAC,2BAA2B,IAAI,EAAE,CAAC,CAAC,CAAA;aACrD;iBAAM;gBACL,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAA;aAClC;QACH,CAAC,CAAC,CAAA;QACF,0CAA0C;QAC1C,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;IAC/B,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAlBY,QAAA,aAAa,iBAkBzB"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getVideoFrameAsImage = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const executeFfmpeg_1 = require("./executeFfmpeg");
|
|
6
|
-
/**
|
|
7
|
-
* Execute FFmpeg with provided input buffer and return video thumbnail image.
|
|
8
|
-
* @param videoBuffer Input video buffer.
|
|
9
|
-
* @returns Output buffer containing the video thumbnail image.
|
|
10
|
-
*/
|
|
11
|
-
const getVideoFrameAsImage = (videoBuffer) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
-
const imageBuffer = yield (0, executeFfmpeg_1.executeFFmpeg)(videoBuffer, ['-i', 'pipe:', '-ss', '00:00:00', '-vframes', '1', '-f', 'image2pipe', '-']);
|
|
13
|
-
return imageBuffer;
|
|
14
|
-
});
|
|
15
|
-
exports.getVideoFrameAsImage = getVideoFrameAsImage;
|
|
16
|
-
//# sourceMappingURL=getVideoFrameAsImage.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getVideoFrameAsImage.js","sourceRoot":"","sources":["../../../../../src/Witness/ffmpeg/spawn/getVideoFrameAsImage.ts"],"names":[],"mappings":";;;;AAAA,mDAA+C;AAE/C;;;;GAIG;AACI,MAAM,oBAAoB,GAAG,CAAO,WAAmB,EAAE,EAAE;IAChE,MAAM,WAAW,GAAG,MAAM,IAAA,6BAAa,EAAC,WAAW,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,CAAC,CAAC,CAAA;IAClI,OAAO,WAAW,CAAA;AACpB,CAAC,CAAA,CAAA;AAHY,QAAA,oBAAoB,wBAGhC"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./executeFfmpeg"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./getVideoFrameAsImage"), exports);
|
|
6
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/Witness/ffmpeg/spawn/index.ts"],"names":[],"mappings":";;;AAAA,0DAA+B;AAC/B,iEAAsC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./Config"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./Params"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./Witness"), exports);
|
|
7
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Witness/index.ts"],"names":[],"mappings":";;;AAAA,mDAAwB;AACxB,mDAAwB;AACxB,oDAAyB"}
|
package/dist/cjs/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ImageThumbnailPlugin = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const Plugin_1 = require("./Plugin");
|
|
6
|
-
Object.defineProperty(exports, "ImageThumbnailPlugin", { enumerable: true, get: function () { return Plugin_1.ImageThumbnailPlugin; } });
|
|
7
|
-
tslib_1.__exportStar(require("./Diviner"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./Witness"), exports);
|
|
9
|
-
// eslint-disable-next-line import/no-default-export
|
|
10
|
-
exports.default = Plugin_1.ImageThumbnailPlugin;
|
|
11
|
-
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA,qCAA+C;AAKtC,qGALA,6BAAoB,OAKA;AAH7B,oDAAyB;AACzB,oDAAyB;AAIzB,oDAAoD;AACpD,kBAAe,6BAAoB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Config.js","sourceRoot":"","sources":["../../../src/Diviner/Config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,6CAA6C,CAAA;AAElF,MAAM,CAAC,MAAM,iCAAiC,GAAG,GAAG,oBAAoB,iBAA0B,CAAA"}
|