diff options
| author | Marie <github@yuugi.dev> | 2025-02-07 03:47:20 +0000 |
|---|---|---|
| committer | Marie <github@yuugi.dev> | 2025-02-07 03:47:20 +0000 |
| commit | d629b882b0b5b231557d395e5554f2b01ac69f92 (patch) | |
| tree | 5ebc3b31443f0b61dedee01489a73de9e5d2ad3d /packages/backend/src/server | |
| parent | merge: Increase the rate limit for `/api/i` endpoint (!882) (diff) | |
| parent | fix check for parts.length (diff) | |
| download | sharkey-d629b882b0b5b231557d395e5554f2b01ac69f92.tar.gz sharkey-d629b882b0b5b231557d395e5554f2b01ac69f92.tar.bz2 sharkey-d629b882b0b5b231557d395e5554f2b01ac69f92.zip | |
merge: Allow users to set a default content warning for their new posts (resolves #901) (!881)
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/881
Closes #901
Approved-by: dakkar <dakkar@thenautilus.net>
Approved-by: Marie <github@yuugi.dev>
Diffstat (limited to 'packages/backend/src/server')
| -rw-r--r-- | packages/backend/src/server/api/endpoints/i/update.ts | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/packages/backend/src/server/api/endpoints/i/update.ts b/packages/backend/src/server/api/endpoints/i/update.ts index 09c06a108d..e1552fed8a 100644 --- a/packages/backend/src/server/api/endpoints/i/update.ts +++ b/packages/backend/src/server/api/endpoints/i/update.ts @@ -133,6 +133,12 @@ export const meta = { id: '0b3f9f6a-2f4d-4b1f-9fb4-49d3a2fd7191', httpStatusCode: 422, }, + + maxCwLength: { + message: 'You tried setting a default content warning which is too long.', + code: 'MAX_CW_LENGTH', + id: '7004c478-bda3-4b4f-acb2-4316398c9d52', + }, }, res: { @@ -243,6 +249,12 @@ export const paramDef = { uniqueItems: true, items: { type: 'string' }, }, + defaultCW: { type: 'string', nullable: true }, + defaultCWPriority: { + type: 'string', + enum: ['default', 'parent', 'defaultParent', 'parentDefault'], + nullable: false, + }, }, } as const; @@ -494,6 +506,19 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint- updates.alsoKnownAs = newAlsoKnownAs.size > 0 ? Array.from(newAlsoKnownAs) : null; } + let defaultCW = ps.defaultCW; + if (defaultCW !== undefined) { + if (defaultCW === '') defaultCW = null; + if (defaultCW && defaultCW.length > this.config.maxCwLength) { + throw new ApiError(meta.errors.maxCwLength); + } + + profileUpdates.defaultCW = defaultCW; + } + if (ps.defaultCWPriority !== undefined) { + profileUpdates.defaultCWPriority = ps.defaultCWPriority; + } + //#region emojis/tags let emojis = [] as string[]; |