mirror of
https://github.com/aljazceru/ditto.git
synced 2026-01-04 14:14:24 +01:00
Rewrite all the uploaders
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user