@seedprotocol/sdk 0.3.2 → 0.3.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.
- package/dist/{ArweaveClient-C0g0es2v.js → ArweaveClient-2RMCxfNZ.js} +2 -2
- package/dist/{ArweaveClient-CzkBgiZY.js.map → ArweaveClient-2RMCxfNZ.js.map} +1 -1
- package/dist/{ArweaveClient-CzkBgiZY.js → ArweaveClient-COlwyYTF.js} +2 -2
- package/dist/{ArweaveClient-C0g0es2v.js.map → ArweaveClient-COlwyYTF.js.map} +1 -1
- package/dist/{Db-DL9szGvt.js → Db-CRWMiKY9.js} +6 -7
- package/dist/Db-CRWMiKY9.js.map +1 -0
- package/dist/{Db-Bn2_MKKq.js → Db-G5dIgZv-.js} +4 -5
- package/dist/Db-G5dIgZv-.js.map +1 -0
- package/dist/{EasClient-DQ93i2ci.js → EasClient-CFnb5g-r.js} +2 -2
- package/dist/{EasClient-DQ93i2ci.js.map → EasClient-CFnb5g-r.js.map} +1 -1
- package/dist/{EasClient-B9a3NsTi.js → EasClient-CO5puCWa.js} +2 -2
- package/dist/{EasClient-B9a3NsTi.js.map → EasClient-CO5puCWa.js.map} +1 -1
- package/dist/{FileManager-Gci1k5HJ.js → FileManager-BOixZyex.js} +3 -3
- package/dist/FileManager-BOixZyex.js.map +1 -0
- package/dist/FileManager-gKGTTa4s.js +1045 -0
- package/dist/FileManager-gKGTTa4s.js.map +1 -0
- package/dist/{Item-CUQ8wILT.js → Item-BD2_tuda.js} +3 -4
- package/dist/{Item-CUQ8wILT.js.map → Item-BD2_tuda.js.map} +1 -1
- package/dist/{ItemProperty-DjGDsSEN.js → ItemProperty-CjcrzEmg.js} +3 -4
- package/dist/{ItemProperty-DjGDsSEN.js.map → ItemProperty-CjcrzEmg.js.map} +1 -1
- package/dist/{QueryClient-hzOtFe99.js → QueryClient-W4slRa7O.js} +2 -2
- package/dist/{QueryClient-hzOtFe99.js.map → QueryClient-W4slRa7O.js.map} +1 -1
- package/dist/{QueryClient-Bmnv_moN.js → QueryClient-ZUsZ1Qxq.js} +2 -2
- package/dist/{QueryClient-Bmnv_moN.js.map → QueryClient-ZUsZ1Qxq.js.map} +1 -1
- package/dist/bin.js +25 -25
- package/dist/bin.js.map +1 -1
- package/dist/{constants-Bhl5dZpN.js → constants-C-6Pg8FW.js} +38 -30
- package/dist/constants-C-6Pg8FW.js.map +1 -0
- package/dist/{index-DtB4Tlwd.js → index-BxAVepOO.js} +3 -4
- package/dist/index-BxAVepOO.js.map +1 -0
- package/dist/{index-DJjmh3u9.js → index-D-O-gmXo.js} +167 -1171
- package/dist/index-D-O-gmXo.js.map +1 -0
- package/dist/main.js +4 -5
- package/dist/main.js.map +1 -1
- package/dist/{seed.schema.config-DzDX8e7g.js → seed.schema.config-DmTl3a9U.js} +3 -4
- package/dist/seed.schema.config-DmTl3a9U.js.map +1 -0
- package/dist/src/ItemProperty/BaseItemProperty.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/hydrateFromDb.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/initialize.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/resolveRelatedValue.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/resolveRemoteStorage.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/saveValueToDb/saveImageSrc.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/saveValueToDb/saveItemStorage.d.ts.map +1 -1
- package/dist/src/browser/db/Db.d.ts.map +1 -1
- package/dist/src/browser/helpers/FileManager.d.ts +2 -0
- package/dist/src/browser/helpers/FileManager.d.ts.map +1 -1
- package/dist/src/browser/index.d.ts.map +1 -1
- package/dist/src/browser/workers/ImageResizer.d.ts.map +1 -1
- package/dist/src/client/ClientManager.d.ts +8 -24
- package/dist/src/client/ClientManager.d.ts.map +1 -1
- package/dist/src/client/actors/initialize.d.ts.map +1 -1
- package/dist/src/db/read/getPublishUploads.d.ts.map +1 -1
- package/dist/src/db/write/createMetadata.d.ts.map +1 -1
- package/dist/src/events/files/index.d.ts.map +1 -1
- package/dist/src/helpers/FileManager/BaseFileManager.d.ts +3 -0
- package/dist/src/helpers/FileManager/BaseFileManager.d.ts.map +1 -1
- package/dist/src/helpers/files.d.ts.map +1 -1
- package/dist/src/helpers/index.d.ts.map +1 -1
- package/dist/src/index.d.ts +1 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/node/codegen/drizzle.d.ts.map +1 -1
- package/dist/src/schema/file/fetchAll/actors.d.ts.map +1 -1
- package/dist/src/services/db/actors/connectToDb.d.ts.map +1 -1
- package/dist/src/services/db/actors/migrate.d.ts.map +1 -1
- package/dist/src/services/db/actors/waitForFiles.d.ts.map +1 -1
- package/dist/src/services/internal/actors/configureFs.d.ts.map +1 -1
- package/dist/src/services/internal/actors/prepareDb.d.ts.map +1 -1
- package/dist/src/services/internal/helpers.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/Db-Bn2_MKKq.js.map +0 -1
- package/dist/Db-DL9szGvt.js.map +0 -1
- package/dist/FileManager-Gci1k5HJ.js.map +0 -1
- package/dist/constants-Bhl5dZpN.js.map +0 -1
- package/dist/index-DJjmh3u9.js.map +0 -1
- package/dist/index-DtB4Tlwd.js.map +0 -1
- package/dist/seed.schema.config-DzDX8e7g.js.map +0 -1
|
@@ -2,7 +2,7 @@ import { immerable, produce, enableMapSet } from 'immer';
|
|
|
2
2
|
import 'reflect-metadata';
|
|
3
3
|
import { Type } from '@sinclair/typebox';
|
|
4
4
|
import { fromCallback, setup, assign, waitFor, raise, createActor } from 'xstate';
|
|
5
|
-
import { c as BaseQueryClient, a as BaseEasClient, G as GLOBAL_INITIALIZING_INTERNAL_SERVICE_READY, f as GLOBAL_INITIALIZING_SEND_CONFIG, g as GLOBAL_INITIALIZING_CREATE_ALL_ITEMS_SERVICES, h as GLOBAL_ADDING_MODELS_TO_DB_SUCCESS, d as BROWSER_FS_TOP_DIR, D as DB_CHECK_STATUS_UPDATE_PATHS, i as DB_CHECK_STATUS_EXISTS, j as DB_CREATING_SUCCESS, k as DB_VALIDATING_SUCCESS, l as DB_VALIDATING_WAIT,
|
|
5
|
+
import { c as BaseFileManager, b as BaseQueryClient, a as BaseEasClient, G as GLOBAL_INITIALIZING_INTERNAL_SERVICE_READY, f as GLOBAL_INITIALIZING_SEND_CONFIG, g as GLOBAL_INITIALIZING_CREATE_ALL_ITEMS_SERVICES, h as GLOBAL_ADDING_MODELS_TO_DB_SUCCESS, d as BROWSER_FS_TOP_DIR, D as DB_CHECK_STATUS_UPDATE_PATHS, i as DB_CHECK_STATUS_EXISTS, j as DB_CREATING_SUCCESS, k as DB_VALIDATING_SUCCESS, l as DB_VALIDATING_WAIT, m as DB_MIGRATING_SUCCESS, n as DB_WAITING_FOR_FILES_RECEIVED, o as DbState, M as MachineIds, p as DB_MIGRATING_WAIT, q as ARWEAVE_HOST, I as INTERNAL_VALIDATING_INPUT_SUCCESS, B as BaseArweaveClient, r as INTERNAL_CONFIGURING_FS_SUCCESS, s as INTERNAL_SAVING_CONFIG_SUCCESS, t as INTERNAL_LOADING_APP_DB_SUCCESS, u as DB_NAME_APP, v as DB_ON_SNAPSHOT, w as InternalState, P as PublishMachineStates, x as GlobalState, y as INTERNAL_DATA_TYPES, z as ImageSize, C as internalPropertyNames, V as VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA, F as defaultAttestationData } from './constants-C-6Pg8FW.js';
|
|
6
6
|
import debug from 'debug';
|
|
7
7
|
import pluralize from 'pluralize';
|
|
8
8
|
import { sqliteTable, int, text, unique, getTableConfig } from 'drizzle-orm/sqlite-core';
|
|
@@ -10,7 +10,6 @@ import { relations, or, and, isNotNull, not, eq, inArray, sql, like, getTableCol
|
|
|
10
10
|
import EventEmitter from 'eventemitter3';
|
|
11
11
|
import { customAlphabet } from 'nanoid';
|
|
12
12
|
import * as nanoIdDictionary from 'nanoid-dictionary';
|
|
13
|
-
import fs from '@zenfs/core';
|
|
14
13
|
import 'graphql-request';
|
|
15
14
|
import { throttle, camelCase, startCase, orderBy } from 'lodash-es';
|
|
16
15
|
import { createBrowserInspector } from '@statelyai/inspect';
|
|
@@ -129,7 +128,7 @@ var BaseDb$1 = /*#__PURE__*/Object.freeze({
|
|
|
129
128
|
BaseDb: BaseDb
|
|
130
129
|
});
|
|
131
130
|
|
|
132
|
-
debug('
|
|
131
|
+
debug('seedSdk:item:service:actors:waitForDb');
|
|
133
132
|
const waitForDb$1 = fromCallback(({ sendBack }) => {
|
|
134
133
|
const _waitForDb = new Promise((resolve) => {
|
|
135
134
|
const interval = setInterval(() => {
|
|
@@ -295,7 +294,7 @@ const initialize$4 = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
295
294
|
|
|
296
295
|
const eventEmitter = new EventEmitter();
|
|
297
296
|
|
|
298
|
-
const logger$
|
|
297
|
+
const logger$o = debug('seedSdk:shared:helpers');
|
|
299
298
|
const { alphanumeric } = nanoIdDictionary;
|
|
300
299
|
const generateId = () => {
|
|
301
300
|
return customAlphabet(alphanumeric, 10)();
|
|
@@ -350,12 +349,13 @@ const getDataTypeFromString = (data) => {
|
|
|
350
349
|
};
|
|
351
350
|
const convertTxIdToImageSrc = async (txId) => {
|
|
352
351
|
const imageFilePath = `/files/images/${txId}`;
|
|
353
|
-
const fileExists = await
|
|
352
|
+
const fileExists = await BaseFileManager.pathExists(imageFilePath);
|
|
354
353
|
if (!fileExists) {
|
|
355
|
-
logger$
|
|
354
|
+
logger$o(`[ItemView] [updateImageSrc] ${imageFilePath} does not exist`);
|
|
356
355
|
return;
|
|
357
356
|
}
|
|
358
|
-
const
|
|
357
|
+
const buffer = await BaseFileManager.readFileAsBuffer(imageFilePath);
|
|
358
|
+
const uint = new Uint8Array(buffer);
|
|
359
359
|
const imageBlob = new Blob([uint]);
|
|
360
360
|
return URL.createObjectURL(imageBlob);
|
|
361
361
|
};
|
|
@@ -1234,7 +1234,7 @@ const getEnvironment = () => {
|
|
|
1234
1234
|
return 'node';
|
|
1235
1235
|
};
|
|
1236
1236
|
|
|
1237
|
-
const logger$
|
|
1237
|
+
const logger$n = debug('seedSdk:services:global:actors:initialize');
|
|
1238
1238
|
const initialize$3 = fromCallback(({ sendBack, input: { event, context } }) => {
|
|
1239
1239
|
const { internalService, models, endpoints, arweaveDomain, addresses, } = context;
|
|
1240
1240
|
if (!internalService) {
|
|
@@ -1253,12 +1253,12 @@ const initialize$3 = fromCallback(({ sendBack, input: { event, context } }) => {
|
|
|
1253
1253
|
const _initInternal = async () => {
|
|
1254
1254
|
return new Promise((resolve) => {
|
|
1255
1255
|
internalSubscription = internalService.subscribe((snapshot) => {
|
|
1256
|
-
logger$
|
|
1256
|
+
logger$n('[sdk] [internal] snapshot.value', snapshot.value);
|
|
1257
1257
|
if (snapshot.value === 'ready') {
|
|
1258
1258
|
resolve();
|
|
1259
1259
|
}
|
|
1260
1260
|
});
|
|
1261
|
-
logger$
|
|
1261
|
+
logger$n('[sdk] [internal] sending init');
|
|
1262
1262
|
internalService.send({
|
|
1263
1263
|
type: 'init',
|
|
1264
1264
|
endpoints,
|
|
@@ -1299,7 +1299,7 @@ const initialize$3 = fromCallback(({ sendBack, input: { event, context } }) => {
|
|
|
1299
1299
|
await fetchSchemaUids();
|
|
1300
1300
|
};
|
|
1301
1301
|
_initFileSystem().then(() => {
|
|
1302
|
-
logger$
|
|
1302
|
+
logger$n('[global/actors] File system initialized');
|
|
1303
1303
|
});
|
|
1304
1304
|
_initInternal()
|
|
1305
1305
|
.then(() => {
|
|
@@ -1309,7 +1309,7 @@ const initialize$3 = fromCallback(({ sendBack, input: { event, context } }) => {
|
|
|
1309
1309
|
return _initEas();
|
|
1310
1310
|
})
|
|
1311
1311
|
.then(() => {
|
|
1312
|
-
logger$
|
|
1312
|
+
logger$n('[global/actors] Internal initialized');
|
|
1313
1313
|
sendBack({ type: GLOBAL_INITIALIZING_INTERNAL_SERVICE_READY });
|
|
1314
1314
|
internalSubscription?.unsubscribe();
|
|
1315
1315
|
});
|
|
@@ -1322,7 +1322,7 @@ const initialize$3 = fromCallback(({ sendBack, input: { event, context } }) => {
|
|
|
1322
1322
|
};
|
|
1323
1323
|
});
|
|
1324
1324
|
|
|
1325
|
-
const logger$
|
|
1325
|
+
const logger$m = debug('seedSdk:services:global:actors:getSchemaForModel');
|
|
1326
1326
|
const getSchemaForModel = fromCallback(({ sendBack, input: { context, event } }) => {
|
|
1327
1327
|
const { modelName } = event;
|
|
1328
1328
|
if (!modelName) {
|
|
@@ -1338,12 +1338,12 @@ const getSchemaForModel = fromCallback(({ sendBack, input: { context, event } })
|
|
|
1338
1338
|
if (!model) {
|
|
1339
1339
|
throw new Error(`Model ${modelName} not found`);
|
|
1340
1340
|
}
|
|
1341
|
-
logger$
|
|
1341
|
+
logger$m('[service/actor] [getSchemaForModel] model:', model);
|
|
1342
1342
|
sendBack({ type: 'schemaForModel', schema: model.schema });
|
|
1343
1343
|
return () => { };
|
|
1344
1344
|
});
|
|
1345
1345
|
|
|
1346
|
-
const logger$
|
|
1346
|
+
const logger$l = debug('seedSdk:services:global:actors:addModelsToDb');
|
|
1347
1347
|
const addModelsToDb = fromCallback(({ sendBack, input: { context } }) => {
|
|
1348
1348
|
const { models: models$1 } = context;
|
|
1349
1349
|
const _addModelsToDb = async () => {
|
|
@@ -1351,7 +1351,7 @@ const addModelsToDb = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
1351
1351
|
if (!models$1) {
|
|
1352
1352
|
return;
|
|
1353
1353
|
}
|
|
1354
|
-
const { models: SeedModels } = await import('./seed.schema.config-
|
|
1354
|
+
const { models: SeedModels } = await import('./seed.schema.config-DmTl3a9U.js');
|
|
1355
1355
|
const allModels = {
|
|
1356
1356
|
...SeedModels,
|
|
1357
1357
|
...models$1,
|
|
@@ -1359,7 +1359,7 @@ const addModelsToDb = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
1359
1359
|
let hasModelsInDb = false;
|
|
1360
1360
|
const schemaDefsByModelName = new Map();
|
|
1361
1361
|
for (const [modelName, _] of Object.entries(allModels)) {
|
|
1362
|
-
logger$
|
|
1362
|
+
logger$l('[helpers/db] [addModelsToInternalDb] starting modelName:', modelName);
|
|
1363
1363
|
let foundModel;
|
|
1364
1364
|
const foundModelsQuery = await appDb
|
|
1365
1365
|
.select()
|
|
@@ -1369,7 +1369,7 @@ const addModelsToDb = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
1369
1369
|
await appDb.insert(models).values({
|
|
1370
1370
|
name: modelName,
|
|
1371
1371
|
});
|
|
1372
|
-
logger$
|
|
1372
|
+
logger$l('[global/actors] [addModelsToDb] inserted model:', modelName);
|
|
1373
1373
|
const foundModels = await appDb
|
|
1374
1374
|
.select({
|
|
1375
1375
|
id: models.id,
|
|
@@ -1439,11 +1439,11 @@ const addModelsToDb = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
1439
1439
|
return () => { };
|
|
1440
1440
|
});
|
|
1441
1441
|
|
|
1442
|
-
const logger$
|
|
1442
|
+
const logger$k = debug('seedSdk:services:db:actors:checkStatus');
|
|
1443
1443
|
const checkStatus = fromCallback(({ sendBack, input: { context, event, } }) => {
|
|
1444
1444
|
const { dbName, } = context;
|
|
1445
1445
|
let { pathToDir, } = context;
|
|
1446
|
-
logger$
|
|
1446
|
+
logger$k('[db/actors] checkStatus context', context);
|
|
1447
1447
|
console.log('[db/actors] checkStatus context', context);
|
|
1448
1448
|
console.log('[db/actors] checkStatus event', event);
|
|
1449
1449
|
if (isBrowser()) {
|
|
@@ -1478,9 +1478,9 @@ const checkStatus = fromCallback(({ sendBack, input: { context, event, } }) => {
|
|
|
1478
1478
|
});
|
|
1479
1479
|
});
|
|
1480
1480
|
|
|
1481
|
-
const logger$
|
|
1481
|
+
const logger$j = debug('seedSdk:services:db:actors:connectToDb');
|
|
1482
1482
|
const connectToDb = fromCallback(({ sendBack, input: { context } }) => {
|
|
1483
|
-
logger$
|
|
1483
|
+
logger$j('[db/actors] connectToDb context', context);
|
|
1484
1484
|
const { dbName, pathToDir } = context;
|
|
1485
1485
|
if (!pathToDir || !dbName) {
|
|
1486
1486
|
throw new Error('pathToDir and dbName are required');
|
|
@@ -1491,6 +1491,12 @@ const connectToDb = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
1491
1491
|
return;
|
|
1492
1492
|
}
|
|
1493
1493
|
isConnecting = true;
|
|
1494
|
+
if (isBrowser()) {
|
|
1495
|
+
await import('./Db-CRWMiKY9.js');
|
|
1496
|
+
}
|
|
1497
|
+
if (!isBrowser()) {
|
|
1498
|
+
await import('./Db-G5dIgZv-.js');
|
|
1499
|
+
}
|
|
1494
1500
|
const dbId = await BaseDb.connectToDb(pathToDir, dbName);
|
|
1495
1501
|
if (dbId) {
|
|
1496
1502
|
sendBack({ type: DB_CREATING_SUCCESS, dbId, });
|
|
@@ -1514,7 +1520,7 @@ const validate = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
1514
1520
|
// If any of the necessary files don't exist, we wipe them all and recreate
|
|
1515
1521
|
let exists = false;
|
|
1516
1522
|
for (const path of pathsToCheck) {
|
|
1517
|
-
exists = await
|
|
1523
|
+
exists = await BaseFileManager.pathExists(path);
|
|
1518
1524
|
if (!exists) {
|
|
1519
1525
|
sendBack({
|
|
1520
1526
|
type: DB_VALIDATING_WAIT,
|
|
@@ -1533,1044 +1539,16 @@ const validate = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
1533
1539
|
});
|
|
1534
1540
|
});
|
|
1535
1541
|
|
|
1536
|
-
const
|
|
1537
|
-
const appDb = BaseDb.getAppDb();
|
|
1538
|
-
await appDb
|
|
1539
|
-
.insert(appState)
|
|
1540
|
-
.values({
|
|
1541
|
-
key,
|
|
1542
|
-
value,
|
|
1543
|
-
})
|
|
1544
|
-
.onConflictDoUpdate({
|
|
1545
|
-
target: appState.key,
|
|
1546
|
-
set: {
|
|
1547
|
-
value,
|
|
1548
|
-
},
|
|
1549
|
-
});
|
|
1550
|
-
};
|
|
1551
|
-
|
|
1552
|
-
var filesDownload = `(
|
|
1553
|
-
${function () {
|
|
1554
|
-
const identifyString = (str) => {
|
|
1555
|
-
try {
|
|
1556
|
-
JSON.parse(str);
|
|
1557
|
-
return 'json';
|
|
1558
|
-
}
|
|
1559
|
-
catch (e) {
|
|
1560
|
-
// Not JSON
|
|
1561
|
-
}
|
|
1562
|
-
if (!str) {
|
|
1563
|
-
return;
|
|
1564
|
-
}
|
|
1565
|
-
if (str.trim().startsWith('<') && str.trim().endsWith('>')) {
|
|
1566
|
-
return 'html';
|
|
1567
|
-
}
|
|
1568
|
-
// Simple markdown checks (very naive)
|
|
1569
|
-
if (/^#{1,6}\s|^-{3,}|\*{3,}|^-{1,2}\s|\*\s/.test(str)) {
|
|
1570
|
-
return 'markdown';
|
|
1571
|
-
}
|
|
1572
|
-
if (/^data:image\/[a-zA-Z]+;base64,[A-Za-z0-9+/]+={0,2}$/.test(str)) {
|
|
1573
|
-
return 'base64';
|
|
1574
|
-
}
|
|
1575
|
-
// Default to plain text if unsure
|
|
1576
|
-
return 'text';
|
|
1577
|
-
};
|
|
1578
|
-
const getMimeType = (base64) => {
|
|
1579
|
-
if (!base64) {
|
|
1580
|
-
return null;
|
|
1581
|
-
}
|
|
1582
|
-
const result = base64.match(/^data:([a-zA-Z0-9]+\/[a-zA-Z0-9-.+]+).*,/);
|
|
1583
|
-
if (result && result.length > 1) {
|
|
1584
|
-
return result[1];
|
|
1585
|
-
}
|
|
1586
|
-
else {
|
|
1587
|
-
return null; // MIME type could not be determined
|
|
1588
|
-
}
|
|
1589
|
-
};
|
|
1590
|
-
const getDataTypeFromString = (data) => {
|
|
1591
|
-
const nonImageBase64Regex = /^(?!data:image\/(?:jpeg|png|gif|bmp|webp);base64,)[A-Za-z0-9+/=]+$/;
|
|
1592
|
-
if (nonImageBase64Regex.test(data)) {
|
|
1593
|
-
return 'base64';
|
|
1594
|
-
}
|
|
1595
|
-
// Regular expression for base64 (simple version, checking for base64 format)
|
|
1596
|
-
const imageBase64Regex = /^data:image\/[a-zA-Z]+;base64,[A-Za-z0-9+/]+={0,2}$/;
|
|
1597
|
-
if (imageBase64Regex.test(data)) {
|
|
1598
|
-
return 'imageBase64';
|
|
1599
|
-
}
|
|
1600
|
-
// Regular expression for URL (simple version, checking for common URL format)
|
|
1601
|
-
const urlRegex = /^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/;
|
|
1602
|
-
if (urlRegex.test(data)) {
|
|
1603
|
-
return 'url';
|
|
1604
|
-
}
|
|
1605
|
-
return null;
|
|
1606
|
-
};
|
|
1607
|
-
const isBinary = (arrayBuffer) => {
|
|
1608
|
-
const view = new Uint8Array(arrayBuffer);
|
|
1609
|
-
let nonTextCount = 0;
|
|
1610
|
-
const threshold = 0.2; // Adjust as needed (e.g., 20% non-text implies binary)
|
|
1611
|
-
for (let i = 0; i < view.length; i++) {
|
|
1612
|
-
const byte = view[i];
|
|
1613
|
-
// ASCII printable characters (32-126) and common whitespace (9, 10, 13)
|
|
1614
|
-
if ((byte >= 32 && byte <= 126) || // Printable ASCII
|
|
1615
|
-
byte === 9 || byte === 10 || byte === 13 // Tab, LF, CR
|
|
1616
|
-
) {
|
|
1617
|
-
continue;
|
|
1618
|
-
}
|
|
1619
|
-
nonTextCount++;
|
|
1620
|
-
if (nonTextCount / view.length > threshold) {
|
|
1621
|
-
return true; // More than threshold are non-text bytes
|
|
1622
|
-
}
|
|
1623
|
-
}
|
|
1624
|
-
return false; // Fewer than threshold are non-text bytes
|
|
1625
|
-
};
|
|
1626
|
-
const saveBufferToOPFS = async (filePath, buffer) => {
|
|
1627
|
-
// Access the OPFS root directory
|
|
1628
|
-
const rootHandle = await navigator.storage.getDirectory();
|
|
1629
|
-
// Split the filePath into directory segments and file name
|
|
1630
|
-
const segments = filePath.split('/').filter(Boolean);
|
|
1631
|
-
const fileName = segments.pop(); // Extract the file name
|
|
1632
|
-
if (!fileName) {
|
|
1633
|
-
throw new Error('Invalid file path: No file name provided.');
|
|
1634
|
-
}
|
|
1635
|
-
// Traverse or create directories as needed
|
|
1636
|
-
let currentDirHandle = rootHandle;
|
|
1637
|
-
for (const segment of segments) {
|
|
1638
|
-
currentDirHandle = await currentDirHandle.getDirectoryHandle(segment, { create: true });
|
|
1639
|
-
}
|
|
1640
|
-
// Create or open the file in OPFS
|
|
1641
|
-
const fileHandleAsync = await currentDirHandle.getFileHandle(fileName, { create: true });
|
|
1642
|
-
const fileHandle = await fileHandleAsync.createSyncAccessHandle();
|
|
1643
|
-
// Write the buffer to the file
|
|
1644
|
-
fileHandle.write(buffer);
|
|
1645
|
-
fileHandle.flush();
|
|
1646
|
-
fileHandle.close();
|
|
1647
|
-
};
|
|
1648
|
-
const downloadFiles = async ({ transactionIds, arweaveHost, }) => {
|
|
1649
|
-
let arrayBuffer;
|
|
1650
|
-
for (const transactionId of transactionIds) {
|
|
1651
|
-
try {
|
|
1652
|
-
const response = await fetch(`https://${arweaveHost}/raw/${transactionId}`);
|
|
1653
|
-
arrayBuffer = await response.arrayBuffer();
|
|
1654
|
-
}
|
|
1655
|
-
catch (error) {
|
|
1656
|
-
console.log(`[filesDownload] transaction ${transactionId} data not found`, error);
|
|
1657
|
-
globalThis.postMessage({
|
|
1658
|
-
message: 'excludeTransaction',
|
|
1659
|
-
transactionId,
|
|
1660
|
-
});
|
|
1661
|
-
continue;
|
|
1662
|
-
}
|
|
1663
|
-
let dataString;
|
|
1664
|
-
const isBinaryData = isBinary(arrayBuffer);
|
|
1665
|
-
if (!isBinaryData) {
|
|
1666
|
-
const decoder = new TextDecoder('utf-8');
|
|
1667
|
-
const text = decoder.decode(arrayBuffer);
|
|
1668
|
-
dataString = text;
|
|
1669
|
-
}
|
|
1670
|
-
if (!dataString && !arrayBuffer) {
|
|
1671
|
-
console.log(`[filesDownload] transaction ${transactionId} data not found`);
|
|
1672
|
-
}
|
|
1673
|
-
if (dataString && dataString.startsWith('===FILE_SEPARATOR===')) {
|
|
1674
|
-
const dataStringParts = dataString
|
|
1675
|
-
.split('===FILE_SEPARATOR===')
|
|
1676
|
-
.slice(1);
|
|
1677
|
-
if (dataStringParts.length % 2 !== 0) {
|
|
1678
|
-
throw new Error('Input array must have an even number of elements.');
|
|
1679
|
-
}
|
|
1680
|
-
for (let i = 0; i < dataStringParts.length; i += 2) {
|
|
1681
|
-
const contentType = dataStringParts[i];
|
|
1682
|
-
const content = dataStringParts[i + 1];
|
|
1683
|
-
const encoder = new TextEncoder();
|
|
1684
|
-
if (contentType === 'html') {
|
|
1685
|
-
const fileName = `${transactionId}.html`;
|
|
1686
|
-
const buffer = encoder.encode(content);
|
|
1687
|
-
saveBufferToOPFS(`/files/html/${fileName}`, buffer);
|
|
1688
|
-
}
|
|
1689
|
-
if (contentType === 'json') {
|
|
1690
|
-
const fileName = `${transactionId}.json`;
|
|
1691
|
-
const buffer = encoder.encode(content);
|
|
1692
|
-
saveBufferToOPFS(`/files/json/${fileName}`, buffer);
|
|
1693
|
-
}
|
|
1694
|
-
}
|
|
1695
|
-
continue;
|
|
1696
|
-
}
|
|
1697
|
-
if (!dataString && arrayBuffer) {
|
|
1698
|
-
saveBufferToOPFS(`/files/images/${transactionId}`, new Uint8Array(arrayBuffer));
|
|
1699
|
-
continue;
|
|
1700
|
-
}
|
|
1701
|
-
if (!dataString) {
|
|
1702
|
-
continue;
|
|
1703
|
-
}
|
|
1704
|
-
let contentType = identifyString(dataString);
|
|
1705
|
-
if (contentType !== 'json' &&
|
|
1706
|
-
contentType !== 'base64' &&
|
|
1707
|
-
contentType !== 'html') {
|
|
1708
|
-
const possibleImageType = getDataTypeFromString(dataString);
|
|
1709
|
-
if (!possibleImageType) {
|
|
1710
|
-
console.log(`[filesDownload] transaction ${transactionId} data not in expected format: ${possibleImageType}`);
|
|
1711
|
-
continue;
|
|
1712
|
-
}
|
|
1713
|
-
contentType = possibleImageType;
|
|
1714
|
-
}
|
|
1715
|
-
if (contentType === 'url') {
|
|
1716
|
-
const url = dataString;
|
|
1717
|
-
let buffer;
|
|
1718
|
-
try {
|
|
1719
|
-
const response = await fetch(url);
|
|
1720
|
-
buffer = await response.arrayBuffer();
|
|
1721
|
-
}
|
|
1722
|
-
catch (error) {
|
|
1723
|
-
console.log(`[filesDownload] transaction ${transactionId} value was url: ${dataString} but failed to fetch`, error);
|
|
1724
|
-
globalThis.postMessage({
|
|
1725
|
-
message: 'excludeTransaction',
|
|
1726
|
-
transactionId,
|
|
1727
|
-
});
|
|
1728
|
-
continue;
|
|
1729
|
-
}
|
|
1730
|
-
const bufferUint8Array = new Uint8Array(buffer);
|
|
1731
|
-
// Extract the file extension from the URL
|
|
1732
|
-
const extensionMatch = url.match(/\.(jpg|jpeg|png|gif|bmp|webp|svg)$/i);
|
|
1733
|
-
if (!extensionMatch) {
|
|
1734
|
-
throw new Error('Unable to determine the file extension from the URL.');
|
|
1735
|
-
}
|
|
1736
|
-
extensionMatch[0]; // e.g., ".jpg"
|
|
1737
|
-
// Set the file name (you can customize this)
|
|
1738
|
-
// const fileNameFromUrl = `${transactionId}${fileExtension}`
|
|
1739
|
-
await saveBufferToOPFS(`/files/images/${transactionId}`, bufferUint8Array);
|
|
1740
|
-
continue;
|
|
1741
|
-
}
|
|
1742
|
-
const mimeType = getMimeType(dataString);
|
|
1743
|
-
let fileExtension = mimeType;
|
|
1744
|
-
if (fileExtension && fileExtension?.startsWith('image')) {
|
|
1745
|
-
fileExtension = fileExtension.replace('image/', '');
|
|
1746
|
-
}
|
|
1747
|
-
let fileName = transactionId;
|
|
1748
|
-
if (contentType === 'base64') {
|
|
1749
|
-
if (fileExtension) {
|
|
1750
|
-
fileName += `.${fileExtension}`;
|
|
1751
|
-
}
|
|
1752
|
-
// Remove the Base64 header if it exists (e.g., "data:image/png;base64,")
|
|
1753
|
-
const base64Data = dataString.split(',').pop() || '';
|
|
1754
|
-
// Decode the Base64 string to binary
|
|
1755
|
-
const binaryString = atob(base64Data);
|
|
1756
|
-
const length = binaryString.length;
|
|
1757
|
-
const binaryData = new Uint8Array(length);
|
|
1758
|
-
for (let i = 0; i < length; i++) {
|
|
1759
|
-
binaryData[i] = binaryString.charCodeAt(i);
|
|
1760
|
-
}
|
|
1761
|
-
await saveBufferToOPFS(`/files/images/${fileName}`, binaryData);
|
|
1762
|
-
}
|
|
1763
|
-
if (contentType === 'html') {
|
|
1764
|
-
fileName += '.html';
|
|
1765
|
-
const encoder = new TextEncoder();
|
|
1766
|
-
const buffer = encoder.encode(dataString);
|
|
1767
|
-
await saveBufferToOPFS(`/files/html/${fileName}`, buffer);
|
|
1768
|
-
}
|
|
1769
|
-
if (contentType === 'json') {
|
|
1770
|
-
fileName += '.json';
|
|
1771
|
-
const encoder = new TextEncoder();
|
|
1772
|
-
const buffer = encoder.encode(dataString);
|
|
1773
|
-
await saveBufferToOPFS(`/files/json/${fileName}`, buffer);
|
|
1774
|
-
}
|
|
1775
|
-
}
|
|
1776
|
-
};
|
|
1777
|
-
onmessage = async (e) => {
|
|
1778
|
-
console.log({
|
|
1779
|
-
message: 'filesDownload onmessage',
|
|
1780
|
-
data: e.data,
|
|
1781
|
-
});
|
|
1782
|
-
await downloadFiles(e.data);
|
|
1783
|
-
globalThis.postMessage({
|
|
1784
|
-
message: 'filesDownload onmessage done',
|
|
1785
|
-
done: true,
|
|
1786
|
-
});
|
|
1787
|
-
};
|
|
1788
|
-
}.toString()}
|
|
1789
|
-
)()`;
|
|
1790
|
-
|
|
1791
|
-
class FileDownloader {
|
|
1792
|
-
constructor() {
|
|
1793
|
-
this.workersArchive = [];
|
|
1794
|
-
this.downloadAll = async ({ transactionIds, arweaveHost, excludedTransactions }) => {
|
|
1795
|
-
if (this.workersArchive.length > 0) {
|
|
1796
|
-
for (let i = 0; i < this.workersArchive.length; i++) {
|
|
1797
|
-
this.workersArchive[i].terminate();
|
|
1798
|
-
delete this.workersArchive[i];
|
|
1799
|
-
}
|
|
1800
|
-
this.workersArchive = [];
|
|
1801
|
-
}
|
|
1802
|
-
const worker = new Worker(this.workerBlobUrl);
|
|
1803
|
-
this.workersArchive.push(worker);
|
|
1804
|
-
const localExcludedTransactions = new Set(excludedTransactions);
|
|
1805
|
-
return new Promise((resolve, reject) => {
|
|
1806
|
-
worker.onmessage = (e) => {
|
|
1807
|
-
console.log('filesDownload main thread onmessage', e.data);
|
|
1808
|
-
if (e.data.message === 'excludeTransaction') {
|
|
1809
|
-
localExcludedTransactions.add(e.data.transactionId);
|
|
1810
|
-
}
|
|
1811
|
-
if (e.data.done) {
|
|
1812
|
-
saveAppState$1('excludedTransactions', JSON.stringify(Array.from(localExcludedTransactions)))
|
|
1813
|
-
.then(() => {
|
|
1814
|
-
resolve(e.data);
|
|
1815
|
-
})
|
|
1816
|
-
.catch((error) => {
|
|
1817
|
-
reject(error);
|
|
1818
|
-
});
|
|
1819
|
-
}
|
|
1820
|
-
if (e.data.error) {
|
|
1821
|
-
reject(e.data.error);
|
|
1822
|
-
}
|
|
1823
|
-
};
|
|
1824
|
-
worker.postMessage({
|
|
1825
|
-
transactionIds,
|
|
1826
|
-
arweaveHost,
|
|
1827
|
-
});
|
|
1828
|
-
});
|
|
1829
|
-
};
|
|
1830
|
-
this.cores = Math.min(navigator.hardwareConcurrency || 4, 4);
|
|
1831
|
-
this.workerBlobUrl = globalThis.URL.createObjectURL(new Blob([filesDownload], { type: 'application/javascript' }));
|
|
1832
|
-
}
|
|
1833
|
-
}
|
|
1834
|
-
|
|
1835
|
-
var imageResize = `(
|
|
1836
|
-
${function () {
|
|
1837
|
-
async function listFilesInDirectory(directoryHandle) {
|
|
1838
|
-
const entries = [];
|
|
1839
|
-
for await (const [name, handle] of directoryHandle.entries()) {
|
|
1840
|
-
entries.push({
|
|
1841
|
-
name,
|
|
1842
|
-
kind: handle.kind,
|
|
1843
|
-
});
|
|
1844
|
-
}
|
|
1845
|
-
return entries;
|
|
1846
|
-
}
|
|
1847
|
-
const getFileHandle = async (path, rootHandle = null) => {
|
|
1848
|
-
// Split the path into segments
|
|
1849
|
-
const segments = path.split('/').filter(Boolean);
|
|
1850
|
-
// Start from the root directory if not provided
|
|
1851
|
-
if (!rootHandle) {
|
|
1852
|
-
rootHandle = await navigator.storage.getDirectory();
|
|
1853
|
-
}
|
|
1854
|
-
let currentHandle = rootHandle;
|
|
1855
|
-
// Traverse the path segments
|
|
1856
|
-
for (let i = 0; i < segments.length; i++) {
|
|
1857
|
-
const segment = segments[i];
|
|
1858
|
-
const isLastSegment = i === segments.length - 1;
|
|
1859
|
-
try {
|
|
1860
|
-
for await (const [name, handle] of currentHandle.entries()) {
|
|
1861
|
-
if (name !== segment) {
|
|
1862
|
-
continue;
|
|
1863
|
-
}
|
|
1864
|
-
if (isLastSegment) {
|
|
1865
|
-
if (handle.kind === 'file') {
|
|
1866
|
-
return handle; // Return the file handle if found
|
|
1867
|
-
}
|
|
1868
|
-
else {
|
|
1869
|
-
throw new Error(`Path '${path}' refers to a directory, not a file.`);
|
|
1870
|
-
}
|
|
1871
|
-
}
|
|
1872
|
-
else if (handle.kind === 'directory') {
|
|
1873
|
-
currentHandle = handle; // Traverse into the directory
|
|
1874
|
-
}
|
|
1875
|
-
else {
|
|
1876
|
-
throw new Error(`Invalid path segment '${segment}'`);
|
|
1877
|
-
}
|
|
1878
|
-
}
|
|
1879
|
-
}
|
|
1880
|
-
catch (err) {
|
|
1881
|
-
if (err instanceof Error && err.name === 'NotFoundError') {
|
|
1882
|
-
throw new Error(`Path '${path}' does not exist.`);
|
|
1883
|
-
}
|
|
1884
|
-
else {
|
|
1885
|
-
throw err;
|
|
1886
|
-
}
|
|
1887
|
-
}
|
|
1888
|
-
}
|
|
1889
|
-
throw new Error(`Path '${path}' could not be resolved.`);
|
|
1890
|
-
};
|
|
1891
|
-
async function getFileFromOPFS(path) {
|
|
1892
|
-
const fileHandleAsync = await getFileHandle(path);
|
|
1893
|
-
const file = await fileHandleAsync.getFile();
|
|
1894
|
-
return file;
|
|
1895
|
-
}
|
|
1896
|
-
const DEFAULT_CONFIG = {
|
|
1897
|
-
argorithm: 'null',
|
|
1898
|
-
processByHalf: true,
|
|
1899
|
-
quality: 0.5,
|
|
1900
|
-
maxWidth: 800,
|
|
1901
|
-
maxHeight: 600,
|
|
1902
|
-
debug: false,
|
|
1903
|
-
mimeType: 'image/jpeg',
|
|
1904
|
-
};
|
|
1905
|
-
function isIos() {
|
|
1906
|
-
if (typeof navigator === 'undefined')
|
|
1907
|
-
return false;
|
|
1908
|
-
if (!navigator.userAgent)
|
|
1909
|
-
return false;
|
|
1910
|
-
return /iPad|iPhone|iPod/.test(navigator.userAgent);
|
|
1911
|
-
}
|
|
1912
|
-
const getTargetHeight = (srcHeight, scale, config) => {
|
|
1913
|
-
return Math.min(Math.floor(srcHeight * scale), config.maxHeight);
|
|
1914
|
-
};
|
|
1915
|
-
const findMaxWidth = (config, canvas) => {
|
|
1916
|
-
//Let's find the max available width for scaled image
|
|
1917
|
-
const ratio = canvas.width / canvas.height;
|
|
1918
|
-
let mWidth = Math.min(canvas.width, config.maxWidth, ratio * config.maxHeight);
|
|
1919
|
-
if (config.maxSize &&
|
|
1920
|
-
config.maxSize > 0 &&
|
|
1921
|
-
config.maxSize < (canvas.width * canvas.height) / 1000)
|
|
1922
|
-
mWidth = Math.min(mWidth, Math.floor((config.maxSize * 1000) / canvas.height));
|
|
1923
|
-
if (!!config.scaleRatio)
|
|
1924
|
-
mWidth = Math.min(mWidth, Math.floor(config.scaleRatio * canvas.width));
|
|
1925
|
-
const rHeight = getTargetHeight(canvas.height, mWidth / canvas.width, config);
|
|
1926
|
-
// console.log(
|
|
1927
|
-
// 'browser-image-resizer: original image size = ' +
|
|
1928
|
-
// canvas.width +
|
|
1929
|
-
// ' px (width) X ' +
|
|
1930
|
-
// canvas.height +
|
|
1931
|
-
// ' px (height)'
|
|
1932
|
-
// );
|
|
1933
|
-
// console.log(
|
|
1934
|
-
// 'browser-image-resizer: scaled image size = ' +
|
|
1935
|
-
// mWidth +
|
|
1936
|
-
// ' px (width) X ' +
|
|
1937
|
-
// rHeight +
|
|
1938
|
-
// ' px (height)'
|
|
1939
|
-
// );
|
|
1940
|
-
if (mWidth <= 0) {
|
|
1941
|
-
mWidth = 1;
|
|
1942
|
-
console.warn("browser-image-resizer: image size is too small");
|
|
1943
|
-
}
|
|
1944
|
-
if (isIos() && mWidth * rHeight > 167777216) {
|
|
1945
|
-
console.error("browser-image-resizer: image size is too large for iOS WebKit.", mWidth, rHeight);
|
|
1946
|
-
throw new Error("browser-image-resizer: image size is too large for iOS WebKit.");
|
|
1947
|
-
}
|
|
1948
|
-
return mWidth;
|
|
1949
|
-
};
|
|
1950
|
-
/**
|
|
1951
|
-
* Hermite resize, multicore version - fast image resize/resample using Hermite filter.
|
|
1952
|
-
*/
|
|
1953
|
-
const resample = (srcCanvas, destCanvas, config) => {
|
|
1954
|
-
return new Promise((resolve, reject) => {
|
|
1955
|
-
const ratio_h = srcCanvas.height / destCanvas.height;
|
|
1956
|
-
const cores = Math.min(navigator.hardwareConcurrency || 4, 4);
|
|
1957
|
-
//prepare source and target data for workers
|
|
1958
|
-
const ctx = srcCanvas.getContext('2d');
|
|
1959
|
-
if (!ctx)
|
|
1960
|
-
return reject('Canvas is empty (resample)');
|
|
1961
|
-
const data_part = [];
|
|
1962
|
-
const block_height = Math.ceil(srcCanvas.height / cores / 2) * 2;
|
|
1963
|
-
let end_y = -1;
|
|
1964
|
-
for (let c = 0; c < cores; c++) {
|
|
1965
|
-
//source
|
|
1966
|
-
const offset_y = end_y + 1;
|
|
1967
|
-
if (offset_y >= srcCanvas.height) {
|
|
1968
|
-
//size too small, nothing left for this core
|
|
1969
|
-
continue;
|
|
1970
|
-
}
|
|
1971
|
-
end_y = Math.min(offset_y + block_height - 1, srcCanvas.height - 1);
|
|
1972
|
-
const current_block_height = Math.min(block_height, srcCanvas.height - offset_y);
|
|
1973
|
-
console.log('browser-image-resizer: source split: ', '#' + c, offset_y, end_y, 'height: ' + current_block_height);
|
|
1974
|
-
data_part.push({
|
|
1975
|
-
source: ctx.getImageData(0, offset_y, srcCanvas.width, block_height),
|
|
1976
|
-
startY: Math.ceil(offset_y / ratio_h),
|
|
1977
|
-
height: current_block_height
|
|
1978
|
-
});
|
|
1979
|
-
}
|
|
1980
|
-
//start
|
|
1981
|
-
const destCtx = destCanvas.getContext('2d');
|
|
1982
|
-
if (!destCtx)
|
|
1983
|
-
return reject('Canvas is empty (resample dest)');
|
|
1984
|
-
for (let c = 0; c < data_part.length; c++) {
|
|
1985
|
-
//draw
|
|
1986
|
-
const height_part = Math.ceil(data_part[c].height / ratio_h);
|
|
1987
|
-
const target = destCtx.createImageData(destCanvas.width, height_part);
|
|
1988
|
-
// target.data.set(event.data.target);
|
|
1989
|
-
destCtx.putImageData(target, 0, data_part[c].startY);
|
|
1990
|
-
}
|
|
1991
|
-
});
|
|
1992
|
-
};
|
|
1993
|
-
/**
|
|
1994
|
-
* Hermite resize - fast image resize/resample using Hermite filter. 1 cpu version!
|
|
1995
|
-
*/
|
|
1996
|
-
const resampleSingle = (srcCanvasData, destCanvasData) => {
|
|
1997
|
-
const ratio_w = srcCanvasData.width / destCanvasData.width;
|
|
1998
|
-
const ratio_h = srcCanvasData.height / destCanvasData.height;
|
|
1999
|
-
const ratio_w_half = Math.ceil(ratio_w / 2);
|
|
2000
|
-
const ratio_h_half = Math.ceil(ratio_h / 2);
|
|
2001
|
-
const data = srcCanvasData.data;
|
|
2002
|
-
const data2 = destCanvasData.data;
|
|
2003
|
-
for (let j = 0; j < destCanvasData.height; j++) {
|
|
2004
|
-
for (let i = 0; i < destCanvasData.width; i++) {
|
|
2005
|
-
const x2 = (i + j * destCanvasData.width) * 4;
|
|
2006
|
-
let weight = 0;
|
|
2007
|
-
let weights = 0;
|
|
2008
|
-
let weights_alpha = 0;
|
|
2009
|
-
let gx_r = 0;
|
|
2010
|
-
let gx_g = 0;
|
|
2011
|
-
let gx_b = 0;
|
|
2012
|
-
let gx_a = 0;
|
|
2013
|
-
const center_y = j * ratio_h;
|
|
2014
|
-
const xx_start = Math.floor(i * ratio_w);
|
|
2015
|
-
const xx_stop = Math.min(Math.ceil((i + 1) * ratio_w), srcCanvasData.width);
|
|
2016
|
-
const yy_start = Math.floor(j * ratio_h);
|
|
2017
|
-
const yy_stop = Math.min(Math.ceil((j + 1) * ratio_h), srcCanvasData.height);
|
|
2018
|
-
for (let yy = yy_start; yy < yy_stop; yy++) {
|
|
2019
|
-
let dy = Math.abs(center_y - yy) / ratio_h_half;
|
|
2020
|
-
let center_x = i * ratio_w;
|
|
2021
|
-
let w0 = dy * dy; //pre-calc part of w
|
|
2022
|
-
for (let xx = xx_start; xx < xx_stop; xx++) {
|
|
2023
|
-
let dx = Math.abs(center_x - xx) / ratio_w_half;
|
|
2024
|
-
let w = Math.sqrt(w0 + dx * dx);
|
|
2025
|
-
if (w >= 1) {
|
|
2026
|
-
//pixel too far
|
|
2027
|
-
continue;
|
|
2028
|
-
}
|
|
2029
|
-
//hermite filter
|
|
2030
|
-
weight = 2 * w * w * w - 3 * w * w + 1;
|
|
2031
|
-
let pos_x = 4 * (xx + yy * srcCanvasData.width);
|
|
2032
|
-
//alpha
|
|
2033
|
-
gx_a += weight * data[pos_x + 3];
|
|
2034
|
-
weights_alpha += weight;
|
|
2035
|
-
//colors
|
|
2036
|
-
if (data[pos_x + 3] < 255)
|
|
2037
|
-
weight = weight * data[pos_x + 3] / 250;
|
|
2038
|
-
gx_r += weight * data[pos_x];
|
|
2039
|
-
gx_g += weight * data[pos_x + 1];
|
|
2040
|
-
gx_b += weight * data[pos_x + 2];
|
|
2041
|
-
weights += weight;
|
|
2042
|
-
}
|
|
2043
|
-
}
|
|
2044
|
-
data2[x2] = gx_r / weights;
|
|
2045
|
-
data2[x2 + 1] = gx_g / weights;
|
|
2046
|
-
data2[x2 + 2] = gx_b / weights;
|
|
2047
|
-
data2[x2 + 3] = gx_a / weights_alpha;
|
|
2048
|
-
}
|
|
2049
|
-
}
|
|
2050
|
-
};
|
|
2051
|
-
/**
|
|
2052
|
-
* Hermite resize. Detect cpu count and use best option for user.
|
|
2053
|
-
*/
|
|
2054
|
-
const resampleAuto = (srcCanvas, destCanvas, config) => {
|
|
2055
|
-
if (!!globalThis.Worker && navigator.hardwareConcurrency > 1 && config?.argorithm !== 'hermite_single') {
|
|
2056
|
-
//workers supported and we have at least 2 cpu cores - using multithreading
|
|
2057
|
-
return resample(srcCanvas, destCanvas);
|
|
2058
|
-
}
|
|
2059
|
-
else {
|
|
2060
|
-
//1 cpu version
|
|
2061
|
-
const { srcImgData, destImgData } = getImageData(srcCanvas, destCanvas);
|
|
2062
|
-
resampleSingle(srcImgData, destImgData);
|
|
2063
|
-
destCanvas.getContext('2d').putImageData(destImgData, 0, 0);
|
|
2064
|
-
return;
|
|
2065
|
-
}
|
|
2066
|
-
};
|
|
2067
|
-
async function scaleCanvasWithAlgorithm(canvas, config) {
|
|
2068
|
-
const scale = config.outputWidth / canvas.width;
|
|
2069
|
-
const scaled = new OffscreenCanvas(Math.floor(config.outputWidth), getTargetHeight(canvas.height, scale, config));
|
|
2070
|
-
switch (config.algorithm) {
|
|
2071
|
-
case 'hermite': {
|
|
2072
|
-
await resampleAuto(canvas, scaled, config);
|
|
2073
|
-
break;
|
|
2074
|
-
}
|
|
2075
|
-
case 'hermite_single': {
|
|
2076
|
-
const { srcImgData, destImgData } = getImageData(canvas, scaled);
|
|
2077
|
-
resampleSingle(srcImgData, destImgData);
|
|
2078
|
-
scaled?.getContext('2d')?.putImageData(destImgData, 0, 0);
|
|
2079
|
-
break;
|
|
2080
|
-
}
|
|
2081
|
-
case 'bilinear': {
|
|
2082
|
-
// const { srcImgData, destImgData } = getImageData(canvas, scaled);
|
|
2083
|
-
// bilinear(srcImgData, destImgData, scale);
|
|
2084
|
-
// scaled?.getContext('2d')?.putImageData(destImgData, 0, 0);
|
|
2085
|
-
break;
|
|
2086
|
-
}
|
|
2087
|
-
default: {
|
|
2088
|
-
scaled.getContext('2d')?.drawImage(canvas, 0, 0, scaled.width, scaled.height);
|
|
2089
|
-
break;
|
|
2090
|
-
}
|
|
2091
|
-
}
|
|
2092
|
-
return scaled;
|
|
2093
|
-
}
|
|
2094
|
-
const getHalfScaleCanvas = (src) => {
|
|
2095
|
-
const half = new OffscreenCanvas(src.width / 2, src.height / 2);
|
|
2096
|
-
half
|
|
2097
|
-
?.getContext('2d')
|
|
2098
|
-
?.drawImage(src, 0, 0, half.width, half.height);
|
|
2099
|
-
return half;
|
|
2100
|
-
};
|
|
2101
|
-
const getImageData = (canvas, scaled) => {
|
|
2102
|
-
const srcImgData = canvas
|
|
2103
|
-
?.getContext('2d')
|
|
2104
|
-
?.getImageData(0, 0, canvas.width, canvas.height);
|
|
2105
|
-
const destImgData = scaled
|
|
2106
|
-
?.getContext('2d')
|
|
2107
|
-
?.createImageData(scaled.width, scaled.height);
|
|
2108
|
-
if (!srcImgData || !destImgData)
|
|
2109
|
-
throw Error('Canvas is empty (scaleCanvasWithAlgorithm). You should run this script after the document is ready.');
|
|
2110
|
-
return { srcImgData, destImgData };
|
|
2111
|
-
};
|
|
2112
|
-
async function saveBlobToOPFS(filePath, blob) {
|
|
2113
|
-
// Access the OPFS root directory
|
|
2114
|
-
const rootHandle = await navigator.storage.getDirectory();
|
|
2115
|
-
// Split the filePath into directory segments and file name
|
|
2116
|
-
const segments = filePath.split('/').filter(Boolean);
|
|
2117
|
-
const fileName = segments.pop(); // Extract the file name
|
|
2118
|
-
if (!fileName) {
|
|
2119
|
-
throw new Error('Invalid file path: No file name provided.');
|
|
2120
|
-
}
|
|
2121
|
-
// Traverse or create directories as needed
|
|
2122
|
-
let currentDirHandle = rootHandle;
|
|
2123
|
-
for (const segment of segments) {
|
|
2124
|
-
currentDirHandle = await currentDirHandle.getDirectoryHandle(segment, { create: true });
|
|
2125
|
-
}
|
|
2126
|
-
// Create or open the file in OPFS
|
|
2127
|
-
const fileHandle = await currentDirHandle.getFileHandle(fileName, { create: true });
|
|
2128
|
-
// Write the Blob to the file
|
|
2129
|
-
const writableStream = await fileHandle.createWritable();
|
|
2130
|
-
await writableStream.write(blob);
|
|
2131
|
-
await writableStream.close();
|
|
2132
|
-
}
|
|
2133
|
-
const imageResize = async (filePath, width, height) => {
|
|
2134
|
-
console.log({ filePath, width, height });
|
|
2135
|
-
const config = {
|
|
2136
|
-
...DEFAULT_CONFIG,
|
|
2137
|
-
algorithm: 'hermite_single',
|
|
2138
|
-
mimeType: 'image/webp',
|
|
2139
|
-
maxWidth: width,
|
|
2140
|
-
maxHeight: height,
|
|
2141
|
-
};
|
|
2142
|
-
const rootHandle = await navigator.storage.getDirectory();
|
|
2143
|
-
// List files in the root directory
|
|
2144
|
-
const files = await listFilesInDirectory(rootHandle);
|
|
2145
|
-
console.log({
|
|
2146
|
-
message: 'listFilesInDirectory',
|
|
2147
|
-
files
|
|
2148
|
-
});
|
|
2149
|
-
const file = await getFileFromOPFS(filePath);
|
|
2150
|
-
const imageBitmap = await createImageBitmap(file);
|
|
2151
|
-
let converting;
|
|
2152
|
-
if (isIos() && imageBitmap.width * imageBitmap.height > 16777216) {
|
|
2153
|
-
const scale = Math.sqrt(16777216 / (imageBitmap.width * imageBitmap.height));
|
|
2154
|
-
console.log(`browser-image-resizer: scale: Image is too large in iOS WebKit`);
|
|
2155
|
-
converting = new OffscreenCanvas(Math.floor(imageBitmap.width * scale), Math.floor(imageBitmap.height * scale));
|
|
2156
|
-
converting.getContext('2d')?.drawImage(imageBitmap, 0, 0, converting.width, converting.height);
|
|
2157
|
-
}
|
|
2158
|
-
else {
|
|
2159
|
-
converting = new OffscreenCanvas(imageBitmap.width, imageBitmap.height);
|
|
2160
|
-
converting.getContext('2d')?.drawImage(imageBitmap, 0, 0);
|
|
2161
|
-
}
|
|
2162
|
-
if (!converting?.getContext('2d')) {
|
|
2163
|
-
console.log('browser-image-resizer: Canvas Context is empty.');
|
|
2164
|
-
}
|
|
2165
|
-
const maxWidth = findMaxWidth(config, converting);
|
|
2166
|
-
if (!maxWidth) {
|
|
2167
|
-
throw Error(`browser-image-resizer: maxWidth is ${maxWidth}!!`);
|
|
2168
|
-
}
|
|
2169
|
-
while (config.processByHalf && converting.width >= 2 * maxWidth) {
|
|
2170
|
-
if (config.debug)
|
|
2171
|
-
console.log(`browser-image-resizer: scale: Scaling canvas by half from ${converting.width}`);
|
|
2172
|
-
converting = getHalfScaleCanvas(converting);
|
|
2173
|
-
}
|
|
2174
|
-
if (converting.width > maxWidth) {
|
|
2175
|
-
if (config.debug)
|
|
2176
|
-
console.log(`browser-image-resizer: scale: Scaling canvas by ${config.argorithm} from ${converting.width} to ${maxWidth}`);
|
|
2177
|
-
converting = await scaleCanvasWithAlgorithm(converting, Object.assign(config, { outputWidth: maxWidth }));
|
|
2178
|
-
}
|
|
2179
|
-
if (config.mimeType === null) {
|
|
2180
|
-
return converting;
|
|
2181
|
-
}
|
|
2182
|
-
const resizedBlob = await converting.convertToBlob({ type: config.mimeType, quality: config.quality });
|
|
2183
|
-
const pathSegments = filePath.split('/');
|
|
2184
|
-
const fileName = pathSegments.pop();
|
|
2185
|
-
if (!fileName) {
|
|
2186
|
-
throw Error('Invalid file path: No file name provided.');
|
|
2187
|
-
}
|
|
2188
|
-
const newSegments = [
|
|
2189
|
-
...pathSegments,
|
|
2190
|
-
width,
|
|
2191
|
-
];
|
|
2192
|
-
const fileNameParts = fileName.split('.');
|
|
2193
|
-
const newFileName = `${fileNameParts[0]}.webp`;
|
|
2194
|
-
const newDirPath = newSegments.join('/');
|
|
2195
|
-
const newFilePath = `${newDirPath}/${newFileName}`;
|
|
2196
|
-
// Save resized image to OPFS with new name
|
|
2197
|
-
await saveBlobToOPFS(newFilePath, resizedBlob);
|
|
2198
|
-
globalThis.postMessage({
|
|
2199
|
-
done: true,
|
|
2200
|
-
filePath: newFilePath,
|
|
2201
|
-
});
|
|
2202
|
-
};
|
|
2203
|
-
onmessage = async (e) => {
|
|
2204
|
-
console.log('[imageResize] onmessage', e.data);
|
|
2205
|
-
const { filePath, width, height } = e.data;
|
|
2206
|
-
await imageResize(filePath, width, height);
|
|
2207
|
-
console.log(`[imageResize] Done`, filePath);
|
|
2208
|
-
};
|
|
2209
|
-
}.toString()}
|
|
2210
|
-
)()`;
|
|
2211
|
-
|
|
2212
|
-
class ImageResizer {
|
|
2213
|
-
constructor() {
|
|
2214
|
-
this.workersArchive = new Map();
|
|
2215
|
-
this.cores = Math.min(navigator.hardwareConcurrency || 4, 4);
|
|
2216
|
-
this.workerBlobUrl = globalThis.URL.createObjectURL(new Blob([imageResize], { type: 'application/javascript' }));
|
|
2217
|
-
}
|
|
2218
|
-
async resize({ filePath, width, height }) {
|
|
2219
|
-
if (this.workersArchive.has(filePath)) {
|
|
2220
|
-
const savedWorker = this.workersArchive.get(filePath);
|
|
2221
|
-
savedWorker?.terminate();
|
|
2222
|
-
console.log('[ImageResizer.resize] Terminated worker for filePath due to incoming request', filePath);
|
|
2223
|
-
this.workersArchive.delete(filePath);
|
|
2224
|
-
}
|
|
2225
|
-
const worker = new Worker(this.workerBlobUrl);
|
|
2226
|
-
this.workersArchive.set(filePath, worker);
|
|
2227
|
-
return new Promise((resolve, reject) => {
|
|
2228
|
-
worker.onmessage = (e) => {
|
|
2229
|
-
console.log('[ImageResizer.resize] main thread onmessage', e.data);
|
|
2230
|
-
if (e.data.done) {
|
|
2231
|
-
const savedWorker = this.workersArchive.get(filePath);
|
|
2232
|
-
savedWorker?.terminate();
|
|
2233
|
-
console.log('[ImageResizer.resize] Terminated worker for filePath due to done', filePath);
|
|
2234
|
-
this.workersArchive.delete(filePath);
|
|
2235
|
-
resolve(e.data);
|
|
2236
|
-
}
|
|
2237
|
-
if (e.data.error) {
|
|
2238
|
-
reject(e.data.error);
|
|
2239
|
-
}
|
|
2240
|
-
};
|
|
2241
|
-
worker.postMessage({
|
|
2242
|
-
filePath,
|
|
2243
|
-
width,
|
|
2244
|
-
height,
|
|
2245
|
-
});
|
|
2246
|
-
});
|
|
2247
|
-
}
|
|
2248
|
-
async resizeAll({ width, height }) {
|
|
2249
|
-
const imageDir = '/files/images';
|
|
2250
|
-
let imageFilesStats = await fs.promises.readdir(imageDir, {
|
|
2251
|
-
withFileTypes: true
|
|
2252
|
-
});
|
|
2253
|
-
imageFilesStats = imageFilesStats.filter(file => file.isFile());
|
|
2254
|
-
const imageFiles = imageFilesStats.map(file => file.path);
|
|
2255
|
-
const widthDir = `${imageDir}/${width}`;
|
|
2256
|
-
await FileManager.createDirIfNotExists(widthDir);
|
|
2257
|
-
for (const imageFile of imageFiles) {
|
|
2258
|
-
const resizedImageExists = await fs.promises.exists(`${widthDir}/${imageFile}`);
|
|
2259
|
-
if (!resizedImageExists) {
|
|
2260
|
-
await this.resize({ filePath: `${imageDir}/${imageFile}`, width, height });
|
|
2261
|
-
}
|
|
2262
|
-
}
|
|
2263
|
-
}
|
|
2264
|
-
}
|
|
2265
|
-
|
|
2266
|
-
const logger$j = debug('app:browser:helpers:FileManager');
|
|
2267
|
-
class FileManager extends BaseFileManager {
|
|
2268
|
-
static async getContentUrlFromPath(path) {
|
|
2269
|
-
const fileExists = await this.pathExists(path);
|
|
2270
|
-
if (fileExists) {
|
|
2271
|
-
const file = await this.readFile(path);
|
|
2272
|
-
return URL.createObjectURL(file);
|
|
2273
|
-
}
|
|
2274
|
-
}
|
|
2275
|
-
static async initializeFileSystem() {
|
|
2276
|
-
const { WebAccess } = await import('@zenfs/dom');
|
|
2277
|
-
const { configureSingle } = await import('@zenfs/core');
|
|
2278
|
-
const handle = await navigator.storage.getDirectory();
|
|
2279
|
-
// await configure({
|
|
2280
|
-
// mounts: {
|
|
2281
|
-
// '/': {
|
|
2282
|
-
// backend: WebAccess,
|
|
2283
|
-
// handle,
|
|
2284
|
-
// },
|
|
2285
|
-
// },
|
|
2286
|
-
// disableUpdateOnRead: true,
|
|
2287
|
-
// onlySyncOnClose: true,
|
|
2288
|
-
// })
|
|
2289
|
-
await configureSingle({
|
|
2290
|
-
backend: WebAccess,
|
|
2291
|
-
handle,
|
|
2292
|
-
});
|
|
2293
|
-
}
|
|
2294
|
-
static async downloadAllFiles({ transactionIds, arweaveHost, excludedTransactions, }) {
|
|
2295
|
-
const fileDownloader = new FileDownloader();
|
|
2296
|
-
await fileDownloader.downloadAll({ transactionIds, arweaveHost, excludedTransactions });
|
|
2297
|
-
}
|
|
2298
|
-
static async resizeImage({ filePath, width, height }) {
|
|
2299
|
-
const imageResizer = new ImageResizer();
|
|
2300
|
-
await imageResizer.resize({ filePath, width, height });
|
|
2301
|
-
}
|
|
2302
|
-
static async resizeAllImages({ width, height }) {
|
|
2303
|
-
const imageResizer = new ImageResizer();
|
|
2304
|
-
await imageResizer.resizeAll({ width, height });
|
|
2305
|
-
}
|
|
2306
|
-
static async pathExists(filePath) {
|
|
2307
|
-
try {
|
|
2308
|
-
// Access the root directory of OPFS
|
|
2309
|
-
const root = await navigator.storage.getDirectory();
|
|
2310
|
-
// Split the path into segments
|
|
2311
|
-
const parts = filePath.split('/').filter(Boolean);
|
|
2312
|
-
let currentDir = root;
|
|
2313
|
-
// Traverse each part of the path
|
|
2314
|
-
for (let i = 0; i < parts.length; i++) {
|
|
2315
|
-
const part = parts[i];
|
|
2316
|
-
try {
|
|
2317
|
-
const handle = await currentDir.getDirectoryHandle(part, { create: false });
|
|
2318
|
-
currentDir = handle; // Move into the directory
|
|
2319
|
-
}
|
|
2320
|
-
catch (error) {
|
|
2321
|
-
try {
|
|
2322
|
-
// If it's not a directory, check if it's a file
|
|
2323
|
-
await currentDir.getFileHandle(part, { create: false });
|
|
2324
|
-
// If we successfully got a file handle and it's the last part, return true
|
|
2325
|
-
return i === parts.length - 1;
|
|
2326
|
-
}
|
|
2327
|
-
catch {
|
|
2328
|
-
// Neither a directory nor a file exists
|
|
2329
|
-
return false;
|
|
2330
|
-
}
|
|
2331
|
-
}
|
|
2332
|
-
}
|
|
2333
|
-
return true; // Directory exists
|
|
2334
|
-
}
|
|
2335
|
-
catch (error) {
|
|
2336
|
-
return false; // Any error means the path does not exist
|
|
2337
|
-
}
|
|
2338
|
-
}
|
|
2339
|
-
static async createDirIfNotExists(filePath) {
|
|
2340
|
-
if (!(await FileManager.pathExists(filePath))) {
|
|
2341
|
-
try {
|
|
2342
|
-
const fs = await import('@zenfs/core');
|
|
2343
|
-
await fs.promises.mkdir(filePath);
|
|
2344
|
-
}
|
|
2345
|
-
catch (error) {
|
|
2346
|
-
// This is a no-op. We tried to create a directory that already exists.
|
|
2347
|
-
console.log('Attempted to create a directory that already exists');
|
|
2348
|
-
}
|
|
2349
|
-
}
|
|
2350
|
-
}
|
|
2351
|
-
/**
|
|
2352
|
-
* Waits for a file to exist at the specified path.
|
|
2353
|
-
* @param {string} filePath - The path of the file to check.
|
|
2354
|
-
* @param {number} interval - The interval in milliseconds between checks (default: 500ms).
|
|
2355
|
-
* @param {number} timeout - The timeout in milliseconds to wait for the file to exist (default: 10s).
|
|
2356
|
-
* @returns {Promise<boolean>} - Resolves to true if the file exists within the timeout period, otherwise false.
|
|
2357
|
-
*/
|
|
2358
|
-
static async waitForFile(filePath, interval = 1000, timeout = 60000) {
|
|
2359
|
-
const fs = await import('@zenfs/core');
|
|
2360
|
-
const fsNode = await import('node:fs');
|
|
2361
|
-
return new Promise((resolve, reject) => {
|
|
2362
|
-
const startTime = Date.now();
|
|
2363
|
-
let isBusy = false;
|
|
2364
|
-
const cancelableInterval = new CancelableInterval(async (stop) => {
|
|
2365
|
-
logger$j('waitForFile', filePath);
|
|
2366
|
-
if (isBusy) {
|
|
2367
|
-
return;
|
|
2368
|
-
}
|
|
2369
|
-
isBusy = true;
|
|
2370
|
-
// TODO: Needs to read from OPFS
|
|
2371
|
-
if (fs.existsSync(filePath) && fsNode.existsSync(filePath)) {
|
|
2372
|
-
stop();
|
|
2373
|
-
resolve(true);
|
|
2374
|
-
}
|
|
2375
|
-
const pathExists = await this.pathExists(filePath);
|
|
2376
|
-
if (pathExists) {
|
|
2377
|
-
stop();
|
|
2378
|
-
resolve(true);
|
|
2379
|
-
}
|
|
2380
|
-
if (Date.now() - startTime >= timeout) {
|
|
2381
|
-
stop();
|
|
2382
|
-
reject(new Error('Timeout exceeded while waiting for file'));
|
|
2383
|
-
}
|
|
2384
|
-
isBusy = false;
|
|
2385
|
-
}, interval);
|
|
2386
|
-
cancelableInterval.start();
|
|
2387
|
-
// const _interval = setInterval(async () => {
|
|
2388
|
-
// logger('waitForFile', filePath)
|
|
2389
|
-
// if (isBusy) {
|
|
2390
|
-
// return
|
|
2391
|
-
// }
|
|
2392
|
-
// isBusy = true
|
|
2393
|
-
// // TODO: Needs to read from OPFS
|
|
2394
|
-
// if (fs.existsSync(filePath) && fsNode.existsSync(filePath)) {
|
|
2395
|
-
// clearInterval(_interval)
|
|
2396
|
-
// resolve(true)
|
|
2397
|
-
// }
|
|
2398
|
-
// const pathExists = await this.pathExists(filePath)
|
|
2399
|
-
// if (pathExists) {
|
|
2400
|
-
// clearInterval(_interval)
|
|
2401
|
-
// resolve(true)
|
|
2402
|
-
// }
|
|
2403
|
-
// if (Date.now() - startTime >= timeout) {
|
|
2404
|
-
// clearInterval(_interval)
|
|
2405
|
-
// reject(new Error('Timeout exceeded while waiting for file'))
|
|
2406
|
-
// }
|
|
2407
|
-
// isBusy = false
|
|
2408
|
-
// }, interval)
|
|
2409
|
-
// retry(
|
|
2410
|
-
// {
|
|
2411
|
-
// times: Math.ceil(timeout / interval),
|
|
2412
|
-
// interval: interval,
|
|
2413
|
-
// },
|
|
2414
|
-
// (callback: Function) => {
|
|
2415
|
-
// if (fs.existsSync(filePath) && fsNode.existsSync(filePath)) {
|
|
2416
|
-
// return callback(null, true) // File exists, finish with success
|
|
2417
|
-
// }
|
|
2418
|
-
// if (Date.now() - startTime >= timeout) {
|
|
2419
|
-
// return callback(new Error('Timeout exceeded while waiting for file'))
|
|
2420
|
-
// }
|
|
2421
|
-
// callback(new Error('File does not exist yet')) // Retry with this error
|
|
2422
|
-
// },
|
|
2423
|
-
// (err: Error, result: boolean) => {
|
|
2424
|
-
// if (err) {
|
|
2425
|
-
// return resolve(false) // Resolve as false if timeout or error occurs
|
|
2426
|
-
// }
|
|
2427
|
-
// resolve(result) // Resolve as true if file exists
|
|
2428
|
-
// },
|
|
2429
|
-
// )
|
|
2430
|
-
});
|
|
2431
|
-
}
|
|
2432
|
-
static async saveFile(filePath, content) {
|
|
2433
|
-
try {
|
|
2434
|
-
// Get a handle to the OPFS root directory
|
|
2435
|
-
const root = await navigator.storage.getDirectory();
|
|
2436
|
-
// Split the file path into directory and file name
|
|
2437
|
-
const pathParts = filePath.split('/');
|
|
2438
|
-
const fileName = pathParts.pop();
|
|
2439
|
-
if (!fileName)
|
|
2440
|
-
throw new Error('Invalid file path');
|
|
2441
|
-
// Traverse directories and create them if they don't exist
|
|
2442
|
-
let currentDir = root;
|
|
2443
|
-
for (const part of pathParts) {
|
|
2444
|
-
if (part !== '') {
|
|
2445
|
-
currentDir = await currentDir.getDirectoryHandle(part, { create: true });
|
|
2446
|
-
}
|
|
2447
|
-
}
|
|
2448
|
-
// Get the file handle and create the file if it doesn't exist
|
|
2449
|
-
const fileHandle = await currentDir.getFileHandle(fileName, { create: true });
|
|
2450
|
-
// Create a writable stream and write the content
|
|
2451
|
-
const writable = await fileHandle.createWritable();
|
|
2452
|
-
if (typeof content === 'string' || content instanceof Uint8Array) {
|
|
2453
|
-
await writable.write(content);
|
|
2454
|
-
}
|
|
2455
|
-
else if (content instanceof Blob) {
|
|
2456
|
-
await writable.write(content);
|
|
2457
|
-
}
|
|
2458
|
-
else if (content instanceof ArrayBuffer) {
|
|
2459
|
-
await writable.write(new Blob([content]));
|
|
2460
|
-
}
|
|
2461
|
-
else {
|
|
2462
|
-
throw new Error('Unsupported content type');
|
|
2463
|
-
}
|
|
2464
|
-
await writable.close();
|
|
2465
|
-
console.log(`File written successfully: ${filePath}`);
|
|
2466
|
-
}
|
|
2467
|
-
catch (error) {
|
|
2468
|
-
console.error(`Error writing to OPFS: ${error.message}`);
|
|
2469
|
-
}
|
|
2470
|
-
}
|
|
2471
|
-
static async readFile(filePath) {
|
|
2472
|
-
try {
|
|
2473
|
-
// Get a handle to the OPFS root directory
|
|
2474
|
-
const root = await navigator.storage.getDirectory();
|
|
2475
|
-
// Split the file path into directory and file name
|
|
2476
|
-
const pathParts = filePath.split('/');
|
|
2477
|
-
const fileName = pathParts.pop();
|
|
2478
|
-
if (!fileName)
|
|
2479
|
-
throw new Error('Invalid file path');
|
|
2480
|
-
// Traverse directories to reach the target file
|
|
2481
|
-
let currentDir = root;
|
|
2482
|
-
for (const part of pathParts) {
|
|
2483
|
-
if (part !== '') {
|
|
2484
|
-
currentDir = await currentDir.getDirectoryHandle(part, { create: false });
|
|
2485
|
-
}
|
|
2486
|
-
}
|
|
2487
|
-
// Get the file handle
|
|
2488
|
-
const fileHandle = await currentDir.getFileHandle(fileName, { create: false });
|
|
2489
|
-
// Get the file and read it as an ArrayBuffer
|
|
2490
|
-
return await fileHandle.getFile();
|
|
2491
|
-
}
|
|
2492
|
-
catch (error) {
|
|
2493
|
-
console.error(`Error reading from OPFS: ${error.message}`);
|
|
2494
|
-
throw error;
|
|
2495
|
-
}
|
|
2496
|
-
}
|
|
2497
|
-
static async readFileAsBuffer(filePath) {
|
|
2498
|
-
try {
|
|
2499
|
-
// Get the file and read it as an ArrayBuffer
|
|
2500
|
-
const file = await this.readFile(filePath);
|
|
2501
|
-
const arrayBuffer = await file.arrayBuffer();
|
|
2502
|
-
// Convert ArrayBuffer to Buffer
|
|
2503
|
-
return Buffer.from(arrayBuffer);
|
|
2504
|
-
}
|
|
2505
|
-
catch (error) {
|
|
2506
|
-
console.error(`Error reading from OPFS: ${error.message}`);
|
|
2507
|
-
throw error;
|
|
2508
|
-
}
|
|
2509
|
-
}
|
|
2510
|
-
}
|
|
2511
|
-
BaseFileManager.setPlatformClass(FileManager);
|
|
2512
|
-
class CancelableInterval {
|
|
2513
|
-
constructor(task, interval) {
|
|
2514
|
-
this.task = task;
|
|
2515
|
-
this.interval = interval;
|
|
2516
|
-
this.intervalId = null;
|
|
2517
|
-
this.currentTaskAbortController = null;
|
|
2518
|
-
}
|
|
2519
|
-
start() {
|
|
2520
|
-
this.intervalId = window.setInterval(async () => {
|
|
2521
|
-
if (this.currentTaskAbortController) {
|
|
2522
|
-
// Cancel the previous running task
|
|
2523
|
-
this.currentTaskAbortController.abort();
|
|
2524
|
-
}
|
|
2525
|
-
// Create a new abort controller for the current task
|
|
2526
|
-
this.currentTaskAbortController = new AbortController();
|
|
2527
|
-
const signal = this.currentTaskAbortController.signal;
|
|
2528
|
-
try {
|
|
2529
|
-
await this.taskWithCancellation(signal);
|
|
2530
|
-
}
|
|
2531
|
-
catch (error) {
|
|
2532
|
-
if (error instanceof DOMException && error.name === 'AbortError') {
|
|
2533
|
-
console.log('Previous task was canceled.');
|
|
2534
|
-
}
|
|
2535
|
-
else {
|
|
2536
|
-
console.error('Task error:', error);
|
|
2537
|
-
}
|
|
2538
|
-
this.stop();
|
|
2539
|
-
}
|
|
2540
|
-
}, this.interval);
|
|
2541
|
-
}
|
|
2542
|
-
async taskWithCancellation(signal) {
|
|
2543
|
-
await this.task(() => this.stop());
|
|
2544
|
-
if (signal.aborted) {
|
|
2545
|
-
throw new DOMException('Task was aborted', 'AbortError');
|
|
2546
|
-
}
|
|
2547
|
-
}
|
|
2548
|
-
stop() {
|
|
2549
|
-
if (this.intervalId !== null) {
|
|
2550
|
-
clearInterval(this.intervalId);
|
|
2551
|
-
this.intervalId = null;
|
|
2552
|
-
}
|
|
2553
|
-
if (this.currentTaskAbortController) {
|
|
2554
|
-
this.currentTaskAbortController.abort();
|
|
2555
|
-
}
|
|
2556
|
-
}
|
|
2557
|
-
}
|
|
2558
|
-
|
|
2559
|
-
var FileManager$1 = /*#__PURE__*/Object.freeze({
|
|
2560
|
-
__proto__: null,
|
|
2561
|
-
FileManager: FileManager
|
|
2562
|
-
});
|
|
2563
|
-
|
|
2564
|
-
const logger$i = debug('app:services:db:actors:migrate');
|
|
1542
|
+
const logger$i = debug('seedSdk:services:db:actors:migrate');
|
|
2565
1543
|
const migrate = fromCallback(({ sendBack, input: { context } }) => {
|
|
2566
1544
|
const { pathToDbDir, dbId, dbName } = context;
|
|
2567
1545
|
logger$i('[db/actors] migrate context', context);
|
|
2568
1546
|
let journalExists = false;
|
|
2569
1547
|
const _checkForFiles = async () => {
|
|
2570
1548
|
const journalPath = `/${pathToDbDir}/meta/_journal.json`;
|
|
2571
|
-
journalExists = await
|
|
1549
|
+
journalExists = await BaseFileManager.pathExists(journalPath);
|
|
2572
1550
|
if (!journalExists && isBrowser()) {
|
|
2573
|
-
await
|
|
1551
|
+
await BaseFileManager.waitForFile(journalPath, 500, 60000);
|
|
2574
1552
|
}
|
|
2575
1553
|
};
|
|
2576
1554
|
const _migrate = async () => {
|
|
@@ -2592,7 +1570,7 @@ const migrate = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
2592
1570
|
return () => { };
|
|
2593
1571
|
});
|
|
2594
1572
|
|
|
2595
|
-
debug('
|
|
1573
|
+
debug('seedSdk:services:db:actors:waitForFiles');
|
|
2596
1574
|
const waitForFiles$1 = fromCallback(({ sendBack, input: { context } }) => {
|
|
2597
1575
|
if (!isBrowser()) {
|
|
2598
1576
|
sendBack({ type: DB_WAITING_FOR_FILES_RECEIVED });
|
|
@@ -2602,7 +1580,7 @@ const waitForFiles$1 = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
2602
1580
|
const _waitForFiles = async () => {
|
|
2603
1581
|
return new Promise((resolve) => {
|
|
2604
1582
|
const interval = setInterval(async () => {
|
|
2605
|
-
const journalExists = await
|
|
1583
|
+
const journalExists = await BaseFileManager.pathExists(`${pathToDbDir}/meta/_journal.json`);
|
|
2606
1584
|
if (journalExists) {
|
|
2607
1585
|
clearInterval(interval);
|
|
2608
1586
|
resolve();
|
|
@@ -2616,7 +1594,7 @@ const waitForFiles$1 = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
2616
1594
|
});
|
|
2617
1595
|
});
|
|
2618
1596
|
|
|
2619
|
-
const logger$h = debug('
|
|
1597
|
+
const logger$h = debug('seedSdk:services:db:machine');
|
|
2620
1598
|
const { CHECKING_STATUS, VALIDATING, WAITING_FOR_FILES, CONNECTING_TO_DB, MIGRATING, } = DbState;
|
|
2621
1599
|
const dbMachine = setup({
|
|
2622
1600
|
types: {
|
|
@@ -2802,6 +1780,12 @@ const prepareDb = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
2802
1780
|
throw new Error('filesDir is required');
|
|
2803
1781
|
}
|
|
2804
1782
|
const _prepareDb = async () => {
|
|
1783
|
+
if (isBrowser()) {
|
|
1784
|
+
await import('./Db-CRWMiKY9.js');
|
|
1785
|
+
}
|
|
1786
|
+
if (!isBrowser()) {
|
|
1787
|
+
await import('./Db-G5dIgZv-.js');
|
|
1788
|
+
}
|
|
2805
1789
|
const appDb = await BaseDb.prepareDb(filesDir);
|
|
2806
1790
|
if (appDb) {
|
|
2807
1791
|
sendBack({ type: 'prepareDbSuccess' });
|
|
@@ -2812,7 +1796,7 @@ const prepareDb = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
2812
1796
|
});
|
|
2813
1797
|
});
|
|
2814
1798
|
|
|
2815
|
-
const logger$g = debug('
|
|
1799
|
+
const logger$g = debug('seedSdk:services:internal:helpers');
|
|
2816
1800
|
/**
|
|
2817
1801
|
* Recursively create directories if they don't exist.
|
|
2818
1802
|
* @param {string} dirPath - The directory path to create.
|
|
@@ -2857,6 +1841,7 @@ class FileDownloadManager {
|
|
|
2857
1841
|
migrationNumber = match[1];
|
|
2858
1842
|
}
|
|
2859
1843
|
if (migrationNumber) {
|
|
1844
|
+
const fs = await BaseFileManager.getFs();
|
|
2860
1845
|
const filesInDir = await fs.promises.readdir(localDirPath);
|
|
2861
1846
|
for (const file of filesInDir) {
|
|
2862
1847
|
if (file === filename) {
|
|
@@ -2875,10 +1860,12 @@ class FileDownloadManager {
|
|
|
2875
1860
|
}
|
|
2876
1861
|
}
|
|
2877
1862
|
try {
|
|
1863
|
+
const fs = await BaseFileManager.getFs();
|
|
2878
1864
|
await fs.promises.writeFile(localFilePath, fileData);
|
|
2879
1865
|
logger$g(`[downloadFile] Wrote file async to ${localFilePath}`);
|
|
2880
1866
|
}
|
|
2881
1867
|
catch (error) {
|
|
1868
|
+
const fs = await BaseFileManager.getFs();
|
|
2882
1869
|
fs.writeFileSync(localFilePath, fileData);
|
|
2883
1870
|
logger$g(`[downloadFile] Wrote file sync to ${localFilePath}`);
|
|
2884
1871
|
}
|
|
@@ -2953,6 +1940,7 @@ const fetchDirectory = async (url) => {
|
|
|
2953
1940
|
const confirmFilesExist = async (filePaths) => {
|
|
2954
1941
|
let everythingDownloaded = false;
|
|
2955
1942
|
for (const filePath of filePaths) {
|
|
1943
|
+
const fs = await BaseFileManager.getFs();
|
|
2956
1944
|
everythingDownloaded = await fs.promises.exists(filePath);
|
|
2957
1945
|
}
|
|
2958
1946
|
if (!everythingDownloaded) {
|
|
@@ -3061,12 +2049,28 @@ const GET_TRANSACTION_TAGS = graphql(/* GraphQL */ `
|
|
|
3061
2049
|
}
|
|
3062
2050
|
`);
|
|
3063
2051
|
|
|
2052
|
+
const saveAppState$1 = async (key, value) => {
|
|
2053
|
+
const appDb = BaseDb.getAppDb();
|
|
2054
|
+
await appDb
|
|
2055
|
+
.insert(appState)
|
|
2056
|
+
.values({
|
|
2057
|
+
key,
|
|
2058
|
+
value,
|
|
2059
|
+
})
|
|
2060
|
+
.onConflictDoUpdate({
|
|
2061
|
+
target: appState.key,
|
|
2062
|
+
set: {
|
|
2063
|
+
value,
|
|
2064
|
+
},
|
|
2065
|
+
});
|
|
2066
|
+
};
|
|
2067
|
+
|
|
3064
2068
|
const initArweaveClient = async () => {
|
|
3065
2069
|
if (isBrowser()) {
|
|
3066
|
-
(await import('./ArweaveClient-
|
|
2070
|
+
(await import('./ArweaveClient-COlwyYTF.js')).ArweaveClient;
|
|
3067
2071
|
}
|
|
3068
2072
|
if (!isBrowser()) {
|
|
3069
|
-
(await import('./ArweaveClient-
|
|
2073
|
+
(await import('./ArweaveClient-2RMCxfNZ.js')).ArweaveClient;
|
|
3070
2074
|
}
|
|
3071
2075
|
};
|
|
3072
2076
|
let domain = 'arweave.net';
|
|
@@ -3109,7 +2113,7 @@ const setArweaveDomain = (newDomain) => {
|
|
|
3109
2113
|
domain = newDomain;
|
|
3110
2114
|
};
|
|
3111
2115
|
|
|
3112
|
-
const logger$f = debug('
|
|
2116
|
+
const logger$f = debug('seedSdk:files:download');
|
|
3113
2117
|
const downloadAllFilesRequestHandler = async ({ endpoints, eventId, }) => {
|
|
3114
2118
|
if (!isBrowser()) {
|
|
3115
2119
|
return;
|
|
@@ -3247,6 +2251,12 @@ const fsInitHandler = async (_) => {
|
|
|
3247
2251
|
return;
|
|
3248
2252
|
}
|
|
3249
2253
|
try {
|
|
2254
|
+
if (isBrowser()) {
|
|
2255
|
+
await import('./FileManager-gKGTTa4s.js');
|
|
2256
|
+
}
|
|
2257
|
+
if (!isBrowser()) {
|
|
2258
|
+
await import('./FileManager-BOixZyex.js');
|
|
2259
|
+
}
|
|
3250
2260
|
await BaseFileManager.initializeFileSystem();
|
|
3251
2261
|
isInitialized = true;
|
|
3252
2262
|
eventEmitter.emit('fs.init.response', { success: true });
|
|
@@ -3276,7 +2286,7 @@ const isFsInitialized = () => {
|
|
|
3276
2286
|
return isInitialized;
|
|
3277
2287
|
};
|
|
3278
2288
|
|
|
3279
|
-
const logger$e = debug('
|
|
2289
|
+
const logger$e = debug('seedSdk:internal:actors:configureFs');
|
|
3280
2290
|
const configureFs = fromCallback(({ sendBack, input: { context } }) => {
|
|
3281
2291
|
const { endpoints, appDbService, filesDir, } = context;
|
|
3282
2292
|
logger$e('[internal/actors] [configureFs] Configuring FS');
|
|
@@ -3296,8 +2306,9 @@ const configureFs = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
3296
2306
|
});
|
|
3297
2307
|
}
|
|
3298
2308
|
const journalPath = `${filesDir || BROWSER_FS_TOP_DIR}/db/meta/_journal.json`;
|
|
3299
|
-
let journalExists = await
|
|
2309
|
+
let journalExists = await BaseFileManager.pathExists(journalPath);
|
|
3300
2310
|
if (!journalExists) {
|
|
2311
|
+
const fs = await BaseFileManager.getFs();
|
|
3301
2312
|
journalExists = fs.existsSync(journalPath);
|
|
3302
2313
|
}
|
|
3303
2314
|
if (journalExists) {
|
|
@@ -3335,7 +2346,7 @@ const configureFs = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
3335
2346
|
return () => { };
|
|
3336
2347
|
});
|
|
3337
2348
|
|
|
3338
|
-
const logger$d = debug('
|
|
2349
|
+
const logger$d = debug('seedSdk:services:internal:actors:saveConfig');
|
|
3339
2350
|
const saveConfig = fromCallback(({ sendBack, input: { context } }) => {
|
|
3340
2351
|
const { endpoints, addresses, arweaveDomain } = context;
|
|
3341
2352
|
if (!endpoints) {
|
|
@@ -3408,7 +2419,7 @@ const saveConfig = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
3408
2419
|
return () => { };
|
|
3409
2420
|
});
|
|
3410
2421
|
|
|
3411
|
-
debug('
|
|
2422
|
+
debug('seedSdk:services:internal:actors:loadAppDb');
|
|
3412
2423
|
const loadAppDb = fromCallback(({ sendBack, input: { context } }) => {
|
|
3413
2424
|
const { appDbService } = context;
|
|
3414
2425
|
let subscription;
|
|
@@ -3435,7 +2446,7 @@ const loadAppDb = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
3435
2446
|
};
|
|
3436
2447
|
});
|
|
3437
2448
|
|
|
3438
|
-
debug('
|
|
2449
|
+
debug('seedSdk:services:internal:actors:waitForFiles');
|
|
3439
2450
|
const waitForFiles = fromCallback(({ sendBack, input: { context } }) => {
|
|
3440
2451
|
if (!isBrowser()) {
|
|
3441
2452
|
sendBack({ type: 'filesReceived' });
|
|
@@ -3446,7 +2457,7 @@ const waitForFiles = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
3446
2457
|
const _waitForFiles = async () => {
|
|
3447
2458
|
return new Promise((resolve) => {
|
|
3448
2459
|
const interval = setInterval(async () => {
|
|
3449
|
-
const journalExists = await
|
|
2460
|
+
const journalExists = await BaseFileManager.pathExists(`${filesDir}/db/meta/_journal.json`);
|
|
3450
2461
|
if (journalExists) {
|
|
3451
2462
|
clearInterval(interval);
|
|
3452
2463
|
resolve();
|
|
@@ -3460,7 +2471,7 @@ const waitForFiles = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
3460
2471
|
});
|
|
3461
2472
|
});
|
|
3462
2473
|
|
|
3463
|
-
const logger$c = debug('
|
|
2474
|
+
const logger$c = debug('seedSdk:services:internal:machine');
|
|
3464
2475
|
const { inspect: inspect$1 } = createBrowserInspector({
|
|
3465
2476
|
autoStart: false,
|
|
3466
2477
|
});
|
|
@@ -3803,7 +2814,7 @@ const fetchDbData = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
3803
2814
|
return () => { };
|
|
3804
2815
|
});
|
|
3805
2816
|
|
|
3806
|
-
debug('
|
|
2817
|
+
debug('seedSdk:allItemsActors:fetchSeeds');
|
|
3807
2818
|
const fetchSeeds = fromCallback(({ sendBack, input: { context } }) => {
|
|
3808
2819
|
const { queryVariables, modelName } = context;
|
|
3809
2820
|
if (!queryVariables) {
|
|
@@ -4262,7 +3273,7 @@ const preparePublishRequestData = fromCallback(({ sendBack, input: { context } }
|
|
|
4262
3273
|
});
|
|
4263
3274
|
});
|
|
4264
3275
|
|
|
4265
|
-
const logger$b = debug('
|
|
3276
|
+
const logger$b = debug('seedSdk:services:publish:actors:upload');
|
|
4266
3277
|
const upload = fromCallback(({ sendBack, input: { context } }) => {
|
|
4267
3278
|
const { localId } = context;
|
|
4268
3279
|
const _upload = async () => {
|
|
@@ -5199,7 +4210,7 @@ const getSeedData = async ({ seedLocalId, seedUid }) => {
|
|
|
5199
4210
|
return rows[0];
|
|
5200
4211
|
};
|
|
5201
4212
|
|
|
5202
|
-
const logger$a = debug('
|
|
4213
|
+
const logger$a = debug('seedSdk:db:read:getItemData');
|
|
5203
4214
|
const getItemData = async ({ modelName, seedLocalId, seedUid, }) => {
|
|
5204
4215
|
if (!seedLocalId && !seedUid) {
|
|
5205
4216
|
throw new Error('[db/queries] [getItem] no seedLocalId or seedUid');
|
|
@@ -5316,12 +4327,13 @@ const resolveRemoteStorage = fromCallback(({ sendBack, input: { context } }) =>
|
|
|
5316
4327
|
const storageTransactionId = propertyInstances.get('storageTransactionId');
|
|
5317
4328
|
const _resolveRemoteStorage = async () => {
|
|
5318
4329
|
const path = await import('path-browserify');
|
|
5319
|
-
const filesDirExists = await
|
|
4330
|
+
const filesDirExists = await BaseFileManager.pathExists('/files');
|
|
5320
4331
|
if (!filesDirExists) {
|
|
5321
|
-
await
|
|
4332
|
+
await BaseFileManager.createDirIfNotExists('/files');
|
|
5322
4333
|
}
|
|
5323
4334
|
const htmlDir = path.join('/files', 'html');
|
|
5324
|
-
const htmlExists = await
|
|
4335
|
+
const htmlExists = await BaseFileManager.pathExists(htmlDir);
|
|
4336
|
+
const fs = await BaseFileManager.getFs();
|
|
5325
4337
|
if (htmlExists) {
|
|
5326
4338
|
const htmlFiles = await fs.promises.readdir(htmlDir);
|
|
5327
4339
|
const matchingHtmlFile = htmlFiles.find((file) => file === `${storageTransactionId}.html`);
|
|
@@ -5361,7 +4373,7 @@ const resolveRemoteStorage = fromCallback(({ sendBack, input: { context } }) =>
|
|
|
5361
4373
|
});
|
|
5362
4374
|
});
|
|
5363
4375
|
|
|
5364
|
-
debug('
|
|
4376
|
+
debug('seedSdk:ItemProperty:service:actors:waitForDb');
|
|
5365
4377
|
const waitForDb = fromCallback(({ sendBack }) => {
|
|
5366
4378
|
const _waitForDb = new Promise((resolve) => {
|
|
5367
4379
|
const interval = setInterval(() => {
|
|
@@ -5400,12 +4412,11 @@ const initialize$1 = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
5400
4412
|
const _getContentsFromFileSystem = async () => {
|
|
5401
4413
|
if (propertyName === 'html') {
|
|
5402
4414
|
const htmlFilePath = `/files/html/${storageTransactionId}.html`;
|
|
5403
|
-
const exists = await
|
|
4415
|
+
const exists = await BaseFileManager.pathExists(htmlFilePath);
|
|
5404
4416
|
if (!exists) {
|
|
5405
4417
|
return;
|
|
5406
4418
|
}
|
|
5407
|
-
const renderValue = await
|
|
5408
|
-
.readFile(`/files/html/${storageTransactionId}.html`, 'utf8')
|
|
4419
|
+
const renderValue = await BaseFileManager.readFileAsString(htmlFilePath)
|
|
5409
4420
|
.catch((error) => {
|
|
5410
4421
|
console.warn('Error reading html file', error);
|
|
5411
4422
|
});
|
|
@@ -5414,12 +4425,11 @@ const initialize$1 = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
5414
4425
|
}
|
|
5415
4426
|
if (propertyName === 'json') {
|
|
5416
4427
|
const jsonFilePath = `/files/json/${storageTransactionId}.json`;
|
|
5417
|
-
const exists = await
|
|
4428
|
+
const exists = await BaseFileManager.pathExists(jsonFilePath);
|
|
5418
4429
|
if (!exists) {
|
|
5419
4430
|
return;
|
|
5420
4431
|
}
|
|
5421
|
-
const renderValue = await
|
|
5422
|
-
.readFile(`/files/json/${storageTransactionId}.json`, 'utf8')
|
|
4432
|
+
const renderValue = await BaseFileManager.readFileAsString(jsonFilePath)
|
|
5423
4433
|
.catch((error) => {
|
|
5424
4434
|
console.warn('Error reading json file', error);
|
|
5425
4435
|
});
|
|
@@ -5471,7 +4481,7 @@ const getRelationValueData = async (propertyValue) => {
|
|
|
5471
4481
|
return rows[0];
|
|
5472
4482
|
};
|
|
5473
4483
|
|
|
5474
|
-
const logger$9 = debug('
|
|
4484
|
+
const logger$9 = debug('seedSdk:property:actors:resolveRelatedValue');
|
|
5475
4485
|
const storageTransactionIdToContentUrl = new Map();
|
|
5476
4486
|
const refResolvedValueToContentUrl = new Map();
|
|
5477
4487
|
const seedUidToContentUrl = new Map();
|
|
@@ -5560,11 +4570,10 @@ const resolveRelatedValue = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
5560
4570
|
});
|
|
5561
4571
|
return true;
|
|
5562
4572
|
}
|
|
5563
|
-
const fileExists = await
|
|
4573
|
+
const fileExists = await BaseFileManager.pathExists('/files/images/' + refResolvedValue);
|
|
5564
4574
|
if (fileExists) {
|
|
5565
|
-
const
|
|
5566
|
-
const
|
|
5567
|
-
const contentUrl = URL.createObjectURL(fileHandler);
|
|
4575
|
+
const file = await BaseFileManager.readFile('/files/images/' + refResolvedValue);
|
|
4576
|
+
const contentUrl = URL.createObjectURL(file);
|
|
5568
4577
|
refResolvedValueToContentUrl.set(refResolvedValue, contentUrl);
|
|
5569
4578
|
sendBack({
|
|
5570
4579
|
type: 'updateContext',
|
|
@@ -5587,11 +4596,10 @@ const resolveRelatedValue = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
5587
4596
|
storageTransactionIdToContentUrl.get(propertyValueFromDb);
|
|
5588
4597
|
}
|
|
5589
4598
|
if (!contentUrl) {
|
|
5590
|
-
const imageFileExists = await
|
|
4599
|
+
const imageFileExists = await BaseFileManager.pathExists(`/images/${propertyValue}`);
|
|
5591
4600
|
if (imageFileExists) {
|
|
5592
|
-
const
|
|
5593
|
-
|
|
5594
|
-
contentUrl = URL.createObjectURL(fileHandler);
|
|
4601
|
+
const file = await BaseFileManager.readFile(`/images/${propertyValue}`);
|
|
4602
|
+
contentUrl = URL.createObjectURL(file);
|
|
5595
4603
|
storageTransactionIdToContentUrl.set(propertyValueFromDb, contentUrl);
|
|
5596
4604
|
}
|
|
5597
4605
|
}
|
|
@@ -5790,7 +4798,7 @@ const updateMetadata = async (metadataValues, propertyRecordSchema) => {
|
|
|
5790
4798
|
await appDb.update(metadata).set(rest).where(eq(metadata.localId, localId));
|
|
5791
4799
|
};
|
|
5792
4800
|
|
|
5793
|
-
debug('
|
|
4801
|
+
debug('seedSdk:property:actors:hydrateFromDb');
|
|
5794
4802
|
const hydrateFromDb = fromCallback(({ sendBack, input: { context } }) => {
|
|
5795
4803
|
const { seedUid, seedLocalId, propertyName: propertyNameRaw, propertyRecordSchema, modelName, } = context;
|
|
5796
4804
|
let propertyName = propertyNameRaw;
|
|
@@ -5897,6 +4905,7 @@ const hydrateFromDb = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
5897
4905
|
}
|
|
5898
4906
|
}
|
|
5899
4907
|
const dirPath = `/files/${dir}`;
|
|
4908
|
+
const fs = await BaseFileManager.getFs();
|
|
5900
4909
|
const files = await fs.promises.readdir(dirPath);
|
|
5901
4910
|
const matchingFiles = files.filter((file) => {
|
|
5902
4911
|
return path.basename(file).includes(refResolvedValue);
|
|
@@ -5910,9 +4919,8 @@ const hydrateFromDb = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
5910
4919
|
filePath = `/files/${dir}/${filename}`;
|
|
5911
4920
|
}
|
|
5912
4921
|
if (fileExists && filename && filePath) {
|
|
5913
|
-
const
|
|
5914
|
-
|
|
5915
|
-
refResolvedDisplayValue = URL.createObjectURL(fileHandler);
|
|
4922
|
+
const file = await BaseFileManager.readFile(filePath);
|
|
4923
|
+
refResolvedDisplayValue = URL.createObjectURL(file);
|
|
5916
4924
|
await updateMetadata({
|
|
5917
4925
|
localId,
|
|
5918
4926
|
refResolvedValue: filename,
|
|
@@ -5946,18 +4954,18 @@ const hydrateFromDb = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
5946
4954
|
if (propertyRecordSchema &&
|
|
5947
4955
|
propertyRecordSchema.storageType &&
|
|
5948
4956
|
propertyRecordSchema.storageType === 'ItemStorage') {
|
|
5949
|
-
const { Item } = await import('./index-
|
|
4957
|
+
const { Item } = await import('./index-BxAVepOO.js');
|
|
5950
4958
|
const item = await Item.find({
|
|
5951
4959
|
seedLocalId,
|
|
5952
4960
|
modelName,
|
|
5953
4961
|
});
|
|
5954
4962
|
if (item) {
|
|
5955
4963
|
const filePath = `/files/${localStorageDir}/${refResolvedValue}`;
|
|
5956
|
-
const exists = await
|
|
4964
|
+
const exists = await BaseFileManager.pathExists(filePath);
|
|
5957
4965
|
if (!exists) {
|
|
5958
4966
|
return;
|
|
5959
4967
|
}
|
|
5960
|
-
const renderValue = await
|
|
4968
|
+
const renderValue = await BaseFileManager.readFileAsString(filePath);
|
|
5961
4969
|
const property = item.properties[propertyName];
|
|
5962
4970
|
property.getService().send({ type: 'updateContext', renderValue });
|
|
5963
4971
|
return;
|
|
@@ -5991,7 +4999,7 @@ const getVersionData = async ({ localId, seedLocalId, uid, }) => {
|
|
|
5991
4999
|
return queryRows[0];
|
|
5992
5000
|
};
|
|
5993
5001
|
|
|
5994
|
-
const logger$8 = debug('
|
|
5002
|
+
const logger$8 = debug('seedSdk:write:updateItemPropertyValue');
|
|
5995
5003
|
const updateItemPropertyValue = async ({ localId, propertyName, newValue, seedUid, seedLocalId, modelName, refSeedType, refResolvedValue, refResolvedDisplayValue, versionLocalId, versionUid, schemaUid, localStorageDir, }) => {
|
|
5996
5004
|
if (!localId && !seedLocalId) {
|
|
5997
5005
|
logger$8(`[db/write] [updateItemPropertyValue] no propertyLocalId or seedLocalId for property: ${propertyName}`);
|
|
@@ -6366,6 +5374,7 @@ const saveImageSrc = fromCallback(({ sendBack, input: { context, event } }) => {
|
|
|
6366
5374
|
await BaseFileManager.saveFile(filePath, new Uint8Array(fileData));
|
|
6367
5375
|
}
|
|
6368
5376
|
catch (e) {
|
|
5377
|
+
const fs = await BaseFileManager.getFs();
|
|
6369
5378
|
fs.writeFileSync(filePath, new Uint8Array(fileData));
|
|
6370
5379
|
eventEmitter.emit('file-saved', filePath);
|
|
6371
5380
|
}
|
|
@@ -6375,6 +5384,7 @@ const saveImageSrc = fromCallback(({ sendBack, input: { context, event } }) => {
|
|
|
6375
5384
|
await BaseFileManager.saveFile(filePath, fileData);
|
|
6376
5385
|
}
|
|
6377
5386
|
catch (e) {
|
|
5387
|
+
const fs = await BaseFileManager.getFs();
|
|
6378
5388
|
fs.writeFileSync(filePath, fileData);
|
|
6379
5389
|
eventEmitter.emit('file-saved', filePath);
|
|
6380
5390
|
}
|
|
@@ -6613,6 +5623,7 @@ const saveItemStorage = fromCallback(({ sendBack, input: { context, event } }) =
|
|
|
6613
5623
|
await BaseFileManager.saveFile(filePath, newValue);
|
|
6614
5624
|
}
|
|
6615
5625
|
catch (error) {
|
|
5626
|
+
const fs = await BaseFileManager.getFs();
|
|
6616
5627
|
fs.writeFileSync(filePath, newValue);
|
|
6617
5628
|
}
|
|
6618
5629
|
await appDb
|
|
@@ -6846,7 +5857,7 @@ const getPropertyData$1 = async ({ propertyName, seedLocalId, seedUid, }) => {
|
|
|
6846
5857
|
};
|
|
6847
5858
|
|
|
6848
5859
|
var _a$1;
|
|
6849
|
-
const logger$7 = debug('
|
|
5860
|
+
const logger$7 = debug('seedSdk:property:class');
|
|
6850
5861
|
class BaseItemProperty {
|
|
6851
5862
|
constructor(initialValues) {
|
|
6852
5863
|
this._isRelation = false;
|
|
@@ -6931,9 +5942,9 @@ class BaseItemProperty {
|
|
|
6931
5942
|
context.localStorageDir) {
|
|
6932
5943
|
const filePath = `/files/${context.localStorageDir}/${context.refResolvedValue}`;
|
|
6933
5944
|
try {
|
|
6934
|
-
const exists = await
|
|
5945
|
+
const exists = await BaseFileManager.pathExists(filePath);
|
|
6935
5946
|
if (exists) {
|
|
6936
|
-
renderValue = await
|
|
5947
|
+
renderValue = await BaseFileManager.readFileAsString(filePath);
|
|
6937
5948
|
}
|
|
6938
5949
|
if (!exists) {
|
|
6939
5950
|
renderValue = 'No file found';
|
|
@@ -7185,7 +6196,7 @@ const getSegmentedItemProperties = (item) => {
|
|
|
7185
6196
|
};
|
|
7186
6197
|
};
|
|
7187
6198
|
|
|
7188
|
-
const logger$6 = debug('
|
|
6199
|
+
const logger$6 = debug('seedSdk:item:getPublishUploads');
|
|
7189
6200
|
const prepareArweaveTransaction = async (data, contentHash) => {
|
|
7190
6201
|
const transactionData = {
|
|
7191
6202
|
data,
|
|
@@ -7207,7 +6218,7 @@ const processUploadProperty = async (uploadProperty, uploads, relatedItemPropert
|
|
|
7207
6218
|
if (!filePath || filePath.endsWith('undefined')) {
|
|
7208
6219
|
continue;
|
|
7209
6220
|
}
|
|
7210
|
-
const exists = await
|
|
6221
|
+
const exists = await BaseFileManager.pathExists(filePath);
|
|
7211
6222
|
if (!exists) {
|
|
7212
6223
|
continue;
|
|
7213
6224
|
}
|
|
@@ -7224,14 +6235,15 @@ const processUploadProperty = async (uploadProperty, uploads, relatedItemPropert
|
|
|
7224
6235
|
if (!filePath || filePath.endsWith('undefined')) {
|
|
7225
6236
|
return uploads;
|
|
7226
6237
|
}
|
|
7227
|
-
const exists = await
|
|
6238
|
+
const exists = await BaseFileManager.pathExists(filePath);
|
|
7228
6239
|
if (!exists) {
|
|
7229
6240
|
return uploads;
|
|
7230
6241
|
}
|
|
7231
6242
|
try {
|
|
7232
|
-
fileContents = await
|
|
6243
|
+
fileContents = await BaseFileManager.readFileAsString(filePath);
|
|
7233
6244
|
}
|
|
7234
6245
|
catch (e) {
|
|
6246
|
+
const fs = await BaseFileManager.getFs();
|
|
7235
6247
|
fileContents = fs.readFileSync(filePath);
|
|
7236
6248
|
}
|
|
7237
6249
|
}
|
|
@@ -7892,31 +6904,10 @@ const initItem = async () => {
|
|
|
7892
6904
|
Item$2 = (await Promise.resolve().then(function () { return Item$1; })).Item;
|
|
7893
6905
|
}
|
|
7894
6906
|
if (!isBrowser()) {
|
|
7895
|
-
Item$2 = (await import('./Item-
|
|
7896
|
-
}
|
|
7897
|
-
};
|
|
7898
|
-
|
|
7899
|
-
let ItemProperty$2;
|
|
7900
|
-
const initItemProperty = async () => {
|
|
7901
|
-
if (isBrowser()) {
|
|
7902
|
-
ItemProperty$2 = (await Promise.resolve().then(function () { return ItemProperty$1; })).ItemProperty;
|
|
7903
|
-
}
|
|
7904
|
-
if (!isBrowser()) {
|
|
7905
|
-
ItemProperty$2 = (await import('./ItemProperty-DjGDsSEN.js')).ItemProperty;
|
|
6907
|
+
Item$2 = (await import('./Item-BD2_tuda.js')).Item;
|
|
7906
6908
|
}
|
|
7907
6909
|
};
|
|
7908
6910
|
|
|
7909
|
-
let Db;
|
|
7910
|
-
const initDb = async () => {
|
|
7911
|
-
if (isBrowser()) {
|
|
7912
|
-
Db = (await import('./Db-DL9szGvt.js')).Db;
|
|
7913
|
-
}
|
|
7914
|
-
if (!isBrowser()) {
|
|
7915
|
-
Db = (await import('./Db-Bn2_MKKq.js')).Db;
|
|
7916
|
-
}
|
|
7917
|
-
// TODO: Add config for React Native
|
|
7918
|
-
};
|
|
7919
|
-
|
|
7920
6911
|
class Item extends BaseItem {
|
|
7921
6912
|
constructor(initialValues) {
|
|
7922
6913
|
super(initialValues);
|
|
@@ -7929,7 +6920,7 @@ var Item$1 = /*#__PURE__*/Object.freeze({
|
|
|
7929
6920
|
Item: Item
|
|
7930
6921
|
});
|
|
7931
6922
|
|
|
7932
|
-
const logger$5 = debug('
|
|
6923
|
+
const logger$5 = debug('seedSdk:react:services');
|
|
7933
6924
|
const finalStrings = ['idle', 'ready', 'done', 'success', 'initialized'];
|
|
7934
6925
|
const getServiceName = (service) => {
|
|
7935
6926
|
let name = 'actor';
|
|
@@ -8064,7 +7055,7 @@ const usePersistedSnapshots = () => {
|
|
|
8064
7055
|
const save = useCallback(async () => {
|
|
8065
7056
|
for (const actor of services) {
|
|
8066
7057
|
const uniqueKey = getServiceUniqueKey(actor);
|
|
8067
|
-
|
|
7058
|
+
logger$5(`would save to db with snapshot__${uniqueKey}:`, JSON.stringify(actor.getPersistedSnapshot()));
|
|
8068
7059
|
// await writeAppState(
|
|
8069
7060
|
// `snapshot__${uniqueKey}`,
|
|
8070
7061
|
// JSON.stringify(actor.getPersistedSnapshot()),
|
|
@@ -8205,7 +7196,7 @@ const useGlobalServiceStatus = () => {
|
|
|
8205
7196
|
};
|
|
8206
7197
|
};
|
|
8207
7198
|
|
|
8208
|
-
const logger$4 = debug('
|
|
7199
|
+
const logger$4 = debug('seedSdk:react:item');
|
|
8209
7200
|
const useItem = ({ modelName, seedLocalId, seedUid }) => {
|
|
8210
7201
|
// const [itemSubscription, setItemSubscription] = useState<
|
|
8211
7202
|
// Subscription | undefined
|
|
@@ -8463,7 +7454,7 @@ var ItemProperty$1 = /*#__PURE__*/Object.freeze({
|
|
|
8463
7454
|
ItemProperty: ItemProperty
|
|
8464
7455
|
});
|
|
8465
7456
|
|
|
8466
|
-
const logger$3 = debug('
|
|
7457
|
+
const logger$3 = debug('seedSdk:react:property');
|
|
8467
7458
|
const useItemProperty = (props = {
|
|
8468
7459
|
propertyName: '',
|
|
8469
7460
|
seedLocalId: '',
|
|
@@ -8560,7 +7551,7 @@ const useItemProperties = (item) => {
|
|
|
8560
7551
|
};
|
|
8561
7552
|
};
|
|
8562
7553
|
|
|
8563
|
-
debug('
|
|
7554
|
+
debug('seedSdk:react:db');
|
|
8564
7555
|
|
|
8565
7556
|
const deleteItem = async ({ seedLocalId, seedUid }) => {
|
|
8566
7557
|
const appDb = BaseDb.getAppDb();
|
|
@@ -8659,32 +7650,32 @@ const withSeed = (config, webpack, isServer) => {
|
|
|
8659
7650
|
|
|
8660
7651
|
const initEasClient = async () => {
|
|
8661
7652
|
if (isBrowser()) {
|
|
8662
|
-
(await import('./EasClient-
|
|
7653
|
+
(await import('./EasClient-CO5puCWa.js')).EasClient;
|
|
8663
7654
|
}
|
|
8664
7655
|
if (!isBrowser()) {
|
|
8665
|
-
(await import('./EasClient-
|
|
7656
|
+
(await import('./EasClient-CFnb5g-r.js')).EasClient;
|
|
8666
7657
|
}
|
|
8667
7658
|
};
|
|
8668
7659
|
|
|
8669
|
-
const
|
|
7660
|
+
const initQueryClient = async () => {
|
|
8670
7661
|
if (isBrowser()) {
|
|
8671
|
-
(await
|
|
7662
|
+
(await import('./QueryClient-W4slRa7O.js')).QueryClient;
|
|
8672
7663
|
}
|
|
8673
7664
|
if (!isBrowser()) {
|
|
8674
|
-
(await import('./
|
|
7665
|
+
(await import('./QueryClient-ZUsZ1Qxq.js')).QueryClient;
|
|
8675
7666
|
}
|
|
8676
7667
|
};
|
|
8677
7668
|
|
|
8678
|
-
const
|
|
7669
|
+
const initItemProperty = async () => {
|
|
8679
7670
|
if (isBrowser()) {
|
|
8680
|
-
(await
|
|
7671
|
+
(await Promise.resolve().then(function () { return ItemProperty$1; })).ItemProperty;
|
|
8681
7672
|
}
|
|
8682
7673
|
if (!isBrowser()) {
|
|
8683
|
-
(await import('./
|
|
7674
|
+
(await import('./ItemProperty-CjcrzEmg.js')).ItemProperty;
|
|
8684
7675
|
}
|
|
8685
7676
|
};
|
|
8686
7677
|
|
|
8687
|
-
const logger$2 = debug('
|
|
7678
|
+
const logger$2 = debug('seedSdk:services:events');
|
|
8688
7679
|
const handleServiceSaveState = (event) => {
|
|
8689
7680
|
const { state, serviceId } = event;
|
|
8690
7681
|
logger$2(`[browser] [service.saveState.request] serviceId: ${serviceId}`);
|
|
@@ -8713,7 +7704,8 @@ const setupServiceHandlers = () => {
|
|
|
8713
7704
|
eventEmitter.addListener('service.save', saveServiceHandler);
|
|
8714
7705
|
};
|
|
8715
7706
|
|
|
8716
|
-
|
|
7707
|
+
// import { initDb } from "@/db/Db";
|
|
7708
|
+
const logger$1 = debug('seedSdk:ClientManager:initialize');
|
|
8717
7709
|
const initialize = fromCallback(({ sendBack, input: { context, event } }) => {
|
|
8718
7710
|
logger$1('initialize from ClientManager');
|
|
8719
7711
|
const { isInitialized } = context;
|
|
@@ -8729,8 +7721,7 @@ const initialize = fromCallback(({ sendBack, input: { context, event } }) => {
|
|
|
8729
7721
|
await initEasClient();
|
|
8730
7722
|
await initArweaveClient();
|
|
8731
7723
|
await initQueryClient();
|
|
8732
|
-
await
|
|
8733
|
-
await initDb();
|
|
7724
|
+
// await initDb()
|
|
8734
7725
|
const { models, endpoints, arweaveDomain, } = config;
|
|
8735
7726
|
const { files } = endpoints;
|
|
8736
7727
|
if (arweaveDomain) {
|
|
@@ -8758,7 +7749,7 @@ const initialize = fromCallback(({ sendBack, input: { context, event } }) => {
|
|
|
8758
7749
|
arweaveDomain,
|
|
8759
7750
|
filesDir: files,
|
|
8760
7751
|
});
|
|
8761
|
-
const { models: internalModels } = await import('./seed.schema.config-
|
|
7752
|
+
const { models: internalModels } = await import('./seed.schema.config-DmTl3a9U.js');
|
|
8762
7753
|
for (const [key, value] of Object.entries(internalModels)) {
|
|
8763
7754
|
setModel(key, value);
|
|
8764
7755
|
}
|
|
@@ -8773,7 +7764,7 @@ const initialize = fromCallback(({ sendBack, input: { context, event } }) => {
|
|
|
8773
7764
|
});
|
|
8774
7765
|
});
|
|
8775
7766
|
|
|
8776
|
-
debug('
|
|
7767
|
+
debug('seedSdk:client:writeToDb');
|
|
8777
7768
|
const saveAppState = fromCallback(({ sendBack, input: { key, value } }) => {
|
|
8778
7769
|
const _saveAppState = async () => {
|
|
8779
7770
|
const { BaseDb } = await Promise.resolve().then(function () { return BaseDb$1; });
|
|
@@ -8875,29 +7866,34 @@ const clientManagerMachine = setup({
|
|
|
8875
7866
|
},
|
|
8876
7867
|
});
|
|
8877
7868
|
|
|
8878
|
-
|
|
7869
|
+
// import { SeedConstructorOptions } from '@/types/index'
|
|
7870
|
+
// import { BaseDb } from '@/db/Db/BaseDb'
|
|
7871
|
+
// import { appState } from '@/seedSchema'
|
|
7872
|
+
// import { eq } from 'drizzle-orm'
|
|
7873
|
+
// import { CLIENT_NOT_INITIALIZED } from '@/helpers/constants'
|
|
7874
|
+
const logger = debug('seedSdk:client');
|
|
8879
7875
|
const clientManager = createActor(clientManagerMachine, {
|
|
8880
7876
|
input: {
|
|
8881
7877
|
isInitialized: false,
|
|
8882
7878
|
}
|
|
8883
7879
|
});
|
|
8884
|
-
|
|
7880
|
+
clientManager.subscribe((snapshot) => {
|
|
8885
7881
|
logger('ClientManager snapshot.value:', snapshot.value);
|
|
8886
7882
|
logger('ClientManager snapshot.context.isInitialized:', snapshot.context.isInitialized);
|
|
8887
7883
|
});
|
|
8888
7884
|
clientManager.start();
|
|
8889
|
-
const ensureInitialized = () => {
|
|
8890
|
-
|
|
8891
|
-
|
|
8892
|
-
|
|
8893
|
-
}
|
|
7885
|
+
// const ensureInitialized = () => {
|
|
7886
|
+
// if (!clientManager.getSnapshot().context.isInitialized) {
|
|
7887
|
+
// throw new Error(CLIENT_NOT_INITIALIZED);
|
|
7888
|
+
// }
|
|
7889
|
+
// }
|
|
8894
7890
|
const ClientManager = {
|
|
8895
7891
|
isInitialized: () => {
|
|
8896
7892
|
return clientManager.getSnapshot().context.isInitialized;
|
|
8897
7893
|
},
|
|
8898
7894
|
getService: () => {
|
|
8899
|
-
ensureInitialized();
|
|
8900
|
-
return clientManager;
|
|
7895
|
+
// ensureInitialized();
|
|
7896
|
+
// return clientManager;
|
|
8901
7897
|
},
|
|
8902
7898
|
// init: async (options: SeedConstructorOptions) => {
|
|
8903
7899
|
init: async (options) => {
|
|
@@ -8905,30 +7901,30 @@ const ClientManager = {
|
|
|
8905
7901
|
await waitFor(clientManager, (snapshot) => snapshot.context.isInitialized);
|
|
8906
7902
|
},
|
|
8907
7903
|
setAddresses: async (addresses) => {
|
|
8908
|
-
ensureInitialized();
|
|
8909
|
-
logger('setAddresses', addresses);
|
|
8910
|
-
clientManager.send({ type: 'setAddresses', addresses });
|
|
8911
|
-
await waitFor(clientManager, (snapshot) => !snapshot.context.isSaving);
|
|
8912
|
-
logger('setAddresses success', addresses);
|
|
7904
|
+
// ensureInitialized();
|
|
7905
|
+
// logger('setAddresses', addresses);
|
|
7906
|
+
// clientManager.send({ type: 'setAddresses', addresses });
|
|
7907
|
+
// await waitFor(clientManager, (snapshot) => !snapshot.context.isSaving);
|
|
7908
|
+
// logger('setAddresses success', addresses);
|
|
8913
7909
|
},
|
|
8914
7910
|
getAddresses: async () => {
|
|
8915
|
-
ensureInitialized();
|
|
8916
|
-
const db = await BaseDb.getAppDb();
|
|
8917
|
-
const results = await db.select().from(appState).where(eq(appState.key, 'addresses'));
|
|
8918
|
-
return JSON.parse(results[0]?.value);
|
|
7911
|
+
// ensureInitialized();
|
|
7912
|
+
// const db = await BaseDb.getAppDb();
|
|
7913
|
+
// const results = await db.select().from(appState).where(eq(appState.key, 'addresses'));
|
|
7914
|
+
// return JSON.parse(results[0]?.value);
|
|
8919
7915
|
},
|
|
8920
7916
|
stop: () => {
|
|
8921
|
-
ensureInitialized();
|
|
8922
|
-
clientManager.stop();
|
|
7917
|
+
// ensureInitialized();
|
|
7918
|
+
// clientManager.stop();
|
|
8923
7919
|
},
|
|
8924
7920
|
unload: () => {
|
|
8925
|
-
ensureInitialized();
|
|
8926
|
-
clientManager.stop();
|
|
8927
|
-
subscription.unsubscribe();
|
|
7921
|
+
// ensureInitialized();
|
|
7922
|
+
// clientManager.stop();
|
|
7923
|
+
// subscription.unsubscribe();
|
|
8928
7924
|
},
|
|
8929
7925
|
};
|
|
8930
7926
|
|
|
8931
7927
|
enableMapSet();
|
|
8932
7928
|
|
|
8933
|
-
export { BaseItem as B, ClientManager as C,
|
|
8934
|
-
//# sourceMappingURL=index-
|
|
7929
|
+
export { BaseItem as B, ClientManager as C, Item as I, Json as J, List as L, Model as M, Property as P, Relation as R, Text as T, BaseDb as a, appState as b, BaseItemProperty as c, ImageSrc as d, Item$2 as e, useItem as f, useItemProperties as g, useCreateItem as h, isBrowser as i, useItemProperty as j, useDeleteItem as k, useGlobalServiceStatus as l, usePublishItem as m, usePersistedSnapshots as n, useServices as o, useService as p, getCorrectId as q, eventEmitter as r, saveAppState$1 as s, useItems as u, withSeed as w };
|
|
7930
|
+
//# sourceMappingURL=index-D-O-gmXo.js.map
|