@seedprotocol/sdk 0.1.108 → 0.1.109
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/bin.js +1 -1
- package/dist/{constants-qIJt7998.js → constants-CEnkzyny.js} +3 -3
- package/dist/{constants-qIJt7998.js.map → constants-CEnkzyny.js.map} +1 -1
- package/dist/{index-BmnXNuNp.js → index-vHcSfvyu.js} +3 -3
- package/dist/{index-BmnXNuNp.js.map → index-vHcSfvyu.js.map} +1 -1
- package/dist/{index-CsC8qxj6.js → index-vtm826YJ.js} +372 -156
- package/dist/index-vtm826YJ.js.map +1 -0
- package/dist/main.js +2 -2
- package/dist/{seed.schema.config-hUwOwJMn.js → seed.schema.config-Brb7H5eC.js} +3 -3
- package/dist/{seed.schema.config-hUwOwJMn.js.map → seed.schema.config-Brb7H5eC.js.map} +1 -1
- package/dist/src/ItemProperty.ts +32 -11
- package/dist/src/actors.ts +289 -7
- package/dist/src/analyzeInput.ts +2 -2
- package/dist/src/getItem.ts +1 -1
- package/dist/src/getPublishPayload.ts +50 -54
- package/dist/src/getPublishUploads.ts +240 -0
- package/dist/src/getSegmentedItemProperties.ts +65 -0
- package/dist/src/hydrateFromDb.ts +4 -4
- package/dist/src/index.ts +62 -10
- package/dist/src/propertyMachine.ts +3 -2
- package/dist/src/read.ts +1 -1
- package/dist/src/resolveRelatedValue.ts +12 -12
- package/dist/src/saveImageSrc.ts +5 -5
- package/dist/src/saveItemStorage.ts +2 -2
- package/dist/src/seed.ts +31 -4
- package/dist/types/src/browser/db/read/getPublishPayload.d.ts +9 -1
- package/dist/types/src/browser/db/read/getPublishPayload.d.ts.map +1 -1
- package/dist/types/src/browser/db/read/getPublishUploads.d.ts +17 -0
- package/dist/types/src/browser/db/read/getPublishUploads.d.ts.map +1 -0
- package/dist/types/src/browser/helpers/arweave.d.ts.map +1 -0
- package/dist/types/src/browser/helpers/getSegmentedItemProperties.d.ts +9 -0
- package/dist/types/src/browser/helpers/getSegmentedItemProperties.d.ts.map +1 -0
- package/dist/types/src/browser/item/Item.d.ts +3 -1
- package/dist/types/src/browser/item/Item.d.ts.map +1 -1
- package/dist/types/src/browser/property/ItemProperty.d.ts +195 -56
- package/dist/types/src/browser/property/ItemProperty.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/hydrateFromDb.d.ts +1 -2
- package/dist/types/src/browser/property/actors/hydrateFromDb.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/initialize.d.ts +1 -2
- package/dist/types/src/browser/property/actors/initialize.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/resolveRelatedValue.d.ts +1 -2
- package/dist/types/src/browser/property/actors/resolveRelatedValue.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/resolveRemoteStorage.d.ts +1 -2
- package/dist/types/src/browser/property/actors/resolveRemoteStorage.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/saveValueToDb/analyzeInput.d.ts +2 -2
- package/dist/types/src/browser/property/actors/saveValueToDb/analyzeInput.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/saveValueToDb/saveImageSrc.d.ts +2 -2
- package/dist/types/src/browser/property/actors/saveValueToDb/saveImageSrc.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/saveValueToDb/saveItemStorage.d.ts +2 -2
- package/dist/types/src/browser/property/actors/saveValueToDb/saveItemStorage.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/saveValueToDb/saveRelation.d.ts +2 -2
- package/dist/types/src/browser/property/actors/saveValueToDb/saveRelation.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/waitForDb.d.ts +2 -2
- package/dist/types/src/browser/property/actors/waitForDb.d.ts.map +1 -1
- package/dist/types/src/browser/property/propertyMachine.d.ts +195 -60
- package/dist/types/src/browser/property/propertyMachine.d.ts.map +1 -1
- package/dist/types/src/browser/schema/file/index.d.ts +1 -1
- package/dist/types/src/browser/schema/file/index.d.ts.map +1 -1
- package/dist/types/src/types/item.d.ts +1 -1
- package/dist/types/src/types/item.d.ts.map +1 -1
- package/dist/types/src/types/property.d.ts +3 -36
- package/dist/types/src/types/property.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/index-CsC8qxj6.js.map +0 -1
- package/dist/types/src/browser/schema/file/arweave.d.ts.map +0 -1
- /package/dist/types/src/browser/{schema/file → helpers}/arweave.d.ts +0 -0
package/dist/main.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { j as ImageSrc, I as Item, k as ItemProperty, J as Json, L as List, M as Model, P as Property, R as Relation, T as Text, t as client, v as getCorrectId, s as getGlobalService, n as useCreateItem, p as useDeleteItem, q as useGlobalServiceStatus, l as useItem, m as useItemProperties, o as useItemProperty, u as useItems, r as useServices, w as withSeed } from './index-
|
|
1
|
+
export { j as ImageSrc, I as Item, k as ItemProperty, J as Json, L as List, M as Model, P as Property, R as Relation, T as Text, t as client, v as getCorrectId, s as getGlobalService, n as useCreateItem, p as useDeleteItem, q as useGlobalServiceStatus, l as useItem, m as useItemProperties, o as useItemProperty, u as useItems, r as useServices, w as withSeed } from './index-vtm826YJ.js';
|
|
2
2
|
import 'immer';
|
|
3
3
|
import 'reflect-metadata';
|
|
4
|
-
import './constants-
|
|
4
|
+
import './constants-CEnkzyny.js';
|
|
5
5
|
import 'xstate';
|
|
6
6
|
import 'arweave';
|
|
7
7
|
import 'drizzle-orm';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { _ as __decorate, a as __metadata } from './constants-
|
|
1
|
+
import { _ as __decorate, a as __metadata } from './constants-CEnkzyny.js';
|
|
2
2
|
import 'drizzle-orm';
|
|
3
|
-
import { T as Text, M as Model } from './index-
|
|
3
|
+
import { T as Text, M as Model } from './index-vtm826YJ.js';
|
|
4
4
|
import 'react';
|
|
5
5
|
import 'reflect-metadata';
|
|
6
6
|
import 'xstate';
|
|
@@ -76,4 +76,4 @@ const models = {
|
|
|
76
76
|
};
|
|
77
77
|
|
|
78
78
|
export { models };
|
|
79
|
-
//# sourceMappingURL=seed.schema.config-
|
|
79
|
+
//# sourceMappingURL=seed.schema.config-Brb7H5eC.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seed.schema.config-
|
|
1
|
+
{"version":3,"file":"seed.schema.config-Brb7H5eC.js","sources":["../../src/shared/configs/seed.schema.config.ts"],"sourcesContent":["import { Model, Text } from '@/browser'\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,KAAA,CAAA,CAAA;AACZ,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAc,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,MAAA,EAAA,KAAA,CAAA,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,KAAA,CAAA,CAAA;AAChB,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAc,CAAA,EAAA,OAAA,CAAA,SAAA,EAAA,MAAA,EAAA,KAAA,CAAA,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,KAAA,CAAA,CAAA;AACZ,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAe,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,OAAA,EAAA,KAAA,CAAA,CAAA;AAFlB,QAAQ,GAAA,UAAA,CAAA;IADb;AACK,CAAA,EAAA,QAAQ,CAGb;AAEY,MAAA,MAAM,GAAG;IACpB,IAAI;IACJ,OAAO;IACP,QAAQ;;;;;"}
|
package/dist/src/ItemProperty.ts
CHANGED
|
@@ -58,15 +58,15 @@ export class ItemProperty<PropertyType> {
|
|
|
58
58
|
seedLocalId,
|
|
59
59
|
versionLocalId,
|
|
60
60
|
versionUid,
|
|
61
|
-
|
|
61
|
+
modelName,
|
|
62
62
|
propertyName,
|
|
63
63
|
storageTransactionId,
|
|
64
64
|
schemaUid,
|
|
65
65
|
}: Partial<CreatePropertyInstanceProps>) {
|
|
66
|
-
const ModelClass = getModel(
|
|
66
|
+
const ModelClass = getModel(modelName)
|
|
67
67
|
|
|
68
68
|
if (!ModelClass) {
|
|
69
|
-
throw new Error(`Model ${
|
|
69
|
+
throw new Error(`Model ${modelName} not found`)
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
if (!propertyName) {
|
|
@@ -80,7 +80,7 @@ export class ItemProperty<PropertyType> {
|
|
|
80
80
|
seedUid,
|
|
81
81
|
versionLocalId,
|
|
82
82
|
versionUid,
|
|
83
|
-
|
|
83
|
+
modelName: modelName,
|
|
84
84
|
storageTransactionId,
|
|
85
85
|
propertyRecordSchema: ModelClass.schema[propertyName],
|
|
86
86
|
schemaUid,
|
|
@@ -150,6 +150,16 @@ export class ItemProperty<PropertyType> {
|
|
|
150
150
|
const { context } = snapshot
|
|
151
151
|
const { propertyRecordSchema } = context
|
|
152
152
|
|
|
153
|
+
// if (
|
|
154
|
+
// context.propertyName &&
|
|
155
|
+
// context.propertyName.includes('featureImage')
|
|
156
|
+
// ) {
|
|
157
|
+
// console.log(
|
|
158
|
+
// `${context.localId} context for ${snapshot.value}`,
|
|
159
|
+
// context,
|
|
160
|
+
// )
|
|
161
|
+
// }
|
|
162
|
+
|
|
153
163
|
if (context.seedLocalId) {
|
|
154
164
|
const cacheKey = ItemProperty.cacheKey(
|
|
155
165
|
context.seedLocalId,
|
|
@@ -217,12 +227,10 @@ export class ItemProperty<PropertyType> {
|
|
|
217
227
|
|
|
218
228
|
this._subject.next(renderValue)
|
|
219
229
|
if (context.seedLocalId) {
|
|
220
|
-
eventEmitter.emit(
|
|
221
|
-
`item.${itemModelName}.${context.seedLocalId}.update`,
|
|
222
|
-
)
|
|
230
|
+
eventEmitter.emit(`item.${modelName}.${context.seedLocalId}.update`)
|
|
223
231
|
}
|
|
224
232
|
if (context.seedUid) {
|
|
225
|
-
eventEmitter.emit(`item.${
|
|
233
|
+
eventEmitter.emit(`item.${modelName}.${context.seedUid}.update`)
|
|
226
234
|
}
|
|
227
235
|
},
|
|
228
236
|
)
|
|
@@ -232,7 +240,7 @@ export class ItemProperty<PropertyType> {
|
|
|
232
240
|
|
|
233
241
|
private _updateResponseListener(event) {
|
|
234
242
|
logger(
|
|
235
|
-
`[ItemProperty] [_updateResponseListener] [${this.
|
|
243
|
+
`[ItemProperty] [_updateResponseListener] [${this.modelName}.${this.seedLocalId}] ${this.propertyName} event`,
|
|
236
244
|
event,
|
|
237
245
|
)
|
|
238
246
|
}
|
|
@@ -351,14 +359,27 @@ export class ItemProperty<PropertyType> {
|
|
|
351
359
|
return this._getSnapshot().context.propertyName
|
|
352
360
|
}
|
|
353
361
|
|
|
354
|
-
get
|
|
355
|
-
return this._getSnapshot().context.
|
|
362
|
+
get modelName() {
|
|
363
|
+
return this._getSnapshot().context.modelName
|
|
356
364
|
}
|
|
357
365
|
|
|
358
366
|
get propertyDef(): Static<typeof TProperty> | undefined {
|
|
359
367
|
return this._getSnapshot().context.propertyRecordSchema
|
|
360
368
|
}
|
|
361
369
|
|
|
370
|
+
get localStoragePath(): string | void {
|
|
371
|
+
if (this.propertyDef && this.propertyDef.localStorageDir) {
|
|
372
|
+
return `/files${this.propertyDef.localStorageDir}/${this._getSnapshot().context.refResolvedValue}`
|
|
373
|
+
}
|
|
374
|
+
if (this._getSnapshot().context.localStorageDir) {
|
|
375
|
+
return `/files${this._getSnapshot().context.localStorageDir}/${this._getSnapshot().context.refResolvedValue}`
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
get versionLocalId(): string | undefined {
|
|
380
|
+
return this._getSnapshot().context.versionLocalId
|
|
381
|
+
}
|
|
382
|
+
|
|
362
383
|
get status() {
|
|
363
384
|
return this._getSnapshot().value
|
|
364
385
|
}
|
package/dist/src/actors.ts
CHANGED
|
@@ -1,10 +1,292 @@
|
|
|
1
1
|
import { EventObject, fromCallback } from 'xstate'
|
|
2
|
-
import {
|
|
2
|
+
import { fetchAllFilesMachine } from '@/browser/schema/file/fetchAll/index'
|
|
3
|
+
import { ARWEAVE_HOST } from '@/browser/services/internal/constants'
|
|
4
|
+
import { GET_FILES_METADATA } from '@/browser/schema/file/queries'
|
|
5
|
+
import { getArweave } from '../../../helpers/arweave'
|
|
6
|
+
import { fs } from '@zenfs/core'
|
|
7
|
+
import {
|
|
8
|
+
getDataTypeFromString,
|
|
9
|
+
getMimeType,
|
|
10
|
+
identifyString,
|
|
11
|
+
} from '@/shared/helpers'
|
|
12
|
+
import { appState } from 'src/shared/seedSchema'
|
|
13
|
+
import { eq } from 'drizzle-orm'
|
|
14
|
+
import { easClient, queryClient } from '@/browser/helpers'
|
|
15
|
+
import debug from 'debug'
|
|
16
|
+
import { getAppDb } from '@/browser/db/sqlWasmClient'
|
|
3
17
|
|
|
4
|
-
|
|
5
|
-
({ sendBack, receive, input }) => {},
|
|
6
|
-
)
|
|
18
|
+
import { saveAppState } from '@/browser/db/write/saveAppState'
|
|
7
19
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
20
|
+
const logger = debug('app:file:actors:fetchAll')
|
|
21
|
+
|
|
22
|
+
type FileType = {
|
|
23
|
+
mimeType: string
|
|
24
|
+
extension: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Map of common MIME types to file extensions
|
|
28
|
+
const fileTypeMap: Record<string, FileType> = {
|
|
29
|
+
'image/jpeg': { mimeType: 'image/jpeg', extension: '.jpg' },
|
|
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
|
+
}
|
|
35
|
+
|
|
36
|
+
export const fetchAllMetadataRecords = fromCallback<
|
|
37
|
+
EventObject,
|
|
38
|
+
typeof fetchAllFilesMachine
|
|
39
|
+
>(({ sendBack, receive, input: { context, event } }) => {
|
|
40
|
+
const { addresses } = context
|
|
41
|
+
|
|
42
|
+
const _fetchAllMetadataRecords = async () => {
|
|
43
|
+
const { filesMetadata } = await queryClient.fetchQuery({
|
|
44
|
+
queryKey: ['getFilesMetadata', ...addresses],
|
|
45
|
+
queryFn: async () =>
|
|
46
|
+
easClient.request(GET_FILES_METADATA, {
|
|
47
|
+
where: {
|
|
48
|
+
attester: {
|
|
49
|
+
in: addresses,
|
|
50
|
+
},
|
|
51
|
+
schema: {
|
|
52
|
+
is: {
|
|
53
|
+
id: {
|
|
54
|
+
equals:
|
|
55
|
+
'0x55fdefb36fcbbaebeb7d6b41dc3a1a9666e4e42154267c889de064faa7ede517',
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
}),
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
return filesMetadata
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
_fetchAllMetadataRecords().then((filesMetadata) => {
|
|
67
|
+
sendBack({ type: 'fetchingAllMetadataRecordsSuccess', filesMetadata })
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
return () => {}
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
export const fetchAllBinaryData = fromCallback<
|
|
74
|
+
EventObject,
|
|
75
|
+
typeof fetchAllFilesMachine
|
|
76
|
+
>(({ sendBack, input: { context } }) => {
|
|
77
|
+
const { filesMetadata, addresses } = context
|
|
78
|
+
|
|
79
|
+
const _fetchAllBinaryData = async () => {
|
|
80
|
+
if (!(await fs.promises.exists('/files'))) {
|
|
81
|
+
await fs.promises.mkdir('/files', { recursive: true })
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (!(await fs.promises.exists('/files/html'))) {
|
|
85
|
+
await fs.promises.mkdir('/files/html', { recursive: true })
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (!(await fs.promises.exists('/files/json'))) {
|
|
89
|
+
await fs.promises.mkdir('/files/json', { recursive: true })
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (!(await fs.promises.exists('/files/images'))) {
|
|
93
|
+
await fs.promises.mkdir('/files/images', { recursive: true })
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const appDb = getAppDb()
|
|
97
|
+
|
|
98
|
+
if (!appDb) {
|
|
99
|
+
logger('[fetchAll/actors] [fetchAllBinaryData] seedDb not available')
|
|
100
|
+
return []
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
for (const fileMetadata of filesMetadata) {
|
|
104
|
+
const json = JSON.parse(fileMetadata.decodedDataJson)
|
|
105
|
+
const transactionId = json[0].value.value
|
|
106
|
+
|
|
107
|
+
const excludedTransactionsQuery = await appDb
|
|
108
|
+
.select()
|
|
109
|
+
.from(appState)
|
|
110
|
+
.where(eq(appState.key, 'excludedTransactions'))
|
|
111
|
+
|
|
112
|
+
let excludedTransactions = new Set<string>()
|
|
113
|
+
|
|
114
|
+
if (excludedTransactionsQuery && excludedTransactionsQuery.length === 1) {
|
|
115
|
+
const valueString = excludedTransactionsQuery[0].value
|
|
116
|
+
if (valueString) {
|
|
117
|
+
const excludedTransactionsArray = JSON.parse(valueString)
|
|
118
|
+
excludedTransactions = new Set(excludedTransactionsArray)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (excludedTransactions.has(transactionId)) {
|
|
123
|
+
continue
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const arweave = getArweave()
|
|
127
|
+
|
|
128
|
+
if (!arweave) {
|
|
129
|
+
logger('[fetchAll/actors] [fetchAllBinaryData] arweave not available')
|
|
130
|
+
return []
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
try {
|
|
134
|
+
const res = await fetch(
|
|
135
|
+
`https://${ARWEAVE_HOST}/tx/${transactionId}/status`,
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
if (res.status !== 200) {
|
|
139
|
+
logger(
|
|
140
|
+
`[fetchAll/actors] [fetchAllBinaryData] error fetching transaction data for ${transactionId}`,
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
excludedTransactions.add(transactionId)
|
|
144
|
+
|
|
145
|
+
await saveAppState(
|
|
146
|
+
'excludedTransactions',
|
|
147
|
+
JSON.stringify(Array.from(excludedTransactions)),
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
logger(
|
|
151
|
+
'[fetchAll/actors] [fetchAllBinaryData] updated excludedTransactions:',
|
|
152
|
+
excludedTransactions,
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
continue
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const dataString = await arweave.transactions
|
|
159
|
+
.getData(transactionId, {
|
|
160
|
+
decode: true,
|
|
161
|
+
string: true,
|
|
162
|
+
})
|
|
163
|
+
.catch((error) => {
|
|
164
|
+
logger(
|
|
165
|
+
`[fetchAll/actors] [fetchAllBinaryData] error fetching transaction data for ${transactionId}`,
|
|
166
|
+
error,
|
|
167
|
+
)
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
const dataUint8Array = await arweave.transactions.getData(transactionId)
|
|
171
|
+
// let buffer
|
|
172
|
+
//
|
|
173
|
+
// if (dataUint8Array && dataUint8Array instanceof Uint8Array) {
|
|
174
|
+
// }
|
|
175
|
+
|
|
176
|
+
let contentType = identifyString(dataString)
|
|
177
|
+
if (
|
|
178
|
+
contentType !== 'json' &&
|
|
179
|
+
contentType !== 'base64' &&
|
|
180
|
+
contentType !== 'html'
|
|
181
|
+
) {
|
|
182
|
+
const possibleImageType = getDataTypeFromString(dataString)
|
|
183
|
+
if (!possibleImageType) {
|
|
184
|
+
logger(
|
|
185
|
+
`[fetchAll/actors] [fetchAllBinaryData] transaction ${transactionId} data not in expected format: ${possibleImageType}`,
|
|
186
|
+
)
|
|
187
|
+
continue
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
contentType = possibleImageType
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (contentType === 'url') {
|
|
194
|
+
const url = dataString as string
|
|
195
|
+
const response = await fetch(url)
|
|
196
|
+
if (!response.ok) {
|
|
197
|
+
throw new Error(`Failed to fetch image: ${response.statusText}`)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Get the image as a Blob
|
|
201
|
+
const blob = await response.blob()
|
|
202
|
+
const buffer = await blob.arrayBuffer()
|
|
203
|
+
const bufferUint8Array = new Uint8Array(buffer)
|
|
204
|
+
|
|
205
|
+
// Extract the file extension from the URL
|
|
206
|
+
const extensionMatch = url.match(
|
|
207
|
+
/\.(jpg|jpeg|png|gif|bmp|webp|svg)$/i,
|
|
208
|
+
)
|
|
209
|
+
if (!extensionMatch) {
|
|
210
|
+
throw new Error(
|
|
211
|
+
'Unable to determine the file extension from the URL.',
|
|
212
|
+
)
|
|
213
|
+
}
|
|
214
|
+
const fileExtension = extensionMatch[0] // e.g., ".jpg"
|
|
215
|
+
|
|
216
|
+
// Set the file name (you can customize this)
|
|
217
|
+
// const fileNameFromUrl = `${transactionId}${fileExtension}`
|
|
218
|
+
|
|
219
|
+
await fs.promises.writeFile(
|
|
220
|
+
`/files/images/${transactionId}`,
|
|
221
|
+
bufferUint8Array,
|
|
222
|
+
{
|
|
223
|
+
encoding: 'binary',
|
|
224
|
+
},
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
continue
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
let mimeType = getMimeType(dataString as string)
|
|
231
|
+
let fileExtension = mimeType
|
|
232
|
+
|
|
233
|
+
if (fileExtension && fileExtension?.startsWith('image')) {
|
|
234
|
+
fileExtension = fileExtension.replace('image/', '')
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
let fileName = transactionId
|
|
238
|
+
|
|
239
|
+
if (contentType === 'base64') {
|
|
240
|
+
if (mimeType) {
|
|
241
|
+
fileName += `.${fileExtension}`
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// Remove the Base64 header if it exists (e.g., "data:image/png;base64,")
|
|
245
|
+
const base64Data = dataString.split(',').pop() || ''
|
|
246
|
+
|
|
247
|
+
// Decode the Base64 string to binary
|
|
248
|
+
const binaryString = atob(base64Data)
|
|
249
|
+
const length = binaryString.length
|
|
250
|
+
const binaryData = new Uint8Array(length)
|
|
251
|
+
|
|
252
|
+
for (let i = 0; i < length; i++) {
|
|
253
|
+
binaryData[i] = binaryString.charCodeAt(i)
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
console.log(`attempting to writeFile to /files/images/${fileName}`)
|
|
257
|
+
|
|
258
|
+
await fs.promises.writeFile(`/files/images/${fileName}`, binaryData, {
|
|
259
|
+
encoding: 'binary',
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
// if (dataUint8Array && dataUint8Array instanceof Uint8Array) {
|
|
263
|
+
// await fs.promises.writeFile(
|
|
264
|
+
// `/files/images/${fileName}`,
|
|
265
|
+
// dataUint8Array,
|
|
266
|
+
// )
|
|
267
|
+
// }
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (contentType === 'html') {
|
|
271
|
+
fileName += '.html'
|
|
272
|
+
await fs.promises.writeFile(`/files/html/${fileName}`, dataString)
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (contentType === 'json') {
|
|
276
|
+
fileName += '.json'
|
|
277
|
+
await fs.promises.writeFile(`/files/json/${fileName}`, dataString)
|
|
278
|
+
}
|
|
279
|
+
} catch (error) {
|
|
280
|
+
logger(error)
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
return []
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
_fetchAllBinaryData().then((binaryData) => {
|
|
288
|
+
sendBack({ type: 'fetchingAllBinaryDataSuccess', binaryData })
|
|
289
|
+
})
|
|
290
|
+
|
|
291
|
+
return () => {}
|
|
292
|
+
})
|
package/dist/src/analyzeInput.ts
CHANGED
|
@@ -23,7 +23,7 @@ export const analyzeInput = fromCallback<
|
|
|
23
23
|
versionUid,
|
|
24
24
|
propertyValue: existingValue,
|
|
25
25
|
propertyRecordSchema,
|
|
26
|
-
|
|
26
|
+
modelName,
|
|
27
27
|
} = context
|
|
28
28
|
|
|
29
29
|
let { schemaUid } = context
|
|
@@ -104,7 +104,7 @@ export const analyzeInput = fromCallback<
|
|
|
104
104
|
seedLocalId,
|
|
105
105
|
versionLocalId,
|
|
106
106
|
versionUid,
|
|
107
|
-
modelName
|
|
107
|
+
modelName,
|
|
108
108
|
schemaUid,
|
|
109
109
|
})
|
|
110
110
|
|
package/dist/src/getItem.ts
CHANGED
|
@@ -18,6 +18,10 @@ import { getSchemaUidForSchemaDefinition } from '@/browser/stores/eas'
|
|
|
18
18
|
import { ItemProperty } from '@/browser/property/ItemProperty'
|
|
19
19
|
import { getCorrectId } from '@/browser/helpers'
|
|
20
20
|
import { Item } from '@/browser/item/Item'
|
|
21
|
+
import debug from 'debug'
|
|
22
|
+
import { getSegmentedItemProperties } from '@/browser/helpers/getSegmentedItemProperties'
|
|
23
|
+
|
|
24
|
+
const logger = debug('app:item:getPublishPayload')
|
|
21
25
|
|
|
22
26
|
const getVersionUid = (item: Item<any>) => {
|
|
23
27
|
let versionUid
|
|
@@ -63,46 +67,6 @@ const getPropertyData = async (itemProperty: ItemProperty<any>) => {
|
|
|
63
67
|
}
|
|
64
68
|
}
|
|
65
69
|
|
|
66
|
-
const getSegmentedItemProperties = (item: Item<any>) => {
|
|
67
|
-
const itemBasicProperties = []
|
|
68
|
-
const itemRelationProperties = []
|
|
69
|
-
const itemListProperties = []
|
|
70
|
-
const itemStorageProperties = []
|
|
71
|
-
|
|
72
|
-
for (const itemProperty of Object.values(item.properties)) {
|
|
73
|
-
if (!itemProperty.propertyDef) {
|
|
74
|
-
continue
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (itemProperty.propertyDef.dataType === 'Relation') {
|
|
78
|
-
itemRelationProperties.push(itemProperty)
|
|
79
|
-
continue
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (itemProperty.propertyDef.dataType === 'List') {
|
|
83
|
-
itemListProperties.push(itemProperty)
|
|
84
|
-
continue
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (
|
|
88
|
-
itemProperty.propertyDef.storageType &&
|
|
89
|
-
itemProperty.propertyDef.storageType === 'ItemStorage'
|
|
90
|
-
) {
|
|
91
|
-
itemStorageProperties.push(itemProperty)
|
|
92
|
-
continue
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
itemBasicProperties.push(itemProperty)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return {
|
|
99
|
-
itemBasicProperties,
|
|
100
|
-
itemRelationProperties,
|
|
101
|
-
itemListProperties,
|
|
102
|
-
itemStorageProperties,
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
70
|
const processBasicProperties = async (
|
|
107
71
|
itemBasicProperties: ItemProperty<any>[],
|
|
108
72
|
itemPublishData: PublishPayload,
|
|
@@ -148,6 +112,7 @@ const processBasicProperties = async (
|
|
|
148
112
|
const processRelationProperty = async (
|
|
149
113
|
relationProperty: ItemProperty<any>,
|
|
150
114
|
multiPublishPayload: MultiPublishPayload,
|
|
115
|
+
uploadedTransactions: UploadedTransaction[],
|
|
151
116
|
): Promise<MultiPublishPayload> => {
|
|
152
117
|
const value = relationProperty.getService().getSnapshot()
|
|
153
118
|
.context.propertyValue
|
|
@@ -185,7 +150,21 @@ const processRelationProperty = async (
|
|
|
185
150
|
propertiesToUpdate: [],
|
|
186
151
|
}
|
|
187
152
|
|
|
188
|
-
const { itemBasicProperties } =
|
|
153
|
+
const { itemBasicProperties, itemUploadProperties } =
|
|
154
|
+
getSegmentedItemProperties(relatedItem)
|
|
155
|
+
|
|
156
|
+
if (itemUploadProperties.length === 1) {
|
|
157
|
+
const uploadProperty = itemUploadProperties[0]
|
|
158
|
+
const itemProperty = uploadProperty.itemProperty
|
|
159
|
+
const transactionData = uploadedTransactions.find(
|
|
160
|
+
(transaction) => transaction.seedLocalId === relatedItem.seedLocalId,
|
|
161
|
+
)
|
|
162
|
+
if (transactionData) {
|
|
163
|
+
itemProperty.value = transactionData.txId
|
|
164
|
+
await itemProperty.save()
|
|
165
|
+
itemBasicProperties.push(itemProperty)
|
|
166
|
+
}
|
|
167
|
+
}
|
|
189
168
|
|
|
190
169
|
publishPayload = await processBasicProperties(
|
|
191
170
|
itemBasicProperties,
|
|
@@ -285,22 +264,25 @@ type PublishPayload = {
|
|
|
285
264
|
|
|
286
265
|
type MultiPublishPayload = PublishPayload[]
|
|
287
266
|
|
|
267
|
+
type UploadedTransaction = {
|
|
268
|
+
txId: string
|
|
269
|
+
itemPropertyLocalId?: string
|
|
270
|
+
seedLocalId?: string
|
|
271
|
+
versionLocalId?: string
|
|
272
|
+
itemPropertyName?: string
|
|
273
|
+
}
|
|
274
|
+
|
|
288
275
|
export const getPublishPayload = async (
|
|
289
|
-
|
|
276
|
+
item: Item<any>,
|
|
277
|
+
uploadedTransactions: UploadedTransaction[],
|
|
290
278
|
): Promise<MultiPublishPayload> => {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
279
|
+
if (item.modelName === 'Post') {
|
|
280
|
+
item.authors = [
|
|
281
|
+
'Sr0bIx9Fwj',
|
|
282
|
+
'0xc2879650e9503a303ceb46f966e55baab480b267dc20cede23ef503622eee6d7',
|
|
283
|
+
]
|
|
295
284
|
}
|
|
296
285
|
|
|
297
|
-
// if (item.modelName === 'Post') {
|
|
298
|
-
// item.authors = [
|
|
299
|
-
// 'Sr0bIx9Fwj',
|
|
300
|
-
// '0xc2879650e9503a303ceb46f966e55baab480b267dc20cede23ef503622eee6d7',
|
|
301
|
-
// ]
|
|
302
|
-
// }
|
|
303
|
-
|
|
304
286
|
let multiPublishPayload: MultiPublishPayload = []
|
|
305
287
|
|
|
306
288
|
// Each PublishPayload is generated from a Seed that needs publishing
|
|
@@ -324,9 +306,22 @@ export const getPublishPayload = async (
|
|
|
324
306
|
itemBasicProperties,
|
|
325
307
|
itemRelationProperties,
|
|
326
308
|
itemListProperties,
|
|
327
|
-
|
|
309
|
+
itemUploadProperties,
|
|
328
310
|
} = getSegmentedItemProperties(item)
|
|
329
311
|
|
|
312
|
+
if (itemUploadProperties.length === 1) {
|
|
313
|
+
const uploadProperty = itemUploadProperties[0]
|
|
314
|
+
const itemProperty = uploadProperty.itemProperty
|
|
315
|
+
const transactionData = uploadedTransactions.find(
|
|
316
|
+
(transaction) => transaction.seedLocalId === item.seedLocalId,
|
|
317
|
+
)
|
|
318
|
+
if (transactionData) {
|
|
319
|
+
itemProperty.value = transactionData.txId
|
|
320
|
+
await itemProperty.save()
|
|
321
|
+
itemBasicProperties.push(itemProperty)
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
330
325
|
itemPublishData = await processBasicProperties(
|
|
331
326
|
itemBasicProperties,
|
|
332
327
|
itemPublishData,
|
|
@@ -338,6 +333,7 @@ export const getPublishPayload = async (
|
|
|
338
333
|
multiPublishPayload = await processRelationProperty(
|
|
339
334
|
relationProperty,
|
|
340
335
|
multiPublishPayload,
|
|
336
|
+
uploadedTransactions,
|
|
341
337
|
)
|
|
342
338
|
}
|
|
343
339
|
|