summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/notes/create.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2019-04-07 21:50:36 +0900
committerGitHub <noreply@github.com>2019-04-07 21:50:36 +0900
commitf0a29721c9fb10f97faf386bc9d6b1b2fad97895 (patch)
treeb5c1d38d698589bb444c0881a431391db91eb5bc /src/server/api/endpoints/notes/create.ts
parentUpdate README.md [AUTOGEN] (#4639) (diff)
downloadsharkey-f0a29721c9fb10f97faf386bc9d6b1b2fad97895.tar.gz
sharkey-f0a29721c9fb10f97faf386bc9d6b1b2fad97895.tar.bz2
sharkey-f0a29721c9fb10f97faf386bc9d6b1b2fad97895.zip
Use PostgreSQL instead of MongoDB (#4572)
* wip * Update note.ts * Update timeline.ts * Update core.ts * wip * Update generate-visibility-query.ts * wip * wip * wip * wip * wip * Update global-timeline.ts * wip * wip * wip * Update vote.ts * wip * wip * Update create.ts * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Update files.ts * wip * wip * Update CONTRIBUTING.md * wip * wip * wip * wip * wip * wip * wip * wip * Update read-notification.ts * wip * wip * wip * wip * wip * wip * wip * Update cancel.ts * wip * wip * wip * Update show.ts * wip * wip * Update gen-id.ts * Update create.ts * Update id.ts * wip * wip * wip * wip * wip * wip * wip * Docker: Update files about Docker (#4599) * Docker: Use cache if files used by `yarn install` was not updated This patch reduces the number of times to installing node_modules. For example, `yarn install` step will be skipped when only ".config/default.yml" is updated. * Docker: Migrate MongoDB to Postgresql Misskey uses Postgresql as a database instead of Mongodb since version 11. * Docker: Uncomment about data persistence This patch will save a lot of databases. * wip * wip * wip * Update activitypub.ts * wip * wip * wip * Update logs.ts * wip * Update drive-file.ts * Update register.ts * wip * wip * Update mentions.ts * wip * wip * wip * Update recommendation.ts * wip * Update index.ts * wip * Update recommendation.ts * Doc: Update docker.ja.md and docker.en.md (#1) (#4608) Update how to set up misskey. * wip * :v: * wip * Update note.ts * Update postgre.ts * wip * wip * wip * wip * Update add-file.ts * wip * wip * wip * Clean up * Update logs.ts * wip * :pizza: * wip * Ad notes * wip * Update api-visibility.ts * Update note.ts * Update add-file.ts * tests * tests * Update postgre.ts * Update utils.ts * wip * wip * Refactor * wip * Refactor * wip * wip * Update show-users.ts * Update update-instance.ts * wip * Update feed.ts * Update outbox.ts * Update outbox.ts * Update user.ts * wip * Update list.ts * Update update-hashtag.ts * wip * Update update-hashtag.ts * Refactor * Update update.ts * wip * wip * :v: * clean up * docs * Update push.ts * wip * Update api.ts * wip * :v: * Update make-pagination-query.ts * :v: * Delete hashtags.ts * Update instances.ts * Update instances.ts * Update create.ts * Update search.ts * Update reversi-game.ts * Update signup.ts * Update user.ts * id * Update example.yml * :art: * objectid * fix * reversi * reversi * Fix bug of chart engine * Add test of chart engine * Improve test * Better testing * Improve chart engine * Refactor * Add test of chart engine * Refactor * Add chart test * Fix bug * コミットし忘れ * Refactoring * :v: * Add tests * Add test * Extarct note tests * Refactor * 存在しないユーザーにメンションできなくなっていた問題を修正 * Fix bug * Update update-meta.ts * Fix bug * Update mention.vue * Fix bug * Update meta.ts * Update CONTRIBUTING.md * Fix bug * Fix bug * Fix bug * Clean up * Clean up * Update notification.ts * Clean up * Add mute tests * Add test * Refactor * Add test * Fix test * Refactor * Refactor * Add tests * Update utils.ts * Update utils.ts * Fix test * Update package.json * Update update.ts * Update manifest.ts * Fix bug * Fix bug * Add test * :art: * Update endpoint permissions * Updaye permisison * Update person.ts #4299 * データベースと同期しないように * Fix bug * Fix bug * Update reversi-game.ts * Use a feature of Node v11.7.0 to extract a public key (#4644) * wip * wip * :v: * Refactoring #1540 * test * test * test * test * test * test * test * Fix bug * Fix test * :sushi: * wip * #4471 * Add test for #4335 * Refactor * Fix test * Add tests * :clock4: * Fix bug * Add test * Add test * rename * Fix bug
Diffstat (limited to 'src/server/api/endpoints/notes/create.ts')
-rw-r--r--src/server/api/endpoints/notes/create.ts67
1 files changed, 23 insertions, 44 deletions
diff --git a/src/server/api/endpoints/notes/create.ts b/src/server/api/endpoints/notes/create.ts
index 8cc5e4b815..138f05fb3b 100644
--- a/src/server/api/endpoints/notes/create.ts
+++ b/src/server/api/endpoints/notes/create.ts
@@ -1,14 +1,15 @@
import $ from 'cafy';
-import ID, { transform, transformMany } from '../../../../misc/cafy-id';
import * as ms from 'ms';
import { length } from 'stringz';
-import Note, { INote, isValidCw, pack } from '../../../../models/note';
-import User, { IUser } from '../../../../models/user';
-import DriveFile, { IDriveFile } from '../../../../models/drive-file';
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 } from '../../../../models';
+import { DriveFile } from '../../../../models/entities/drive-file';
+import { Note } from '../../../../models/entities/note';
let maxNoteTextLength = 1000;
@@ -34,7 +35,7 @@ export const meta = {
max: 300
},
- kind: 'note-write',
+ kind: 'write:notes',
params: {
visibility: {
@@ -47,7 +48,6 @@ export const meta = {
visibleUserIds: {
validator: $.optional.arr($.type(ID)).unique().min(0),
- transform: transformMany,
desc: {
'ja-JP': '(投稿の公開範囲が specified の場合)投稿を閲覧できるユーザー'
}
@@ -64,7 +64,7 @@ export const meta = {
},
cw: {
- validator: $.optional.nullable.str.pipe(isValidCw),
+ validator: $.optional.nullable.str.pipe(Notes.validateCw),
desc: {
'ja-JP': 'コンテンツの警告。このパラメータを指定すると設定したテキストで投稿のコンテンツを隠す事が出来ます。'
}
@@ -129,7 +129,6 @@ export const meta = {
fileIds: {
validator: $.optional.arr($.type(ID)).unique().range(1, 4),
- transform: transformMany,
desc: {
'ja-JP': '添付するファイル'
}
@@ -137,7 +136,6 @@ export const meta = {
mediaIds: {
validator: $.optional.arr($.type(ID)).unique().range(1, 4),
- transform: transformMany,
deprecated: true,
desc: {
'ja-JP': '添付するファイル (このパラメータは廃止予定です。代わりに fileIds を使ってください。)'
@@ -146,7 +144,6 @@ export const meta = {
replyId: {
validator: $.optional.type(ID),
- transform: transform,
desc: {
'ja-JP': '返信対象'
}
@@ -154,7 +151,6 @@ export const meta = {
renoteId: {
validator: $.optional.type(ID),
- transform: transform,
desc: {
'ja-JP': 'Renote対象'
}
@@ -227,32 +223,28 @@ export const meta = {
};
export default define(meta, async (ps, user, app) => {
- let visibleUsers: IUser[] = [];
+ let visibleUsers: User[] = [];
if (ps.visibleUserIds) {
- visibleUsers = await Promise.all(ps.visibleUserIds.map(id => User.findOne({
- _id: id
- })));
+ visibleUsers = await Promise.all(ps.visibleUserIds.map(id => Users.findOne(id)));
}
- let files: IDriveFile[] = [];
+ let files: DriveFile[] = [];
const fileIds = ps.fileIds != null ? ps.fileIds : ps.mediaIds != null ? ps.mediaIds : null;
if (fileIds != null) {
files = await Promise.all(fileIds.map(fileId => {
- return DriveFile.findOne({
- _id: fileId,
- 'metadata.userId': user._id
+ return DriveFiles.findOne({
+ id: fileId,
+ userId: user.id
});
}));
files = files.filter(file => file != null);
}
- let renote: INote = null;
+ let renote: Note = null;
if (ps.renoteId != null) {
// Fetch renote to note
- renote = await Note.findOne({
- _id: ps.renoteId
- });
+ renote = await Notes.findOne(ps.renoteId);
if (renote == null) {
throw new ApiError(meta.errors.noSuchRenoteTarget);
@@ -261,14 +253,12 @@ export default define(meta, async (ps, user, app) => {
}
}
- let reply: INote = null;
+ let reply: Note = null;
if (ps.replyId != null) {
// Fetch reply
- reply = await Note.findOne({
- _id: ps.replyId
- });
+ reply = await Notes.findOne(ps.replyId);
- if (reply === null) {
+ if (reply == null) {
throw new ApiError(meta.errors.noSuchReplyTarget);
}
@@ -279,12 +269,6 @@ export default define(meta, async (ps, user, app) => {
}
if (ps.poll) {
- (ps.poll as any).choices = (ps.poll as any).choices.map((choice: string, i: number) => ({
- id: i, // IDを付与
- text: choice.trim(),
- votes: 0
- }));
-
if (typeof ps.poll.expiresAt === 'number') {
if (ps.poll.expiresAt < Date.now())
throw new ApiError(meta.errors.cannotCreateAlreadyExpiredPoll);
@@ -298,11 +282,6 @@ export default define(meta, async (ps, user, app) => {
throw new ApiError(meta.errors.contentRequired);
}
- // 後方互換性のため
- if (ps.visibility == 'private') {
- ps.visibility = 'specified';
- }
-
// 投稿を作成
const note = await create(user, {
createdAt: new Date(),
@@ -311,7 +290,7 @@ export default define(meta, async (ps, user, app) => {
choices: ps.poll.choices,
multiple: ps.poll.multiple || false,
expiresAt: ps.poll.expiresAt ? new Date(ps.poll.expiresAt) : null
- } : undefined,
+ } : null,
text: ps.text,
reply,
renote,
@@ -321,13 +300,13 @@ export default define(meta, async (ps, user, app) => {
localOnly: ps.localOnly,
visibility: ps.visibility,
visibleUsers,
- apMentions: ps.noExtractMentions ? [] : undefined,
- apHashtags: ps.noExtractHashtags ? [] : undefined,
- apEmojis: ps.noExtractEmojis ? [] : undefined,
+ apMentions: ps.noExtractMentions ? [] : null,
+ apHashtags: ps.noExtractHashtags ? [] : null,
+ apEmojis: ps.noExtractEmojis ? [] : null,
geo: ps.geo
});
return {
- createdNote: await pack(note, user)
+ createdNote: await Notes.pack(note, user)
};
});