diff --git a/apps/envited.ascs.digital/common/asset/utils.ts b/apps/envited.ascs.digital/common/asset/utils.ts index 73ce8ef3..23171685 100644 --- a/apps/envited.ascs.digital/common/asset/utils.ts +++ b/apps/envited.ascs.digital/common/asset/utils.ts @@ -47,6 +47,12 @@ export const createFilename = _createFilename({ CID, }) +export const jsonToUint8Array = (json: object): Uint8Array => { + const jsonString = JSON.stringify(json) + const buffer = Buffer.from(jsonString) + return new Uint8Array(buffer) +} + export const getFileFromByteArray = async (byteArray: Uint8Array, filename: string) => extractFromByteArray(byteArray, filename).then(read) @@ -142,7 +148,7 @@ export const getPathAndBufferFromFile = _getPathAndBufferFromFile({ export const _getFilenameFromFile = ({ createFilename }: { createFilename: (byteArray: Uint8Array) => Promise }) => async (path: string, type: string, arrayBuffer: ArrayBuffer): Promise => ({ - cid: await createFilename(Buffer.from(arrayBuffer)), + cid: await createFilename(new Uint8Array(arrayBuffer)), path, type, arrayBuffer, diff --git a/apps/envited.ascs.digital/common/asset/validateAndCreateMetadata.ts b/apps/envited.ascs.digital/common/asset/validateAndCreateMetadata.ts index 6b52ed6d..1a1c412b 100644 --- a/apps/envited.ascs.digital/common/asset/validateAndCreateMetadata.ts +++ b/apps/envited.ascs.digital/common/asset/validateAndCreateMetadata.ts @@ -19,6 +19,7 @@ import { getDomainMetadataPath, getFileFromByteArray, getFilesAsPathAndByteArrayFromManifest, + jsonToUint8Array, } from './utils' export const _getShaclSchemaAndValidate = @@ -230,7 +231,7 @@ export const _validateAndCreateMetadata = try { const { conforms, reports, data } = await getShaclSchemaAndValidate(byteArray) const assetCID = await createFilename(byteArray) - const domainMetadataCID = await createFilename(Buffer.from(JSON.stringify(data.domainMetadata))) + const domainMetadataCID = await createFilename(jsonToUint8Array(data.domainMetadata)) const connection = await db() const user = await connection.getUserById(asset.userId) if (!user) { @@ -250,7 +251,7 @@ export const _validateAndCreateMetadata = visualizationFiles, })(data.manifest) const modifiedManifestBuffer = Buffer.from(JSON.stringify(modifiedManifest)) - const modifiedManifestCID = await createFilename(modifiedManifestBuffer) + const modifiedManifestCID = await createFilename(jsonToUint8Array(modifiedManifest)) const assetObject = { cid: assetCID,