Merge pull request #41 from oceanprotocol/feature/oep-8-files

update file metadata structure
This commit is contained in:
Matthias Kretschmann 2019-04-01 12:39:13 +02:00 committed by GitHub
commit 7b8a49c6e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 57 additions and 17 deletions

View File

@ -8,14 +8,10 @@ const AssetModel = {
name: null,
description: null,
dateCreated: null,
size: null,
author: null,
type: '',
license: null,
copyrightHolder: null,
encoding: null,
compression: null,
contentType: null,
workExample: null,
files: [],
categories: [],

View File

@ -1,6 +1,5 @@
import React, { Component } from 'react'
import { Logger } from '@oceanprotocol/squid'
import queryString from 'query-string'
import Route from '../../components/templates/Route'
import Spinner from '../../components/atoms/Spinner'
import { User } from '../../context/User'
@ -37,8 +36,14 @@ export default class Details extends Component<DetailsProps, DetailsState> {
accessService.serviceDefinitionId,
account[0]
)
const folder = ""
const path = await this.context.ocean.assets.consume(agreementId, ddo.id, accessService.serviceDefinitionId, account[0], folder)
const folder = ''
const path = await this.context.ocean.assets.consume(
agreementId,
ddo.id,
accessService.serviceDefinitionId,
account[0],
folder
)
Logger.log('path', path)
} catch (e) {
Logger.log('error', e)

View File

@ -8,10 +8,15 @@ const Item = ({ item, removeItem }: { item: any; removeItem: any }) => (
<div className={styles.details}>
<span>url: {item.found ? 'confirmed' : 'unconfirmed'}</span>
<span>
size:
{item.found && item.size ? filesize(item.size) : 'unknown'}
{item.found && item.contentLength
? filesize(item.contentLength)
: 'unknown size'}
</span>
<span>
{item.found && item.contentType
? item.contentType
: 'unknown type'}
</span>
<span>type: {item.found && item.type ? item.type : 'unknown'}</span>
</div>
<button
type="button"

View File

@ -8,8 +8,19 @@ import styles from './index.module.scss'
import { serviceHost, servicePort, serviceScheme } from '../../../config'
interface File {
url: string
checksum?: string
checksumType?: string
contentLength?: string
contentType?: string
resourceId?: string
encoding?: string
compression?: string
}
interface FilesProps {
files: any[]
files: File[]
placeholder: string
help?: string
name: string
@ -20,6 +31,32 @@ interface FilesStates {
isFormShown: boolean
}
const getFileCompression = async (contentType: string) => {
// TODO: add all the possible archive & compression MIME types
if (
contentType === 'application/zip' ||
contentType === 'application/gzip' ||
contentType === 'application/x-lzma' ||
contentType === 'application/x-xz' ||
contentType === 'application/x-tar' ||
contentType === 'application/x-gtar' ||
contentType === 'application/x-bzip2' ||
contentType === 'application/x-7z-compressed' ||
contentType === 'application/x-rar-compressed' ||
contentType === 'application/x-apple-diskimage'
) {
const contentTypeSplit = contentType.split('/')
if (contentTypeSplit[1].includes('x-')) {
return contentTypeSplit[1].replace('x-', '')
}
return contentTypeSplit[1]
} else {
return 'none'
}
}
export default class Files extends PureComponent<FilesProps, FilesStates> {
public state: FilesStates = {
isFormShown: false
@ -46,8 +83,9 @@ export default class Files extends PureComponent<FilesProps, FilesStates> {
}
)
res = await response.json()
file.size = res.result.contentLength
file.type = res.result.contentType
file.contentLength = res.result.contentLength
file.contentType = res.result.contentType
file.compression = await getFileCompression(file.contentType)
file.found = res.result.found
} catch (error) {
// error

View File

@ -258,10 +258,6 @@ class Publish extends Component<{}, PublishState> {
price: this.state.price,
type: this.state.type,
categories: [this.state.categories],
size: '',
encoding: '',
compression: undefined,
contentType: '',
workExample: undefined,
inLanguage: undefined,
tags: ''