separate character limits for local and remote notes
This commit is contained in:
parent
55df1ad10f
commit
560ee43dcf
19 changed files with 142 additions and 47 deletions
|
|
@ -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<typeof meta, typeof paramDef> { // 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<typeof meta, typeof paramDef> { // 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({
|
||||
|
|
|
|||
|
|
@ -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<typeof meta, typeof paramDef> { // 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<typeof meta, typeof paramDef> { // 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 {
|
||||
|
|
|
|||
|
|
@ -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<typeof meta, typeof paramDef> { // 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', {
|
||||
|
|
|
|||
|
|
@ -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 },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue