From 560ee43dcf2b76cce4b69a449fcd8b9601b7d68d Mon Sep 17 00:00:00 2001 From: Hazel K Date: Mon, 7 Oct 2024 21:03:31 -0400 Subject: separate character limits for local and remote notes --- .../src/server/api/endpoints/drive/files/create.ts | 17 ++++++++++++++-- .../src/server/api/endpoints/drive/files/update.ts | 16 +++++++++++++-- .../api/endpoints/drive/files/upload-from-url.ts | 23 +++++++++++++++++++--- .../src/server/api/endpoints/notes/create.ts | 2 +- 4 files changed, 50 insertions(+), 8 deletions(-) (limited to 'packages/backend/src/server/api') diff --git a/packages/backend/src/server/api/endpoints/drive/files/create.ts b/packages/backend/src/server/api/endpoints/drive/files/create.ts index 74eb4dded7..b8763af96a 100644 --- a/packages/backend/src/server/api/endpoints/drive/files/create.ts +++ b/packages/backend/src/server/api/endpoints/drive/files/create.ts @@ -5,11 +5,11 @@ import ms from 'ms'; import { Inject, Injectable } from '@nestjs/common'; -import { DB_MAX_IMAGE_COMMENT_LENGTH } from '@/const.js'; import { IdentifiableError } from '@/misc/identifiable-error.js'; import { Endpoint } from '@/server/api/endpoint-base.js'; import { DriveFileEntityService } from '@/core/entities/DriveFileEntityService.js'; import { DriveService } from '@/core/DriveService.js'; +import type { Config } from '@/config.js'; import { ApiError } from '../../../error.js'; import { MiMeta } from '@/models/_.js'; import { DI } from '@/di-symbols.js'; @@ -56,6 +56,12 @@ export const meta = { code: 'NO_FREE_SPACE', id: 'd08dbc37-a6a9-463a-8c47-96c32ab5f064', }, + + commentTooLong: { + message: 'Cannot upload the file because the comment exceeds the instance limit.', + code: 'COMMENT_TOO_LONG', + id: 'sj3hsm2l-s83j-4sk3-sk3j-sn3k2k4nsm3l', + }, }, } as const; @@ -64,7 +70,7 @@ export const paramDef = { properties: { folderId: { type: 'string', format: 'misskey:id', nullable: true, default: null }, name: { type: 'string', nullable: true, default: null }, - comment: { type: 'string', nullable: true, maxLength: DB_MAX_IMAGE_COMMENT_LENGTH, default: null }, + comment: { type: 'string', nullable: true, default: null }, isSensitive: { type: 'boolean', default: false }, force: { type: 'boolean', default: false }, }, @@ -77,6 +83,9 @@ export default class extends Endpoint { // eslint- @Inject(DI.meta) private serverSettings: MiMeta, + @Inject(DI.config) + private config: Config, + private driveFileEntityService: DriveFileEntityService, private driveService: DriveService, ) { @@ -94,6 +103,10 @@ export default class extends Endpoint { // eslint- } } + if (ps.comment && ps.comment.length > this.config.maxAltTextLength) { + throw new ApiError(meta.errors.commentTooLong); + } + try { // Create file const driveFile = await this.driveService.addFile({ diff --git a/packages/backend/src/server/api/endpoints/drive/files/update.ts b/packages/backend/src/server/api/endpoints/drive/files/update.ts index 5541018126..afad4ba0a6 100644 --- a/packages/backend/src/server/api/endpoints/drive/files/update.ts +++ b/packages/backend/src/server/api/endpoints/drive/files/update.ts @@ -9,8 +9,8 @@ import { Endpoint } from '@/server/api/endpoint-base.js'; import { DI } from '@/di-symbols.js'; import { RoleService } from '@/core/RoleService.js'; import { DriveService } from '@/core/DriveService.js'; +import type { Config } from '@/config.js'; import { ApiError } from '../../../error.js'; -import { DB_MAX_IMAGE_COMMENT_LENGTH } from '@/const.js'; export const meta = { tags: ['drive'], @@ -51,6 +51,12 @@ export const meta = { code: 'RESTRICTED_BY_ROLE', id: '7f59dccb-f465-75ab-5cf4-3ce44e3282f7', }, + + commentTooLong: { + message: 'Cannot upload the file because the comment exceeds the instance limit.', + code: 'COMMENT_TOO_LONG', + id: 'sj3hsm2l-s83j-4sk3-sk3j-sn3k2k4nsm3l', + }, }, res: { type: 'object', @@ -66,7 +72,7 @@ export const paramDef = { folderId: { type: 'string', format: 'misskey:id', nullable: true }, name: { type: 'string' }, isSensitive: { type: 'boolean' }, - comment: { type: 'string', nullable: true, maxLength: DB_MAX_IMAGE_COMMENT_LENGTH }, + comment: { type: 'string', nullable: true }, }, required: ['fileId'], } as const; @@ -76,6 +82,8 @@ export default class extends Endpoint { // eslint- constructor( @Inject(DI.driveFilesRepository) private driveFilesRepository: DriveFilesRepository, + @Inject(DI.config) + private config: Config, private driveService: DriveService, private roleService: RoleService, @@ -90,6 +98,10 @@ export default class extends Endpoint { // eslint- throw new ApiError(meta.errors.accessDenied); } + if (ps.comment && ps.comment.length > this.config.maxAltTextLength) { + throw new ApiError(meta.errors.commentTooLong); + } + let packedFile; try { diff --git a/packages/backend/src/server/api/endpoints/drive/files/upload-from-url.ts b/packages/backend/src/server/api/endpoints/drive/files/upload-from-url.ts index 49d2e78d08..52a1c51b2c 100644 --- a/packages/backend/src/server/api/endpoints/drive/files/upload-from-url.ts +++ b/packages/backend/src/server/api/endpoints/drive/files/upload-from-url.ts @@ -4,12 +4,14 @@ */ import ms from 'ms'; -import { Injectable } from '@nestjs/common'; +import { Inject, Injectable } from '@nestjs/common'; import { Endpoint } from '@/server/api/endpoint-base.js'; import { GlobalEventService } from '@/core/GlobalEventService.js'; import { DriveFileEntityService } from '@/core/entities/DriveFileEntityService.js'; import { DriveService } from '@/core/DriveService.js'; -import { DB_MAX_IMAGE_COMMENT_LENGTH } from '@/const.js'; +import { ApiError } from '@/server/api/error.js'; +import { DI } from '@/di-symbols.js'; +import type { Config } from '@/config.js'; export const meta = { tags: ['drive'], @@ -26,6 +28,14 @@ export const meta = { prohibitMoved: true, kind: 'write:drive', + + errors: { + commentTooLong: { + message: 'Cannot upload the file because the comment exceeds the instance limit.', + code: 'COMMENT_TOO_LONG', + id: 'sj3hsm2l-s83j-4sk3-sk3j-sn3k2k4nsm3l', + }, + }, } as const; export const paramDef = { @@ -34,7 +44,7 @@ export const paramDef = { url: { type: 'string' }, folderId: { type: 'string', format: 'misskey:id', nullable: true, default: null }, isSensitive: { type: 'boolean', default: false }, - comment: { type: 'string', nullable: true, maxLength: DB_MAX_IMAGE_COMMENT_LENGTH, default: null }, + comment: { type: 'string', nullable: true, default: null }, marker: { type: 'string', nullable: true, default: null }, force: { type: 'boolean', default: false }, }, @@ -44,11 +54,18 @@ export const paramDef = { @Injectable() export default class extends Endpoint { // eslint-disable-line import/no-default-export constructor( + @Inject(DI.config) + private config: Config, + private driveFileEntityService: DriveFileEntityService, private driveService: DriveService, private globalEventService: GlobalEventService, ) { super(meta, paramDef, async (ps, user, _1, _2, _3, ip, headers) => { + if (ps.comment && ps.comment.length > this.config.maxAltTextLength) { + throw new ApiError(meta.errors.commentTooLong); + } + this.driveService.uploadFromUrl({ url: ps.url, user, folderId: ps.folderId, sensitive: ps.isSensitive, force: ps.force, comment: ps.comment, requestIp: ip, requestHeaders: headers }).then(file => { this.driveFileEntityService.pack(file, { self: true }).then(packedFile => { this.globalEventService.publishMainStream(user.id, 'urlUploadFinished', { diff --git a/packages/backend/src/server/api/endpoints/notes/create.ts b/packages/backend/src/server/api/endpoints/notes/create.ts index 412491afaa..a66395f25c 100644 --- a/packages/backend/src/server/api/endpoints/notes/create.ts +++ b/packages/backend/src/server/api/endpoints/notes/create.ts @@ -147,7 +147,7 @@ export const paramDef = { visibleUserIds: { type: 'array', uniqueItems: true, items: { type: 'string', format: 'misskey:id', } }, - cw: { type: 'string', nullable: true, minLength: 1, maxLength: 500 }, + cw: { type: 'string', nullable: true, minLength: 1 }, localOnly: { type: 'boolean', default: false }, reactionAcceptance: { type: 'string', nullable: true, enum: [null, 'likeOnly', 'likeOnlyForRemote', 'nonSensitiveOnly', 'nonSensitiveOnlyForLocalLikeOnlyForRemote'], default: null }, noExtractMentions: { type: 'boolean', default: false }, -- cgit v1.2.3-freya From 67185a5d5d7d7a6912e772c7ab6021e6da8b72fd Mon Sep 17 00:00:00 2001 From: Hazel K Date: Wed, 9 Oct 2024 16:17:52 -0400 Subject: fix UUID format --- packages/backend/src/server/api/endpoints/drive/files/create.ts | 2 +- packages/backend/src/server/api/endpoints/drive/files/update.ts | 2 +- .../backend/src/server/api/endpoints/drive/files/upload-from-url.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'packages/backend/src/server/api') diff --git a/packages/backend/src/server/api/endpoints/drive/files/create.ts b/packages/backend/src/server/api/endpoints/drive/files/create.ts index b8763af96a..f67ff6ddc4 100644 --- a/packages/backend/src/server/api/endpoints/drive/files/create.ts +++ b/packages/backend/src/server/api/endpoints/drive/files/create.ts @@ -60,7 +60,7 @@ export const meta = { commentTooLong: { message: 'Cannot upload the file because the comment exceeds the instance limit.', code: 'COMMENT_TOO_LONG', - id: 'sj3hsm2l-s83j-4sk3-sk3j-sn3k2k4nsm3l', + id: '333652d9-0826-40f5-a2c3-e2bedcbb9fe5', }, }, } as const; diff --git a/packages/backend/src/server/api/endpoints/drive/files/update.ts b/packages/backend/src/server/api/endpoints/drive/files/update.ts index afad4ba0a6..1501abf9ce 100644 --- a/packages/backend/src/server/api/endpoints/drive/files/update.ts +++ b/packages/backend/src/server/api/endpoints/drive/files/update.ts @@ -55,7 +55,7 @@ export const meta = { commentTooLong: { message: 'Cannot upload the file because the comment exceeds the instance limit.', code: 'COMMENT_TOO_LONG', - id: 'sj3hsm2l-s83j-4sk3-sk3j-sn3k2k4nsm3l', + id: '333652d9-0826-40f5-a2c3-e2bedcbb9fe5', }, }, res: { diff --git a/packages/backend/src/server/api/endpoints/drive/files/upload-from-url.ts b/packages/backend/src/server/api/endpoints/drive/files/upload-from-url.ts index 52a1c51b2c..e20d482e70 100644 --- a/packages/backend/src/server/api/endpoints/drive/files/upload-from-url.ts +++ b/packages/backend/src/server/api/endpoints/drive/files/upload-from-url.ts @@ -33,7 +33,7 @@ export const meta = { commentTooLong: { message: 'Cannot upload the file because the comment exceeds the instance limit.', code: 'COMMENT_TOO_LONG', - id: 'sj3hsm2l-s83j-4sk3-sk3j-sn3k2k4nsm3l', + id: '333652d9-0826-40f5-a2c3-e2bedcbb9fe5', }, }, } as const; -- cgit v1.2.3-freya From 10d3d9f382ad00426854f4434180afdf84501bd8 Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Sun, 20 Oct 2024 00:49:36 -0400 Subject: fix unit tests --- .config/ci.yml | 8 ++++---- .config/cypress-devcontainer.yml | 9 +++++++++ .config/docker_example.yml | 12 ++++++------ .config/example.yml | 12 ++++++------ .../src/server/api/endpoints/notes/create.test.ts | 20 +++++++++++--------- 5 files changed, 36 insertions(+), 25 deletions(-) (limited to 'packages/backend/src/server/api') diff --git a/.config/ci.yml b/.config/ci.yml index ab6bbd5773..f29ac392d9 100644 --- a/.config/ci.yml +++ b/.config/ci.yml @@ -168,13 +168,13 @@ id: 'aidx' #outgoingAddressFamily: ipv4 # Amount of characters that can be used when writing notes. Longer notes will be rejected. (minimum: 1) -maxNoteLength: 3000 +#maxNoteLength: 3000 # Amount of characters that will be saved for remote notes. Longer notes will be truncated to this length. (minimum: 1) -maxRemoteNoteLength: 100000 +#maxRemoteNoteLength: 100000 # Amount of characters that can be used when writing media descriptions (alt text). Longer descriptions will be rejected. (minimum: 1) -maxAltTextLength: 20000 +#maxAltTextLength: 20000 # Amount of characters that will be saved for remote media descriptions (alt text). Longer descriptions will be truncated to this length. (minimum: 1) -maxRemoteAltTextLength: 100000 +#maxRemoteAltTextLength: 100000 # Proxy for HTTP/HTTPS #proxy: http://127.0.0.1:3128 diff --git a/.config/cypress-devcontainer.yml b/.config/cypress-devcontainer.yml index 91dce35155..66b5dceac8 100644 --- a/.config/cypress-devcontainer.yml +++ b/.config/cypress-devcontainer.yml @@ -179,6 +179,15 @@ id: 'aidx' # IP address family used for outgoing request (ipv4, ipv6 or dual) #outgoingAddressFamily: ipv4 +# Amount of characters that can be used when writing notes. Longer notes will be rejected. (minimum: 1) +#maxNoteLength: 3000 +# Amount of characters that will be saved for remote notes. Longer notes will be truncated to this length. (minimum: 1) +#maxRemoteNoteLength: 100000 +# Amount of characters that can be used when writing media descriptions (alt text). Longer descriptions will be rejected. (minimum: 1) +#maxAltTextLength: 20000 +# Amount of characters that will be saved for remote media descriptions (alt text). Longer descriptions will be truncated to this length. (minimum: 1) +#maxRemoteAltTextLength: 100000 + # Proxy for HTTP/HTTPS #proxy: http://127.0.0.1:3128 diff --git a/.config/docker_example.yml b/.config/docker_example.yml index 8bd555dffc..dd8ea1727a 100644 --- a/.config/docker_example.yml +++ b/.config/docker_example.yml @@ -250,14 +250,14 @@ id: 'aidx' # IP address family used for outgoing request (ipv4, ipv6 or dual) #outgoingAddressFamily: ipv4 -# Amount of characters that can be used when writing notes. Longer notes will be rejected. (maximum: 100000, minimum: 1) -maxNoteLength: 3000 -# Amount of characters that will be saved for remote notes. Longer notes will be truncated to this length. (maximum: 100000, minimum: 1) -maxRemoteNoteLength: 100000 +# Amount of characters that can be used when writing notes. Longer notes will be rejected. (minimum: 1) +#maxNoteLength: 3000 +# Amount of characters that will be saved for remote notes. Longer notes will be truncated to this length. (minimum: 1) +#maxRemoteNoteLength: 100000 # Amount of characters that can be used when writing media descriptions (alt text). Longer descriptions will be rejected. (minimum: 1) -maxAltTextLength: 20000 +#maxAltTextLength: 20000 # Amount of characters that will be saved for remote media descriptions (alt text). Longer descriptions will be truncated to this length. (minimum: 1) -maxRemoteAltTextLength: 100000 +#maxRemoteAltTextLength: 100000 # Proxy for HTTP/HTTPS #proxy: http://127.0.0.1:3128 diff --git a/.config/example.yml b/.config/example.yml index 6b80dab747..8794a25ffb 100644 --- a/.config/example.yml +++ b/.config/example.yml @@ -261,14 +261,14 @@ id: 'aidx' # IP address family used for outgoing request (ipv4, ipv6 or dual) #outgoingAddressFamily: ipv4 -# Amount of characters that can be used when writing notes. Longer notes will be rejected. (maximum: 100000, minimum: 1) -maxNoteLength: 3000 -# Amount of characters that will be saved for remote notes. Longer notes will be truncated to this length. (maximum: 100000, minimum: 1) -maxRemoteNoteLength: 100000 +# Amount of characters that can be used when writing notes. Longer notes will be rejected. (minimum: 1) +#maxNoteLength: 3000 +# Amount of characters that will be saved for remote notes. Longer notes will be truncated to this length. (minimum: 1) +#maxRemoteNoteLength: 100000 # Amount of characters that can be used when writing media descriptions (alt text). Longer descriptions will be rejected. (minimum: 1) -maxAltTextLength: 20000 +#maxAltTextLength: 20000 # Amount of characters that will be saved for remote media descriptions (alt text). Longer descriptions will be truncated to this length. (minimum: 1) -maxRemoteAltTextLength: 100000 +#maxRemoteAltTextLength: 100000 # Proxy for HTTP/HTTPS #proxy: http://127.0.0.1:3128 diff --git a/packages/backend/src/server/api/endpoints/notes/create.test.ts b/packages/backend/src/server/api/endpoints/notes/create.test.ts index f3d887bb20..18d80e867b 100644 --- a/packages/backend/src/server/api/endpoints/notes/create.test.ts +++ b/packages/backend/src/server/api/endpoints/notes/create.test.ts @@ -5,15 +5,12 @@ process.env.NODE_ENV = 'test'; -import { readFile } from 'node:fs/promises'; -import { fileURLToPath } from 'node:url'; -import { dirname } from 'node:path'; import { describe, test, expect } from '@jest/globals'; +import { loadConfig } from '@/config.js'; import { getValidator } from '../../../../../test/prelude/get-api-validator.js'; import { paramDef } from './create.js'; -const _filename = fileURLToPath(import.meta.url); -const _dirname = dirname(_filename); +const config = loadConfig(); const VALID = true; const INVALID = false; @@ -21,7 +18,12 @@ const INVALID = false; describe('api:notes/create', () => { describe('validation', () => { const v = getValidator(paramDef); - const tooLong = readFile(_dirname + '/../../../../../test/resources/misskey.svg', 'utf-8'); + const tooLong = (limit: number) => { + const arr: string[] = ['']; + arr.length = limit + 1; + arr.fill('a'); + return arr.join(''); + }; test('reject empty', () => { const valid = v({ }); @@ -71,8 +73,8 @@ describe('api:notes/create', () => { .toBe(INVALID); }); - test('over 500 characters cw', async () => { - expect(v({ text: 'Body', cw: await tooLong })) + test('over max characters cw', async () => { + expect(v({ text: '', cw: tooLong(config.maxNoteLength) })) .toBe(INVALID); }); }); @@ -220,7 +222,7 @@ describe('api:notes/create', () => { }); test('reject poll with too long choice', async () => { - expect(v({ poll: { choices: [await tooLong, '2'] } })) + expect(v({ poll: { choices: [tooLong(config.maxNoteLength), '2'] } })) .toBe(INVALID); }); -- cgit v1.2.3-freya From 01e98c75abc548bcd674526494cfc8ec0c7912ed Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Sat, 26 Oct 2024 10:04:23 -0400 Subject: add separate limits for CW length --- .config/ci.yml | 4 +++ .config/cypress-devcontainer.yml | 4 +++ .config/docker_example.yml | 4 +++ .config/example.yml | 4 +++ locales/index.d.ts | 36 ++++++++++++++++++++++ packages/backend/src/config.ts | 6 ++++ packages/backend/src/core/NoteCreateService.ts | 8 +++-- packages/backend/src/core/NoteEditService.ts | 8 +++-- .../src/server/api/endpoints/notes/create.ts | 12 ++++++-- .../backend/src/server/api/endpoints/notes/edit.ts | 14 +++++++-- 10 files changed, 91 insertions(+), 9 deletions(-) (limited to 'packages/backend/src/server/api') diff --git a/.config/ci.yml b/.config/ci.yml index f29ac392d9..d20ede8d35 100644 --- a/.config/ci.yml +++ b/.config/ci.yml @@ -171,6 +171,10 @@ id: 'aidx' #maxNoteLength: 3000 # Amount of characters that will be saved for remote notes. Longer notes will be truncated to this length. (minimum: 1) #maxRemoteNoteLength: 100000 +# Amount of characters that can be used when writing content warnings. Longer warnings will be rejected. (minimum: 1) +#maxCwLength: 500 +# Amount of characters that will be saved for remote content warnings. Longer warnings will be truncated to this length. (minimum: 1) +#maxRemoteCwLength: 5000 # Amount of characters that can be used when writing media descriptions (alt text). Longer descriptions will be rejected. (minimum: 1) #maxAltTextLength: 20000 # Amount of characters that will be saved for remote media descriptions (alt text). Longer descriptions will be truncated to this length. (minimum: 1) diff --git a/.config/cypress-devcontainer.yml b/.config/cypress-devcontainer.yml index 66b5dceac8..d8013a1c95 100644 --- a/.config/cypress-devcontainer.yml +++ b/.config/cypress-devcontainer.yml @@ -183,6 +183,10 @@ id: 'aidx' #maxNoteLength: 3000 # Amount of characters that will be saved for remote notes. Longer notes will be truncated to this length. (minimum: 1) #maxRemoteNoteLength: 100000 +# Amount of characters that can be used when writing content warnings. Longer warnings will be rejected. (minimum: 1) +#maxCwLength: 500 +# Amount of characters that will be saved for remote content warnings. Longer warnings will be truncated to this length. (minimum: 1) +#maxRemoteCwLength: 5000 # Amount of characters that can be used when writing media descriptions (alt text). Longer descriptions will be rejected. (minimum: 1) #maxAltTextLength: 20000 # Amount of characters that will be saved for remote media descriptions (alt text). Longer descriptions will be truncated to this length. (minimum: 1) diff --git a/.config/docker_example.yml b/.config/docker_example.yml index dd8ea1727a..5fac3dc41e 100644 --- a/.config/docker_example.yml +++ b/.config/docker_example.yml @@ -254,6 +254,10 @@ id: 'aidx' #maxNoteLength: 3000 # Amount of characters that will be saved for remote notes. Longer notes will be truncated to this length. (minimum: 1) #maxRemoteNoteLength: 100000 +# Amount of characters that can be used when writing content warnings. Longer warnings will be rejected. (minimum: 1) +#maxCwLength: 500 +# Amount of characters that will be saved for remote content warnings. Longer warnings will be truncated to this length. (minimum: 1) +#maxRemoteCwLength: 5000 # Amount of characters that can be used when writing media descriptions (alt text). Longer descriptions will be rejected. (minimum: 1) #maxAltTextLength: 20000 # Amount of characters that will be saved for remote media descriptions (alt text). Longer descriptions will be truncated to this length. (minimum: 1) diff --git a/.config/example.yml b/.config/example.yml index 8794a25ffb..0062b6670c 100644 --- a/.config/example.yml +++ b/.config/example.yml @@ -265,6 +265,10 @@ id: 'aidx' #maxNoteLength: 3000 # Amount of characters that will be saved for remote notes. Longer notes will be truncated to this length. (minimum: 1) #maxRemoteNoteLength: 100000 +# Amount of characters that can be used when writing content warnings. Longer warnings will be rejected. (minimum: 1) +#maxCwLength: 500 +# Amount of characters that will be saved for remote content warnings. Longer warnings will be truncated to this length. (minimum: 1) +#maxRemoteCwLength: 5000 # Amount of characters that can be used when writing media descriptions (alt text). Longer descriptions will be rejected. (minimum: 1) #maxAltTextLength: 20000 # Amount of characters that will be saved for remote media descriptions (alt text). Longer descriptions will be truncated to this length. (minimum: 1) diff --git a/locales/index.d.ts b/locales/index.d.ts index 535e88f7c7..d1cb1f97ea 100644 --- a/locales/index.d.ts +++ b/locales/index.d.ts @@ -5353,6 +5353,10 @@ export interface Locale extends ILocale { * オンにすると、このお知らせは通知されず、既読にする必要もなくなります。 */ "silenceDescription": string; + /** + * New + */ + "new": string; }; "_initialAccountSetting": { /** @@ -8442,6 +8446,10 @@ export interface Locale extends ILocale { * アプリケーションにアクセス許可を与えるには、ログインが必要です。 */ "pleaseLogin": string; + /** + * Allowed + */ + "allowed": string; }; "_antennaSources": { /** @@ -10603,6 +10611,30 @@ export interface Locale extends ILocale { * Mutuals */ "mutuals": string; + /** + * Private account + */ + "isLocked": string; + /** + * Administrator + */ + "isAdmin": string; + /** + * Bot user + */ + "isBot": string; + /** + * Open + */ + "open": string; + /** + * Destination address + */ + "emailDestination": string; + /** + * Date + */ + "date": string; /** * Quoted. */ @@ -10964,6 +10996,10 @@ export interface Locale extends ILocale { * Blocking you */ "blockingYou": string; + /** + * Show warning when opening external URLs + */ + "warnExternalUrl": string; "_mfm": { /** * This is not a widespread feature, it may not display properly on most other fedi software, including other Misskey forks diff --git a/packages/backend/src/config.ts b/packages/backend/src/config.ts index 19f1d6c066..3dc49c7eb6 100644 --- a/packages/backend/src/config.ts +++ b/packages/backend/src/config.ts @@ -73,6 +73,8 @@ type Source = { maxFileSize?: number; maxNoteLength?: number; + maxCwLength?: number; + maxRemoteCwLength?: number; maxRemoteNoteLength?: number; maxAltTextLength?: number; maxRemoteAltTextLength?: number; @@ -153,6 +155,8 @@ export type Config = { maxFileSize: number; maxNoteLength: number; maxRemoteNoteLength: number; + maxCwLength: number; + maxRemoteCwLength: number; maxAltTextLength: number; maxRemoteAltTextLength: number; clusterLimit: number | undefined; @@ -308,6 +312,8 @@ export function loadConfig(): Config { maxFileSize: config.maxFileSize ?? 262144000, maxNoteLength: config.maxNoteLength ?? 3000, maxRemoteNoteLength: config.maxRemoteNoteLength ?? 100000, + maxCwLength: config.maxCwLength ?? 500, + maxRemoteCwLength: config.maxRemoteCwLength ?? 5000, maxAltTextLength: config.maxAltTextLength ?? 20000, maxRemoteAltTextLength: config.maxRemoteAltTextLength ?? 100000, clusterLimit: config.clusterLimit, diff --git a/packages/backend/src/core/NoteCreateService.ts b/packages/backend/src/core/NoteCreateService.ts index 25286992d6..1bc4599a60 100644 --- a/packages/backend/src/core/NoteCreateService.ts +++ b/packages/backend/src/core/NoteCreateService.ts @@ -350,9 +350,13 @@ export class NoteCreateService implements OnApplicationShutdown { data.text = null; } + const maxCwLength = user.host == null + ? this.config.maxCwLength + : this.config.maxRemoteCwLength; + if (data.cw) { - if (data.cw.length > maxTextLength) { - data.cw = data.cw.slice(0, maxTextLength); + if (data.cw.length > maxCwLength) { + data.cw = data.cw.slice(0, maxCwLength); } data.cw = data.cw.trim(); if (data.cw === '') { diff --git a/packages/backend/src/core/NoteEditService.ts b/packages/backend/src/core/NoteEditService.ts index b1dd32aef8..d31958e5d4 100644 --- a/packages/backend/src/core/NoteEditService.ts +++ b/packages/backend/src/core/NoteEditService.ts @@ -380,9 +380,13 @@ export class NoteEditService implements OnApplicationShutdown { data.text = null; } + const maxCwLength = user.host == null + ? this.config.maxCwLength + : this.config.maxRemoteCwLength; + if (data.cw) { - if (data.cw.length > maxTextLength) { - data.cw = data.cw.slice(0, maxTextLength); + if (data.cw.length > maxCwLength) { + data.cw = data.cw.slice(0, maxCwLength); } data.cw = data.cw.trim(); if (data.cw === '') { diff --git a/packages/backend/src/server/api/endpoints/notes/create.ts b/packages/backend/src/server/api/endpoints/notes/create.ts index a66395f25c..d1cf0123dc 100644 --- a/packages/backend/src/server/api/endpoints/notes/create.ts +++ b/packages/backend/src/server/api/endpoints/notes/create.ts @@ -90,6 +90,12 @@ export const meta = { id: '3ac74a84-8fd5-4bb0-870f-01804f82ce16', }, + maxCwLength: { + message: 'You tried posting a content warning which is too long.', + code: 'MAX_CW_LENGTH', + id: '7004c478-bda3-4b4f-acb2-4316398c9d52', + }, + cannotReplyToSpecifiedVisibilityNoteWithExtendedVisibility: { message: 'You cannot reply to a specified visibility note with extended visibility.', code: 'CANNOT_REPLY_TO_SPECIFIED_VISIBILITY_NOTE_WITH_EXTENDED_VISIBILITY', @@ -250,10 +256,12 @@ export default class extends Endpoint { // eslint- private noteCreateService: NoteCreateService, ) { super(meta, paramDef, async (ps, me) => { - const contentLength = (ps.text?.length ?? 0) + (ps.cw?.length ?? 0); - if (contentLength > this.config.maxNoteLength) { + if (ps.text && ps.text.length > this.config.maxNoteLength) { throw new ApiError(meta.errors.maxLength); } + if (ps.cw && ps.cw.length > this.config.maxCwLength) { + throw new ApiError(meta.errors.maxCwLength); + } let visibleUsers: MiUser[] = []; if (ps.visibleUserIds) { diff --git a/packages/backend/src/server/api/endpoints/notes/edit.ts b/packages/backend/src/server/api/endpoints/notes/edit.ts index b9be145caf..dc94c78e75 100644 --- a/packages/backend/src/server/api/endpoints/notes/edit.ts +++ b/packages/backend/src/server/api/endpoints/notes/edit.ts @@ -86,6 +86,12 @@ export const meta = { id: '3ac74a84-8fd5-4bb0-870f-01804f82ce16', }, + maxCwLength: { + message: 'You tried posting a content warning which is too long.', + code: 'MAX_CW_LENGTH', + id: '7004c478-bda3-4b4f-acb2-4316398c9d52', + }, + cannotReplyToSpecifiedVisibilityNoteWithExtendedVisibility: { message: 'You cannot reply to a specified visibility note with extended visibility.', code: 'CANNOT_REPLY_TO_SPECIFIED_VISIBILITY_NOTE_WITH_EXTENDED_VISIBILITY', @@ -197,7 +203,7 @@ export const paramDef = { format: 'misskey:id', }, }, - cw: { type: 'string', nullable: true, minLength: 1, maxLength: 500 }, + cw: { type: 'string', nullable: true, minLength: 1 }, localOnly: { type: 'boolean', default: false }, reactionAcceptance: { type: 'string', nullable: true, enum: [null, 'likeOnly', 'likeOnlyForRemote', 'nonSensitiveOnly', 'nonSensitiveOnlyForLocalLikeOnlyForRemote'], default: null }, noExtractMentions: { type: 'boolean', default: false }, @@ -297,10 +303,12 @@ export default class extends Endpoint { // eslint- private noteEditService: NoteEditService, ) { super(meta, paramDef, async (ps, me) => { - const contentLength = (ps.text?.length ?? 0) + (ps.cw?.length ?? 0); - if (contentLength > this.config.maxNoteLength) { + if (ps.text && ps.text.length > this.config.maxNoteLength) { throw new ApiError(meta.errors.maxLength); } + if (ps.cw && ps.cw.length > this.config.maxCwLength) { + throw new ApiError(meta.errors.maxCwLength); + } let visibleUsers: MiUser[] = []; if (ps.visibleUserIds) { -- cgit v1.2.3-freya From ca1cdc4ea3daba4483b4cfa601ce9b113ccd4a3a Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Sat, 26 Oct 2024 10:38:29 -0400 Subject: fix poll option limit in masto API --- packages/backend/src/server/api/mastodon/endpoints/meta.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/backend/src/server/api') diff --git a/packages/backend/src/server/api/mastodon/endpoints/meta.ts b/packages/backend/src/server/api/mastodon/endpoints/meta.ts index 79d2c62a24..c9833b85d7 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/meta.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/meta.ts @@ -54,7 +54,7 @@ export async function getInstance( }, polls: { max_options: 10, - max_characters_per_option: 50, + max_characters_per_option: 150, min_expiration: 50, max_expiration: 2629746, }, -- cgit v1.2.3-freya