@seedprotocol/sdk 0.2.43 → 0.2.45
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-BXD_aTsx.js → ArweaveClient-CoFomTCN.js} +2 -2
- package/dist/{ArweaveClient-CkcZD_QE.js.map → ArweaveClient-CoFomTCN.js.map} +1 -1
- package/dist/{ArweaveClient-CkcZD_QE.js → ArweaveClient-DQrXvrNN.js} +2 -2
- package/dist/{ArweaveClient-BXD_aTsx.js.map → ArweaveClient-DQrXvrNN.js.map} +1 -1
- package/dist/{Db-Bug4efsE.js → Db-BlgPVb_Z.js} +156 -166
- package/dist/Db-BlgPVb_Z.js.map +1 -0
- package/dist/{Db-B4XyOmGy.js → Db-gw_uZA_e.js} +34 -43
- package/dist/{Db-B4XyOmGy.js.map → Db-gw_uZA_e.js.map} +1 -1
- package/dist/{EasClient-BNwSwDTO.js → EasClient-CBu9ENAi.js} +2 -2
- package/dist/{EasClient-epqE9aWI.js.map → EasClient-CBu9ENAi.js.map} +1 -1
- package/dist/{EasClient-epqE9aWI.js → EasClient-sCbTHcO8.js} +2 -2
- package/dist/{EasClient-BNwSwDTO.js.map → EasClient-sCbTHcO8.js.map} +1 -1
- package/dist/FileManager-BNqJl6Bz.js +781 -0
- package/dist/FileManager-BNqJl6Bz.js.map +1 -0
- package/dist/FileManager-COOp89Mj.js +38 -0
- package/dist/FileManager-COOp89Mj.js.map +1 -0
- package/dist/{Item-vjJTzf1d.js → Item-BO38NUjz.js} +9 -12
- package/dist/{Item-vjJTzf1d.js.map → Item-BO38NUjz.js.map} +1 -1
- package/dist/{ItemProperty-DJpbernm.js → ItemProperty-8H7B05zy.js} +9 -12
- package/dist/{ItemProperty-DJpbernm.js.map → ItemProperty-8H7B05zy.js.map} +1 -1
- package/dist/{QueryClient-Ckl99FYC.js → QueryClient-BBaE-LKI.js} +2 -2
- package/dist/{QueryClient-Ckl99FYC.js.map → QueryClient-BBaE-LKI.js.map} +1 -1
- package/dist/{QueryClient-Do0C7Jnt.js → QueryClient-C-ZzUnWq.js} +2 -2
- package/dist/{QueryClient-Do0C7Jnt.js.map → QueryClient-C-ZzUnWq.js.map} +1 -1
- package/dist/bin.js +28 -27
- package/dist/bin.js.map +1 -1
- package/dist/{constants-BakHTrB9.js → constants-Dgv-tSO3.js} +76 -41
- package/dist/constants-Dgv-tSO3.js.map +1 -0
- package/dist/{index-DcPIAiHD.js → index-CsbUKGXp.js} +1330 -1571
- package/dist/index-CsbUKGXp.js.map +1 -0
- package/dist/{index-BWIn7kWN.js → index-Km3L1_LR.js} +9 -12
- package/dist/index-Km3L1_LR.js.map +1 -0
- package/dist/main.js +7 -10
- package/dist/main.js.map +1 -1
- package/dist/node/codegen/templates/index.njk +0 -4
- package/dist/{seed.schema.config-DGcg6TCS.js → seed.schema.config-Dn_1QbD7.js} +9 -11
- package/dist/seed.schema.config-Dn_1QbD7.js.map +1 -0
- package/dist/seedSchema/index.ts +0 -2
- package/dist/src/BaseFileManager.ts +31 -2
- package/dist/src/BaseItem.ts +4 -3
- package/dist/src/BaseItemProperty.ts +2 -2
- package/dist/src/FileDownloader.ts +63 -0
- package/dist/src/FileManager.ts +37 -6
- package/dist/src/ImageResizer.ts +84 -0
- package/dist/src/analyzeInput.ts +22 -2
- package/dist/src/configureFs.ts +18 -5
- package/dist/src/constants.ts +67 -60
- package/dist/src/createMetadata.ts +27 -2
- package/dist/src/dbMachine.ts +6 -0
- package/dist/src/download.ts +48 -203
- package/dist/src/filesDownload.ts +326 -0
- package/dist/src/getItem.ts +5 -0
- package/dist/src/getPublishPayload.ts +15 -8
- package/dist/src/getPublishUploads.ts +0 -27
- package/dist/src/helpers.ts +7 -15
- package/dist/src/hydrateFromDb.ts +4 -1
- package/dist/src/imageResize.ts +507 -0
- package/dist/src/internalMachine.ts +16 -0
- package/dist/src/migrate.ts +0 -24
- package/dist/src/model.ts +6 -5
- package/dist/src/saveImageSrc.ts +15 -1
- package/dist/src/syncDbWithEas.ts +0 -90
- package/dist/src/updateItemPropertyValue.ts +16 -3
- package/dist/src/validate.ts +6 -3
- package/dist/src/waitForDb.ts +18 -17
- package/dist/src/waitForFiles.ts +9 -8
- package/dist/types/src/Item/BaseItem.d.ts +2 -2
- package/dist/types/src/Item/BaseItem.d.ts.map +1 -1
- package/dist/types/src/ItemProperty/BaseItemProperty.d.ts +2 -2
- package/dist/types/src/ItemProperty/BaseItemProperty.d.ts.map +1 -1
- package/dist/types/src/ItemProperty/service/actors/hydrateFromDb.d.ts.map +1 -1
- package/dist/types/src/ItemProperty/service/actors/saveValueToDb/analyzeInput.d.ts.map +1 -1
- package/dist/types/src/ItemProperty/service/actors/saveValueToDb/saveImageSrc.d.ts.map +1 -1
- package/dist/types/src/browser/db/Db.d.ts.map +1 -1
- package/dist/types/src/browser/helpers/FileManager.d.ts +5 -1
- package/dist/types/src/browser/helpers/FileManager.d.ts.map +1 -1
- package/dist/types/src/browser/workers/FileDownloader.d.ts +8 -0
- package/dist/types/src/browser/workers/FileDownloader.d.ts.map +1 -0
- package/dist/types/src/browser/workers/ImageResizer.d.ts +9 -0
- package/dist/types/src/browser/workers/ImageResizer.d.ts.map +1 -0
- package/dist/types/src/browser/workers/content-hash.d.ts.map +1 -0
- package/dist/types/src/browser/workers/filesDownload.d.ts +3 -0
- package/dist/types/src/browser/workers/filesDownload.d.ts.map +1 -0
- package/dist/types/src/browser/workers/imageResize.d.ts +3 -0
- package/dist/types/src/browser/workers/imageResize.d.ts.map +1 -0
- package/dist/types/src/db/read/getItem.d.ts.map +1 -1
- package/dist/types/src/db/read/getPublishPayload.d.ts.map +1 -1
- package/dist/types/src/db/read/getPublishUploads.d.ts.map +1 -1
- package/dist/types/src/db/write/createMetadata.d.ts.map +1 -1
- package/dist/types/src/db/write/updateItemPropertyValue.d.ts +5 -1
- package/dist/types/src/db/write/updateItemPropertyValue.d.ts.map +1 -1
- package/dist/types/src/events/files/download.d.ts.map +1 -1
- package/dist/types/src/events/files/index.d.ts.map +1 -1
- package/dist/types/src/events/item/syncDbWithEas.d.ts.map +1 -1
- package/dist/types/src/helpers/FileManager/BaseFileManager.d.ts +6 -0
- package/dist/types/src/helpers/FileManager/BaseFileManager.d.ts.map +1 -1
- package/dist/types/src/helpers/constants.d.ts +7 -0
- package/dist/types/src/helpers/constants.d.ts.map +1 -1
- package/dist/types/src/helpers/files.d.ts +1 -1
- package/dist/types/src/helpers/files.d.ts.map +1 -1
- package/dist/types/src/node/helpers/FileManager.d.ts +5 -0
- package/dist/types/src/node/helpers/FileManager.d.ts.map +1 -1
- package/dist/types/src/schema/model/index.d.ts +2 -2
- package/dist/types/src/schema/model/index.d.ts.map +1 -1
- package/dist/types/src/seedSchema/index.d.ts +0 -2
- package/dist/types/src/seedSchema/index.d.ts.map +1 -1
- package/dist/types/src/services/allItems/actors/initialize.d.ts.map +1 -1
- package/dist/types/src/services/db/actors/migrate.d.ts.map +1 -1
- package/dist/types/src/services/db/actors/validate.d.ts.map +1 -1
- package/dist/types/src/services/db/dbMachine.d.ts +10 -0
- package/dist/types/src/services/db/dbMachine.d.ts.map +1 -1
- package/dist/types/src/services/internal/actors/configureFs.d.ts.map +1 -1
- package/dist/types/src/services/internal/actors/waitForFiles.d.ts +4 -0
- package/dist/types/src/services/internal/actors/waitForFiles.d.ts.map +1 -0
- package/dist/types/src/services/internal/constants.d.ts +2 -2
- package/dist/types/src/services/internal/constants.d.ts.map +1 -1
- package/dist/types/src/services/internal/helpers.d.ts.map +1 -1
- package/dist/types/src/services/internal/internalMachine.d.ts +10 -0
- package/dist/types/src/services/internal/internalMachine.d.ts.map +1 -1
- package/dist/types/src/types/fileManager.d.ts +15 -0
- package/dist/types/src/types/fileManager.d.ts.map +1 -0
- package/dist/types/src/types/model.d.ts +6 -5
- package/dist/types/src/types/model.d.ts.map +1 -1
- package/package.json +5 -3
- package/dist/Db-Bug4efsE.js.map +0 -1
- package/dist/FileManager-CXk83EW5.js +0 -16
- package/dist/FileManager-CXk83EW5.js.map +0 -1
- package/dist/FileManager-DXi-X7r5.js +0 -28
- package/dist/FileManager-DXi-X7r5.js.map +0 -1
- package/dist/constants-BakHTrB9.js.map +0 -1
- package/dist/content-hash.js +0 -27
- package/dist/content-hash.js.map +0 -1
- package/dist/index-BWIn7kWN.js.map +0 -1
- package/dist/index-DcPIAiHD.js.map +0 -1
- package/dist/seed.schema.config-DGcg6TCS.js.map +0 -1
- package/dist/types/__tests__/__mocks__/browser/project/schema.d.ts +0 -52
- package/dist/types/__tests__/__mocks__/browser/project/schema.d.ts.map +0 -1
- package/dist/types/__tests__/__mocks__/node/schema.d.ts +0 -52
- package/dist/types/__tests__/__mocks__/node/schema.d.ts.map +0 -1
- package/dist/types/__tests__/browser/db/drizzle.test.d.ts +0 -2
- package/dist/types/__tests__/browser/db/drizzle.test.d.ts.map +0 -1
- package/dist/types/__tests__/browser/property/propertyMachine.test.d.ts +0 -2
- package/dist/types/__tests__/browser/property/propertyMachine.test.d.ts.map +0 -1
- package/dist/types/__tests__/browser/react/index.test.d.ts +0 -2
- package/dist/types/__tests__/browser/react/index.test.d.ts.map +0 -1
- package/dist/types/__tests__/dist/exports.test.d.ts +0 -2
- package/dist/types/__tests__/dist/exports.test.d.ts.map +0 -1
- package/dist/types/__tests__/fs/index.test.d.ts +0 -2
- package/dist/types/__tests__/fs/index.test.d.ts.map +0 -1
- package/dist/types/__tests__/index.test.d.ts +0 -2
- package/dist/types/__tests__/index.test.d.ts.map +0 -1
- package/dist/types/__tests__/node/Item/Item.test.d.ts +0 -2
- package/dist/types/__tests__/node/Item/Item.test.d.ts.map +0 -1
- package/dist/types/__tests__/node/setup.d.ts +0 -2
- package/dist/types/__tests__/node/setup.d.ts.map +0 -1
- package/dist/types/__tests__/scripts/bin.test.d.ts +0 -2
- package/dist/types/__tests__/scripts/bin.test.d.ts.map +0 -1
- package/dist/types/__tests__/setup.d.ts +0 -2
- package/dist/types/__tests__/setup.d.ts.map +0 -1
- package/dist/types/src/workers/content-hash.d.ts.map +0 -1
- /package/dist/types/src/{workers → browser/workers}/content-hash.d.ts +0 -0
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
|
|
2
|
+
export default `(
|
|
3
|
+
${
|
|
4
|
+
function () {
|
|
5
|
+
|
|
6
|
+
const identifyString = (str: string) => {
|
|
7
|
+
try {
|
|
8
|
+
JSON.parse(str)
|
|
9
|
+
return 'json'
|
|
10
|
+
} catch (e) {
|
|
11
|
+
// Not JSON
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (!str) {
|
|
15
|
+
return
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (str.trim().startsWith('<') && str.trim().endsWith('>')) {
|
|
19
|
+
return 'html'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Simple markdown checks (very naive)
|
|
23
|
+
if (/^#{1,6}\s|^-{3,}|\*{3,}|^-{1,2}\s|\*\s/.test(str)) {
|
|
24
|
+
return 'markdown'
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (/^data:image\/[a-zA-Z]+;base64,[A-Za-z0-9+/]+={0,2}$/.test(str)) {
|
|
28
|
+
return 'base64'
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Default to plain text if unsure
|
|
32
|
+
return 'text'
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const getMimeType = (base64: string) => {
|
|
36
|
+
if (!base64) {
|
|
37
|
+
return null
|
|
38
|
+
}
|
|
39
|
+
const result = base64.match(/^data:([a-zA-Z0-9]+\/[a-zA-Z0-9-.+]+).*,/)
|
|
40
|
+
|
|
41
|
+
if (result && result.length > 1) {
|
|
42
|
+
return result[1]
|
|
43
|
+
} else {
|
|
44
|
+
return null // MIME type could not be determined
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const getDataTypeFromString = (
|
|
49
|
+
data: string,
|
|
50
|
+
): 'imageBase64' | 'base64' | 'url' | null => {
|
|
51
|
+
const nonImageBase64Regex =
|
|
52
|
+
/^(?!data:image\/(?:jpeg|png|gif|bmp|webp);base64,)[A-Za-z0-9+/=]+$/
|
|
53
|
+
|
|
54
|
+
if (nonImageBase64Regex.test(data)) {
|
|
55
|
+
return 'base64'
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Regular expression for base64 (simple version, checking for base64 format)
|
|
59
|
+
const imageBase64Regex = /^data:image\/[a-zA-Z]+;base64,[A-Za-z0-9+/]+={0,2}$/
|
|
60
|
+
|
|
61
|
+
if (imageBase64Regex.test(data)) {
|
|
62
|
+
return 'imageBase64'
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Regular expression for URL (simple version, checking for common URL format)
|
|
66
|
+
const urlRegex =
|
|
67
|
+
/^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/
|
|
68
|
+
|
|
69
|
+
if (urlRegex.test(data)) {
|
|
70
|
+
return 'url'
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return null
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const isBinary = (arrayBuffer: ArrayBuffer): boolean => {
|
|
77
|
+
const view = new Uint8Array(arrayBuffer);
|
|
78
|
+
|
|
79
|
+
let nonTextCount = 0;
|
|
80
|
+
const threshold = 0.2; // Adjust as needed (e.g., 20% non-text implies binary)
|
|
81
|
+
|
|
82
|
+
for (let i = 0; i < view.length; i++) {
|
|
83
|
+
const byte = view[i];
|
|
84
|
+
|
|
85
|
+
// ASCII printable characters (32-126) and common whitespace (9, 10, 13)
|
|
86
|
+
if (
|
|
87
|
+
(byte >= 32 && byte <= 126) || // Printable ASCII
|
|
88
|
+
byte === 9 || byte === 10 || byte === 13 // Tab, LF, CR
|
|
89
|
+
) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
nonTextCount++;
|
|
94
|
+
if (nonTextCount / view.length > threshold) {
|
|
95
|
+
return true; // More than threshold are non-text bytes
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return false; // Fewer than threshold are non-text bytes
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const saveBufferToOPFS = async (filePath: string, buffer: Uint8Array): Promise<void> => {
|
|
103
|
+
// Access the OPFS root directory
|
|
104
|
+
const rootHandle = await navigator.storage.getDirectory();
|
|
105
|
+
|
|
106
|
+
// Split the filePath into directory segments and file name
|
|
107
|
+
const segments = filePath.split('/').filter(Boolean);
|
|
108
|
+
const fileName = segments.pop(); // Extract the file name
|
|
109
|
+
if (!fileName) {
|
|
110
|
+
throw new Error('Invalid file path: No file name provided.');
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Traverse or create directories as needed
|
|
114
|
+
let currentDirHandle = rootHandle;
|
|
115
|
+
for (const segment of segments) {
|
|
116
|
+
currentDirHandle = await currentDirHandle.getDirectoryHandle(segment, { create: true });
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Create or open the file in OPFS
|
|
120
|
+
const fileHandleAsync = await currentDirHandle.getFileHandle(fileName, { create: true });
|
|
121
|
+
const fileHandle = await fileHandleAsync.createSyncAccessHandle();
|
|
122
|
+
// Write the buffer to the file
|
|
123
|
+
fileHandle.write(buffer);
|
|
124
|
+
fileHandle.flush();
|
|
125
|
+
fileHandle.close();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const downloadFiles = async ({
|
|
129
|
+
transactionIds,
|
|
130
|
+
arweaveHost,
|
|
131
|
+
}: {
|
|
132
|
+
transactionIds: string[],
|
|
133
|
+
arweaveHost: string,
|
|
134
|
+
}) => {
|
|
135
|
+
|
|
136
|
+
let arrayBuffer: ArrayBuffer | undefined
|
|
137
|
+
|
|
138
|
+
for (const transactionId of transactionIds) {
|
|
139
|
+
try {
|
|
140
|
+
const response = await fetch(`https://${arweaveHost}/raw/${transactionId}`);
|
|
141
|
+
|
|
142
|
+
arrayBuffer = await response.arrayBuffer();
|
|
143
|
+
} catch(error) {
|
|
144
|
+
console.log(`[filesDownload] transaction ${transactionId} data not found`, error)
|
|
145
|
+
globalThis.postMessage({
|
|
146
|
+
message: 'excludeTransaction',
|
|
147
|
+
transactionId,
|
|
148
|
+
})
|
|
149
|
+
continue
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
let dataString
|
|
153
|
+
const isBinaryData = isBinary(arrayBuffer)
|
|
154
|
+
|
|
155
|
+
if (!isBinaryData) {
|
|
156
|
+
const decoder = new TextDecoder('utf-8')
|
|
157
|
+
const text = decoder.decode(arrayBuffer)
|
|
158
|
+
dataString = text
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (!dataString && !arrayBuffer) {
|
|
162
|
+
console.log(
|
|
163
|
+
`[filesDownload] transaction ${transactionId} data not found`,
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (dataString && dataString.startsWith('===FILE_SEPARATOR===')) {
|
|
168
|
+
const dataStringParts = dataString
|
|
169
|
+
.split('===FILE_SEPARATOR===')
|
|
170
|
+
.slice(1)
|
|
171
|
+
|
|
172
|
+
if (dataStringParts.length % 2 !== 0) {
|
|
173
|
+
throw new Error('Input array must have an even number of elements.')
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
for (let i = 0; i < dataStringParts.length; i += 2) {
|
|
177
|
+
const contentType = dataStringParts[i]
|
|
178
|
+
const content = dataStringParts[i + 1]
|
|
179
|
+
const encoder = new TextEncoder()
|
|
180
|
+
if (contentType === 'html') {
|
|
181
|
+
const fileName = `${transactionId}.html`
|
|
182
|
+
const buffer = encoder.encode(content)
|
|
183
|
+
saveBufferToOPFS(`/files/html/${fileName}`, buffer)
|
|
184
|
+
}
|
|
185
|
+
if (contentType === 'json') {
|
|
186
|
+
const fileName = `${transactionId}.json`
|
|
187
|
+
const buffer = encoder.encode(content)
|
|
188
|
+
saveBufferToOPFS(`/files/json/${fileName}`, buffer)
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
continue
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (!dataString && arrayBuffer) {
|
|
196
|
+
saveBufferToOPFS(
|
|
197
|
+
`/files/images/${transactionId}`,
|
|
198
|
+
new Uint8Array(arrayBuffer),
|
|
199
|
+
)
|
|
200
|
+
continue
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (!dataString) {
|
|
204
|
+
continue
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
let contentType = identifyString(dataString)
|
|
208
|
+
|
|
209
|
+
if (
|
|
210
|
+
contentType !== 'json' &&
|
|
211
|
+
contentType !== 'base64' &&
|
|
212
|
+
contentType !== 'html'
|
|
213
|
+
) {
|
|
214
|
+
const possibleImageType = getDataTypeFromString(dataString)
|
|
215
|
+
if (!possibleImageType) {
|
|
216
|
+
console.log(
|
|
217
|
+
`[filesDownload] transaction ${transactionId} data not in expected format: ${possibleImageType}`,
|
|
218
|
+
)
|
|
219
|
+
continue
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
contentType = possibleImageType
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (contentType === 'url') {
|
|
226
|
+
const url = dataString as string
|
|
227
|
+
|
|
228
|
+
let buffer: ArrayBuffer | undefined
|
|
229
|
+
|
|
230
|
+
try {
|
|
231
|
+
const response = await fetch(url)
|
|
232
|
+
|
|
233
|
+
buffer = await response.arrayBuffer()
|
|
234
|
+
|
|
235
|
+
} catch(error) {
|
|
236
|
+
console.log(`[filesDownload] transaction ${transactionId} value was url: ${dataString} but failed to fetch`, error)
|
|
237
|
+
globalThis.postMessage({
|
|
238
|
+
message: 'excludeTransaction',
|
|
239
|
+
transactionId,
|
|
240
|
+
})
|
|
241
|
+
continue
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const bufferUint8Array = new Uint8Array(buffer)
|
|
245
|
+
|
|
246
|
+
// Extract the file extension from the URL
|
|
247
|
+
const extensionMatch = url.match(/\.(jpg|jpeg|png|gif|bmp|webp|svg)$/i)
|
|
248
|
+
if (!extensionMatch) {
|
|
249
|
+
throw new Error(
|
|
250
|
+
'Unable to determine the file extension from the URL.',
|
|
251
|
+
)
|
|
252
|
+
}
|
|
253
|
+
const fileExtension = extensionMatch[0] // e.g., ".jpg"
|
|
254
|
+
|
|
255
|
+
// Set the file name (you can customize this)
|
|
256
|
+
// const fileNameFromUrl = `${transactionId}${fileExtension}`
|
|
257
|
+
|
|
258
|
+
await saveBufferToOPFS(
|
|
259
|
+
`/files/images/${transactionId}`,
|
|
260
|
+
bufferUint8Array,
|
|
261
|
+
)
|
|
262
|
+
|
|
263
|
+
continue
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const mimeType = getMimeType(dataString as string)
|
|
267
|
+
let fileExtension = mimeType
|
|
268
|
+
|
|
269
|
+
if (fileExtension && fileExtension?.startsWith('image')) {
|
|
270
|
+
fileExtension = fileExtension.replace('image/', '')
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
let fileName = transactionId
|
|
274
|
+
|
|
275
|
+
if (contentType === 'base64') {
|
|
276
|
+
if (fileExtension) {
|
|
277
|
+
fileName += `.${fileExtension}`
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// Remove the Base64 header if it exists (e.g., "data:image/png;base64,")
|
|
281
|
+
const base64Data = dataString.split(',').pop() || ''
|
|
282
|
+
|
|
283
|
+
// Decode the Base64 string to binary
|
|
284
|
+
const binaryString = atob(base64Data)
|
|
285
|
+
const length = binaryString.length
|
|
286
|
+
const binaryData = new Uint8Array(length)
|
|
287
|
+
|
|
288
|
+
for (let i = 0; i < length; i++) {
|
|
289
|
+
binaryData[i] = binaryString.charCodeAt(i)
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
await saveBufferToOPFS(`/files/images/${fileName}`, binaryData)
|
|
293
|
+
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (contentType === 'html') {
|
|
297
|
+
fileName += '.html'
|
|
298
|
+
const encoder = new TextEncoder()
|
|
299
|
+
const buffer = encoder.encode(dataString)
|
|
300
|
+
await saveBufferToOPFS(`/files/html/${fileName}`, buffer)
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if (contentType === 'json') {
|
|
304
|
+
fileName += '.json'
|
|
305
|
+
const encoder = new TextEncoder()
|
|
306
|
+
const buffer = encoder.encode(dataString)
|
|
307
|
+
await saveBufferToOPFS(`/files/json/${fileName}`, buffer)
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
onmessage = async (e) => {
|
|
313
|
+
console.log({
|
|
314
|
+
message: 'filesDownload onmessage',
|
|
315
|
+
data: e.data,
|
|
316
|
+
})
|
|
317
|
+
await downloadFiles(e.data);
|
|
318
|
+
globalThis.postMessage({
|
|
319
|
+
message: 'filesDownload onmessage done',
|
|
320
|
+
done: true,
|
|
321
|
+
})
|
|
322
|
+
|
|
323
|
+
}
|
|
324
|
+
}.toString()
|
|
325
|
+
}
|
|
326
|
+
)()`
|
package/dist/src/getItem.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getItemData } from './getItemData'
|
|
2
2
|
import { GetItem } from '@/types'
|
|
3
3
|
import { BaseItem } from '@/Item/BaseItem'
|
|
4
|
+
import { startCase } from 'lodash-es'
|
|
4
5
|
|
|
5
6
|
export const getItem: GetItem = async ({ modelName, seedLocalId, seedUid }) => {
|
|
6
7
|
const itemInitObj = await getItemData({
|
|
@@ -23,5 +24,9 @@ export const getItem: GetItem = async ({ modelName, seedLocalId, seedUid }) => {
|
|
|
23
24
|
return
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
if (!itemInitObj.modelName && itemInitObj.type) {
|
|
28
|
+
itemInitObj.modelName = startCase(itemInitObj.type)
|
|
29
|
+
}
|
|
30
|
+
|
|
26
31
|
return BaseItem.create(itemInitObj)
|
|
27
32
|
}
|
|
@@ -145,7 +145,12 @@ const processRelationProperty = async (
|
|
|
145
145
|
seedSchemaUid,
|
|
146
146
|
versionUid,
|
|
147
147
|
listOfAttestations: [],
|
|
148
|
-
propertiesToUpdate: [
|
|
148
|
+
propertiesToUpdate: [
|
|
149
|
+
{
|
|
150
|
+
publishLocalId: relationProperty.localId,
|
|
151
|
+
propertySchemaUid: relationProperty.schemaUid,
|
|
152
|
+
},
|
|
153
|
+
],
|
|
149
154
|
}
|
|
150
155
|
|
|
151
156
|
const { itemBasicProperties, itemUploadProperties } =
|
|
@@ -315,20 +320,22 @@ export const getPublishPayload = async (
|
|
|
315
320
|
}
|
|
316
321
|
}
|
|
317
322
|
|
|
318
|
-
itemPublishData = await processBasicProperties(
|
|
319
|
-
itemBasicProperties,
|
|
320
|
-
itemPublishData,
|
|
321
|
-
)
|
|
322
|
-
|
|
323
|
-
multiPublishPayload.push(itemPublishData)
|
|
324
|
-
|
|
325
323
|
for (const relationProperty of itemRelationProperties) {
|
|
326
324
|
multiPublishPayload = await processRelationProperty(
|
|
327
325
|
relationProperty,
|
|
328
326
|
multiPublishPayload,
|
|
329
327
|
uploadedTransactions,
|
|
330
328
|
)
|
|
329
|
+
itemBasicProperties.push(relationProperty)
|
|
331
330
|
}
|
|
331
|
+
|
|
332
|
+
itemPublishData = await processBasicProperties(
|
|
333
|
+
itemBasicProperties,
|
|
334
|
+
itemPublishData,
|
|
335
|
+
)
|
|
336
|
+
|
|
337
|
+
multiPublishPayload.push(itemPublishData)
|
|
338
|
+
|
|
332
339
|
|
|
333
340
|
for (const listProperty of itemListProperties) {
|
|
334
341
|
multiPublishPayload = await processListProperty(
|
|
@@ -66,27 +66,6 @@ const processUploadProperty = async (
|
|
|
66
66
|
})
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
// const filePath = itemProperty.localStoragePath
|
|
70
|
-
//
|
|
71
|
-
// if (!filePath) {
|
|
72
|
-
// throw new Error(
|
|
73
|
-
// `No localStoragePath found for ItemProperty ${itemProperty.propertyName}`,
|
|
74
|
-
// )
|
|
75
|
-
// }
|
|
76
|
-
//
|
|
77
|
-
// const exists = await fs.promises.exists(filePath)
|
|
78
|
-
// if (!exists) {
|
|
79
|
-
// throw new Error(`File doesn't exist at ${filePath}`)
|
|
80
|
-
//
|
|
81
|
-
// // const handle = await navigator.storage.getDirectory()
|
|
82
|
-
// //
|
|
83
|
-
// // await configureSingle({
|
|
84
|
-
// // backend: WebAccess,
|
|
85
|
-
// // handle,
|
|
86
|
-
// // })
|
|
87
|
-
// }
|
|
88
|
-
//
|
|
89
|
-
// const mainFileContents = await fs.promises.readFile(filePath)
|
|
90
69
|
let fileContents
|
|
91
70
|
let transaction: Transaction
|
|
92
71
|
|
|
@@ -102,12 +81,6 @@ const processUploadProperty = async (
|
|
|
102
81
|
if (!exists) {
|
|
103
82
|
return uploads
|
|
104
83
|
|
|
105
|
-
// const handle = await navigator.storage.getDirectory()
|
|
106
|
-
//
|
|
107
|
-
// await configureSingle({
|
|
108
|
-
// backend: WebAccess,
|
|
109
|
-
// handle,
|
|
110
|
-
// })
|
|
111
84
|
}
|
|
112
85
|
|
|
113
86
|
try {
|
package/dist/src/helpers.ts
CHANGED
|
@@ -80,22 +80,14 @@ export const downloadFile = async (url: string, localFilePath: string) => {
|
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
// }
|
|
90
|
-
//
|
|
91
|
-
// if (filename !== '_journal.json') {
|
|
92
|
-
// await fs.promises.writeFile(localFilePath, fileData)
|
|
93
|
-
// }
|
|
94
|
-
await fs.promises.writeFile(localFilePath, fileData)
|
|
95
|
-
} catch (error) {
|
|
96
|
-
if (JSON.stringify(error).includes('File exists')) {
|
|
97
|
-
const fileData = await fs.promises.readFile(localFilePath, 'utf-8')
|
|
83
|
+
try {
|
|
84
|
+
await fs.promises.writeFile(localFilePath, fileData)
|
|
85
|
+
logger(`[downloadFile] Wrote file async to ${localFilePath}`)
|
|
86
|
+
} catch (error) {
|
|
87
|
+
fs.writeFileSync(localFilePath, fileData)
|
|
88
|
+
logger(`[downloadFile] Wrote file sync to ${localFilePath}`)
|
|
98
89
|
}
|
|
90
|
+
} catch (error) {
|
|
99
91
|
logger(`[Error] Failed to download file from ${url}:`, error)
|
|
100
92
|
}
|
|
101
93
|
|
|
@@ -168,7 +168,10 @@ export const hydrateFromDb = fromCallback<
|
|
|
168
168
|
.where(
|
|
169
169
|
and(
|
|
170
170
|
eq(metadata.seedUid, propertyValueFromDb),
|
|
171
|
-
|
|
171
|
+
or(
|
|
172
|
+
eq(metadata.propertyName, 'storageTransactionId'),
|
|
173
|
+
eq(metadata.propertyName, 'transactionId'),
|
|
174
|
+
),
|
|
172
175
|
),
|
|
173
176
|
)
|
|
174
177
|
|