support fallback tag in NIP-94
This commit is contained in:
parent
753ff323ea
commit
986b9d0cce
|
@ -21,6 +21,7 @@ describe('generateEventTemplate', () => {
|
||||||
image: 'https://example.com/image.jpg',
|
image: 'https://example.com/image.jpg',
|
||||||
summary: 'Lorem ipsum',
|
summary: 'Lorem ipsum',
|
||||||
alt: 'Image alt text',
|
alt: 'Image alt text',
|
||||||
|
fallback: ['https://fallback1.example.com/image.jpg', 'https://fallback2.example.com/image.jpg'],
|
||||||
}
|
}
|
||||||
|
|
||||||
const expectedEventTemplate: EventTemplate = {
|
const expectedEventTemplate: EventTemplate = {
|
||||||
|
@ -40,6 +41,8 @@ describe('generateEventTemplate', () => {
|
||||||
['image', 'https://example.com/image.jpg'],
|
['image', 'https://example.com/image.jpg'],
|
||||||
['summary', 'Lorem ipsum'],
|
['summary', 'Lorem ipsum'],
|
||||||
['alt', 'Image alt text'],
|
['alt', 'Image alt text'],
|
||||||
|
['fallback', 'https://fallback1.example.com/image.jpg'],
|
||||||
|
['fallback', 'https://fallback2.example.com/image.jpg'],
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,6 +74,7 @@ describe('validateEvent', () => {
|
||||||
['image', 'https://example.com/image.jpg'],
|
['image', 'https://example.com/image.jpg'],
|
||||||
['summary', 'Lorem ipsum'],
|
['summary', 'Lorem ipsum'],
|
||||||
['alt', 'Image alt text'],
|
['alt', 'Image alt text'],
|
||||||
|
['fallback', 'https://fallback.example.com/image.jpg'],
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
sk,
|
sk,
|
||||||
|
@ -100,6 +104,7 @@ describe('validateEvent', () => {
|
||||||
['image', 'https://example.com/image.jpg'],
|
['image', 'https://example.com/image.jpg'],
|
||||||
['summary', 'Lorem ipsum'],
|
['summary', 'Lorem ipsum'],
|
||||||
['alt', 'Image alt text'],
|
['alt', 'Image alt text'],
|
||||||
|
['fallback', 'https://fallback.example.com/image.jpg'],
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
sk,
|
sk,
|
||||||
|
@ -129,6 +134,7 @@ describe('validateEvent', () => {
|
||||||
['image', 'https://example.com/image.jpg'],
|
['image', 'https://example.com/image.jpg'],
|
||||||
['summary', 'Lorem ipsum'],
|
['summary', 'Lorem ipsum'],
|
||||||
['alt', 'Image alt text'],
|
['alt', 'Image alt text'],
|
||||||
|
['fallback', 'https://fallback.example.com/image.jpg'],
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
sk,
|
sk,
|
||||||
|
@ -158,6 +164,7 @@ describe('validateEvent', () => {
|
||||||
['image', 'https://example.com/image.jpg'],
|
['image', 'https://example.com/image.jpg'],
|
||||||
['summary', 'Lorem ipsum'],
|
['summary', 'Lorem ipsum'],
|
||||||
['alt', 'Image alt text'],
|
['alt', 'Image alt text'],
|
||||||
|
['fallback', 'https://fallback.example.com/image.jpg'],
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
sk,
|
sk,
|
||||||
|
@ -181,6 +188,7 @@ describe('validateEvent', () => {
|
||||||
['image', 'https://example.com/image.jpg'],
|
['image', 'https://example.com/image.jpg'],
|
||||||
['summary', 'Lorem ipsum'],
|
['summary', 'Lorem ipsum'],
|
||||||
['alt', 'Image alt text'],
|
['alt', 'Image alt text'],
|
||||||
|
['fallback', 'https://fallback.example.com/image.jpg'],
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
sk,
|
sk,
|
||||||
|
@ -204,6 +212,7 @@ describe('validateEvent', () => {
|
||||||
['image', 'https://example.com/image.jpg'],
|
['image', 'https://example.com/image.jpg'],
|
||||||
['summary', 'Lorem ipsum'],
|
['summary', 'Lorem ipsum'],
|
||||||
['alt', 'Image alt text'],
|
['alt', 'Image alt text'],
|
||||||
|
['fallback', 'https://fallback.example.com/image.jpg'],
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
sk,
|
sk,
|
||||||
|
@ -227,6 +236,7 @@ describe('validateEvent', () => {
|
||||||
['image', 'https://example.com/image.jpg'],
|
['image', 'https://example.com/image.jpg'],
|
||||||
['summary', 'Lorem ipsum'],
|
['summary', 'Lorem ipsum'],
|
||||||
['alt', 'Image alt text'],
|
['alt', 'Image alt text'],
|
||||||
|
['fallback', 'https://fallback.example.com/image.jpg'],
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
sk,
|
sk,
|
||||||
|
@ -259,6 +269,7 @@ describe('validateEvent', () => {
|
||||||
['image', 'https://example.com/image.jpg'],
|
['image', 'https://example.com/image.jpg'],
|
||||||
['summary', 'Lorem ipsum'],
|
['summary', 'Lorem ipsum'],
|
||||||
['alt', 'Image alt text'],
|
['alt', 'Image alt text'],
|
||||||
|
['fallback', 'https://fallback.example.com/image.jpg'],
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
sk,
|
sk,
|
||||||
|
@ -288,6 +299,7 @@ describe('validateEvent', () => {
|
||||||
['image', 'https://example.com/image.jpg'],
|
['image', 'https://example.com/image.jpg'],
|
||||||
['summary', 'Lorem ipsum'],
|
['summary', 'Lorem ipsum'],
|
||||||
['alt', 'Image alt text'],
|
['alt', 'Image alt text'],
|
||||||
|
['fallback', 'https://fallback.example.com/image.jpg'],
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
sk,
|
sk,
|
||||||
|
@ -319,6 +331,8 @@ describe('parseEvent', () => {
|
||||||
['image', 'https://example.com/image.jpg'],
|
['image', 'https://example.com/image.jpg'],
|
||||||
['summary', 'Lorem ipsum'],
|
['summary', 'Lorem ipsum'],
|
||||||
['alt', 'Image alt text'],
|
['alt', 'Image alt text'],
|
||||||
|
['fallback', 'https://fallback1.example.com/image.jpg'],
|
||||||
|
['fallback', 'https://fallback2.example.com/image.jpg'],
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
sk,
|
sk,
|
||||||
|
@ -340,6 +354,7 @@ describe('parseEvent', () => {
|
||||||
image: 'https://example.com/image.jpg',
|
image: 'https://example.com/image.jpg',
|
||||||
summary: 'Lorem ipsum',
|
summary: 'Lorem ipsum',
|
||||||
alt: 'Image alt text',
|
alt: 'Image alt text',
|
||||||
|
fallback: ['https://fallback1.example.com/image.jpg', 'https://fallback2.example.com/image.jpg'],
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -364,6 +379,7 @@ describe('parseEvent', () => {
|
||||||
['image', 'https://example.com/image.jpg'],
|
['image', 'https://example.com/image.jpg'],
|
||||||
['summary', 'Lorem ipsum'],
|
['summary', 'Lorem ipsum'],
|
||||||
['alt', 'Image alt text'],
|
['alt', 'Image alt text'],
|
||||||
|
['fallback', 'https://fallback.example.com/image.jpg'],
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
sk,
|
sk,
|
||||||
|
|
10
nip94.ts
10
nip94.ts
|
@ -75,6 +75,11 @@ export type FileMetadataObject = {
|
||||||
* Optional: A description for accessibility, providing context or a brief description of the file.
|
* Optional: A description for accessibility, providing context or a brief description of the file.
|
||||||
*/
|
*/
|
||||||
alt?: string
|
alt?: string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional: fallback URLs in case url fails.
|
||||||
|
*/
|
||||||
|
fallback?: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -104,6 +109,7 @@ export function generateEventTemplate(fileMetadata: FileMetadataObject): EventTe
|
||||||
if (fileMetadata.image) eventTemplate.tags.push(['image', fileMetadata.image])
|
if (fileMetadata.image) eventTemplate.tags.push(['image', fileMetadata.image])
|
||||||
if (fileMetadata.summary) eventTemplate.tags.push(['summary', fileMetadata.summary])
|
if (fileMetadata.summary) eventTemplate.tags.push(['summary', fileMetadata.summary])
|
||||||
if (fileMetadata.alt) eventTemplate.tags.push(['alt', fileMetadata.alt])
|
if (fileMetadata.alt) eventTemplate.tags.push(['alt', fileMetadata.alt])
|
||||||
|
if (fileMetadata.fallback) fileMetadata.fallback.forEach(url => eventTemplate.tags.push(['fallback', url]))
|
||||||
|
|
||||||
return eventTemplate
|
return eventTemplate
|
||||||
}
|
}
|
||||||
|
@ -194,6 +200,10 @@ export function parseEvent(event: Event): FileMetadataObject {
|
||||||
case 'alt':
|
case 'alt':
|
||||||
fileMetadata.alt = value
|
fileMetadata.alt = value
|
||||||
break
|
break
|
||||||
|
case 'fallback':
|
||||||
|
fileMetadata.fallback ??= []
|
||||||
|
fileMetadata.fallback.push(value)
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue