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 b342a00 commit e53204e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,9 @@ export const _validateAndCreateMetadata =
}) =>
async (byteArray: Uint8Array, asset: Asset) => {
try {
console.log("2a")
const { conforms, reports, data } = await getShaclSchemaAndValidate(byteArray)

console.log("2b")
const assetCID = await createFilename(byteArray)
const domainMetadataCID = await createFilename(data.domainMetadata)

Expand All @@ -230,18 +231,18 @@ export const _validateAndCreateMetadata =
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 @@ -261,7 +262,7 @@ 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 @@ -59,6 +59,7 @@ export const _main =
}): S3Handler =>
async event => {
try {
console.log(1)
// Read uploaded asset
const s3Record = event.Records[0].s3

Expand All @@ -70,21 +71,22 @@ 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 e53204e

Please sign in to comment.