Skip to content

Commit

Permalink
Merge pull request #12 from cesardeazevedo/blossom
Browse files Browse the repository at this point in the history
Add size tag and provide default tags for blossom uploads
  • Loading branch information
cesardeazevedo authored Dec 30, 2024
2 parents 73baef9 + 61e15dd commit d8dc03c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/__tests__/storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ describe('Storage', () => {
['p', ref.pubkey, 'relay1'],
['q', ref.id, 'relay1', ref.pubkey],
['a', `1:${ref.pubkey}:identifier`, 'relay1'],
['imeta', `url https://localhost:3000/${hash1}.png`, 'size 21792', `x ${hash1}`, 'm image/png', 'dim 500x500'],
['imeta', `url https://localhost:3000/${hash2}.png`, 'size 16630', `x ${hash2}`, 'm image/png', 'dim 500x500'],
['imeta', 'dim 500x500', 'm image/png', 'size 21792', `url https://localhost:3000/${hash1}.png`, `x ${hash1}`],
['imeta', 'dim 500x500', 'm image/png', 'size 16630', `url https://localhost:3000/${hash2}.png`, `x ${hash2}`],
['t', '#asknostr'],
])

Expand All @@ -95,8 +95,8 @@ describe('Storage', () => {
['p', ref.pubkey],
['q', ref.id, '', ref.pubkey],
['a', `1:${ref.pubkey}:identifier`],
['imeta', `url https://localhost:3000/${hash1}.png`, 'size 21792', `x ${hash1}`, 'm image/png', 'dim 500x500'],
['imeta', `url https://localhost:3000/${hash2}.png`, 'size 16630', `x ${hash2}`, 'm image/png', 'dim 500x500'],
['imeta', 'dim 500x500', 'm image/png', 'size 21792', `url https://localhost:3000/${hash1}.png`, `x ${hash1}`],
['imeta', 'dim 500x500', 'm image/png', 'size 16630', `url https://localhost:3000/${hash2}.png`, `x ${hash2}`],
['t', '#asknostr'],
])
})
Expand Down
16 changes: 15 additions & 1 deletion src/extensions/NostrExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,21 @@ export const NostrExtension = Extension.create<NostrOptions, NostrStorage>({
uploader
.getFiles()
.filter((x) => !!x.sha256)
.map((x) => ['imeta', ...x.tags.map(([key, value]) => `${key} ${value}`)]) || []
.map((x) => {
// Provide default imeta based on what we know
const meta: Record<string, string> = {
url: x.src,
x: x.sha256,
m: x.file.type,
}

// Add imeta based on tags returned by our uploader
for (const [k, v] of x.tags) {
meta[k] = v
}

return ['imeta', ...Object.entries(meta).map(kv => kv.join(' ')).sort()]
})
)
}

Expand Down
1 change: 1 addition & 0 deletions src/uploaders/blossom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export async function uploadBlossom(options: BlossomOptions): Promise<UploadTask
['method', 'PUT'],
['t', 'upload'],
['x', hash],
["size", options.file.size.toString()],
['expiration', Math.floor(now + (options.expiration || 60000)).toString()],
],
})
Expand Down

0 comments on commit d8dc03c

Please sign in to comment.