2021-10-28 11:38:40 +02:00
|
|
|
import {
|
|
|
|
dateToStringNoMS,
|
|
|
|
transformTags,
|
|
|
|
getAlgorithmComponent,
|
|
|
|
getAlgorithmFileExtension
|
|
|
|
} from '@utils/ddo'
|
|
|
|
import { FormPublishData } from './_types'
|
|
|
|
|
2021-11-11 08:51:13 +01:00
|
|
|
function encryptMe(files: string | FileMetadata[]): string {
|
|
|
|
throw new Error('Function not implemented.')
|
|
|
|
}
|
|
|
|
|
2021-10-28 11:38:40 +02:00
|
|
|
export function getFieldContent(
|
|
|
|
fieldName: string,
|
|
|
|
fields: FormFieldContent[]
|
|
|
|
): FormFieldContent {
|
|
|
|
return fields.filter((field: FormFieldContent) => field.name === fieldName)[0]
|
|
|
|
}
|
|
|
|
|
2021-11-11 08:51:13 +01:00
|
|
|
export function transformPublishFormToDdo(data: Partial<FormPublishData>): DDO {
|
2021-10-28 11:38:40 +02:00
|
|
|
const currentTime = dateToStringNoMS(new Date())
|
2021-11-11 08:51:13 +01:00
|
|
|
const { type } = data.metadata
|
2021-10-28 11:38:40 +02:00
|
|
|
const { name, description, tags, author, termsAndConditions } = data.metadata
|
2021-11-11 08:51:13 +01:00
|
|
|
const {
|
|
|
|
access,
|
|
|
|
files,
|
|
|
|
links,
|
2021-10-28 11:38:40 +02:00
|
|
|
image,
|
|
|
|
containerTag,
|
|
|
|
entrypoint,
|
2021-11-11 08:51:13 +01:00
|
|
|
providerUrl,
|
|
|
|
timeout
|
|
|
|
} = data.services[0]
|
|
|
|
|
|
|
|
const fileUrl = typeof files !== 'string' && files[0].url
|
|
|
|
const filesEncrypted = encryptMe(files)
|
2021-10-28 11:38:40 +02:00
|
|
|
|
2021-11-11 08:51:13 +01:00
|
|
|
const service: Service = {
|
|
|
|
type: access,
|
|
|
|
files: filesEncrypted,
|
|
|
|
datatokenAddress: '',
|
|
|
|
serviceEndpoint: providerUrl,
|
|
|
|
timeout
|
2021-10-28 11:38:40 +02:00
|
|
|
}
|
|
|
|
|
2021-11-11 08:51:13 +01:00
|
|
|
const newDdo: DDO = {
|
|
|
|
'@context': [''],
|
|
|
|
id: '',
|
|
|
|
version: '4.0.0',
|
|
|
|
created: currentTime,
|
2021-11-11 09:46:52 +01:00
|
|
|
updated: currentTime,
|
2021-11-11 08:51:13 +01:00
|
|
|
chainId: data.chainId,
|
2021-10-28 11:38:40 +02:00
|
|
|
metadata: {
|
2021-11-11 08:51:13 +01:00
|
|
|
type,
|
2021-10-28 11:38:40 +02:00
|
|
|
name,
|
|
|
|
description,
|
|
|
|
tags: transformTags(tags),
|
|
|
|
author,
|
2021-11-11 08:51:13 +01:00
|
|
|
license: 'https://market.oceanprotocol.com/terms',
|
|
|
|
links,
|
|
|
|
...(type === 'algorithm' && {
|
|
|
|
...getAlgorithmComponent(
|
|
|
|
image,
|
|
|
|
containerTag,
|
|
|
|
entrypoint,
|
|
|
|
getAlgorithmFileExtension(fileUrl)
|
|
|
|
)
|
|
|
|
})
|
2021-10-28 11:38:40 +02:00
|
|
|
},
|
|
|
|
services: [service]
|
|
|
|
}
|
|
|
|
|
|
|
|
return newDdo
|
|
|
|
}
|