mirror of
https://github.com/aljazceru/ditto.git
synced 2026-01-13 18:44:22 +01:00
Merge branch 'store-alt-text' into 'main'
Store alt text along with other imeta, and render it when requested Closes #172 See merge request soapbox-pub/ditto!464
This commit is contained in:
@@ -5,6 +5,7 @@ import { fileSchema } from '@/schema.ts';
|
||||
import { parseBody } from '@/utils/api.ts';
|
||||
import { renderAttachment } from '@/views/mastodon/attachments.ts';
|
||||
import { uploadFile } from '@/utils/upload.ts';
|
||||
import { setMediaDescription } from '@/db/unattached-media.ts';
|
||||
|
||||
const mediaBodySchema = z.object({
|
||||
file: fileSchema,
|
||||
@@ -13,6 +14,10 @@ const mediaBodySchema = z.object({
|
||||
focus: z.string().optional(),
|
||||
});
|
||||
|
||||
const mediaUpdateSchema = z.object({
|
||||
description: z.string(),
|
||||
});
|
||||
|
||||
const mediaController: AppController = async (c) => {
|
||||
const pubkey = await c.get('signer')?.getPublicKey()!;
|
||||
const result = mediaBodySchema.safeParse(await parseBody(c.req.raw));
|
||||
@@ -32,4 +37,22 @@ const mediaController: AppController = async (c) => {
|
||||
}
|
||||
};
|
||||
|
||||
export { mediaController };
|
||||
const updateMediaController: AppController = async (c) => {
|
||||
const result = mediaUpdateSchema.safeParse(await parseBody(c.req.raw));
|
||||
if (!result.success) {
|
||||
return c.json({ error: 'Bad request.', schema: result.error }, 422);
|
||||
}
|
||||
try {
|
||||
const { description } = result.data;
|
||||
if (!await setMediaDescription(c.req.param('id'), description)) {
|
||||
return c.json({ error: 'File with specified ID not found.' }, 404);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return c.json({ error: 'Failed to set media description.' }, 500);
|
||||
}
|
||||
|
||||
return c.json({ message: 'ok' }, 200);
|
||||
};
|
||||
|
||||
export { mediaController, updateMediaController };
|
||||
|
||||
Reference in New Issue
Block a user