mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Merge branch 'fix-updateInstanceController-schema' into 'main'
Update updateInstanceController schema See merge request soapbox-pub/ditto!584
This commit is contained in:
commit
858692d2f3
2 changed files with 16 additions and 53 deletions
|
|
@ -1,10 +1,8 @@
|
||||||
import { NostrEvent, NostrFilter, NSchema as n } from '@nostrify/nostrify';
|
import { NostrEvent, NostrFilter, NSchema as n } from '@nostrify/nostrify';
|
||||||
import { HTTPException } from '@hono/hono/http-exception';
|
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import { AppController } from '@/app.ts';
|
import { AppController } from '@/app.ts';
|
||||||
import { Conf } from '@/config.ts';
|
import { Conf } from '@/config.ts';
|
||||||
import { dittoUploads } from '@/DittoUploads.ts';
|
|
||||||
import { addTag } from '@/utils/tags.ts';
|
import { addTag } from '@/utils/tags.ts';
|
||||||
import { getAuthor } from '@/queries.ts';
|
import { getAuthor } from '@/queries.ts';
|
||||||
import { createEvent, paginated, parseBody, updateEvent } from '@/utils/api.ts';
|
import { createEvent, paginated, parseBody, updateEvent } from '@/utils/api.ts';
|
||||||
|
|
@ -18,7 +16,6 @@ import { booleanParamSchema, percentageSchema } from '@/schema.ts';
|
||||||
import { hydrateEvents } from '@/storages/hydrate.ts';
|
import { hydrateEvents } from '@/storages/hydrate.ts';
|
||||||
import { renderNameRequest } from '@/views/ditto.ts';
|
import { renderNameRequest } from '@/views/ditto.ts';
|
||||||
import { accountFromPubkey } from '@/views/mastodon/accounts.ts';
|
import { accountFromPubkey } from '@/views/mastodon/accounts.ts';
|
||||||
import { renderAttachment } from '@/views/mastodon/attachments.ts';
|
|
||||||
import { renderAccount } from '@/views/mastodon/accounts.ts';
|
import { renderAccount } from '@/views/mastodon/accounts.ts';
|
||||||
import { Storages } from '@/storages.ts';
|
import { Storages } from '@/storages.ts';
|
||||||
import { updateListAdminEvent } from '@/utils/api.ts';
|
import { updateListAdminEvent } from '@/utils/api.ts';
|
||||||
|
|
@ -294,14 +291,15 @@ export const statusZapSplitsController: AppController = async (c) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateInstanceSchema = z.object({
|
const updateInstanceSchema = z.object({
|
||||||
title: z.string().optional(),
|
title: z.string(),
|
||||||
description: z.string().optional(),
|
description: z.string(),
|
||||||
|
short_description: z.string(),
|
||||||
/** Mastodon doesn't have this field. */
|
/** Mastodon doesn't have this field. */
|
||||||
short_description: z.string().optional(),
|
screenshots: screenshotsSchema,
|
||||||
/** Mastodon doesn't have this field. */
|
/** https://docs.joinmastodon.org/entities/Instance/#thumbnail-url */
|
||||||
screenshot_ids: z.string().array().nullish(),
|
thumbnail: z.object({
|
||||||
/** Mastodon doesn't have this field. */
|
url: z.string().url(),
|
||||||
thumbnail_id: z.string().optional(),
|
}),
|
||||||
}).strict();
|
}).strict();
|
||||||
|
|
||||||
export const updateInstanceController: AppController = async (c) => {
|
export const updateInstanceController: AppController = async (c) => {
|
||||||
|
|
@ -321,51 +319,15 @@ export const updateInstanceController: AppController = async (c) => {
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
short_description,
|
short_description,
|
||||||
screenshot_ids,
|
screenshots,
|
||||||
thumbnail_id,
|
thumbnail,
|
||||||
} = result.data;
|
} = result.data;
|
||||||
|
|
||||||
const thumbnailUrl: string | undefined = (() => {
|
meta.name = title;
|
||||||
if (!thumbnail_id) {
|
meta.about = description;
|
||||||
return undefined;
|
meta.tagline = short_description;
|
||||||
}
|
meta.screenshots = screenshots;
|
||||||
|
meta.picture = thumbnail.url;
|
||||||
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;
|
|
||||||
delete meta.event;
|
delete meta.event;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,7 @@ const instanceV2Controller: AppController = async (c) => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
screenshots: meta.screenshots,
|
screenshots: meta.screenshots,
|
||||||
|
short_description: meta.tagline,
|
||||||
languages: [
|
languages: [
|
||||||
'en',
|
'en',
|
||||||
],
|
],
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue