Skip to content

Commit

Permalink
refactor(envited.ascs.digital): debug
Browse files Browse the repository at this point in the history
Signed-off-by: Roy Scheeren <[email protected]>
  • Loading branch information
royscheeren committed Nov 22, 2024
1 parent ac9bb6f commit 2dbe99e
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,31 +220,24 @@ export const _validateAndCreateMetadata =
}) =>
async (byteArray: Uint8Array, asset: Asset) => {
try {
console.log('2a')
const { conforms, reports, data } = await getShaclSchemaAndValidate(byteArray)
console.log('2b')
console.log(byteArray)
const assetCID = await createFilename(byteArray)
console.log(assetCID)
const domainMetadataCID = await createFilename(data.domainMetadata)

const connection = await db()
const user = await connection.getUserById(asset.userId)
if (!user) {
throw new Error('User not found')
}
console.log('2c')
const [issuer] = await connection.getUserWithProfileById(user.issuerId)

if (!issuer) {
throw new Error('Issuer not found')
}
console.log('2d')
const files = await getFilesAsPathAndByteArrayFromManifest(byteArray, data.manifest)
const visualization = filter(propEq('visualization', 'type'))(files.publicUser) as ExtractedFile[]
const visualizationFiles = await getAllFilenamesFromFiles(visualization)
const displayUri = find(propEq('visualization', 'type'))(visualizationFiles) as ExtractedFileWithCID
console.log('2e')
const modifiedManifest = createModifiedManifest({
assetCID,
domainMetadataCID,
Expand All @@ -264,7 +257,6 @@ export const _validateAndCreateMetadata =
manifest: data.manifest,
domainMetadata: data.domainMetadata,
})
console.log('2f')
return {
conforms,
reports,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const _createFilename =
({ raw, sha256, CID }: { raw: any; sha256: Hasher<'sha2-256', 18>; CID: any }) =>
async (byteArray: any) => {
try {
console.log(typeof byteArray, instanceof byteArray)
const rawBytes = raw.encode(byteArray)
const hash = await sha256.digest(rawBytes)
const cid = CID.create(1, raw.code, hash)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export const _main =
}): S3Handler =>
async event => {
try {
console.log(1)
// Read uploaded asset
const s3Record = event.Records[0].s3

Expand All @@ -71,22 +70,19 @@ export const _main =
if (isNil(Body)) {
return
}
console.log(2)
const uploadedFile = await Body.transformToByteArray()

// Validate uploaded asset
const asset = await getAsset(Key)
const { conforms, metadata, assetCID, modifiedManifest, files, visualizationFiles } =
await validateAndCreateMetadata(uploadedFile, asset)
console.log(3)
if (!conforms) {
// Revert if validation fails
await deleteFile({ Bucket, Key })
await updateAsset(Key, Key, AssetStatus.not_accepted)

return
}
console.log(4)
// Copy asset ZIP file to S3 with CID as name
await copyFile({
Bucket,
Expand Down

0 comments on commit 2dbe99e

Please sign in to comment.