Use dimensions from nostr.build
This commit is contained in:
parent
ce49c500ae
commit
353111051a
|
@ -6,11 +6,12 @@ export const nostrbuildFileSchema = z.object({
|
|||
thumbnail: z.string(),
|
||||
blurhash: z.string(),
|
||||
sha256: z.string(),
|
||||
original_sha256: z.string(),
|
||||
mime: z.string(),
|
||||
dimensions: z.object({
|
||||
width: z.number(),
|
||||
height: z.number(),
|
||||
}),
|
||||
}).optional().catch(undefined),
|
||||
});
|
||||
|
||||
export const nostrbuildSchema = z.object({
|
||||
|
|
|
@ -16,7 +16,7 @@ async function uploadFile(file: File, meta: FileMeta, signal?: AbortSignal): Pro
|
|||
throw new Error('File size is too large.');
|
||||
}
|
||||
|
||||
const { url, sha256, cid, blurhash } = await uploader.upload(file, { signal });
|
||||
const { url, sha256, cid, blurhash, width, height } = await uploader.upload(file, { signal });
|
||||
|
||||
const data: string[][] = [
|
||||
['url', url],
|
||||
|
@ -24,6 +24,10 @@ async function uploadFile(file: File, meta: FileMeta, signal?: AbortSignal): Pro
|
|||
['size', size.toString()],
|
||||
];
|
||||
|
||||
if (typeof width === 'number' && typeof height === 'number') {
|
||||
data.push(['dim', `${width}x${height}`]);
|
||||
}
|
||||
|
||||
if (sha256) {
|
||||
data.push(['x', sha256]);
|
||||
}
|
||||
|
|
|
@ -15,8 +15,6 @@ export const nostrbuildUploader: Uploader = {
|
|||
});
|
||||
|
||||
const json = await response.json();
|
||||
console.log(JSON.stringify(json));
|
||||
|
||||
const [data] = nostrbuildSchema.parse(json).data;
|
||||
|
||||
return {
|
||||
|
@ -24,6 +22,8 @@ export const nostrbuildUploader: Uploader = {
|
|||
sha256: data.sha256,
|
||||
url: data.url,
|
||||
blurhash: data.blurhash,
|
||||
width: data.dimensions?.width,
|
||||
height: data.dimensions?.height,
|
||||
};
|
||||
},
|
||||
// deno-lint-ignore require-await
|
||||
|
|
|
@ -18,6 +18,10 @@ interface UploadResult {
|
|||
blurhash?: string;
|
||||
/** IPFS CID of the file. */
|
||||
cid?: string;
|
||||
/** Width of the file, if applicable. */
|
||||
width?: number;
|
||||
/** Height of the file, if applicable. */
|
||||
height?: number;
|
||||
}
|
||||
|
||||
export type { Uploader };
|
||||
|
|
|
@ -6,10 +6,23 @@ function renderAttachment(media: { id?: string; data: string[][] }) {
|
|||
const url = tags.find(([name]) => name === 'url')?.[1];
|
||||
const alt = tags.find(([name]) => name === 'alt')?.[1];
|
||||
const cid = tags.find(([name]) => name === 'cid')?.[1];
|
||||
const dim = tags.find(([name]) => name === 'dim')?.[1];
|
||||
const blurhash = tags.find(([name]) => name === 'blurhash')?.[1];
|
||||
|
||||
if (!url) return;
|
||||
|
||||
const [width, height] = dim?.split('x').map(Number) ?? [null, null];
|
||||
|
||||
const meta = (typeof width === 'number' && typeof height === 'number')
|
||||
? {
|
||||
original: {
|
||||
width,
|
||||
height,
|
||||
aspect: width / height,
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
id: id ?? url,
|
||||
type: getAttachmentType(m ?? ''),
|
||||
|
@ -18,6 +31,7 @@ function renderAttachment(media: { id?: string; data: string[][] }) {
|
|||
remote_url: null,
|
||||
description: alt ?? '',
|
||||
blurhash: blurhash || null,
|
||||
meta,
|
||||
cid: cid,
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue