Rewrite all the uploaders

This commit is contained in:
Alex Gleason
2024-05-18 22:00:24 -05:00
parent 6090c4a6d9
commit 82c03dcb56
16 changed files with 260 additions and 215 deletions

View File

@@ -202,6 +202,7 @@ const updateCredentialsSchema = z.object({
const updateCredentialsController: AppController = async (c) => {
const pubkey = await c.get('signer')?.getPublicKey()!;
const uploader = c.get('uploader');
const body = await parseBody(c.req.raw);
const result = updateCredentialsSchema.safeParse(body);
@@ -220,9 +221,13 @@ const updateCredentialsController: AppController = async (c) => {
nip05,
} = result.data;
if ((avatarFile || headerFile) && !uploader) {
return c.json({ error: 'No uploader configured.' }, 500);
}
const [avatar, header] = await Promise.all([
avatarFile ? uploadFile(avatarFile, { pubkey }) : undefined,
headerFile ? uploadFile(headerFile, { pubkey }) : undefined,
(avatarFile && uploader) ? uploadFile(uploader, avatarFile, { pubkey }) : undefined,
(headerFile && uploader) ? uploadFile(uploader, headerFile, { pubkey }) : undefined,
]);
meta.name = display_name ?? meta.name;

View File

@@ -14,6 +14,11 @@ const mediaBodySchema = z.object({
});
const mediaController: AppController = async (c) => {
const uploader = c.get('uploader');
if (!uploader) {
return c.json({ error: 'No uploader configured.' }, 500);
}
const pubkey = await c.get('signer')?.getPublicKey()!;
const result = mediaBodySchema.safeParse(await parseBody(c.req.raw));
const { signal } = c.req.raw;
@@ -24,7 +29,7 @@ const mediaController: AppController = async (c) => {
try {
const { file, description } = result.data;
const media = await uploadFile(file, { pubkey, description }, signal);
const media = await uploadFile(uploader, file, { pubkey, description }, signal);
return c.json(renderAttachment(media));
} catch (e) {
console.error(e);