@xyo-network/image-thumbnail-plugin 2.75.7 → 2.75.9
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 +17132 -7878
- package/dist/node/Plugin.d.cts +4 -4
- package/dist/node/Plugin.d.cts.map +1 -1
- package/dist/node/Plugin.d.mts +4 -4
- package/dist/node/Plugin.d.mts.map +1 -1
- package/dist/node/Plugin.d.ts +4 -4
- package/dist/node/Plugin.d.ts.map +1 -1
- package/dist/node/Plugin.js +27 -256
- package/dist/node/Plugin.js.map +1 -1
- package/dist/node/Plugin.mjs +21 -250
- package/dist/node/Plugin.mjs.map +1 -1
- package/dist/node/Witness/Witness.d.cts +0 -25
- package/dist/node/Witness/Witness.d.cts.map +1 -1
- package/dist/node/Witness/Witness.d.mts +0 -25
- package/dist/node/Witness/Witness.d.mts.map +1 -1
- package/dist/node/Witness/Witness.d.ts +0 -25
- package/dist/node/Witness/Witness.d.ts.map +1 -1
- package/dist/node/Witness/Witness.js +7 -30
- package/dist/node/Witness/Witness.js.map +1 -1
- package/dist/node/Witness/Witness.mjs +7 -30
- package/dist/node/Witness/Witness.mjs.map +1 -1
- package/dist/node/Witness/index.js +7 -30
- package/dist/node/Witness/index.js.map +1 -1
- package/dist/node/Witness/index.mjs +7 -30
- package/dist/node/Witness/index.mjs.map +1 -1
- package/dist/node/index.d.cts +1 -1
- package/dist/node/index.d.cts.map +1 -1
- package/dist/node/index.d.mts +1 -1
- package/dist/node/index.d.mts.map +1 -1
- package/dist/node/index.d.ts +1 -1
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +31 -261
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +22 -252
- package/dist/node/index.mjs.map +1 -1
- package/package.json +19 -24
- package/src/Plugin.ts +1 -1
- package/src/Witness/Witness.ts +5 -30
- package/src/index.ts +1 -1
- package/dist/node/Diviner/Config.d.cts +0 -34
- package/dist/node/Diviner/Config.d.cts.map +0 -1
- package/dist/node/Diviner/Config.d.mts +0 -34
- package/dist/node/Diviner/Config.d.mts.map +0 -1
- package/dist/node/Diviner/Config.d.ts +0 -34
- package/dist/node/Diviner/Config.d.ts.map +0 -1
- package/dist/node/Diviner/Config.js +0 -32
- package/dist/node/Diviner/Config.js.map +0 -1
- package/dist/node/Diviner/Config.mjs +0 -7
- package/dist/node/Diviner/Config.mjs.map +0 -1
- package/dist/node/Diviner/Diviner.d.cts +0 -48
- package/dist/node/Diviner/Diviner.d.cts.map +0 -1
- package/dist/node/Diviner/Diviner.d.mts +0 -48
- package/dist/node/Diviner/Diviner.d.mts.map +0 -1
- package/dist/node/Diviner/Diviner.d.ts +0 -48
- package/dist/node/Diviner/Diviner.d.ts.map +0 -1
- package/dist/node/Diviner/Diviner.js +0 -237
- package/dist/node/Diviner/Diviner.js.map +0 -1
- package/dist/node/Diviner/Diviner.mjs +0 -212
- package/dist/node/Diviner/Diviner.mjs.map +0 -1
- package/dist/node/Diviner/Params.d.cts +0 -5
- package/dist/node/Diviner/Params.d.cts.map +0 -1
- package/dist/node/Diviner/Params.d.mts +0 -5
- package/dist/node/Diviner/Params.d.mts.map +0 -1
- package/dist/node/Diviner/Params.d.ts +0 -5
- package/dist/node/Diviner/Params.d.ts.map +0 -1
- package/dist/node/Diviner/Params.js +0 -19
- package/dist/node/Diviner/Params.js.map +0 -1
- package/dist/node/Diviner/Params.mjs +0 -1
- package/dist/node/Diviner/Params.mjs.map +0 -1
- package/dist/node/Diviner/index.d.cts +0 -4
- package/dist/node/Diviner/index.d.cts.map +0 -1
- package/dist/node/Diviner/index.d.mts +0 -4
- package/dist/node/Diviner/index.d.mts.map +0 -1
- package/dist/node/Diviner/index.d.ts +0 -4
- package/dist/node/Diviner/index.d.ts.map +0 -1
- package/dist/node/Diviner/index.js +0 -239
- package/dist/node/Diviner/index.js.map +0 -1
- package/dist/node/Diviner/index.mjs +0 -211
- package/dist/node/Diviner/index.mjs.map +0 -1
- package/src/Diviner/Config.ts +0 -37
- package/src/Diviner/Diviner.ts +0 -280
- package/src/Diviner/Params.ts +0 -6
- package/src/Diviner/index.ts +0 -3
package/dist/node/Plugin.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ImageThumbnailDiviner } from '
|
|
1
|
+
import { ImageThumbnailDiviner } from '@xyo-network/diviner-image-thumbnail';
|
|
2
2
|
import { ImageThumbnailWitness } from './Witness';
|
|
3
3
|
export declare const ImageThumbnailPlugin: () => import("@xyo-network/payloadset-plugin").PayloadSetDualPlugin<ImageThumbnailWitness<import("@xyo-network/core").BaseParamsFields & {
|
|
4
4
|
account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
|
|
@@ -99,13 +99,13 @@ export declare const ImageThumbnailPlugin: () => import("@xyo-network/payloadset
|
|
|
99
99
|
schema: "network.xyo.image.thumbnail.diviner.config";
|
|
100
100
|
} & Omit<{
|
|
101
101
|
archivist?: string | undefined;
|
|
102
|
-
indexStore?: import("
|
|
102
|
+
indexStore?: import("@xyo-network/image-thumbnail-payload-plugin").SearchableStorage | undefined;
|
|
103
103
|
payloadDiviner?: string | undefined;
|
|
104
104
|
payloadDivinerLimit?: number | undefined;
|
|
105
105
|
pollFrequency?: number | undefined;
|
|
106
106
|
schema: "network.xyo.image.thumbnail.diviner.config";
|
|
107
|
-
stateStore?: import("
|
|
108
|
-
thumbnailStore?: import("
|
|
107
|
+
stateStore?: import("@xyo-network/image-thumbnail-payload-plugin").SearchableStorage | undefined;
|
|
108
|
+
thumbnailStore?: import("@xyo-network/image-thumbnail-payload-plugin").SearchableStorage | undefined;
|
|
109
109
|
}, "schema">, "schema"> & {
|
|
110
110
|
schema: "network.xyo.image.thumbnail.diviner.config";
|
|
111
111
|
}, "schema"> & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAA;AAK5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAA;AAEjD,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAa9B,CAAA"}
|
package/dist/node/Plugin.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ImageThumbnailDiviner } from '
|
|
1
|
+
import { ImageThumbnailDiviner } from '@xyo-network/diviner-image-thumbnail';
|
|
2
2
|
import { ImageThumbnailWitness } from './Witness';
|
|
3
3
|
export declare const ImageThumbnailPlugin: () => import("@xyo-network/payloadset-plugin").PayloadSetDualPlugin<ImageThumbnailWitness<import("@xyo-network/core").BaseParamsFields & {
|
|
4
4
|
account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
|
|
@@ -99,13 +99,13 @@ export declare const ImageThumbnailPlugin: () => import("@xyo-network/payloadset
|
|
|
99
99
|
schema: "network.xyo.image.thumbnail.diviner.config";
|
|
100
100
|
} & Omit<{
|
|
101
101
|
archivist?: string | undefined;
|
|
102
|
-
indexStore?: import("
|
|
102
|
+
indexStore?: import("@xyo-network/image-thumbnail-payload-plugin").SearchableStorage | undefined;
|
|
103
103
|
payloadDiviner?: string | undefined;
|
|
104
104
|
payloadDivinerLimit?: number | undefined;
|
|
105
105
|
pollFrequency?: number | undefined;
|
|
106
106
|
schema: "network.xyo.image.thumbnail.diviner.config";
|
|
107
|
-
stateStore?: import("
|
|
108
|
-
thumbnailStore?: import("
|
|
107
|
+
stateStore?: import("@xyo-network/image-thumbnail-payload-plugin").SearchableStorage | undefined;
|
|
108
|
+
thumbnailStore?: import("@xyo-network/image-thumbnail-payload-plugin").SearchableStorage | undefined;
|
|
109
109
|
}, "schema">, "schema"> & {
|
|
110
110
|
schema: "network.xyo.image.thumbnail.diviner.config";
|
|
111
111
|
}, "schema"> & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAA;AAK5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAA;AAEjD,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAa9B,CAAA"}
|
package/dist/node/Plugin.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ImageThumbnailDiviner } from '
|
|
1
|
+
import { ImageThumbnailDiviner } from '@xyo-network/diviner-image-thumbnail';
|
|
2
2
|
import { ImageThumbnailWitness } from './Witness';
|
|
3
3
|
export declare const ImageThumbnailPlugin: () => import("@xyo-network/payloadset-plugin").PayloadSetDualPlugin<ImageThumbnailWitness<import("@xyo-network/core").BaseParamsFields & {
|
|
4
4
|
account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
|
|
@@ -99,13 +99,13 @@ export declare const ImageThumbnailPlugin: () => import("@xyo-network/payloadset
|
|
|
99
99
|
schema: "network.xyo.image.thumbnail.diviner.config";
|
|
100
100
|
} & Omit<{
|
|
101
101
|
archivist?: string | undefined;
|
|
102
|
-
indexStore?: import("
|
|
102
|
+
indexStore?: import("@xyo-network/image-thumbnail-payload-plugin").SearchableStorage | undefined;
|
|
103
103
|
payloadDiviner?: string | undefined;
|
|
104
104
|
payloadDivinerLimit?: number | undefined;
|
|
105
105
|
pollFrequency?: number | undefined;
|
|
106
106
|
schema: "network.xyo.image.thumbnail.diviner.config";
|
|
107
|
-
stateStore?: import("
|
|
108
|
-
thumbnailStore?: import("
|
|
107
|
+
stateStore?: import("@xyo-network/image-thumbnail-payload-plugin").SearchableStorage | undefined;
|
|
108
|
+
thumbnailStore?: import("@xyo-network/image-thumbnail-payload-plugin").SearchableStorage | undefined;
|
|
109
109
|
}, "schema">, "schema"> & {
|
|
110
110
|
schema: "network.xyo.image.thumbnail.diviner.config";
|
|
111
111
|
}, "schema"> & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAA;AAK5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAA;AAEjD,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAa9B,CAAA"}
|
package/dist/node/Plugin.js
CHANGED
|
@@ -33,241 +33,34 @@ __export(Plugin_exports, {
|
|
|
33
33
|
ImageThumbnailPlugin: () => ImageThumbnailPlugin
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(Plugin_exports);
|
|
36
|
-
var
|
|
37
|
-
var
|
|
38
|
-
var import_payloadset_plugin = require("@xyo-network/payloadset-plugin");
|
|
39
|
-
|
|
40
|
-
// src/Diviner/Config.ts
|
|
41
|
-
var import_image_thumbnail_payload_plugin = require("@xyo-network/image-thumbnail-payload-plugin");
|
|
42
|
-
var ImageThumbnailDivinerConfigSchema = `${import_image_thumbnail_payload_plugin.ImageThumbnailSchema}.diviner.config`;
|
|
43
|
-
|
|
44
|
-
// src/Diviner/Diviner.ts
|
|
45
|
-
var import_assert = require("@xylabs/assert");
|
|
46
|
-
var import_exists = require("@xylabs/exists");
|
|
47
|
-
var import_abstract_diviner = require("@xyo-network/abstract-diviner");
|
|
48
|
-
var import_archivist_model = require("@xyo-network/archivist-model");
|
|
49
|
-
var import_archivist_wrapper = require("@xyo-network/archivist-wrapper");
|
|
50
|
-
var import_boundwitness_model = require("@xyo-network/boundwitness-model");
|
|
51
|
-
var import_core = require("@xyo-network/core");
|
|
52
|
-
var import_diviner_boundwitness_model = require("@xyo-network/diviner-boundwitness-model");
|
|
53
|
-
var import_diviner_model = require("@xyo-network/diviner-model");
|
|
54
|
-
var import_diviner_payload_model = require("@xyo-network/diviner-payload-model");
|
|
55
|
-
var import_diviner_wrapper = require("@xyo-network/diviner-wrapper");
|
|
56
|
-
var import_image_thumbnail_payload_plugin2 = require("@xyo-network/image-thumbnail-payload-plugin");
|
|
57
|
-
var import_payload_builder = require("@xyo-network/payload-builder");
|
|
36
|
+
var import_diviner_image_thumbnail = require("@xyo-network/diviner-image-thumbnail");
|
|
37
|
+
var import_image_thumbnail_payload_plugin3 = require("@xyo-network/image-thumbnail-payload-plugin");
|
|
58
38
|
var import_payload_model = require("@xyo-network/payload-model");
|
|
59
|
-
var
|
|
60
|
-
var import_witness_timestamp = require("@xyo-network/witness-timestamp");
|
|
61
|
-
var ModuleStateSchema = "network.xyo.module.state";
|
|
62
|
-
var isModuleState = (0, import_payload_model.isPayloadOfSchemaType)(ModuleStateSchema);
|
|
63
|
-
var ImageThumbnailResultIndexSchema = `${import_image_thumbnail_payload_plugin2.ImageThumbnailSchema}.index`;
|
|
64
|
-
var isImageThumbnailResult = (0, import_payload_model.isPayloadOfSchemaType)(ImageThumbnailResultIndexSchema);
|
|
65
|
-
var moduleName = "ImageThumbnailDiviner";
|
|
66
|
-
var ImageThumbnailDiviner = class extends import_abstract_diviner.AbstractDiviner {
|
|
67
|
-
static configSchemas = [ImageThumbnailDivinerConfigSchema, import_diviner_model.DivinerConfigSchema];
|
|
68
|
-
_pollId;
|
|
69
|
-
get payloadDivinerLimit() {
|
|
70
|
-
return this.config.payloadDivinerLimit ?? 1e4;
|
|
71
|
-
}
|
|
72
|
-
get pollFrequency() {
|
|
73
|
-
return this.config.pollFrequency ?? 1e4;
|
|
74
|
-
}
|
|
75
|
-
backgroundDivine = async () => {
|
|
76
|
-
const lastState = await this.retrieveState() ?? { offset: 0 };
|
|
77
|
-
const { offset } = lastState;
|
|
78
|
-
const boundWitnessDiviner = await this.getBoundWitnessDivinerForStore("thumbnailStore");
|
|
79
|
-
const query = new import_payload_builder.PayloadBuilder({ schema: import_diviner_boundwitness_model.BoundWitnessDivinerQuerySchema }).fields({
|
|
80
|
-
limit: this.payloadDivinerLimit,
|
|
81
|
-
offset,
|
|
82
|
-
order: "asc",
|
|
83
|
-
payload_schemas: [import_image_thumbnail_payload_plugin2.ImageThumbnailSchema, import_witness_timestamp.TimestampSchema]
|
|
84
|
-
});
|
|
85
|
-
const batch = await boundWitnessDiviner.divine([query]);
|
|
86
|
-
if (batch.length === 0)
|
|
87
|
-
return;
|
|
88
|
-
const imageThumbnailTimestampTuples = batch.filter(import_boundwitness_model.isBoundWitness).map((bw) => {
|
|
89
|
-
var _a, _b, _c;
|
|
90
|
-
const imageThumbnailIndexes = (_a = bw.payload_schemas) == null ? void 0 : _a.map((schema, index) => schema === import_image_thumbnail_payload_plugin2.ImageThumbnailSchema ? index : void 0).filter(import_exists.exists);
|
|
91
|
-
const timestampIndex = (_b = bw.payload_schemas) == null ? void 0 : _b.findIndex((schema) => schema === import_witness_timestamp.TimestampSchema);
|
|
92
|
-
if (!imageThumbnailIndexes.length || timestampIndex === -1)
|
|
93
|
-
return void 0;
|
|
94
|
-
const imageThumbnails = bw.payload_hashes.map((hash, index) => imageThumbnailIndexes.includes(index) ? hash : void 0).filter(import_exists.exists);
|
|
95
|
-
const timestamp = (_c = bw.payload_hashes) == null ? void 0 : _c[timestampIndex];
|
|
96
|
-
return imageThumbnails.map((imageThumbnail) => [imageThumbnail, timestamp]);
|
|
97
|
-
}).flat().filter(import_exists.exists);
|
|
98
|
-
const archivist = await this.getArchivistForStore("thumbnailStore");
|
|
99
|
-
const payloadTuples = (await Promise.all(
|
|
100
|
-
imageThumbnailTimestampTuples.map(async ([imageThumbnailHash, timestampHash]) => {
|
|
101
|
-
const results = await archivist.get([imageThumbnailHash, timestampHash]);
|
|
102
|
-
const imageThumbnailPayload = results.find(import_image_thumbnail_payload_plugin2.isImageThumbnail);
|
|
103
|
-
const timestampPayload = results.find(import_witness_timestamp.isTimestamp);
|
|
104
|
-
if (!imageThumbnailPayload || !timestampPayload)
|
|
105
|
-
return void 0;
|
|
106
|
-
const calculatedImageThumbnailHash = await import_core.PayloadHasher.hashAsync(imageThumbnailPayload);
|
|
107
|
-
const calculatedTimestampHash = await import_core.PayloadHasher.hashAsync(timestampPayload);
|
|
108
|
-
if (imageThumbnailHash !== calculatedImageThumbnailHash || timestampHash !== calculatedTimestampHash)
|
|
109
|
-
return void 0;
|
|
110
|
-
return [imageThumbnailHash, imageThumbnailPayload, timestampHash, timestampPayload];
|
|
111
|
-
})
|
|
112
|
-
)).filter(import_exists.exists);
|
|
113
|
-
const indexedResults = payloadTuples.map(([thumbnailHash, thumbnailPayload, timestampHash, timestampPayload]) => {
|
|
114
|
-
var _a;
|
|
115
|
-
const { sourceUrl: url } = thumbnailPayload;
|
|
116
|
-
const { timestamp } = timestampPayload;
|
|
117
|
-
const status = ((_a = thumbnailPayload.http) == null ? void 0 : _a.status) ?? -1;
|
|
118
|
-
const sources = [thumbnailHash, timestampHash];
|
|
119
|
-
const result = new import_payload_builder.PayloadBuilder({ schema: ImageThumbnailResultIndexSchema }).fields({ sources, status, timestamp, url }).build();
|
|
120
|
-
return result;
|
|
121
|
-
});
|
|
122
|
-
const indexArchivist = await this.getArchivistForStore("indexStore");
|
|
123
|
-
await indexArchivist.insert(indexedResults);
|
|
124
|
-
const nextOffset = offset + batch.length + 1;
|
|
125
|
-
const currentState = { ...lastState, offset: nextOffset };
|
|
126
|
-
await this.commitState(currentState);
|
|
127
|
-
};
|
|
128
|
-
/**
|
|
129
|
-
* Commit the internal state of the Diviner process. This is similar
|
|
130
|
-
* to a transaction completion in a database and should only be called
|
|
131
|
-
* when results have been successfully persisted to the appropriate
|
|
132
|
-
* external stores.
|
|
133
|
-
*/
|
|
134
|
-
async commitState(state) {
|
|
135
|
-
var _a;
|
|
136
|
-
const stateStore = (0, import_assert.assertEx)((_a = this.config.stateStore) == null ? void 0 : _a.archivist, `${moduleName}: No stateStore configured`);
|
|
137
|
-
const module2 = (0, import_assert.assertEx)(await this.resolve(stateStore), `${moduleName}: Failed to resolve stateStore`);
|
|
138
|
-
await (0, import_archivist_model.withArchivistModule)(module2, async (archivist) => {
|
|
139
|
-
const mod = import_archivist_wrapper.ArchivistWrapper.wrap(archivist, this.account);
|
|
140
|
-
const payload = new import_payload_builder.PayloadBuilder({ schema: ModuleStateSchema }).fields({ state }).build();
|
|
141
|
-
await mod.insert([payload]);
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
async divineHandler(payloads = []) {
|
|
145
|
-
const urls = payloads.filter(import_url_payload_plugin.isUrlPayload).map((urlPayload) => urlPayload.url);
|
|
146
|
-
const diviner = await this.getPayloadDivinerForStore("indexStore");
|
|
147
|
-
const results = (await Promise.all(
|
|
148
|
-
urls.map(async (url) => {
|
|
149
|
-
const query = new import_payload_builder.PayloadBuilder({ schema: import_diviner_payload_model.PayloadDivinerQuerySchema }).fields({ limit: 1, offset: 0, order: "desc", url }).build();
|
|
150
|
-
return await diviner.divine([query]);
|
|
151
|
-
})
|
|
152
|
-
)).flat().filter(isImageThumbnailResult);
|
|
153
|
-
return results;
|
|
154
|
-
}
|
|
155
|
-
async getArchivistForStore(store, wrap) {
|
|
156
|
-
var _a, _b;
|
|
157
|
-
const name = (0, import_assert.assertEx)((_b = (_a = this.config) == null ? void 0 : _a[store]) == null ? void 0 : _b.archivist, () => `${moduleName}: Config for ${store}.archivist not specified`);
|
|
158
|
-
const mod = (0, import_assert.assertEx)(await this.resolve(name), () => `${moduleName}: Failed to resolve ${store}.archivist`);
|
|
159
|
-
return wrap ? import_archivist_wrapper.ArchivistWrapper.wrap(mod, this.account) : (0, import_archivist_model.asArchivistInstance)(mod, () => `${moduleName}: ${store}.archivist is not an Archivist`);
|
|
160
|
-
}
|
|
161
|
-
async getBoundWitnessDivinerForStore(store, wrap) {
|
|
162
|
-
var _a, _b;
|
|
163
|
-
const name = (0, import_assert.assertEx)((_b = (_a = this.config) == null ? void 0 : _a[store]) == null ? void 0 : _b.boundWitnessDiviner, () => `${moduleName}: Config for ${store}.boundWitnessDiviner not specified`);
|
|
164
|
-
const mod = (0, import_assert.assertEx)(await this.resolve(name), () => `${moduleName}: Failed to resolve ${store}.boundWitnessDiviner`);
|
|
165
|
-
return wrap ? import_diviner_wrapper.DivinerWrapper.wrap(mod, this.account) : (0, import_diviner_model.asDivinerInstance)(mod, () => `${moduleName}: ${store}.boundWitnessDiviner is not a Diviner`);
|
|
166
|
-
}
|
|
167
|
-
async getPayloadDivinerForStore(store, wrap) {
|
|
168
|
-
var _a, _b;
|
|
169
|
-
const name = (0, import_assert.assertEx)((_b = (_a = this.config) == null ? void 0 : _a[store]) == null ? void 0 : _b.payloadDiviner, () => `${moduleName}: Config for ${store}.payloadDiviner not specified`);
|
|
170
|
-
const mod = (0, import_assert.assertEx)(await this.resolve(name), () => `${moduleName}: Failed to resolve ${store}.payloadDiviner`);
|
|
171
|
-
return wrap ? import_diviner_wrapper.DivinerWrapper.wrap(mod, this.account) : (0, import_diviner_model.asDivinerInstance)(mod, () => `${moduleName}: ${store}.payloadDiviner is not a Diviner`);
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Retrieves the last state of the Diviner process. Used to recover state after
|
|
175
|
-
* preemptions, reboots, etc.
|
|
176
|
-
*/
|
|
177
|
-
async retrieveState() {
|
|
178
|
-
var _a;
|
|
179
|
-
let hash = "";
|
|
180
|
-
const diviner = await this.getBoundWitnessDivinerForStore("stateStore");
|
|
181
|
-
const query = new import_payload_builder.PayloadBuilder({ schema: import_diviner_boundwitness_model.BoundWitnessDivinerQuerySchema }).fields({
|
|
182
|
-
address: this.account.address,
|
|
183
|
-
limit: 1,
|
|
184
|
-
offset: 0,
|
|
185
|
-
order: "desc",
|
|
186
|
-
payload_schemas: [ModuleStateSchema]
|
|
187
|
-
});
|
|
188
|
-
const boundWitnesses = await diviner.divine([query]);
|
|
189
|
-
if (boundWitnesses.length > 0) {
|
|
190
|
-
const boundWitness = boundWitnesses[0];
|
|
191
|
-
if ((0, import_boundwitness_model.isBoundWitness)(boundWitness)) {
|
|
192
|
-
hash = boundWitness.addresses.map((address, index) => ({ address, index })).filter(({ address }) => address === this.account.address).reduce(
|
|
193
|
-
(prev, curr) => {
|
|
194
|
-
var _a2;
|
|
195
|
-
return ((_a2 = boundWitness.payload_schemas) == null ? void 0 : _a2[curr == null ? void 0 : curr.index]) === ModuleStateSchema ? boundWitness.payload_hashes[curr == null ? void 0 : curr.index] : prev;
|
|
196
|
-
},
|
|
197
|
-
""
|
|
198
|
-
);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
if (hash) {
|
|
202
|
-
const stateStoreArchivist = (0, import_assert.assertEx)((_a = this.config.stateStore) == null ? void 0 : _a.archivist, `${moduleName}: No stateStore archivist configured`);
|
|
203
|
-
await (0, import_archivist_model.withArchivistModule)(
|
|
204
|
-
(0, import_assert.assertEx)(await this.resolve(stateStoreArchivist), `${moduleName}: Failed to resolve stateStore archivist`),
|
|
205
|
-
async (mod) => {
|
|
206
|
-
const archivist = import_archivist_wrapper.ArchivistWrapper.wrap(mod, this.account);
|
|
207
|
-
const payloads = await archivist.get([hash]);
|
|
208
|
-
if (payloads.length > 0) {
|
|
209
|
-
const payload = payloads[0];
|
|
210
|
-
if (isModuleState(payload)) {
|
|
211
|
-
return payload.state;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
|
-
return void 0;
|
|
218
|
-
}
|
|
219
|
-
async startHandler() {
|
|
220
|
-
await super.startHandler();
|
|
221
|
-
this.poll();
|
|
222
|
-
return true;
|
|
223
|
-
}
|
|
224
|
-
async stopHandler(_timeout) {
|
|
225
|
-
if (this._pollId) {
|
|
226
|
-
clearTimeout(this._pollId);
|
|
227
|
-
this._pollId = void 0;
|
|
228
|
-
}
|
|
229
|
-
return await super.stopHandler();
|
|
230
|
-
}
|
|
231
|
-
poll() {
|
|
232
|
-
this._pollId = setTimeout(async () => {
|
|
233
|
-
try {
|
|
234
|
-
await this.backgroundDivine();
|
|
235
|
-
} catch (e) {
|
|
236
|
-
console.log(e);
|
|
237
|
-
} finally {
|
|
238
|
-
if (this._pollId)
|
|
239
|
-
clearTimeout(this._pollId);
|
|
240
|
-
this._pollId = void 0;
|
|
241
|
-
this.poll();
|
|
242
|
-
}
|
|
243
|
-
}, this.pollFrequency);
|
|
244
|
-
}
|
|
245
|
-
};
|
|
39
|
+
var import_payloadset_plugin = require("@xyo-network/payloadset-plugin");
|
|
246
40
|
|
|
247
41
|
// src/Witness/Config.ts
|
|
248
|
-
var
|
|
249
|
-
var ImageThumbnailWitnessConfigSchema = `${
|
|
42
|
+
var import_image_thumbnail_payload_plugin = require("@xyo-network/image-thumbnail-payload-plugin");
|
|
43
|
+
var ImageThumbnailWitnessConfigSchema = `${import_image_thumbnail_payload_plugin.ImageThumbnailSchema}.witness.config`;
|
|
250
44
|
|
|
251
45
|
// src/Witness/Witness.ts
|
|
252
46
|
var import_node_dns = require("dns");
|
|
253
47
|
var import_lodash = require("@xylabs/lodash");
|
|
254
48
|
var import_url = require("@xylabs/url");
|
|
255
49
|
var import_axios = require("@xyo-network/axios");
|
|
256
|
-
var
|
|
257
|
-
var
|
|
258
|
-
var
|
|
50
|
+
var import_core2 = require("@xyo-network/core");
|
|
51
|
+
var import_image_thumbnail_payload_plugin2 = require("@xyo-network/image-thumbnail-payload-plugin");
|
|
52
|
+
var import_url_payload_plugin = require("@xyo-network/url-payload-plugin");
|
|
259
53
|
var import_witness = require("@xyo-network/witness");
|
|
260
54
|
var import_async_mutex = require("async-mutex");
|
|
261
55
|
var import_file_type = __toESM(require("file-type"));
|
|
262
56
|
var import_gm = __toESM(require("gm"));
|
|
263
57
|
var import_hasbin = __toESM(require("hasbin"));
|
|
264
58
|
var import_hash_wasm = require("hash-wasm");
|
|
265
|
-
var import_lru_cache = require("lru-cache");
|
|
266
59
|
var import_sha = __toESM(require("sha.js"));
|
|
267
60
|
var import_url_parse = __toESM(require("url-parse"));
|
|
268
61
|
|
|
269
62
|
// src/Witness/ffmpeg/fluent/getVideoFrameAsImageFluent.ts
|
|
270
|
-
var
|
|
63
|
+
var import_core = require("@xyo-network/core");
|
|
271
64
|
var import_fluent_ffmpeg = __toESM(require("fluent-ffmpeg"));
|
|
272
65
|
var import_promises = require("fs/promises");
|
|
273
66
|
var import_os = require("os");
|
|
@@ -289,7 +82,7 @@ var FfmpegOutputStream = class extends import_stream.Writable {
|
|
|
289
82
|
toBuffer = () => Buffer.concat(this.chunks);
|
|
290
83
|
};
|
|
291
84
|
var getVideoFrameAsImageFluent = async (videoBuffer) => {
|
|
292
|
-
const tmpFile = `/${(0, import_os.tmpdir)()}/${(0,
|
|
85
|
+
const tmpFile = `/${(0, import_os.tmpdir)()}/${(0, import_core.uuid)()}`;
|
|
293
86
|
try {
|
|
294
87
|
await (0, import_promises.writeFile)(tmpFile, videoBuffer, { encoding: "binary" });
|
|
295
88
|
const imageBuffer = await new Promise((resolve, reject) => {
|
|
@@ -309,20 +102,7 @@ var getVideoFrameAsImageFluent = async (videoBuffer) => {
|
|
|
309
102
|
var gm = import_gm.default.subClass({ imageMagick: "7+" });
|
|
310
103
|
var ImageThumbnailWitness = class _ImageThumbnailWitness extends import_witness.AbstractWitness {
|
|
311
104
|
static configSchemas = [ImageThumbnailWitnessConfigSchema];
|
|
312
|
-
_cache;
|
|
313
105
|
_semaphore = new import_async_mutex.Semaphore(this.maxAsyncProcesses);
|
|
314
|
-
get cache() {
|
|
315
|
-
this._cache = this._cache ?? new import_lru_cache.LRUCache({
|
|
316
|
-
max: this.maxCacheEntries,
|
|
317
|
-
maxSize: this.maxCacheBytes,
|
|
318
|
-
//just returning the size of the data
|
|
319
|
-
sizeCalculation: (value) => {
|
|
320
|
-
var _a;
|
|
321
|
-
return ((_a = value.url) == null ? void 0 : _a.length) ?? 1;
|
|
322
|
-
}
|
|
323
|
-
});
|
|
324
|
-
return this._cache;
|
|
325
|
-
}
|
|
326
106
|
get encoding() {
|
|
327
107
|
return this.config.encoding ?? "PNG";
|
|
328
108
|
}
|
|
@@ -335,12 +115,6 @@ var ImageThumbnailWitness = class _ImageThumbnailWitness extends import_witness.
|
|
|
335
115
|
get maxAsyncProcesses() {
|
|
336
116
|
return this.config.maxAsyncProcesses ?? 2;
|
|
337
117
|
}
|
|
338
|
-
get maxCacheBytes() {
|
|
339
|
-
return this.config.maxCacheBytes ?? 1024 * 1024 * 16;
|
|
340
|
-
}
|
|
341
|
-
get maxCacheEntries() {
|
|
342
|
-
return this.config.maxCacheEntries ?? 500;
|
|
343
|
-
}
|
|
344
118
|
get quality() {
|
|
345
119
|
return this.config.quality ?? 50;
|
|
346
120
|
}
|
|
@@ -348,12 +122,12 @@ var ImageThumbnailWitness = class _ImageThumbnailWitness extends import_witness.
|
|
|
348
122
|
return this.config.width ?? 128;
|
|
349
123
|
}
|
|
350
124
|
static async binaryToSha256(data) {
|
|
351
|
-
await
|
|
352
|
-
if (
|
|
125
|
+
await import_core2.PayloadHasher.wasmInitialized;
|
|
126
|
+
if (import_core2.PayloadHasher.wasmSupport.canUseWasm) {
|
|
353
127
|
try {
|
|
354
128
|
return await (0, import_hash_wasm.sha256)(data);
|
|
355
129
|
} catch (ex) {
|
|
356
|
-
|
|
130
|
+
import_core2.PayloadHasher.wasmSupport.allowWasm = false;
|
|
357
131
|
}
|
|
358
132
|
}
|
|
359
133
|
return (0, import_sha.default)("sha256").update(data).digest().toString();
|
|
@@ -399,20 +173,16 @@ var ImageThumbnailWitness = class _ImageThumbnailWitness extends import_witness.
|
|
|
399
173
|
if (!import_hasbin.default.sync("magick")) {
|
|
400
174
|
throw Error("ImageMagick is required for this witness");
|
|
401
175
|
}
|
|
402
|
-
const urlPayloads = payloads.filter((payload) => payload.schema ===
|
|
176
|
+
const urlPayloads = payloads.filter((payload) => payload.schema === import_url_payload_plugin.UrlSchema);
|
|
403
177
|
return await this._semaphore.runExclusive(
|
|
404
178
|
async () => (0, import_lodash.compact)(
|
|
405
179
|
await Promise.all(
|
|
406
180
|
urlPayloads.map(async ({ url }) => {
|
|
407
|
-
const cachedResult = this.cache.get(url);
|
|
408
|
-
if (cachedResult) {
|
|
409
|
-
return cachedResult;
|
|
410
|
-
}
|
|
411
181
|
let result;
|
|
412
182
|
const dataBuffer = _ImageThumbnailWitness.bufferFromDataUrl(url);
|
|
413
183
|
if (dataBuffer) {
|
|
414
184
|
result = {
|
|
415
|
-
schema:
|
|
185
|
+
schema: import_image_thumbnail_payload_plugin2.ImageThumbnailSchema,
|
|
416
186
|
sourceHash: await _ImageThumbnailWitness.binaryToSha256(dataBuffer),
|
|
417
187
|
sourceUrl: url,
|
|
418
188
|
url
|
|
@@ -421,7 +191,6 @@ var ImageThumbnailWitness = class _ImageThumbnailWitness extends import_witness.
|
|
|
421
191
|
const mutatedUrl = this.checkIpfsUrl(url);
|
|
422
192
|
result = await this.fromHttp(mutatedUrl, url);
|
|
423
193
|
}
|
|
424
|
-
this.cache.set(url, result);
|
|
425
194
|
return result;
|
|
426
195
|
})
|
|
427
196
|
)
|
|
@@ -449,8 +218,9 @@ var ImageThumbnailWitness = class _ImageThumbnailWitness extends import_witness.
|
|
|
449
218
|
const imageBuffer = await getVideoFrameAsImageFluent(videoBuffer);
|
|
450
219
|
return this.createThumbnailDataUrl(imageBuffer);
|
|
451
220
|
}
|
|
221
|
+
// eslint-disable-next-line complexity
|
|
452
222
|
async fromHttp(url, sourceUrl) {
|
|
453
|
-
var _a, _b, _c, _d, _e, _f;
|
|
223
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
454
224
|
let response;
|
|
455
225
|
let dnsResult;
|
|
456
226
|
try {
|
|
@@ -462,7 +232,7 @@ var ImageThumbnailWitness = class _ImageThumbnailWitness extends import_witness.
|
|
|
462
232
|
http: {
|
|
463
233
|
dnsError: error.code
|
|
464
234
|
},
|
|
465
|
-
schema:
|
|
235
|
+
schema: import_image_thumbnail_payload_plugin2.ImageThumbnailSchema,
|
|
466
236
|
sourceUrl: sourceUrl ?? url
|
|
467
237
|
};
|
|
468
238
|
return result2;
|
|
@@ -479,7 +249,7 @@ var ImageThumbnailWitness = class _ImageThumbnailWitness extends import_witness.
|
|
|
479
249
|
ipAddress: dnsResult[0],
|
|
480
250
|
status: (_a = axiosError == null ? void 0 : axiosError.response) == null ? void 0 : _a.status
|
|
481
251
|
},
|
|
482
|
-
schema:
|
|
252
|
+
schema: import_image_thumbnail_payload_plugin2.ImageThumbnailSchema,
|
|
483
253
|
sourceUrl: sourceUrl ?? url
|
|
484
254
|
};
|
|
485
255
|
return result2;
|
|
@@ -491,12 +261,12 @@ var ImageThumbnailWitness = class _ImageThumbnailWitness extends import_witness.
|
|
|
491
261
|
http: {
|
|
492
262
|
status: response.status
|
|
493
263
|
},
|
|
494
|
-
schema:
|
|
264
|
+
schema: import_image_thumbnail_payload_plugin2.ImageThumbnailSchema,
|
|
495
265
|
sourceUrl: sourceUrl ?? url
|
|
496
266
|
};
|
|
497
267
|
if (response.status >= 200 && response.status < 300) {
|
|
498
268
|
const contentType = (_b = response.headers["content-type"]) == null ? void 0 : _b.toString();
|
|
499
|
-
const [mediaType, fileType] = contentType.split("/");
|
|
269
|
+
const [mediaType, fileType] = (contentType == null ? void 0 : contentType.split("/")) ?? ["", ""];
|
|
500
270
|
result.mime = result.mime ?? {};
|
|
501
271
|
result.mime.returned = mediaType;
|
|
502
272
|
const sourceBuffer = Buffer.from(response.data, "binary");
|
|
@@ -541,15 +311,16 @@ var ImageThumbnailWitness = class _ImageThumbnailWitness extends import_witness.
|
|
|
541
311
|
break;
|
|
542
312
|
}
|
|
543
313
|
default: {
|
|
544
|
-
|
|
314
|
+
const [detectedMediaType] = ((_e = (_d = result.mime.detected) == null ? void 0 : _d.mime) == null ? void 0 : _e.split("/")) ?? ["", ""];
|
|
315
|
+
switch (detectedMediaType) {
|
|
545
316
|
case "image": {
|
|
546
317
|
await processImage();
|
|
547
|
-
result.mime.type = (
|
|
318
|
+
result.mime.type = (_f = result.mime.detected) == null ? void 0 : _f.mime;
|
|
548
319
|
break;
|
|
549
320
|
}
|
|
550
321
|
case "video": {
|
|
551
322
|
await processVideo();
|
|
552
|
-
result.mime.type = (
|
|
323
|
+
result.mime.type = (_g = result.mime.detected) == null ? void 0 : _g.mime;
|
|
553
324
|
break;
|
|
554
325
|
}
|
|
555
326
|
default: {
|
|
@@ -567,10 +338,10 @@ var ImageThumbnailWitness = class _ImageThumbnailWitness extends import_witness.
|
|
|
567
338
|
|
|
568
339
|
// src/Plugin.ts
|
|
569
340
|
var ImageThumbnailPlugin = () => (0, import_payloadset_plugin.createPayloadSetDualPlugin)(
|
|
570
|
-
{ required: { [
|
|
341
|
+
{ required: { [import_image_thumbnail_payload_plugin3.ImageThumbnailSchema]: 1 }, schema: import_payload_model.PayloadSetSchema },
|
|
571
342
|
{
|
|
572
343
|
diviner: async (params) => {
|
|
573
|
-
const result = await ImageThumbnailDiviner.create(params);
|
|
344
|
+
const result = await import_diviner_image_thumbnail.ImageThumbnailDiviner.create(params);
|
|
574
345
|
return result;
|
|
575
346
|
},
|
|
576
347
|
witness: async (params) => {
|