Skip to content

Commit

Permalink
Merge pull request #67 from art-by-city/39-support-ancient-legacy-dat…
Browse files Browse the repository at this point in the history
…aurl-publications

Adds support for ancient legacy publications using embedded dataUrl
  • Loading branch information
jim-toth authored Oct 20, 2023
2 parents 53018e1 + 5698f29 commit 7a71281
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
21 changes: 14 additions & 7 deletions src/legacy/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,21 @@ export default class ArtByCityLegacy {
: []
const images = dataImages.map(di => {
if (di && typeof di === 'object' && !Array.isArray(di)) {
const image = {
image: typeof di.image === 'string' ? di.image : '',
preview: typeof di.preview === 'string' ? di.preview : '',
preview4k: typeof di.preview4k === 'string' ? di.preview4k : '',
animated: typeof di.animated === 'boolean' ? di.animated : false
if (typeof di.dataUrl === 'string') {
return {
image: di.dataUrl,
preview: di.dataUrl,
preview4k: di.dataUrl,
animated: di.imageType === 'image/gif'
}
} else {
return {
image: typeof di.image === 'string' ? di.image : '',
preview: typeof di.preview === 'string' ? di.preview : '',
preview4k: typeof di.preview4k === 'string' ? di.preview4k : '',
animated: typeof di.animated === 'boolean' ? di.animated : false
}
}

return image
}

return { image: '', preview: '', preview4k: '' }
Expand Down
27 changes: 26 additions & 1 deletion test/spec/legacy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const localApiConfig = {
port: 1984
}

describe('ArtByCity Legacy Module', () => {
describe('Legacy Module', () => {
beforeEach(() => {
arweaveMock.api = {
getConfig: sinon.stub().returns(localApiConfig) as unknown
Expand Down Expand Up @@ -158,6 +158,31 @@ describe('ArtByCity Legacy Module', () => {

expect(manifest.creator).to.equal(address)
})

it('Populates images for ancient legacy dataUrl publications', async () => {
const legacy = new ArtByCityLegacy(
arweaveMock,
warpMock,
MOCK_ABC_CONFIG
)
const manifestId = 'mock-manifest-id'

/* eslint-disable-next-line @typescript-eslint/no-unsafe-argument */
sinon.stub(legacy.transactions, 'fetchData').resolves({
ok: true,
data: {
images: [{
dataUrl: 'data-url',
imageType: 'image/jpeg'
}]
},
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
} as any)

const manifest = await legacy.fetchPublication(manifestId)

expect(manifest.images)
})
})

context('Profiles', () => {
Expand Down

0 comments on commit 7a71281

Please sign in to comment.