Skip to content

Commit

Permalink
Merge pull request #210 from kodadot/chore--add-generative_uri
Browse files Browse the repository at this point in the history
chore: add generative_uri
  • Loading branch information
vikiival authored Jul 3, 2024
2 parents ad3bb1d + fb33db3 commit 0b73a23
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion hyperdata/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"lint:fix": "eslint --cache --ext .ts,.js,.mjs,.cjs . --fix && prettier -c src test -w",
"prepack": "pnpm run build",
"release": "pnpm test && changelogen --release && npm publish && git push --follow-tags",
"test": "vitest run"
"test": "vitest"
},
"devDependencies": {
"@kodadot1/minipfs": "0.4.1-rc.0",
Expand Down
7 changes: 5 additions & 2 deletions hyperdata/src/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,17 @@ export function contentFrom(meta: any, eager?: boolean): Content {

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function generativeFrom(meta: any): GenArt | undefined {
const uri = meta.generativeUri || meta.generatorUri
const uri = meta.generativeUri || meta.generatorUri || meta.generative_uri

if (!uri) {
return undefined
}

const hash = meta.previewHash || meta.iterationHash
const previewParam = meta.previewParam || 'fxhash'
const previewParam =
meta.previewParam ||
(meta.external_url?.includes('koda') && 'hash') ||
'fxhash'
const capture = meta.capture
const settings = meta.settings

Expand Down
8 changes: 8 additions & 0 deletions hyperdata/tests/examples/koda-generative-collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "test - genart - meadow",
"description": "test [LikeMurvin](https://twitter.com/LikeMurvin) genart",
"image": "ipfs://bafkreic7ii2fvo3fhe557pyozhzitkfnhgmxovaebnf3shqmjiva42erb4",
"external_url": "https://koda.art",
"base_uri": "https://dyndata.koda.art/v1/metadata/ahk/461",
"generative_uri": "ipfs://bafybeicdv7iu5racra3vsvg2k2uvp2jxvb534h67f6lqdwidhmvzg2tjou"
}
13 changes: 13 additions & 0 deletions hyperdata/tests/generative.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, expect, it } from 'vitest'
import { FXHashMetadata, GenArt, generativeFrom } from '../src'
import fxhash from './examples/fxhash.json'
import koda from './examples/koda-generative-collection.json'

describe('generativeFrom', () => {
it(`should parse FXhash metadata to Content correctly`, () => {
Expand All @@ -15,4 +16,16 @@ describe('generativeFrom', () => {

expect(generativeFrom(metadata)).toStrictEqual(res)
})

it('should parse koda.art generative metadata correctly', () => {
const metadata = koda

expect(generativeFrom(metadata)).toStrictEqual({
uri: metadata.generative_uri,
previewParam: 'koda',
capture: undefined,
hash: undefined,
settings: undefined,
})
})
})

0 comments on commit 0b73a23

Please sign in to comment.