mirror of
https://codeberg.org/yeentown/barkey
synced 2024-11-21 17:55:11 +00:00
add separate limits for CW length
This commit is contained in:
parent
10d3d9f382
commit
01e98c75ab
10 changed files with 91 additions and 9 deletions
|
@ -171,6 +171,10 @@ id: 'aidx'
|
||||||
#maxNoteLength: 3000
|
#maxNoteLength: 3000
|
||||||
# Amount of characters that will be saved for remote notes. Longer notes will be truncated to this length. (minimum: 1)
|
# 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 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)
|
# 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)
|
# Amount of characters that will be saved for remote media descriptions (alt text). Longer descriptions will be truncated to this length. (minimum: 1)
|
||||||
|
|
|
@ -183,6 +183,10 @@ id: 'aidx'
|
||||||
#maxNoteLength: 3000
|
#maxNoteLength: 3000
|
||||||
# Amount of characters that will be saved for remote notes. Longer notes will be truncated to this length. (minimum: 1)
|
# 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 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)
|
# 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)
|
# Amount of characters that will be saved for remote media descriptions (alt text). Longer descriptions will be truncated to this length. (minimum: 1)
|
||||||
|
|
|
@ -254,6 +254,10 @@ id: 'aidx'
|
||||||
#maxNoteLength: 3000
|
#maxNoteLength: 3000
|
||||||
# Amount of characters that will be saved for remote notes. Longer notes will be truncated to this length. (minimum: 1)
|
# 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 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)
|
# 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)
|
# Amount of characters that will be saved for remote media descriptions (alt text). Longer descriptions will be truncated to this length. (minimum: 1)
|
||||||
|
|
|
@ -265,6 +265,10 @@ id: 'aidx'
|
||||||
#maxNoteLength: 3000
|
#maxNoteLength: 3000
|
||||||
# Amount of characters that will be saved for remote notes. Longer notes will be truncated to this length. (minimum: 1)
|
# 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 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)
|
# 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)
|
# Amount of characters that will be saved for remote media descriptions (alt text). Longer descriptions will be truncated to this length. (minimum: 1)
|
||||||
|
|
36
locales/index.d.ts
vendored
36
locales/index.d.ts
vendored
|
@ -5353,6 +5353,10 @@ export interface Locale extends ILocale {
|
||||||
* オンにすると、このお知らせは通知されず、既読にする必要もなくなります。
|
* オンにすると、このお知らせは通知されず、既読にする必要もなくなります。
|
||||||
*/
|
*/
|
||||||
"silenceDescription": string;
|
"silenceDescription": string;
|
||||||
|
/**
|
||||||
|
* New
|
||||||
|
*/
|
||||||
|
"new": string;
|
||||||
};
|
};
|
||||||
"_initialAccountSetting": {
|
"_initialAccountSetting": {
|
||||||
/**
|
/**
|
||||||
|
@ -8442,6 +8446,10 @@ export interface Locale extends ILocale {
|
||||||
* アプリケーションにアクセス許可を与えるには、ログインが必要です。
|
* アプリケーションにアクセス許可を与えるには、ログインが必要です。
|
||||||
*/
|
*/
|
||||||
"pleaseLogin": string;
|
"pleaseLogin": string;
|
||||||
|
/**
|
||||||
|
* Allowed
|
||||||
|
*/
|
||||||
|
"allowed": string;
|
||||||
};
|
};
|
||||||
"_antennaSources": {
|
"_antennaSources": {
|
||||||
/**
|
/**
|
||||||
|
@ -10603,6 +10611,30 @@ export interface Locale extends ILocale {
|
||||||
* Mutuals
|
* Mutuals
|
||||||
*/
|
*/
|
||||||
"mutuals": string;
|
"mutuals": string;
|
||||||
|
/**
|
||||||
|
* Private account
|
||||||
|
*/
|
||||||
|
"isLocked": string;
|
||||||
|
/**
|
||||||
|
* Administrator
|
||||||
|
*/
|
||||||
|
"isAdmin": string;
|
||||||
|
/**
|
||||||
|
* Bot user
|
||||||
|
*/
|
||||||
|
"isBot": string;
|
||||||
|
/**
|
||||||
|
* Open
|
||||||
|
*/
|
||||||
|
"open": string;
|
||||||
|
/**
|
||||||
|
* Destination address
|
||||||
|
*/
|
||||||
|
"emailDestination": string;
|
||||||
|
/**
|
||||||
|
* Date
|
||||||
|
*/
|
||||||
|
"date": string;
|
||||||
/**
|
/**
|
||||||
* Quoted.
|
* Quoted.
|
||||||
*/
|
*/
|
||||||
|
@ -10964,6 +10996,10 @@ export interface Locale extends ILocale {
|
||||||
* Blocking you
|
* Blocking you
|
||||||
*/
|
*/
|
||||||
"blockingYou": string;
|
"blockingYou": string;
|
||||||
|
/**
|
||||||
|
* Show warning when opening external URLs
|
||||||
|
*/
|
||||||
|
"warnExternalUrl": string;
|
||||||
"_mfm": {
|
"_mfm": {
|
||||||
/**
|
/**
|
||||||
* This is not a widespread feature, it may not display properly on most other fedi software, including other Misskey forks
|
* This is not a widespread feature, it may not display properly on most other fedi software, including other Misskey forks
|
||||||
|
|
|
@ -73,6 +73,8 @@ type Source = {
|
||||||
|
|
||||||
maxFileSize?: number;
|
maxFileSize?: number;
|
||||||
maxNoteLength?: number;
|
maxNoteLength?: number;
|
||||||
|
maxCwLength?: number;
|
||||||
|
maxRemoteCwLength?: number;
|
||||||
maxRemoteNoteLength?: number;
|
maxRemoteNoteLength?: number;
|
||||||
maxAltTextLength?: number;
|
maxAltTextLength?: number;
|
||||||
maxRemoteAltTextLength?: number;
|
maxRemoteAltTextLength?: number;
|
||||||
|
@ -153,6 +155,8 @@ export type Config = {
|
||||||
maxFileSize: number;
|
maxFileSize: number;
|
||||||
maxNoteLength: number;
|
maxNoteLength: number;
|
||||||
maxRemoteNoteLength: number;
|
maxRemoteNoteLength: number;
|
||||||
|
maxCwLength: number;
|
||||||
|
maxRemoteCwLength: number;
|
||||||
maxAltTextLength: number;
|
maxAltTextLength: number;
|
||||||
maxRemoteAltTextLength: number;
|
maxRemoteAltTextLength: number;
|
||||||
clusterLimit: number | undefined;
|
clusterLimit: number | undefined;
|
||||||
|
@ -308,6 +312,8 @@ export function loadConfig(): Config {
|
||||||
maxFileSize: config.maxFileSize ?? 262144000,
|
maxFileSize: config.maxFileSize ?? 262144000,
|
||||||
maxNoteLength: config.maxNoteLength ?? 3000,
|
maxNoteLength: config.maxNoteLength ?? 3000,
|
||||||
maxRemoteNoteLength: config.maxRemoteNoteLength ?? 100000,
|
maxRemoteNoteLength: config.maxRemoteNoteLength ?? 100000,
|
||||||
|
maxCwLength: config.maxCwLength ?? 500,
|
||||||
|
maxRemoteCwLength: config.maxRemoteCwLength ?? 5000,
|
||||||
maxAltTextLength: config.maxAltTextLength ?? 20000,
|
maxAltTextLength: config.maxAltTextLength ?? 20000,
|
||||||
maxRemoteAltTextLength: config.maxRemoteAltTextLength ?? 100000,
|
maxRemoteAltTextLength: config.maxRemoteAltTextLength ?? 100000,
|
||||||
clusterLimit: config.clusterLimit,
|
clusterLimit: config.clusterLimit,
|
||||||
|
|
|
@ -350,9 +350,13 @@ export class NoteCreateService implements OnApplicationShutdown {
|
||||||
data.text = null;
|
data.text = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const maxCwLength = user.host == null
|
||||||
|
? this.config.maxCwLength
|
||||||
|
: this.config.maxRemoteCwLength;
|
||||||
|
|
||||||
if (data.cw) {
|
if (data.cw) {
|
||||||
if (data.cw.length > maxTextLength) {
|
if (data.cw.length > maxCwLength) {
|
||||||
data.cw = data.cw.slice(0, maxTextLength);
|
data.cw = data.cw.slice(0, maxCwLength);
|
||||||
}
|
}
|
||||||
data.cw = data.cw.trim();
|
data.cw = data.cw.trim();
|
||||||
if (data.cw === '') {
|
if (data.cw === '') {
|
||||||
|
|
|
@ -380,9 +380,13 @@ export class NoteEditService implements OnApplicationShutdown {
|
||||||
data.text = null;
|
data.text = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const maxCwLength = user.host == null
|
||||||
|
? this.config.maxCwLength
|
||||||
|
: this.config.maxRemoteCwLength;
|
||||||
|
|
||||||
if (data.cw) {
|
if (data.cw) {
|
||||||
if (data.cw.length > maxTextLength) {
|
if (data.cw.length > maxCwLength) {
|
||||||
data.cw = data.cw.slice(0, maxTextLength);
|
data.cw = data.cw.slice(0, maxCwLength);
|
||||||
}
|
}
|
||||||
data.cw = data.cw.trim();
|
data.cw = data.cw.trim();
|
||||||
if (data.cw === '') {
|
if (data.cw === '') {
|
||||||
|
|
|
@ -90,6 +90,12 @@ export const meta = {
|
||||||
id: '3ac74a84-8fd5-4bb0-870f-01804f82ce16',
|
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: {
|
cannotReplyToSpecifiedVisibilityNoteWithExtendedVisibility: {
|
||||||
message: 'You cannot reply to a specified visibility note with extended visibility.',
|
message: 'You cannot reply to a specified visibility note with extended visibility.',
|
||||||
code: 'CANNOT_REPLY_TO_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<typeof meta, typeof paramDef> { // eslint-
|
||||||
private noteCreateService: NoteCreateService,
|
private noteCreateService: NoteCreateService,
|
||||||
) {
|
) {
|
||||||
super(meta, paramDef, async (ps, me) => {
|
super(meta, paramDef, async (ps, me) => {
|
||||||
const contentLength = (ps.text?.length ?? 0) + (ps.cw?.length ?? 0);
|
if (ps.text && ps.text.length > this.config.maxNoteLength) {
|
||||||
if (contentLength > this.config.maxNoteLength) {
|
|
||||||
throw new ApiError(meta.errors.maxLength);
|
throw new ApiError(meta.errors.maxLength);
|
||||||
}
|
}
|
||||||
|
if (ps.cw && ps.cw.length > this.config.maxCwLength) {
|
||||||
|
throw new ApiError(meta.errors.maxCwLength);
|
||||||
|
}
|
||||||
|
|
||||||
let visibleUsers: MiUser[] = [];
|
let visibleUsers: MiUser[] = [];
|
||||||
if (ps.visibleUserIds) {
|
if (ps.visibleUserIds) {
|
||||||
|
|
|
@ -86,6 +86,12 @@ export const meta = {
|
||||||
id: '3ac74a84-8fd5-4bb0-870f-01804f82ce16',
|
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: {
|
cannotReplyToSpecifiedVisibilityNoteWithExtendedVisibility: {
|
||||||
message: 'You cannot reply to a specified visibility note with extended visibility.',
|
message: 'You cannot reply to a specified visibility note with extended visibility.',
|
||||||
code: 'CANNOT_REPLY_TO_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',
|
format: 'misskey:id',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
cw: { type: 'string', nullable: true, minLength: 1, maxLength: 500 },
|
cw: { type: 'string', nullable: true, minLength: 1 },
|
||||||
localOnly: { type: 'boolean', default: false },
|
localOnly: { type: 'boolean', default: false },
|
||||||
reactionAcceptance: { type: 'string', nullable: true, enum: [null, 'likeOnly', 'likeOnlyForRemote', 'nonSensitiveOnly', 'nonSensitiveOnlyForLocalLikeOnlyForRemote'], default: null },
|
reactionAcceptance: { type: 'string', nullable: true, enum: [null, 'likeOnly', 'likeOnlyForRemote', 'nonSensitiveOnly', 'nonSensitiveOnlyForLocalLikeOnlyForRemote'], default: null },
|
||||||
noExtractMentions: { type: 'boolean', default: false },
|
noExtractMentions: { type: 'boolean', default: false },
|
||||||
|
@ -297,10 +303,12 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
private noteEditService: NoteEditService,
|
private noteEditService: NoteEditService,
|
||||||
) {
|
) {
|
||||||
super(meta, paramDef, async (ps, me) => {
|
super(meta, paramDef, async (ps, me) => {
|
||||||
const contentLength = (ps.text?.length ?? 0) + (ps.cw?.length ?? 0);
|
if (ps.text && ps.text.length > this.config.maxNoteLength) {
|
||||||
if (contentLength > this.config.maxNoteLength) {
|
|
||||||
throw new ApiError(meta.errors.maxLength);
|
throw new ApiError(meta.errors.maxLength);
|
||||||
}
|
}
|
||||||
|
if (ps.cw && ps.cw.length > this.config.maxCwLength) {
|
||||||
|
throw new ApiError(meta.errors.maxCwLength);
|
||||||
|
}
|
||||||
|
|
||||||
let visibleUsers: MiUser[] = [];
|
let visibleUsers: MiUser[] = [];
|
||||||
if (ps.visibleUserIds) {
|
if (ps.visibleUserIds) {
|
||||||
|
|
Loading…
Reference in a new issue