Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add generative_uri #210

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will leave vitest in watch mode - not preffered as it cannot run in CI

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"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') && 'koda') ||
'fxhash'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preview param of this

ipfs://bafybeihxrnjmqs7po3jw3p37csyscvgxuwg2khow5zm46liutxq466q45m/?hash=0x044852b2a670ade5407e78fb2863c51de9fcb96542a07186fe3aeda6bb8a116

is hash

Suggested change
const previewParam =
meta.previewParam ||
(meta.external_url?.includes('koda') && 'koda') ||
'fxhash'
const previewParam =
meta.previewParam || 'hash'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

const capture = meta.capture
const settings = meta.settings

Expand Down
8 changes: 8 additions & 0 deletions hyperdata/tests/examples/koda-art-generative.json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this represent collection or NFT

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

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-art-generative.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,
})
})
})