mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
fix(updateInstanceController): stop using screenshot_ids and thumbnail_id
This commit is contained in:
parent
115641b3c2
commit
715908082f
1 changed files with 15 additions and 50 deletions
|
|
@ -294,14 +294,15 @@ export const statusZapSplitsController: AppController = async (c) => {
|
|||
};
|
||||
|
||||
const updateInstanceSchema = z.object({
|
||||
title: z.string().optional(),
|
||||
description: z.string().optional(),
|
||||
title: z.string(),
|
||||
description: z.string(),
|
||||
short_description: z.string(),
|
||||
/** Mastodon doesn't have this field. */
|
||||
short_description: z.string().optional(),
|
||||
/** Mastodon doesn't have this field. */
|
||||
screenshot_ids: z.string().array().nullish(),
|
||||
/** Mastodon doesn't have this field. */
|
||||
thumbnail_id: z.string().optional(),
|
||||
screenshots: screenshotsSchema,
|
||||
/** https://docs.joinmastodon.org/entities/Instance/#thumbnail-url */
|
||||
thumbnail: z.object({
|
||||
url: z.string().url(),
|
||||
}),
|
||||
}).strict();
|
||||
|
||||
export const updateInstanceController: AppController = async (c) => {
|
||||
|
|
@ -321,51 +322,15 @@ export const updateInstanceController: AppController = async (c) => {
|
|||
title,
|
||||
description,
|
||||
short_description,
|
||||
screenshot_ids,
|
||||
thumbnail_id,
|
||||
screenshots,
|
||||
thumbnail,
|
||||
} = result.data;
|
||||
|
||||
const thumbnailUrl: string | undefined = (() => {
|
||||
if (!thumbnail_id) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const upload = dittoUploads.get(thumbnail_id);
|
||||
|
||||
if (!upload) {
|
||||
throw new HTTPException(422, { message: 'Uploaded attachment is no longer available.' });
|
||||
}
|
||||
return upload.url;
|
||||
})();
|
||||
|
||||
const screenshots: z.infer<typeof screenshotsSchema> = (screenshot_ids ?? []).map((id) => {
|
||||
const upload = dittoUploads.get(id);
|
||||
|
||||
if (!upload) {
|
||||
throw new HTTPException(422, { message: 'Uploaded attachment is no longer available.' });
|
||||
}
|
||||
|
||||
const data = renderAttachment(upload);
|
||||
|
||||
if (!data?.url || !data.meta?.original) {
|
||||
throw new HTTPException(422, { message: 'Image must have an URL and size dimensions.' });
|
||||
}
|
||||
|
||||
const screenshot = {
|
||||
src: data.url,
|
||||
label: data.description,
|
||||
sizes: `${data?.meta?.original?.width}x${data?.meta?.original?.height}`,
|
||||
type: data?.type, // FIX-ME, I BEG YOU: Returns just `image` instead of a valid MIME type
|
||||
};
|
||||
|
||||
return screenshot;
|
||||
});
|
||||
|
||||
meta.name = title ?? meta.name;
|
||||
meta.about = description ?? meta.about;
|
||||
meta.tagline = short_description ?? meta.tagline;
|
||||
meta.screenshots = screenshot_ids ? screenshots : meta.screenshots;
|
||||
meta.picture = thumbnailUrl ?? meta.picture;
|
||||
meta.name = title;
|
||||
meta.about = description;
|
||||
meta.tagline = short_description;
|
||||
meta.screenshots = screenshots;
|
||||
meta.picture = thumbnail.url;
|
||||
delete meta.event;
|
||||
|
||||
return {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue