@seedprotocol/sdk 0.2.46 → 0.2.48
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-CoFomTCN.js → ArweaveClient-Dcqcpsq4.js} +2 -2
- package/dist/{ArweaveClient-DQrXvrNN.js.map → ArweaveClient-Dcqcpsq4.js.map} +1 -1
- package/dist/{ArweaveClient-DQrXvrNN.js → ArweaveClient-Dh7LRIqD.js} +2 -2
- package/dist/{ArweaveClient-CoFomTCN.js.map → ArweaveClient-Dh7LRIqD.js.map} +1 -1
- package/dist/{Db-5C5VqRWb.js → Db-BhLWMUOe.js} +7 -7
- package/dist/Db-BhLWMUOe.js.map +1 -0
- package/dist/{Db-Dv890NJZ.js → Db-DrcygP77.js} +3 -4
- package/dist/{Db-Dv890NJZ.js.map → Db-DrcygP77.js.map} +1 -1
- package/dist/{EasClient-CBu9ENAi.js → EasClient-A1xC7Gm-.js} +2 -2
- package/dist/{EasClient-sCbTHcO8.js.map → EasClient-A1xC7Gm-.js.map} +1 -1
- package/dist/{EasClient-sCbTHcO8.js → EasClient-m2mXad59.js} +2 -2
- package/dist/{EasClient-CBu9ENAi.js.map → EasClient-m2mXad59.js.map} +1 -1
- package/dist/{FileManager-COOp89Mj.js → FileManager-Dv2zn1RW.js} +12 -2
- package/dist/FileManager-Dv2zn1RW.js.map +1 -0
- package/dist/{Item-BmPvgaG4.js → Item-D0rGmrZg.js} +3 -4
- package/dist/{Item-BmPvgaG4.js.map → Item-D0rGmrZg.js.map} +1 -1
- package/dist/{ItemProperty-BW4k1h0o.js → ItemProperty-D0tkeKx1.js} +3 -4
- package/dist/{ItemProperty-BW4k1h0o.js.map → ItemProperty-D0tkeKx1.js.map} +1 -1
- package/dist/{QueryClient-BBaE-LKI.js → QueryClient-C-hFMF2j.js} +2 -2
- package/dist/{QueryClient-BBaE-LKI.js.map → QueryClient-C-hFMF2j.js.map} +1 -1
- package/dist/{QueryClient-C-ZzUnWq.js → QueryClient-C02sPZ-K.js} +2 -2
- package/dist/{QueryClient-C-ZzUnWq.js.map → QueryClient-C02sPZ-K.js.map} +1 -1
- package/dist/bin.js +5 -5
- package/dist/{constants-Dgv-tSO3.js → constants-C03RQQht.js} +12 -5
- package/dist/constants-C03RQQht.js.map +1 -0
- package/dist/{index-CGeSKilQ.js → index-B6FQruEq.js} +1069 -134
- package/dist/index-B6FQruEq.js.map +1 -0
- package/dist/{index-CPxn1SR4.js → index-C93o7-zP.js} +3 -4
- package/dist/index-C93o7-zP.js.map +1 -0
- package/dist/main.js +2 -3
- package/dist/main.js.map +1 -1
- package/dist/{seed.schema.config-BXWvwsZQ.js → seed.schema.config-ClOsMOKS.js} +3 -4
- package/dist/seed.schema.config-ClOsMOKS.js.map +1 -0
- package/dist/src/BaseFileManager.ts +14 -2
- package/dist/src/FileManager.ts +14 -1
- package/dist/src/ImageResizer.ts +2 -5
- package/dist/src/actors.ts +34 -272
- package/dist/src/client.ts +19 -0
- package/dist/src/download.ts +5 -15
- package/dist/src/helpers.ts +200 -83
- package/dist/src/migrate.ts +2 -2
- package/dist/types/src/browser/db/Db.d.ts +1 -1
- package/dist/types/src/browser/db/Db.d.ts.map +1 -1
- package/dist/types/src/browser/helpers/FileManager.d.ts +10 -0
- package/dist/types/src/browser/helpers/FileManager.d.ts.map +1 -1
- package/dist/types/src/browser/helpers/index.d.ts +1 -2
- package/dist/types/src/browser/helpers/index.d.ts.map +1 -1
- package/dist/types/src/browser/workers/ImageResizer.d.ts.map +1 -1
- package/dist/types/src/client.d.ts +1 -0
- package/dist/types/src/client.d.ts.map +1 -1
- package/dist/types/src/events/files/download.d.ts.map +1 -1
- package/dist/types/src/helpers/FileManager/BaseFileManager.d.ts +5 -2
- package/dist/types/src/helpers/FileManager/BaseFileManager.d.ts.map +1 -1
- package/dist/types/src/node/helpers/FileManager.d.ts +2 -0
- package/dist/types/src/node/helpers/FileManager.d.ts.map +1 -1
- package/dist/types/src/services/internal/helpers.d.ts +0 -2
- package/dist/types/src/services/internal/helpers.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/Db-5C5VqRWb.js.map +0 -1
- package/dist/FileManager-AhAsy_F_.js +0 -794
- package/dist/FileManager-AhAsy_F_.js.map +0 -1
- package/dist/FileManager-COOp89Mj.js.map +0 -1
- package/dist/constants-Dgv-tSO3.js.map +0 -1
- package/dist/index-CGeSKilQ.js.map +0 -1
- package/dist/index-CPxn1SR4.js.map +0 -1
- package/dist/seed.schema.config-BXWvwsZQ.js.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export { I as Item } from './index-
|
|
1
|
+
export { I as Item } from './index-B6FQruEq.js';
|
|
2
2
|
import 'immer';
|
|
3
3
|
import 'reflect-metadata';
|
|
4
4
|
import '@sinclair/typebox';
|
|
5
5
|
import 'xstate';
|
|
6
|
-
import './constants-
|
|
6
|
+
import './constants-C03RQQht.js';
|
|
7
7
|
import '@ethereum-attestation-service/eas-sdk';
|
|
8
8
|
import 'debug';
|
|
9
9
|
import 'pluralize';
|
|
@@ -15,7 +15,6 @@ import 'nanoid-dictionary';
|
|
|
15
15
|
import '@zenfs/core';
|
|
16
16
|
import 'lodash-es';
|
|
17
17
|
import '@statelyai/inspect';
|
|
18
|
-
import 'node:fs';
|
|
19
18
|
import 'path';
|
|
20
19
|
import 'arweave';
|
|
21
20
|
import 'rxjs';
|
|
@@ -23,4 +22,4 @@ import 'drizzle-orm/casing';
|
|
|
23
22
|
import 'react';
|
|
24
23
|
import 'use-immer';
|
|
25
24
|
import '@xstate/react';
|
|
26
|
-
//# sourceMappingURL=index-
|
|
25
|
+
//# sourceMappingURL=index-C93o7-zP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-C93o7-zP.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/main.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import 'immer';
|
|
2
2
|
import 'reflect-metadata';
|
|
3
|
-
export { D as Db, c as ImageSrc, d as Item, e as ItemProperty, J as Json, L as List, M as Model, P as Property, R as Relation, T as Text,
|
|
4
|
-
export { B as BaseArweaveClient, a as BaseEasClient, c as BaseFileManager, b as BaseQueryClient } from './constants-
|
|
3
|
+
export { D as Db, c as ImageSrc, d as Item, e as ItemProperty, J as Json, L as List, M as Model, P as Property, R as Relation, T as Text, s as client, r as eventEmitter, p as getCorrectId, q as getGlobalService, h as useCreateItem, j as useDeleteItem, k as useGlobalServiceStatus, f as useItem, g as useItemProperties, i as useItemProperty, u as useItems, m as usePersistedSnapshots, l as usePublishItem, o as useService, n as useServices, w as withSeed } from './index-B6FQruEq.js';
|
|
4
|
+
export { B as BaseArweaveClient, a as BaseEasClient, c as BaseFileManager, b as BaseQueryClient } from './constants-C03RQQht.js';
|
|
5
5
|
import '@sinclair/typebox';
|
|
6
6
|
import 'xstate';
|
|
7
7
|
import 'debug';
|
|
@@ -14,7 +14,6 @@ import 'nanoid-dictionary';
|
|
|
14
14
|
import '@zenfs/core';
|
|
15
15
|
import 'lodash-es';
|
|
16
16
|
import '@statelyai/inspect';
|
|
17
|
-
import 'node:fs';
|
|
18
17
|
import 'path';
|
|
19
18
|
import 'arweave';
|
|
20
19
|
import 'rxjs';
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"main.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { __decorate, __metadata } from 'tslib';
|
|
2
2
|
import 'reflect-metadata';
|
|
3
|
-
import { T as Text, M as Model } from './index-
|
|
3
|
+
import { T as Text, M as Model } from './index-B6FQruEq.js';
|
|
4
4
|
import 'immer';
|
|
5
5
|
import '@sinclair/typebox';
|
|
6
6
|
import 'xstate';
|
|
7
|
-
import './constants-
|
|
7
|
+
import './constants-C03RQQht.js';
|
|
8
8
|
import '@ethereum-attestation-service/eas-sdk';
|
|
9
9
|
import 'debug';
|
|
10
10
|
import 'pluralize';
|
|
@@ -16,7 +16,6 @@ import 'nanoid-dictionary';
|
|
|
16
16
|
import '@zenfs/core';
|
|
17
17
|
import 'lodash-es';
|
|
18
18
|
import '@statelyai/inspect';
|
|
19
|
-
import 'node:fs';
|
|
20
19
|
import 'path';
|
|
21
20
|
import 'arweave';
|
|
22
21
|
import 'rxjs';
|
|
@@ -71,4 +70,4 @@ const models = {
|
|
|
71
70
|
};
|
|
72
71
|
|
|
73
72
|
export { models };
|
|
74
|
-
//# sourceMappingURL=seed.schema.config-
|
|
73
|
+
//# sourceMappingURL=seed.schema.config-ClOsMOKS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seed.schema.config-ClOsMOKS.js","sources":["../../src/db/configs/seed.schema.config.ts"],"sourcesContent":["import { Model, Text } from '@/schema'\n\n@Model\nclass Seed {\n @Text() uid!: string\n @Text() type!: string\n}\n\n@Model\nclass Version {\n @Text() seedUid!: string\n @Text() note!: string\n}\n\n@Model\nclass Metadata {\n @Text() key!: string\n @Text() value!: string\n}\n\nexport const models = {\n Seed,\n Version,\n Metadata,\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,IAAM,IAAI,GAAV,MAAM,IAAI,CAAA;CAGT;AAFS,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAa,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,KAAA,EAAA,SAAA,CAAA;AACZ,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAc,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,MAAA,EAAA,SAAA,CAAA;AAFjB,IAAI,GAAA,UAAA,CAAA;IADT;AACK,CAAA,EAAA,IAAI,CAGT;AAGD,IAAM,OAAO,GAAb,MAAM,OAAO,CAAA;CAGZ;AAFS,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAiB,CAAA,EAAA,OAAA,CAAA,SAAA,EAAA,SAAA,EAAA,SAAA,CAAA;AAChB,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAc,CAAA,EAAA,OAAA,CAAA,SAAA,EAAA,MAAA,EAAA,SAAA,CAAA;AAFjB,OAAO,GAAA,UAAA,CAAA;IADZ;AACK,CAAA,EAAA,OAAO,CAGZ;AAGD,IAAM,QAAQ,GAAd,MAAM,QAAQ,CAAA;CAGb;AAFS,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAa,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,KAAA,EAAA,SAAA,CAAA;AACZ,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAe,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,OAAA,EAAA,SAAA,CAAA;AAFlB,QAAQ,GAAA,UAAA,CAAA;IADb;AACK,CAAA,EAAA,QAAQ,CAGb;AAEY,MAAA,MAAM,GAAG;IACpB,IAAI;IACJ,OAAO;IACP,QAAQ;;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export abstract class BaseFileManager {
|
|
2
|
-
private fileSystemInitialized = false
|
|
3
|
-
private initializing = false
|
|
2
|
+
private static fileSystemInitialized = false
|
|
3
|
+
private static initializing = false
|
|
4
4
|
|
|
5
5
|
static PlatformClass: typeof BaseFileManager
|
|
6
6
|
|
|
@@ -37,4 +37,16 @@ export abstract class BaseFileManager {
|
|
|
37
37
|
static resizeAllImages( { width, height }: ResizeAllImagesParams ): Promise<void> {
|
|
38
38
|
return this.PlatformClass.resizeAllImages({ width, height })
|
|
39
39
|
}
|
|
40
|
+
|
|
41
|
+
static pathExists(filePath: string): Promise<boolean> {
|
|
42
|
+
return this.PlatformClass.pathExists(filePath)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static createDirIfNotExists(filePath: string): Promise<void> {
|
|
46
|
+
return this.PlatformClass.createDirIfNotExists(filePath)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static async waitForFile(filePath: string): Promise<boolean> {
|
|
50
|
+
return this.PlatformClass.waitForFile(filePath)
|
|
51
|
+
}
|
|
40
52
|
}
|
package/dist/src/FileManager.ts
CHANGED
|
@@ -37,8 +37,21 @@ class FileManager extends BaseFileManager {
|
|
|
37
37
|
})
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
static async pathExists(filePath: string): Promise<boolean> {
|
|
41
|
+
return new Promise(( resolve, reject ) => {
|
|
42
|
+
reject(new Error('Not implemented'))
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static async createDirIfNotExists(filePath: string): Promise<void> {
|
|
47
|
+
return new Promise(( resolve, reject ) => {
|
|
48
|
+
reject(new Error('Not implemented'))
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
|
|
40
52
|
}
|
|
41
53
|
|
|
42
54
|
BaseFileManager.setPlatformClass(FileManager)
|
|
43
55
|
|
|
44
|
-
export { FileManager }
|
|
56
|
+
export { FileManager }
|
|
57
|
+
|
package/dist/src/ImageResizer.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from '@zenfs/core';
|
|
2
2
|
import imageResize from './imageResize'
|
|
3
|
+
import { FileManager } from '@/browser/helpers/FileManager';
|
|
3
4
|
|
|
4
5
|
|
|
5
6
|
|
|
@@ -66,11 +67,7 @@ export class ImageResizer {
|
|
|
66
67
|
|
|
67
68
|
const widthDir = `${imageDir}/${width}`
|
|
68
69
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (!widthDirExists) {
|
|
72
|
-
await fs.promises.mkdir(widthDir)
|
|
73
|
-
}
|
|
70
|
+
await FileManager.createDirIfNotExists(widthDir)
|
|
74
71
|
|
|
75
72
|
for (const imageFile of imageFiles) {
|
|
76
73
|
const resizedImageExists = await fs.promises.exists(`${widthDir}/${imageFile}`)
|
package/dist/src/actors.ts
CHANGED
|
@@ -1,294 +1,56 @@
|
|
|
1
1
|
import { EventObject, fromCallback } from 'xstate'
|
|
2
|
-
import {
|
|
3
|
-
import { ARWEAVE_HOST } from '@/services/internal/constants'
|
|
2
|
+
import { downloadMachine } from '@/schema/file/download'
|
|
4
3
|
import { GET_FILES_METADATA } from '@/schema/file/queries'
|
|
5
|
-
import { getArweave } from '@/helpers/ArweaveClient'
|
|
6
|
-
import fs from '@zenfs/core'
|
|
7
|
-
import {
|
|
8
|
-
getDataTypeFromString,
|
|
9
|
-
getMimeType,
|
|
10
|
-
identifyString,
|
|
11
|
-
} from '@/helpers'
|
|
12
|
-
import { appState } from '@/seedSchema'
|
|
13
|
-
import { eq } from 'drizzle-orm'
|
|
14
4
|
import { BaseEasClient } from '@/helpers/EasClient/BaseEasClient'
|
|
15
5
|
import { BaseQueryClient } from '@/helpers/QueryClient/BaseQueryClient'
|
|
16
|
-
import debug from 'debug'
|
|
17
|
-
import { BaseDb } from '@/db/Db/BaseDb'
|
|
18
|
-
import { saveAppState } from '@/db/write/saveAppState'
|
|
19
6
|
|
|
20
|
-
const logger = debug('app:file:actors:fetchAll')
|
|
21
7
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
8
|
+
export const fetchMetadata = fromCallback<EventObject, typeof downloadMachine>(
|
|
9
|
+
({ sendBack, input: { context } }) => {
|
|
10
|
+
const { addresses } = context
|
|
26
11
|
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
'image/png': { mimeType: 'image/png', extension: '.png' },
|
|
31
|
-
'application/json': { mimeType: 'application/json', extension: '.json' },
|
|
32
|
-
'text/plain': { mimeType: 'text/plain', extension: '.txt' },
|
|
33
|
-
// Add more MIME types and file extensions as needed
|
|
34
|
-
}
|
|
12
|
+
const fetchMetadata = async () => {
|
|
13
|
+
const queryClient = BaseQueryClient.getQueryClient()
|
|
14
|
+
const easClient = BaseEasClient.getEasClient()
|
|
35
15
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const { filesMetadata } = await queryClient.fetchQuery({
|
|
47
|
-
queryKey: ['getFilesMetadata', ...addresses],
|
|
48
|
-
queryFn: async () =>
|
|
49
|
-
easClient.request(GET_FILES_METADATA, {
|
|
50
|
-
where: {
|
|
51
|
-
attester: {
|
|
52
|
-
in: addresses,
|
|
53
|
-
},
|
|
54
|
-
schema: {
|
|
55
|
-
is: {
|
|
56
|
-
id: {
|
|
57
|
-
equals:
|
|
58
|
-
'0x55fdefb36fcbbaebeb7d6b41dc3a1a9666e4e42154267c889de064faa7ede517',
|
|
59
|
-
},
|
|
16
|
+
const metadataRecords = await queryClient.fetchQuery({
|
|
17
|
+
queryKey: ['getFilesMetadata', ...addresses],
|
|
18
|
+
queryFn: async () =>
|
|
19
|
+
easClient.request(GET_FILES_METADATA, {
|
|
20
|
+
where: {
|
|
21
|
+
attester: {
|
|
22
|
+
in: addresses,
|
|
23
|
+
},
|
|
24
|
+
decodedDataJson: {
|
|
25
|
+
contains: 'transactionId',
|
|
60
26
|
},
|
|
61
27
|
},
|
|
62
|
-
},
|
|
63
|
-
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
return filesMetadata
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
_fetchAllMetadataRecords().then((filesMetadata) => {
|
|
70
|
-
sendBack({ type: 'fetchingAllMetadataRecordsSuccess', filesMetadata })
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
return () => { }
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
export const fetchAllBinaryData = fromCallback<
|
|
77
|
-
EventObject,
|
|
78
|
-
typeof fetchAllFilesMachine
|
|
79
|
-
>(({ sendBack, input: { context } }) => {
|
|
80
|
-
const { filesMetadata, addresses } = context
|
|
28
|
+
}),
|
|
29
|
+
})
|
|
81
30
|
|
|
82
|
-
|
|
83
|
-
if (!(await fs.promises.exists('/files'))) {
|
|
84
|
-
await fs.promises.mkdir('/files', { recursive: true })
|
|
31
|
+
return metadataRecords
|
|
85
32
|
}
|
|
86
33
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (!(await fs.promises.exists('/files/json'))) {
|
|
92
|
-
await fs.promises.mkdir('/files/json', { recursive: true })
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (!(await fs.promises.exists('/files/images'))) {
|
|
96
|
-
await fs.promises.mkdir('/files/images', { recursive: true })
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const appDb = BaseDb.getAppDb()
|
|
100
|
-
|
|
101
|
-
if (!appDb) {
|
|
102
|
-
logger('[fetchAll/actors] [fetchAllBinaryData] seedDb not available')
|
|
103
|
-
return []
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
for (const fileMetadata of filesMetadata) {
|
|
107
|
-
const json = JSON.parse(fileMetadata.decodedDataJson)
|
|
108
|
-
const transactionId = json[0].value.value
|
|
109
|
-
|
|
110
|
-
const excludedTransactionsQuery = await appDb
|
|
111
|
-
.select()
|
|
112
|
-
.from(appState)
|
|
113
|
-
.where(eq(appState.key, 'excludedTransactions'))
|
|
114
|
-
|
|
115
|
-
let excludedTransactions = new Set<string>()
|
|
116
|
-
|
|
117
|
-
if (excludedTransactionsQuery && excludedTransactionsQuery.length === 1) {
|
|
118
|
-
const valueString = excludedTransactionsQuery[0].value
|
|
119
|
-
if (valueString) {
|
|
120
|
-
const excludedTransactionsArray = JSON.parse(valueString)
|
|
121
|
-
excludedTransactions = new Set(excludedTransactionsArray)
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (excludedTransactions.has(transactionId)) {
|
|
126
|
-
continue
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const arweave = getArweave()
|
|
130
|
-
|
|
131
|
-
if (!arweave) {
|
|
132
|
-
logger('[fetchAll/actors] [fetchAllBinaryData] arweave not available')
|
|
133
|
-
return []
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
try {
|
|
137
|
-
const res = await fetch(
|
|
138
|
-
`https://${ARWEAVE_HOST}/tx/${transactionId}/status`,
|
|
139
|
-
)
|
|
140
|
-
|
|
141
|
-
if (res.status !== 200) {
|
|
142
|
-
logger(
|
|
143
|
-
`[fetchAll/actors] [fetchAllBinaryData] error fetching transaction data for ${transactionId}`,
|
|
144
|
-
)
|
|
145
|
-
|
|
146
|
-
excludedTransactions.add(transactionId)
|
|
147
|
-
|
|
148
|
-
await saveAppState(
|
|
149
|
-
'excludedTransactions',
|
|
150
|
-
JSON.stringify(Array.from(excludedTransactions)),
|
|
151
|
-
)
|
|
152
|
-
|
|
153
|
-
logger(
|
|
154
|
-
'[fetchAll/actors] [fetchAllBinaryData] updated excludedTransactions:',
|
|
155
|
-
excludedTransactions,
|
|
156
|
-
)
|
|
157
|
-
|
|
158
|
-
continue
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const dataString = await arweave.transactions
|
|
162
|
-
.getData(transactionId, {
|
|
163
|
-
decode: true,
|
|
164
|
-
string: true,
|
|
165
|
-
})
|
|
166
|
-
.catch((error) => {
|
|
167
|
-
logger(
|
|
168
|
-
`[fetchAll/actors] [fetchAllBinaryData] error fetching transaction data for ${transactionId}`,
|
|
169
|
-
error,
|
|
170
|
-
)
|
|
171
|
-
})
|
|
172
|
-
|
|
173
|
-
const dataUint8Array = await arweave.transactions.getData(transactionId)
|
|
174
|
-
// let buffer
|
|
175
|
-
//
|
|
176
|
-
// if (dataUint8Array && dataUint8Array instanceof Uint8Array) {
|
|
177
|
-
// }
|
|
178
|
-
|
|
179
|
-
let contentType = identifyString(dataString)
|
|
180
|
-
if (
|
|
181
|
-
contentType !== 'json' &&
|
|
182
|
-
contentType !== 'base64' &&
|
|
183
|
-
contentType !== 'html'
|
|
184
|
-
) {
|
|
185
|
-
const possibleImageType = getDataTypeFromString(dataString)
|
|
186
|
-
if (!possibleImageType) {
|
|
187
|
-
logger(
|
|
188
|
-
`[fetchAll/actors] [fetchAllBinaryData] transaction ${transactionId} data not in expected format: ${possibleImageType}`,
|
|
189
|
-
)
|
|
190
|
-
continue
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
contentType = possibleImageType
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
if (contentType === 'url') {
|
|
197
|
-
const url = dataString as string
|
|
198
|
-
const response = await fetch(url)
|
|
199
|
-
if (!response.ok) {
|
|
200
|
-
throw new Error(`Failed to fetch image: ${response.statusText}`)
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// Get the image as a Blob
|
|
204
|
-
const blob = await response.blob()
|
|
205
|
-
const buffer = await blob.arrayBuffer()
|
|
206
|
-
const bufferUint8Array = new Uint8Array(buffer)
|
|
207
|
-
|
|
208
|
-
// Extract the file extension from the URL
|
|
209
|
-
const extensionMatch = url.match(
|
|
210
|
-
/\.(jpg|jpeg|png|gif|bmp|webp|svg)$/i,
|
|
211
|
-
)
|
|
212
|
-
if (!extensionMatch) {
|
|
213
|
-
throw new Error(
|
|
214
|
-
'Unable to determine the file extension from the URL.',
|
|
215
|
-
)
|
|
216
|
-
}
|
|
217
|
-
const fileExtension = extensionMatch[0] // e.g., ".jpg"
|
|
218
|
-
|
|
219
|
-
// Set the file name (you can customize this)
|
|
220
|
-
// const fileNameFromUrl = `${transactionId}${fileExtension}`
|
|
221
|
-
|
|
222
|
-
await fs.promises.writeFile(
|
|
223
|
-
`/files/images/${transactionId}`,
|
|
224
|
-
bufferUint8Array,
|
|
225
|
-
{
|
|
226
|
-
encoding: 'binary',
|
|
227
|
-
},
|
|
228
|
-
)
|
|
229
|
-
|
|
230
|
-
continue
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
let mimeType = getMimeType(dataString as string)
|
|
234
|
-
let fileExtension = mimeType
|
|
235
|
-
|
|
236
|
-
if (fileExtension && fileExtension?.startsWith('image')) {
|
|
237
|
-
fileExtension = fileExtension.replace('image/', '')
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
let fileName = transactionId
|
|
241
|
-
|
|
242
|
-
if (contentType === 'base64') {
|
|
243
|
-
if (mimeType) {
|
|
244
|
-
fileName += `.${fileExtension}`
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
// Remove the Base64 header if it exists (e.g., "data:image/png;base64,")
|
|
248
|
-
const base64Data = dataString.split(',').pop() || ''
|
|
249
|
-
|
|
250
|
-
// Decode the Base64 string to binary
|
|
251
|
-
const binaryString = atob(base64Data)
|
|
252
|
-
const length = binaryString.length
|
|
253
|
-
const binaryData = new Uint8Array(length)
|
|
254
|
-
|
|
255
|
-
for (let i = 0; i < length; i++) {
|
|
256
|
-
binaryData[i] = binaryString.charCodeAt(i)
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
console.log(`attempting to writeFile to /files/images/${fileName}`)
|
|
260
|
-
|
|
261
|
-
await fs.promises.writeFile(`/files/images/${fileName}`, binaryData, {
|
|
262
|
-
encoding: 'binary',
|
|
263
|
-
})
|
|
264
|
-
|
|
265
|
-
// if (dataUint8Array && dataUint8Array instanceof Uint8Array) {
|
|
266
|
-
// await fs.promises.writeFile(
|
|
267
|
-
// `/files/images/${fileName}`,
|
|
268
|
-
// dataUint8Array,
|
|
269
|
-
// )
|
|
270
|
-
// }
|
|
271
|
-
}
|
|
34
|
+
fetchMetadata().then((metadataRecords) => {
|
|
35
|
+
sendBack({ type: 'fetchingMetadataSuccess', metadataRecords })
|
|
36
|
+
})
|
|
272
37
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
}
|
|
38
|
+
return () => { }
|
|
39
|
+
},
|
|
40
|
+
)
|
|
277
41
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
logger(error)
|
|
284
|
-
}
|
|
285
|
-
}
|
|
42
|
+
export const fetchBinaryData = fromCallback<
|
|
43
|
+
EventObject,
|
|
44
|
+
typeof downloadMachine
|
|
45
|
+
>(({ sendBack, receive, input: { context } }) => {
|
|
46
|
+
const { addresses } = context
|
|
286
47
|
|
|
48
|
+
const fetchBinaryData = async () => {
|
|
287
49
|
return []
|
|
288
50
|
}
|
|
289
51
|
|
|
290
|
-
|
|
291
|
-
sendBack({ type: '
|
|
52
|
+
fetchBinaryData().then(() => {
|
|
53
|
+
sendBack({ type: 'fetchingBinaryDataSuccess' })
|
|
292
54
|
})
|
|
293
55
|
|
|
294
56
|
return () => { }
|
package/dist/src/client.ts
CHANGED
|
@@ -19,6 +19,8 @@ import { initQueryClient } from './helpers/QueryClient'
|
|
|
19
19
|
import { initFileManager } from './helpers/FileManager'
|
|
20
20
|
import { initDb } from './db/Db'
|
|
21
21
|
import debug from 'debug'
|
|
22
|
+
import { appState } from './seedSchema'
|
|
23
|
+
import { BaseDb } from './db/Db/BaseDb'
|
|
22
24
|
|
|
23
25
|
const logger = debug('app:client')
|
|
24
26
|
|
|
@@ -76,6 +78,23 @@ const client = {
|
|
|
76
78
|
setModel(key, value)
|
|
77
79
|
}
|
|
78
80
|
},
|
|
81
|
+
setAddresses: (addresses: string[]) => {
|
|
82
|
+
const appDb = BaseDb.getAppDb()
|
|
83
|
+
if (!appDb) {
|
|
84
|
+
throw new Error('App DB not found')
|
|
85
|
+
}
|
|
86
|
+
appDb.insert(appState)
|
|
87
|
+
.values({
|
|
88
|
+
key: 'addresses',
|
|
89
|
+
value: JSON.stringify(addresses),
|
|
90
|
+
})
|
|
91
|
+
.onConflictDoUpdate({
|
|
92
|
+
target: appState.key,
|
|
93
|
+
set: {
|
|
94
|
+
value: JSON.stringify(addresses),
|
|
95
|
+
},
|
|
96
|
+
})
|
|
97
|
+
},
|
|
79
98
|
subscribe: (callback: any) => {
|
|
80
99
|
const subscription = globalService.subscribe(callback)
|
|
81
100
|
|
package/dist/src/download.ts
CHANGED
|
@@ -23,6 +23,7 @@ import { getArweave } from '@/helpers/ArweaveClient'
|
|
|
23
23
|
|
|
24
24
|
const logger = debug('app:files:download')
|
|
25
25
|
|
|
26
|
+
|
|
26
27
|
export const downloadAllFilesRequestHandler = async ({
|
|
27
28
|
endpoints,
|
|
28
29
|
eventId,
|
|
@@ -78,21 +79,10 @@ export const downloadAllFilesBinaryRequestHandler = async () => {
|
|
|
78
79
|
}),
|
|
79
80
|
})
|
|
80
81
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (!(await fs.promises.exists('/files/html'))) {
|
|
86
|
-
await fs.promises.mkdir('/files/html', { recursive: true })
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (!(await fs.promises.exists('/files/json'))) {
|
|
90
|
-
await fs.promises.mkdir('/files/json', { recursive: true })
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (!(await fs.promises.exists('/files/images'))) {
|
|
94
|
-
await fs.promises.mkdir('/files/images', { recursive: true })
|
|
95
|
-
}
|
|
82
|
+
await BaseFileManager.createDirIfNotExists('/files')
|
|
83
|
+
await BaseFileManager.createDirIfNotExists('/files/html')
|
|
84
|
+
await BaseFileManager.createDirIfNotExists('/files/json')
|
|
85
|
+
await BaseFileManager.createDirIfNotExists('/files/images')
|
|
96
86
|
|
|
97
87
|
const appDb = BaseDb.getAppDb()
|
|
98
88
|
|