summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api/endpoints/notes/create.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/backend/src/server/api/endpoints/notes/create.ts')
-rw-r--r--packages/backend/src/server/api/endpoints/notes/create.ts123
1 files changed, 42 insertions, 81 deletions
diff --git a/packages/backend/src/server/api/endpoints/notes/create.ts b/packages/backend/src/server/api/endpoints/notes/create.ts
index 4efa76b248..7d81abc3a7 100644
--- a/packages/backend/src/server/api/endpoints/notes/create.ts
+++ b/packages/backend/src/server/api/endpoints/notes/create.ts
@@ -1,11 +1,9 @@
-import $ from 'cafy';
import ms from 'ms';
import { length } from 'stringz';
import create from '@/services/note/create';
import define from '../../define';
import { fetchMeta } from '@/misc/fetch-meta';
import { ApiError } from '../../error';
-import { ID } from '@/misc/cafy-id';
import { User } from '@/models/entities/user';
import { Users, DriveFiles, Notes, Channels, Blockings } from '@/models/index';
import { DriveFile } from '@/models/entities/drive-file';
@@ -34,84 +32,6 @@ export const meta = {
kind: 'write:notes',
- params: {
- visibility: {
- validator: $.optional.str.or(noteVisibilities as unknown as string[]),
- default: 'public',
- },
-
- visibleUserIds: {
- validator: $.optional.arr($.type(ID)).unique().min(0),
- },
-
- text: {
- validator: $.optional.nullable.str.pipe(text =>
- text.trim() != ''
- && length(text.trim()) <= maxNoteTextLength
- && Array.from(text.trim()).length <= DB_MAX_NOTE_TEXT_LENGTH, // DB limit
- ),
- default: null,
- },
-
- cw: {
- validator: $.optional.nullable.str.pipe(Notes.validateCw),
- },
-
- localOnly: {
- validator: $.optional.bool,
- default: false,
- },
-
- noExtractMentions: {
- validator: $.optional.bool,
- default: false,
- },
-
- noExtractHashtags: {
- validator: $.optional.bool,
- default: false,
- },
-
- noExtractEmojis: {
- validator: $.optional.bool,
- default: false,
- },
-
- fileIds: {
- validator: $.optional.arr($.type(ID)).unique().range(1, 16),
- },
-
- mediaIds: {
- validator: $.optional.arr($.type(ID)).unique().range(1, 16),
- deprecated: true,
- },
-
- replyId: {
- validator: $.optional.nullable.type(ID),
- },
-
- renoteId: {
- validator: $.optional.nullable.type(ID),
- },
-
- channelId: {
- validator: $.optional.nullable.type(ID),
- },
-
- poll: {
- validator: $.optional.nullable.obj({
- choices: $.arr($.str)
- .unique()
- .range(2, 10)
- .each(c => c.length > 0 && c.length < 50),
- multiple: $.optional.bool,
- expiresAt: $.optional.nullable.num.int(),
- expiredAfter: $.optional.nullable.num.int().min(1),
- }).strict(),
- ref: 'poll',
- },
- },
-
res: {
type: 'object',
optional: false, nullable: false,
@@ -175,8 +95,49 @@ export const meta = {
},
} as const;
+const paramDef = {
+ type: 'object',
+ properties: {
+ visibility: { type: 'string', enum: ['public', 'home', 'followers', 'specified'], default: "public" },
+ visibleUserIds: { type: 'array', uniqueItems: true, items: {
+ type: 'string', format: 'misskey:id',
+ } },
+ text: { type: 'string', nullable: true, maxLength: 3000, default: null },
+ cw: { type: 'string', nullable: true, maxLength: 100 },
+ localOnly: { type: 'boolean', default: false },
+ noExtractMentions: { type: 'boolean', default: false },
+ noExtractHashtags: { type: 'boolean', default: false },
+ noExtractEmojis: { type: 'boolean', default: false },
+ fileIds: { type: 'array', uniqueItems: true, minItems: 1, maxItems: 16, items: {
+ type: 'string', format: 'misskey:id',
+ } },
+ mediaIds: { type: 'array', uniqueItems: true, minItems: 1, maxItems: 16, items: {
+ type: 'string', format: 'misskey:id',
+ } },
+ replyId: { type: 'string', format: 'misskey:id', nullable: true },
+ renoteId: { type: 'string', format: 'misskey:id', nullable: true },
+ channelId: { type: 'string', format: 'misskey:id', nullable: true },
+ poll: {
+ type: 'object', nullable: true,
+ properties: {
+ choices: {
+ type: 'array', uniqueItems: true, minItems: 2, maxItems: 10,
+ items: {
+ type: 'string', minLength: 1, maxLength: 50,
+ },
+ },
+ multiple: { type: 'boolean', default: false },
+ expiresAt: { type: 'integer', nullable: true },
+ expiredAfter: { type: 'integer', nullable: true, minimum: 1 },
+ },
+ required: ['choices'],
+ },
+ },
+ required: [],
+} as const;
+
// eslint-disable-next-line import/no-default-export
-export default define(meta, async (ps, user) => {
+export default define(meta, paramDef, async (ps, user) => {
let visibleUsers: User[] = [];
if (ps.visibleUserIds) {
visibleUsers = (await Promise.all(ps.visibleUserIds.map(id => Users.findOne(id))))