From 3d5cdb8d2d60932caf1d29b0581c7d6243e06e37 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 28 Mar 2018 16:39:14 +0900 Subject: [PATCH] wip --- src/api/authenticate.ts | 4 +- src/api/bot/core.ts | 2 +- src/api/bot/interfaces/line.ts | 10 +- src/api/common/add-file-to-drive.ts | 306 ++++++++++++++++++ src/api/common/drive/add-file.ts | 16 +- src/api/common/get-friends.ts | 8 +- src/api/common/notify.ts | 18 +- src/api/common/push-sw.ts | 4 +- src/api/common/read-messaging-message.ts | 12 +- src/api/common/read-notification.ts | 8 +- src/api/common/watch-post.ts | 14 +- src/api/endpoints/aggregation/posts.ts | 16 +- .../endpoints/aggregation/posts/reaction.ts | 16 +- .../endpoints/aggregation/posts/reactions.ts | 16 +- src/api/endpoints/aggregation/posts/reply.ts | 14 +- src/api/endpoints/aggregation/posts/repost.ts | 16 +- src/api/endpoints/aggregation/users.ts | 8 +- .../endpoints/aggregation/users/activity.ts | 24 +- .../endpoints/aggregation/users/followers.ts | 20 +- .../endpoints/aggregation/users/following.ts | 20 +- src/api/endpoints/aggregation/users/post.ts | 24 +- .../endpoints/aggregation/users/reaction.ts | 16 +- src/api/endpoints/app/create.ts | 16 +- src/api/endpoints/app/name_id/available.ts | 18 +- src/api/endpoints/app/show.ts | 24 +- src/api/endpoints/auth/accept.ts | 14 +- src/api/endpoints/auth/session/generate.ts | 4 +- src/api/endpoints/auth/session/show.ts | 6 +- src/api/endpoints/auth/session/userkey.ts | 12 +- src/api/endpoints/channels/create.ts | 12 +- src/api/endpoints/channels/posts.ts | 8 +- src/api/endpoints/channels/show.ts | 6 +- src/api/endpoints/channels/unwatch.ts | 16 +- src/api/endpoints/channels/watch.ts | 20 +- src/api/endpoints/drive.ts | 4 +- src/api/endpoints/drive/files.ts | 10 +- src/api/endpoints/drive/files/create.ts | 6 +- src/api/endpoints/drive/files/find.ts | 10 +- src/api/endpoints/drive/files/show.ts | 8 +- src/api/endpoints/drive/files/update.ts | 22 +- .../endpoints/drive/files/upload_from_url.ts | 6 +- src/api/endpoints/drive/folders.ts | 10 +- src/api/endpoints/drive/folders/create.ts | 14 +- src/api/endpoints/drive/folders/find.ts | 10 +- src/api/endpoints/drive/folders/show.ts | 8 +- src/api/endpoints/drive/folders/update.ts | 32 +- src/api/endpoints/drive/stream.ts | 2 +- src/api/endpoints/following/create.ts | 22 +- src/api/endpoints/following/delete.ts | 18 +- src/api/endpoints/i.ts | 2 +- src/api/endpoints/i/2fa/done.ts | 8 +- src/api/endpoints/i/2fa/register.ts | 2 +- src/api/endpoints/i/2fa/unregister.ts | 4 +- src/api/endpoints/i/appdata/get.ts | 4 +- src/api/endpoints/i/appdata/set.ts | 8 +- src/api/endpoints/i/authorized_apps.ts | 4 +- src/api/endpoints/i/favorites.ts | 2 +- src/api/endpoints/i/notifications.ts | 12 +- src/api/endpoints/i/pin.ts | 10 +- src/api/endpoints/i/signin_history.ts | 2 +- src/api/endpoints/i/update.ts | 30 +- src/api/endpoints/i/update_client_setting.ts | 4 +- src/api/endpoints/i/update_home.ts | 6 +- src/api/endpoints/i/update_mobile_home.ts | 6 +- src/api/endpoints/messaging/history.ts | 14 +- src/api/endpoints/messaging/messages.ts | 14 +- .../endpoints/messaging/messages/create.ts | 74 ++--- src/api/endpoints/messaging/unread.ts | 12 +- src/api/endpoints/mute/create.ts | 18 +- src/api/endpoints/mute/delete.ts | 14 +- src/api/endpoints/mute/list.ts | 8 +- src/api/endpoints/my/apps.ts | 2 +- .../notifications/get_unread_count.ts | 12 +- .../notifications/mark_as_read_all.ts | 6 +- src/api/endpoints/othello/games.ts | 8 +- src/api/endpoints/othello/games/show.ts | 6 +- src/api/endpoints/othello/invitations.ts | 2 +- src/api/endpoints/othello/match.ts | 40 +-- src/api/endpoints/othello/match/cancel.ts | 2 +- src/api/endpoints/posts.ts | 8 +- src/api/endpoints/posts/categorize.ts | 8 +- src/api/endpoints/posts/context.ts | 14 +- src/api/endpoints/posts/create.ts | 152 ++++----- src/api/endpoints/posts/favorites/create.ts | 16 +- src/api/endpoints/posts/favorites/delete.ts | 10 +- src/api/endpoints/posts/mentions.ts | 2 +- .../endpoints/posts/polls/recommendation.ts | 8 +- src/api/endpoints/posts/polls/vote.ts | 32 +- src/api/endpoints/posts/reactions.ts | 10 +- src/api/endpoints/posts/reactions/create.ts | 42 +-- src/api/endpoints/posts/reactions/delete.ts | 14 +- src/api/endpoints/posts/replies.ts | 8 +- src/api/endpoints/posts/reposts.ts | 8 +- src/api/endpoints/posts/search.ts | 74 ++--- src/api/endpoints/posts/show.ts | 6 +- src/api/endpoints/posts/timeline.ts | 30 +- src/api/endpoints/posts/trend.ts | 8 +- src/api/endpoints/stats.ts | 4 +- src/api/endpoints/sw/register.ts | 6 +- src/api/endpoints/username/available.ts | 2 +- src/api/endpoints/users.ts | 4 +- src/api/endpoints/users/followers.ts | 14 +- src/api/endpoints/users/following.ts | 14 +- .../users/get_frequently_replied_users.ts | 20 +- src/api/endpoints/users/posts.ts | 22 +- src/api/endpoints/users/recommendation.ts | 4 +- src/api/endpoints/users/search.ts | 2 +- src/api/endpoints/users/search_by_username.ts | 2 +- src/api/endpoints/users/show.ts | 56 ++-- src/api/models/channel-watching.ts | 2 +- src/api/models/channel.ts | 2 +- src/api/models/messaging-message.ts | 8 +- src/api/models/notification.ts | 22 +- src/api/models/othello-game.ts | 8 +- src/api/models/othello-matching.ts | 4 +- src/api/models/post-reaction.ts | 2 +- src/api/models/post.ts | 36 +-- src/api/models/user.ts | 117 +++---- src/api/private/signin.ts | 10 +- src/api/private/signup.ts | 22 +- src/api/service/github.ts | 2 +- src/api/service/twitter.ts | 10 +- src/api/stream/home.ts | 16 +- src/api/stream/othello-game.ts | 96 +++--- src/api/stream/othello.ts | 6 +- src/api/streaming.ts | 2 +- src/common/get-post-summary.ts | 4 +- src/common/othello/ai/back.ts | 28 +- src/common/othello/ai/front.ts | 16 +- src/common/user/get-summary.ts | 2 +- src/config.ts | 2 +- src/tools/analysis/extract-user-domains.ts | 2 +- src/tools/analysis/extract-user-keywords.ts | 2 +- src/tools/analysis/predict-user-interst.ts | 2 +- src/web/app/auth/views/form.vue | 2 +- src/web/app/ch/tags/channel.tag | 20 +- src/web/app/common/define-widget.ts | 4 +- src/web/app/common/mios.ts | 4 +- src/web/app/common/scripts/streaming/home.ts | 2 +- .../views/components/messaging-room.form.vue | 6 +- .../components/messaging-room.message.vue | 6 +- .../views/components/messaging-room.vue | 14 +- .../app/common/views/components/messaging.vue | 12 +- .../common/views/components/othello.game.vue | 54 ++-- .../views/components/othello.gameroom.vue | 2 +- .../common/views/components/othello.room.vue | 26 +- .../app/common/views/components/othello.vue | 10 +- src/web/app/common/views/components/poll.vue | 2 +- .../app/common/views/components/post-menu.vue | 4 +- .../views/components/reaction-picker.vue | 2 +- .../app/common/views/components/signin.vue | 4 +- .../views/components/twitter-setting.vue | 4 +- .../app/common/views/components/uploader.vue | 2 +- .../views/components/welcome-timeline.vue | 2 +- .../app/common/views/widgets/slideshow.vue | 2 +- src/web/app/desktop/api/update-avatar.ts | 6 +- src/web/app/desktop/api/update-banner.ts | 6 +- .../app/desktop/views/components/activity.vue | 2 +- .../desktop/views/components/drive.file.vue | 14 +- .../desktop/views/components/drive.folder.vue | 10 +- .../views/components/drive.nav-folder.vue | 8 +- .../app/desktop/views/components/drive.vue | 28 +- .../views/components/follow-button.vue | 4 +- .../desktop/views/components/followers.vue | 4 +- .../desktop/views/components/following.vue | 4 +- src/web/app/desktop/views/components/home.vue | 20 +- .../desktop/views/components/media-image.vue | 2 +- .../views/components/notifications.vue | 22 +- .../views/components/post-detail.sub.vue | 8 +- .../desktop/views/components/post-detail.vue | 16 +- .../desktop/views/components/post-form.vue | 8 +- .../desktop/views/components/post-preview.vue | 8 +- .../views/components/posts.post.sub.vue | 8 +- .../desktop/views/components/posts.post.vue | 20 +- .../app/desktop/views/components/posts.vue | 4 +- .../desktop/views/components/repost-form.vue | 2 +- .../desktop/views/components/settings.2fa.vue | 8 +- .../views/components/settings.profile.vue | 4 +- .../views/components/settings.signins.vue | 2 +- .../app/desktop/views/components/settings.vue | 10 +- .../views/components/sub-post-content.vue | 4 +- .../app/desktop/views/components/timeline.vue | 4 +- .../desktop/views/components/ui.header.vue | 4 +- .../desktop/views/components/user-preview.vue | 8 +- .../views/components/widget-container.vue | 4 +- .../app/desktop/views/components/window.vue | 4 +- src/web/app/desktop/views/pages/home.vue | 2 +- src/web/app/desktop/views/pages/post.vue | 2 +- .../pages/user/user.followers-you-know.vue | 2 +- .../desktop/views/pages/user/user.friends.vue | 2 +- .../desktop/views/pages/user/user.home.vue | 6 +- .../desktop/views/pages/user/user.photos.vue | 2 +- .../desktop/views/pages/user/user.profile.vue | 12 +- .../views/pages/user/user.timeline.vue | 4 +- .../views/widgets/channel.channel.form.vue | 4 +- .../desktop/views/widgets/channel.channel.vue | 2 +- src/web/app/desktop/views/widgets/channel.vue | 2 +- src/web/app/dev/views/app.vue | 2 +- src/web/app/dev/views/new-app.vue | 6 +- src/web/app/mobile/api/post.ts | 2 +- .../app/mobile/views/components/activity.vue | 2 +- .../views/components/drive.file-detail.vue | 14 +- .../mobile/views/components/drive.file.vue | 4 +- src/web/app/mobile/views/components/drive.vue | 28 +- .../mobile/views/components/follow-button.vue | 4 +- .../mobile/views/components/media-image.vue | 2 +- .../mobile/views/components/notification.vue | 8 +- .../mobile/views/components/notifications.vue | 4 +- .../app/mobile/views/components/post-card.vue | 2 +- .../views/components/post-detail.sub.vue | 2 +- .../mobile/views/components/post-detail.vue | 12 +- .../app/mobile/views/components/post-form.vue | 8 +- .../mobile/views/components/post-preview.vue | 2 +- .../app/mobile/views/components/post.sub.vue | 2 +- src/web/app/mobile/views/components/post.vue | 14 +- src/web/app/mobile/views/components/posts.vue | 4 +- .../views/components/sub-post-content.vue | 4 +- .../app/mobile/views/components/timeline.vue | 2 +- .../app/mobile/views/components/ui.header.vue | 4 +- .../mobile/views/components/user-timeline.vue | 4 +- src/web/app/mobile/views/pages/followers.vue | 4 +- src/web/app/mobile/views/pages/following.vue | 4 +- src/web/app/mobile/views/pages/home.vue | 22 +- src/web/app/mobile/views/pages/post.vue | 2 +- .../mobile/views/pages/profile-setting.vue | 4 +- src/web/app/mobile/views/pages/user.vue | 6 +- .../pages/user/home.followers-you-know.vue | 2 +- .../mobile/views/pages/user/home.friends.vue | 2 +- .../mobile/views/pages/user/home.photos.vue | 2 +- .../mobile/views/pages/user/home.posts.vue | 2 +- src/web/app/mobile/views/pages/user/home.vue | 4 +- src/web/app/mobile/views/pages/welcome.vue | 4 +- src/web/app/stats/tags/index.tag | 2 +- src/web/docs/api/endpoints/posts/create.yaml | 6 +- src/web/docs/api/entities/drive-file.yaml | 6 +- src/web/docs/api/entities/post.yaml | 12 +- src/web/docs/api/entities/user.yaml | 26 +- 237 files changed, 1661 insertions(+), 1354 deletions(-) create mode 100644 src/api/common/add-file-to-drive.ts diff --git a/src/api/authenticate.ts b/src/api/authenticate.ts index 537c3d1e1..7b3983a83 100644 --- a/src/api/authenticate.ts +++ b/src/api/authenticate.ts @@ -55,10 +55,10 @@ export default (req: express.Request) => new Promise(async (resolv } const app = await App - .findOne({ _id: accessToken.app_id }); + .findOne({ _id: accessToken.appId }); const user = await User - .findOne({ _id: accessToken.user_id }); + .findOne({ _id: accessToken.userId }); return resolve({ app: app, diff --git a/src/api/bot/core.ts b/src/api/bot/core.ts index d6706e9a1..9e699572d 100644 --- a/src/api/bot/core.ts +++ b/src/api/bot/core.ts @@ -208,7 +208,7 @@ class SigninContext extends Context { if (this.temporaryUser == null) { // Fetch user const user: IUser = await User.findOne({ - username_lower: query.toLowerCase(), + usernameLower: query.toLowerCase(), host: null }, { fields: { diff --git a/src/api/bot/interfaces/line.ts b/src/api/bot/interfaces/line.ts index 8036b2fde..dc600125c 100644 --- a/src/api/bot/interfaces/line.ts +++ b/src/api/bot/interfaces/line.ts @@ -115,7 +115,7 @@ class LineBot extends BotCore { actions.push({ type: 'uri', label: 'Twitterアカウントを見る', - uri: `https://twitter.com/${user.account.twitter.screen_name}` + uri: `https://twitter.com/${user.account.twitter.screenName}` }); } @@ -142,7 +142,7 @@ class LineBot extends BotCore { public async showUserTimelinePostback(userId: string) { const tl = await require('../../endpoints/users/posts')({ - user_id: userId, + userId: userId, limit: 5 }, this.user); @@ -174,7 +174,7 @@ module.exports = async (app: express.Application) => { const user = await User.findOne({ host: null, 'account.line': { - user_id: sourceId + userId: sourceId } }); @@ -184,7 +184,7 @@ module.exports = async (app: express.Application) => { User.update(user._id, { $set: { 'account.line': { - user_id: sourceId + userId: sourceId } } }); @@ -194,7 +194,7 @@ module.exports = async (app: express.Application) => { User.update(user._id, { $set: { 'account.line': { - user_id: null + userId: null } } }); diff --git a/src/api/common/add-file-to-drive.ts b/src/api/common/add-file-to-drive.ts new file mode 100644 index 000000000..6bf5fcbc0 --- /dev/null +++ b/src/api/common/add-file-to-drive.ts @@ -0,0 +1,306 @@ +import { Buffer } from 'buffer'; +import * as fs from 'fs'; +import * as tmp from 'tmp'; +import * as stream from 'stream'; + +import * as mongodb from 'mongodb'; +import * as crypto from 'crypto'; +import * as _gm from 'gm'; +import * as debug from 'debug'; +import fileType = require('file-type'); +import prominence = require('prominence'); + +import DriveFile, { getGridFSBucket } from '../models/drive-file'; +import DriveFolder from '../models/drive-folder'; +import { pack } from '../models/drive-file'; +import event, { publishDriveStream } from '../event'; +import config from '../../conf'; + +const gm = _gm.subClass({ + imageMagick: true +}); + +const log = debug('misskey:register-drive-file'); + +const tmpFile = (): Promise => new Promise((resolve, reject) => { + tmp.file((e, path) => { + if (e) return reject(e); + resolve(path); + }); +}); + +const addToGridFS = (name: string, readable: stream.Readable, type: string, metadata: any): Promise => + getGridFSBucket() + .then(bucket => new Promise((resolve, reject) => { + const writeStream = bucket.openUploadStream(name, { contentType: type, metadata }); + writeStream.once('finish', (doc) => { resolve(doc); }); + writeStream.on('error', reject); + readable.pipe(writeStream); + })); + +const addFile = async ( + user: any, + path: string, + name: string = null, + comment: string = null, + folderId: mongodb.ObjectID = null, + force: boolean = false +) => { + log(`registering ${name} (user: ${user.username}, path: ${path})`); + + // Calculate hash, get content type and get file size + const [hash, [mime, ext], size] = await Promise.all([ + // hash + ((): Promise => new Promise((res, rej) => { + const readable = fs.createReadStream(path); + const hash = crypto.createHash('md5'); + const chunks = []; + readable + .on('error', rej) + .pipe(hash) + .on('error', rej) + .on('data', (chunk) => chunks.push(chunk)) + .on('end', () => { + const buffer = Buffer.concat(chunks); + res(buffer.toString('hex')); + }); + }))(), + // mime + ((): Promise<[string, string | null]> => new Promise((res, rej) => { + const readable = fs.createReadStream(path); + readable + .on('error', rej) + .once('data', (buffer: Buffer) => { + readable.destroy(); + const type = fileType(buffer); + if (type) { + return res([type.mime, type.ext]); + } else { + // 種類が同定できなかったら application/octet-stream にする + return res(['application/octet-stream', null]); + } + }); + }))(), + // size + ((): Promise => new Promise((res, rej) => { + fs.stat(path, (err, stats) => { + if (err) return rej(err); + res(stats.size); + }); + }))() + ]); + + log(`hash: ${hash}, mime: ${mime}, ext: ${ext}, size: ${size}`); + + // detect name + const detectedName: string = name || (ext ? `untitled.${ext}` : 'untitled'); + + if (!force) { + // Check if there is a file with the same hash + const much = await DriveFile.findOne({ + md5: hash, + 'metadata.userId': user._id + }); + + if (much !== null) { + log('file with same hash is found'); + return much; + } else { + log('file with same hash is not found'); + } + } + + const [wh, avgColor, folder] = await Promise.all([ + // Width and height (when image) + (async () => { + // 画像かどうか + if (!/^image\/.*$/.test(mime)) { + return null; + } + + const imageType = mime.split('/')[1]; + + // 画像でもPNGかJPEGかGIFでないならスキップ + if (imageType != 'png' && imageType != 'jpeg' && imageType != 'gif') { + return null; + } + + log('calculate image width and height...'); + + // Calculate width and height + const g = gm(fs.createReadStream(path), name); + const size = await prominence(g).size(); + + log(`image width and height is calculated: ${size.width}, ${size.height}`); + + return [size.width, size.height]; + })(), + // average color (when image) + (async () => { + // 画像かどうか + if (!/^image\/.*$/.test(mime)) { + return null; + } + + const imageType = mime.split('/')[1]; + + // 画像でもPNGかJPEGでないならスキップ + if (imageType != 'png' && imageType != 'jpeg') { + return null; + } + + log('calculate average color...'); + + const buffer = await prominence(gm(fs.createReadStream(path), name) + .setFormat('ppm') + .resize(1, 1)) // 1pxのサイズに縮小して平均色を取得するというハック + .toBuffer(); + + const r = buffer.readUInt8(buffer.length - 3); + const g = buffer.readUInt8(buffer.length - 2); + const b = buffer.readUInt8(buffer.length - 1); + + log(`average color is calculated: ${r}, ${g}, ${b}`); + + return [r, g, b]; + })(), + // folder + (async () => { + if (!folderId) { + return null; + } + const driveFolder = await DriveFolder.findOne({ + _id: folderId, + userId: user._id + }); + if (!driveFolder) { + throw 'folder-not-found'; + } + return driveFolder; + })(), + // usage checker + (async () => { + // Calculate drive usage + const usage = await DriveFile + .aggregate([{ + $match: { 'metadata.userId': user._id } + }, { + $project: { + length: true + } + }, { + $group: { + _id: null, + usage: { $sum: '$length' } + } + }]) + .then((aggregates: any[]) => { + if (aggregates.length > 0) { + return aggregates[0].usage; + } + return 0; + }); + + log(`drive usage is ${usage}`); + + // If usage limit exceeded + if (usage + size > user.driveCapacity) { + throw 'no-free-space'; + } + })() + ]); + + const readable = fs.createReadStream(path); + + const properties = {}; + + if (wh) { + properties['width'] = wh[0]; + properties['height'] = wh[1]; + } + + if (avgColor) { + properties['avgColor'] = avgColor; + } + + return addToGridFS(detectedName, readable, mime, { + userId: user._id, + folderId: folder !== null ? folder._id : null, + comment: comment, + properties: properties + }); +}; + +/** + * Add file to drive + * + * @param user User who wish to add file + * @param file File path or readableStream + * @param comment Comment + * @param type File type + * @param folderId Folder ID + * @param force If set to true, forcibly upload the file even if there is a file with the same hash. + * @return Object that represents added file + */ +export default (user: any, file: string | stream.Readable, ...args) => new Promise((resolve, reject) => { + // Get file path + new Promise((res: (v: [string, boolean]) => void, rej) => { + if (typeof file === 'string') { + res([file, false]); + return; + } + if (typeof file === 'object' && typeof file.read === 'function') { + tmpFile() + .then(path => { + const readable: stream.Readable = file; + const writable = fs.createWriteStream(path); + readable + .on('error', rej) + .on('end', () => { + res([path, true]); + }) + .pipe(writable) + .on('error', rej); + }) + .catch(rej); + } + rej(new Error('un-compatible file.')); + }) + .then(([path, shouldCleanup]): Promise => new Promise((res, rej) => { + addFile(user, path, ...args) + .then(file => { + res(file); + if (shouldCleanup) { + fs.unlink(path, (e) => { + if (e) log(e.stack); + }); + } + }) + .catch(rej); + })) + .then(file => { + log(`drive file has been created ${file._id}`); + resolve(file); + + pack(file).then(serializedFile => { + // Publish drive_file_created event + event(user._id, 'drive_file_created', serializedFile); + publishDriveStream(user._id, 'file_created', serializedFile); + + // Register to search database + if (config.elasticsearch.enable) { + const es = require('../../db/elasticsearch'); + es.index({ + index: 'misskey', + type: 'drive_file', + id: file._id.toString(), + body: { + name: file.name, + userId: user._id.toString() + } + }); + } + }); + }) + .catch(reject); +}); diff --git a/src/api/common/drive/add-file.ts b/src/api/common/drive/add-file.ts index c4f2f212a..b10f9e381 100644 --- a/src/api/common/drive/add-file.ts +++ b/src/api/common/drive/add-file.ts @@ -100,7 +100,7 @@ const addFile = async ( // Check if there is a file with the same hash const much = await DriveFile.findOne({ md5: hash, - 'metadata.user_id': user._id + 'metadata.userId': user._id }); if (much !== null) { @@ -172,7 +172,7 @@ const addFile = async ( } const driveFolder = await DriveFolder.findOne({ _id: folderId, - user_id: user._id + userId: user._id }); if (!driveFolder) { throw 'folder-not-found'; @@ -184,7 +184,7 @@ const addFile = async ( // Calculate drive usage const usage = await DriveFile .aggregate([{ - $match: { 'metadata.user_id': user._id } + $match: { 'metadata.userId': user._id } }, { $project: { length: true @@ -205,7 +205,7 @@ const addFile = async ( log(`drive usage is ${usage}`); // If usage limit exceeded - if (usage + size > user.drive_capacity) { + if (usage + size > user.driveCapacity) { throw 'no-free-space'; } })() @@ -221,12 +221,12 @@ const addFile = async ( } if (averageColor) { - properties['average_color'] = averageColor; + properties['avgColor'] = averageColor; } return addToGridFS(detectedName, readable, mime, { - user_id: user._id, - folder_id: folder !== null ? folder._id : null, + userId: user._id, + folderId: folder !== null ? folder._id : null, comment: comment, properties: properties }); @@ -297,7 +297,7 @@ export default (user: any, file: string | stream.Readable, ...args) => new Promi id: file._id.toString(), body: { name: file.name, - user_id: user._id.toString() + userId: user._id.toString() } }); } diff --git a/src/api/common/get-friends.ts b/src/api/common/get-friends.ts index db6313816..7f548b3bb 100644 --- a/src/api/common/get-friends.ts +++ b/src/api/common/get-friends.ts @@ -6,17 +6,17 @@ export default async (me: mongodb.ObjectID, includeMe: boolean = true) => { // SELECT followee const myfollowing = await Following .find({ - follower_id: me, + followerId: me, // 削除されたドキュメントは除く - deleted_at: { $exists: false } + deletedAt: { $exists: false } }, { fields: { - followee_id: true + followeeId: true } }); // ID list of other users who the I follows - const myfollowingIds = myfollowing.map(follow => follow.followee_id); + const myfollowingIds = myfollowing.map(follow => follow.followeeId); if (includeMe) { myfollowingIds.push(me); diff --git a/src/api/common/notify.ts b/src/api/common/notify.ts index ae5669b84..c4df17f88 100644 --- a/src/api/common/notify.ts +++ b/src/api/common/notify.ts @@ -16,11 +16,11 @@ export default ( // Create notification const notification = await Notification.insert(Object.assign({ - created_at: new Date(), - notifiee_id: notifiee, - notifier_id: notifier, + createdAt: new Date(), + notifieeId: notifiee, + notifierId: notifier, type: type, - is_read: false + isRead: false }, content)); resolve(notification); @@ -31,14 +31,14 @@ export default ( // 3秒経っても(今回作成した)通知が既読にならなかったら「未読の通知がありますよ」イベントを発行する setTimeout(async () => { - const fresh = await Notification.findOne({ _id: notification._id }, { is_read: true }); - if (!fresh.is_read) { + const fresh = await Notification.findOne({ _id: notification._id }, { isRead: true }); + if (!fresh.isRead) { //#region ただしミュートしているユーザーからの通知なら無視 const mute = await Mute.find({ - muter_id: notifiee, - deleted_at: { $exists: false } + muterId: notifiee, + deletedAt: { $exists: false } }); - const mutedUserIds = mute.map(m => m.mutee_id.toString()); + const mutedUserIds = mute.map(m => m.muteeId.toString()); if (mutedUserIds.indexOf(notifier.toString()) != -1) { return; } diff --git a/src/api/common/push-sw.ts b/src/api/common/push-sw.ts index 2993c760e..f90233233 100644 --- a/src/api/common/push-sw.ts +++ b/src/api/common/push-sw.ts @@ -20,7 +20,7 @@ export default async function(userId: mongo.ObjectID | string, type, body?) { // Fetch const subscriptions = await Subscription.find({ - user_id: userId + userId: userId }); subscriptions.forEach(subscription => { @@ -41,7 +41,7 @@ export default async function(userId: mongo.ObjectID | string, type, body?) { if (err.statusCode == 410) { Subscription.remove({ - user_id: userId, + userId: userId, endpoint: subscription.endpoint, auth: subscription.auth, publickey: subscription.publickey diff --git a/src/api/common/read-messaging-message.ts b/src/api/common/read-messaging-message.ts index 8e5e5b2b6..9047edec8 100644 --- a/src/api/common/read-messaging-message.ts +++ b/src/api/common/read-messaging-message.ts @@ -37,12 +37,12 @@ export default ( // Update documents await Message.update({ _id: { $in: ids }, - user_id: otherpartyId, - recipient_id: userId, - is_read: false + userId: otherpartyId, + recipientId: userId, + isRead: false }, { $set: { - is_read: true + isRead: true } }, { multi: true @@ -55,8 +55,8 @@ export default ( // Calc count of my unread messages const count = await Message .count({ - recipient_id: userId, - is_read: false + recipientId: userId, + isRead: false }); if (count == 0) { diff --git a/src/api/common/read-notification.ts b/src/api/common/read-notification.ts index 3009cc5d0..5bbf13632 100644 --- a/src/api/common/read-notification.ts +++ b/src/api/common/read-notification.ts @@ -29,10 +29,10 @@ export default ( // Update documents await Notification.update({ _id: { $in: ids }, - is_read: false + isRead: false }, { $set: { - is_read: true + isRead: true } }, { multi: true @@ -41,8 +41,8 @@ export default ( // Calc count of my unread notifications const count = await Notification .count({ - notifiee_id: userId, - is_read: false + notifieeId: userId, + isRead: false }); if (count == 0) { diff --git a/src/api/common/watch-post.ts b/src/api/common/watch-post.ts index 1a50f0eda..61ea44443 100644 --- a/src/api/common/watch-post.ts +++ b/src/api/common/watch-post.ts @@ -3,15 +3,15 @@ import Watching from '../models/post-watching'; export default async (me: mongodb.ObjectID, post: object) => { // 自分の投稿はwatchできない - if (me.equals((post as any).user_id)) { + if (me.equals((post as any).userId)) { return; } // if watching now const exist = await Watching.findOne({ - post_id: (post as any)._id, - user_id: me, - deleted_at: { $exists: false } + postId: (post as any)._id, + userId: me, + deletedAt: { $exists: false } }); if (exist !== null) { @@ -19,8 +19,8 @@ export default async (me: mongodb.ObjectID, post: object) => { } await Watching.insert({ - created_at: new Date(), - post_id: (post as any)._id, - user_id: me + createdAt: new Date(), + postId: (post as any)._id, + userId: me }); }; diff --git a/src/api/endpoints/aggregation/posts.ts b/src/api/endpoints/aggregation/posts.ts index 9d8bccbdb..67d261964 100644 --- a/src/api/endpoints/aggregation/posts.ts +++ b/src/api/endpoints/aggregation/posts.ts @@ -18,23 +18,23 @@ module.exports = params => new Promise(async (res, rej) => { const datas = await Post .aggregate([ { $project: { - repost_id: '$repost_id', - reply_id: '$reply_id', - created_at: { $add: ['$created_at', 9 * 60 * 60 * 1000] } // Convert into JST + repostId: '$repostId', + replyId: '$replyId', + createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST }}, { $project: { date: { - year: { $year: '$created_at' }, - month: { $month: '$created_at' }, - day: { $dayOfMonth: '$created_at' } + year: { $year: '$createdAt' }, + month: { $month: '$createdAt' }, + day: { $dayOfMonth: '$createdAt' } }, type: { $cond: { - if: { $ne: ['$repost_id', null] }, + if: { $ne: ['$repostId', null] }, then: 'repost', else: { $cond: { - if: { $ne: ['$reply_id', null] }, + if: { $ne: ['$replyId', null] }, then: 'reply', else: 'post' } diff --git a/src/api/endpoints/aggregation/posts/reaction.ts b/src/api/endpoints/aggregation/posts/reaction.ts index eb99b9d08..9f9a4f37e 100644 --- a/src/api/endpoints/aggregation/posts/reaction.ts +++ b/src/api/endpoints/aggregation/posts/reaction.ts @@ -12,9 +12,9 @@ import Reaction from '../../../models/post-reaction'; * @return {Promise} */ module.exports = (params) => new Promise(async (res, rej) => { - // Get 'post_id' parameter - const [postId, postIdErr] = $(params.post_id).id().$; - if (postIdErr) return rej('invalid post_id param'); + // Get 'postId' parameter + const [postId, postIdErr] = $(params.postId).id().$; + if (postIdErr) return rej('invalid postId param'); // Lookup post const post = await Post.findOne({ @@ -27,15 +27,15 @@ module.exports = (params) => new Promise(async (res, rej) => { const datas = await Reaction .aggregate([ - { $match: { post_id: post._id } }, + { $match: { postId: post._id } }, { $project: { - created_at: { $add: ['$created_at', 9 * 60 * 60 * 1000] } // Convert into JST + createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST }}, { $project: { date: { - year: { $year: '$created_at' }, - month: { $month: '$created_at' }, - day: { $dayOfMonth: '$created_at' } + year: { $year: '$createdAt' }, + month: { $month: '$createdAt' }, + day: { $dayOfMonth: '$createdAt' } } }}, { $group: { diff --git a/src/api/endpoints/aggregation/posts/reactions.ts b/src/api/endpoints/aggregation/posts/reactions.ts index 790b523be..2dc989281 100644 --- a/src/api/endpoints/aggregation/posts/reactions.ts +++ b/src/api/endpoints/aggregation/posts/reactions.ts @@ -12,9 +12,9 @@ import Reaction from '../../../models/post-reaction'; * @return {Promise} */ module.exports = (params) => new Promise(async (res, rej) => { - // Get 'post_id' parameter - const [postId, postIdErr] = $(params.post_id).id().$; - if (postIdErr) return rej('invalid post_id param'); + // Get 'postId' parameter + const [postId, postIdErr] = $(params.postId).id().$; + if (postIdErr) return rej('invalid postId param'); // Lookup post const post = await Post.findOne({ @@ -29,10 +29,10 @@ module.exports = (params) => new Promise(async (res, rej) => { const reactions = await Reaction .find({ - post_id: post._id, + postId: post._id, $or: [ - { deleted_at: { $exists: false } }, - { deleted_at: { $gt: startTime } } + { deletedAt: { $exists: false } }, + { deletedAt: { $gt: startTime } } ] }, { sort: { @@ -40,7 +40,7 @@ module.exports = (params) => new Promise(async (res, rej) => { }, fields: { _id: false, - post_id: false + postId: false } }); @@ -55,7 +55,7 @@ module.exports = (params) => new Promise(async (res, rej) => { // day = day.getTime(); const count = reactions.filter(r => - r.created_at < day && (r.deleted_at == null || r.deleted_at > day) + r.createdAt < day && (r.deletedAt == null || r.deletedAt > day) ).length; graph.push({ diff --git a/src/api/endpoints/aggregation/posts/reply.ts b/src/api/endpoints/aggregation/posts/reply.ts index b114c34e1..3b050582a 100644 --- a/src/api/endpoints/aggregation/posts/reply.ts +++ b/src/api/endpoints/aggregation/posts/reply.ts @@ -11,9 +11,9 @@ import Post from '../../../models/post'; * @return {Promise} */ module.exports = (params) => new Promise(async (res, rej) => { - // Get 'post_id' parameter - const [postId, postIdErr] = $(params.post_id).id().$; - if (postIdErr) return rej('invalid post_id param'); + // Get 'postId' parameter + const [postId, postIdErr] = $(params.postId).id().$; + if (postIdErr) return rej('invalid postId param'); // Lookup post const post = await Post.findOne({ @@ -28,13 +28,13 @@ module.exports = (params) => new Promise(async (res, rej) => { .aggregate([ { $match: { reply: post._id } }, { $project: { - created_at: { $add: ['$created_at', 9 * 60 * 60 * 1000] } // Convert into JST + createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST }}, { $project: { date: { - year: { $year: '$created_at' }, - month: { $month: '$created_at' }, - day: { $dayOfMonth: '$created_at' } + year: { $year: '$createdAt' }, + month: { $month: '$createdAt' }, + day: { $dayOfMonth: '$createdAt' } } }}, { $group: { diff --git a/src/api/endpoints/aggregation/posts/repost.ts b/src/api/endpoints/aggregation/posts/repost.ts index 217159caa..d9f3e36a0 100644 --- a/src/api/endpoints/aggregation/posts/repost.ts +++ b/src/api/endpoints/aggregation/posts/repost.ts @@ -11,9 +11,9 @@ import Post from '../../../models/post'; * @return {Promise} */ module.exports = (params) => new Promise(async (res, rej) => { - // Get 'post_id' parameter - const [postId, postIdErr] = $(params.post_id).id().$; - if (postIdErr) return rej('invalid post_id param'); + // Get 'postId' parameter + const [postId, postIdErr] = $(params.postId).id().$; + if (postIdErr) return rej('invalid postId param'); // Lookup post const post = await Post.findOne({ @@ -26,15 +26,15 @@ module.exports = (params) => new Promise(async (res, rej) => { const datas = await Post .aggregate([ - { $match: { repost_id: post._id } }, + { $match: { repostId: post._id } }, { $project: { - created_at: { $add: ['$created_at', 9 * 60 * 60 * 1000] } // Convert into JST + createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST }}, { $project: { date: { - year: { $year: '$created_at' }, - month: { $month: '$created_at' }, - day: { $dayOfMonth: '$created_at' } + year: { $year: '$createdAt' }, + month: { $month: '$createdAt' }, + day: { $dayOfMonth: '$createdAt' } } }}, { $group: { diff --git a/src/api/endpoints/aggregation/users.ts b/src/api/endpoints/aggregation/users.ts index e38ce92ff..a4e91a228 100644 --- a/src/api/endpoints/aggregation/users.ts +++ b/src/api/endpoints/aggregation/users.ts @@ -22,8 +22,8 @@ module.exports = params => new Promise(async (res, rej) => { }, fields: { _id: false, - created_at: true, - deleted_at: true + createdAt: true, + deletedAt: true } }); @@ -44,11 +44,11 @@ module.exports = params => new Promise(async (res, rej) => { // day = day.getTime(); const total = users.filter(u => - u.created_at < dayEnd && (u.deleted_at == null || u.deleted_at > dayEnd) + u.createdAt < dayEnd && (u.deletedAt == null || u.deletedAt > dayEnd) ).length; const created = users.filter(u => - u.created_at < dayEnd && u.created_at > dayStart + u.createdAt < dayEnd && u.createdAt > dayStart ).length; graph.push({ diff --git a/src/api/endpoints/aggregation/users/activity.ts b/src/api/endpoints/aggregation/users/activity.ts index 102a71d7c..d47761657 100644 --- a/src/api/endpoints/aggregation/users/activity.ts +++ b/src/api/endpoints/aggregation/users/activity.ts @@ -18,9 +18,9 @@ module.exports = (params) => new Promise(async (res, rej) => { const [limit = 365, limitErr] = $(params.limit).optional.number().range(1, 365).$; if (limitErr) return rej('invalid limit param'); - // Get 'user_id' parameter - const [userId, userIdErr] = $(params.user_id).id().$; - if (userIdErr) return rej('invalid user_id param'); + // Get 'userId' parameter + const [userId, userIdErr] = $(params.userId).id().$; + if (userIdErr) return rej('invalid userId param'); // Lookup user const user = await User.findOne({ @@ -37,25 +37,25 @@ module.exports = (params) => new Promise(async (res, rej) => { const datas = await Post .aggregate([ - { $match: { user_id: user._id } }, + { $match: { userId: user._id } }, { $project: { - repost_id: '$repost_id', - reply_id: '$reply_id', - created_at: { $add: ['$created_at', 9 * 60 * 60 * 1000] } // Convert into JST + repostId: '$repostId', + replyId: '$replyId', + createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST }}, { $project: { date: { - year: { $year: '$created_at' }, - month: { $month: '$created_at' }, - day: { $dayOfMonth: '$created_at' } + year: { $year: '$createdAt' }, + month: { $month: '$createdAt' }, + day: { $dayOfMonth: '$createdAt' } }, type: { $cond: { - if: { $ne: ['$repost_id', null] }, + if: { $ne: ['$repostId', null] }, then: 'repost', else: { $cond: { - if: { $ne: ['$reply_id', null] }, + if: { $ne: ['$replyId', null] }, then: 'reply', else: 'post' } diff --git a/src/api/endpoints/aggregation/users/followers.ts b/src/api/endpoints/aggregation/users/followers.ts index 3022b2b00..73a30281b 100644 --- a/src/api/endpoints/aggregation/users/followers.ts +++ b/src/api/endpoints/aggregation/users/followers.ts @@ -12,9 +12,9 @@ import Following from '../../../models/following'; * @return {Promise} */ module.exports = (params) => new Promise(async (res, rej) => { - // Get 'user_id' parameter - const [userId, userIdErr] = $(params.user_id).id().$; - if (userIdErr) return rej('invalid user_id param'); + // Get 'userId' parameter + const [userId, userIdErr] = $(params.userId).id().$; + if (userIdErr) return rej('invalid userId param'); // Lookup user const user = await User.findOne({ @@ -33,17 +33,17 @@ module.exports = (params) => new Promise(async (res, rej) => { const following = await Following .find({ - followee_id: user._id, + followeeId: user._id, $or: [ - { deleted_at: { $exists: false } }, - { deleted_at: { $gt: startTime } } + { deletedAt: { $exists: false } }, + { deletedAt: { $gt: startTime } } ] }, { _id: false, - follower_id: false, - followee_id: false + followerId: false, + followeeId: false }, { - sort: { created_at: -1 } + sort: { createdAt: -1 } }); const graph = []; @@ -57,7 +57,7 @@ module.exports = (params) => new Promise(async (res, rej) => { // day = day.getTime(); const count = following.filter(f => - f.created_at < day && (f.deleted_at == null || f.deleted_at > day) + f.createdAt < day && (f.deletedAt == null || f.deletedAt > day) ).length; graph.push({ diff --git a/src/api/endpoints/aggregation/users/following.ts b/src/api/endpoints/aggregation/users/following.ts index 92da7e692..16fc568d5 100644 --- a/src/api/endpoints/aggregation/users/following.ts +++ b/src/api/endpoints/aggregation/users/following.ts @@ -12,9 +12,9 @@ import Following from '../../../models/following'; * @return {Promise} */ module.exports = (params) => new Promise(async (res, rej) => { - // Get 'user_id' parameter - const [userId, userIdErr] = $(params.user_id).id().$; - if (userIdErr) return rej('invalid user_id param'); + // Get 'userId' parameter + const [userId, userIdErr] = $(params.userId).id().$; + if (userIdErr) return rej('invalid userId param'); // Lookup user const user = await User.findOne({ @@ -33,17 +33,17 @@ module.exports = (params) => new Promise(async (res, rej) => { const following = await Following .find({ - follower_id: user._id, + followerId: user._id, $or: [ - { deleted_at: { $exists: false } }, - { deleted_at: { $gt: startTime } } + { deletedAt: { $exists: false } }, + { deletedAt: { $gt: startTime } } ] }, { _id: false, - follower_id: false, - followee_id: false + followerId: false, + followeeId: false }, { - sort: { created_at: -1 } + sort: { createdAt: -1 } }); const graph = []; @@ -56,7 +56,7 @@ module.exports = (params) => new Promise(async (res, rej) => { day = new Date(day.setHours(23)); const count = following.filter(f => - f.created_at < day && (f.deleted_at == null || f.deleted_at > day) + f.createdAt < day && (f.deletedAt == null || f.deletedAt > day) ).length; graph.push({ diff --git a/src/api/endpoints/aggregation/users/post.ts b/src/api/endpoints/aggregation/users/post.ts index c6a75eee3..c98874859 100644 --- a/src/api/endpoints/aggregation/users/post.ts +++ b/src/api/endpoints/aggregation/users/post.ts @@ -12,9 +12,9 @@ import Post from '../../../models/post'; * @return {Promise} */ module.exports = (params) => new Promise(async (res, rej) => { - // Get 'user_id' parameter - const [userId, userIdErr] = $(params.user_id).id().$; - if (userIdErr) return rej('invalid user_id param'); + // Get 'userId' parameter + const [userId, userIdErr] = $(params.userId).id().$; + if (userIdErr) return rej('invalid userId param'); // Lookup user const user = await User.findOne({ @@ -31,25 +31,25 @@ module.exports = (params) => new Promise(async (res, rej) => { const datas = await Post .aggregate([ - { $match: { user_id: user._id } }, + { $match: { userId: user._id } }, { $project: { - repost_id: '$repost_id', - reply_id: '$reply_id', - created_at: { $add: ['$created_at', 9 * 60 * 60 * 1000] } // Convert into JST + repostId: '$repostId', + replyId: '$replyId', + createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST }}, { $project: { date: { - year: { $year: '$created_at' }, - month: { $month: '$created_at' }, - day: { $dayOfMonth: '$created_at' } + year: { $year: '$createdAt' }, + month: { $month: '$createdAt' }, + day: { $dayOfMonth: '$createdAt' } }, type: { $cond: { - if: { $ne: ['$repost_id', null] }, + if: { $ne: ['$repostId', null] }, then: 'repost', else: { $cond: { - if: { $ne: ['$reply_id', null] }, + if: { $ne: ['$replyId', null] }, then: 'reply', else: 'post' } diff --git a/src/api/endpoints/aggregation/users/reaction.ts b/src/api/endpoints/aggregation/users/reaction.ts index 0a082ed1b..60b33e9d1 100644 --- a/src/api/endpoints/aggregation/users/reaction.ts +++ b/src/api/endpoints/aggregation/users/reaction.ts @@ -12,9 +12,9 @@ import Reaction from '../../../models/post-reaction'; * @return {Promise} */ module.exports = (params) => new Promise(async (res, rej) => { - // Get 'user_id' parameter - const [userId, userIdErr] = $(params.user_id).id().$; - if (userIdErr) return rej('invalid user_id param'); + // Get 'userId' parameter + const [userId, userIdErr] = $(params.userId).id().$; + if (userIdErr) return rej('invalid userId param'); // Lookup user const user = await User.findOne({ @@ -31,15 +31,15 @@ module.exports = (params) => new Promise(async (res, rej) => { const datas = await Reaction .aggregate([ - { $match: { user_id: user._id } }, + { $match: { userId: user._id } }, { $project: { - created_at: { $add: ['$created_at', 9 * 60 * 60 * 1000] } // Convert into JST + createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST }}, { $project: { date: { - year: { $year: '$created_at' }, - month: { $month: '$created_at' }, - day: { $dayOfMonth: '$created_at' } + year: { $year: '$createdAt' }, + month: { $month: '$createdAt' }, + day: { $dayOfMonth: '$createdAt' } } }}, { $group: { diff --git a/src/api/endpoints/app/create.ts b/src/api/endpoints/app/create.ts index 0f688792a..cde4846e0 100644 --- a/src/api/endpoints/app/create.ts +++ b/src/api/endpoints/app/create.ts @@ -13,7 +13,7 @@ import App, { isValidNameId, pack } from '../../models/app'; * parameters: * - $ref: "#/parameters/AccessToken" * - - * name: name_id + * name: nameId * description: Application unique name * in: formData * required: true @@ -66,9 +66,9 @@ import App, { isValidNameId, pack } from '../../models/app'; * @return {Promise} */ module.exports = async (params, user) => new Promise(async (res, rej) => { - // Get 'name_id' parameter - const [nameId, nameIdErr] = $(params.name_id).string().pipe(isValidNameId).$; - if (nameIdErr) return rej('invalid name_id param'); + // Get 'nameId' parameter + const [nameId, nameIdErr] = $(params.nameId).string().pipe(isValidNameId).$; + if (nameIdErr) return rej('invalid nameId param'); // Get 'name' parameter const [name, nameErr] = $(params.name).string().$; @@ -92,11 +92,11 @@ module.exports = async (params, user) => new Promise(async (res, rej) => { // Create account const app = await App.insert({ - created_at: new Date(), - user_id: user._id, + createdAt: new Date(), + userId: user._id, name: name, - name_id: nameId, - name_id_lower: nameId.toLowerCase(), + nameId: nameId, + nameIdLower: nameId.toLowerCase(), description: description, permission: permission, callback_url: callbackUrl, diff --git a/src/api/endpoints/app/name_id/available.ts b/src/api/endpoints/app/name_id/available.ts index 3d2c71032..6d02b26d2 100644 --- a/src/api/endpoints/app/name_id/available.ts +++ b/src/api/endpoints/app/name_id/available.ts @@ -7,12 +7,12 @@ import { isValidNameId } from '../../../models/app'; /** * @swagger - * /app/name_id/available: + * /app/nameId/available: * post: - * summary: Check available name_id on creation an application + * summary: Check available nameId on creation an application * parameters: * - - * name: name_id + * name: nameId * description: Application unique name * in: formData * required: true @@ -25,7 +25,7 @@ import { isValidNameId } from '../../../models/app'; * type: object * properties: * available: - * description: Whether name_id is available + * description: Whether nameId is available * type: boolean * * default: @@ -35,20 +35,20 @@ import { isValidNameId } from '../../../models/app'; */ /** - * Check available name_id of app + * Check available nameId of app * * @param {any} params * @return {Promise} */ module.exports = async (params) => new Promise(async (res, rej) => { - // Get 'name_id' parameter - const [nameId, nameIdErr] = $(params.name_id).string().pipe(isValidNameId).$; - if (nameIdErr) return rej('invalid name_id param'); + // Get 'nameId' parameter + const [nameId, nameIdErr] = $(params.nameId).string().pipe(isValidNameId).$; + if (nameIdErr) return rej('invalid nameId param'); // Get exist const exist = await App .count({ - name_id_lower: nameId.toLowerCase() + nameIdLower: nameId.toLowerCase() }, { limit: 1 }); diff --git a/src/api/endpoints/app/show.ts b/src/api/endpoints/app/show.ts index 8bc3dda42..34bb958ee 100644 --- a/src/api/endpoints/app/show.ts +++ b/src/api/endpoints/app/show.ts @@ -9,15 +9,15 @@ import App, { pack } from '../../models/app'; * /app/show: * post: * summary: Show an application's information - * description: Require app_id or name_id + * description: Require appId or nameId * parameters: * - - * name: app_id + * name: appId * description: Application ID * in: formData * type: string * - - * name: name_id + * name: nameId * description: Application unique name * in: formData * type: string @@ -44,22 +44,22 @@ import App, { pack } from '../../models/app'; * @return {Promise} */ module.exports = (params, user, _, isSecure) => new Promise(async (res, rej) => { - // Get 'app_id' parameter - const [appId, appIdErr] = $(params.app_id).optional.id().$; - if (appIdErr) return rej('invalid app_id param'); + // Get 'appId' parameter + const [appId, appIdErr] = $(params.appId).optional.id().$; + if (appIdErr) return rej('invalid appId param'); - // Get 'name_id' parameter - const [nameId, nameIdErr] = $(params.name_id).optional.string().$; - if (nameIdErr) return rej('invalid name_id param'); + // Get 'nameId' parameter + const [nameId, nameIdErr] = $(params.nameId).optional.string().$; + if (nameIdErr) return rej('invalid nameId param'); if (appId === undefined && nameId === undefined) { - return rej('app_id or name_id is required'); + return rej('appId or nameId is required'); } // Lookup app const app = appId !== undefined ? await App.findOne({ _id: appId }) - : await App.findOne({ name_id_lower: nameId.toLowerCase() }); + : await App.findOne({ nameIdLower: nameId.toLowerCase() }); if (app === null) { return rej('app not found'); @@ -67,6 +67,6 @@ module.exports = (params, user, _, isSecure) => new Promise(async (res, rej) => // Send response res(await pack(app, user, { - includeSecret: isSecure && app.user_id.equals(user._id) + includeSecret: isSecure && app.userId.equals(user._id) })); }); diff --git a/src/api/endpoints/auth/accept.ts b/src/api/endpoints/auth/accept.ts index 4ee20a6d2..5a1925144 100644 --- a/src/api/endpoints/auth/accept.ts +++ b/src/api/endpoints/auth/accept.ts @@ -56,14 +56,14 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Fetch exist access token const exist = await AccessToken.findOne({ - app_id: session.app_id, - user_id: user._id, + appId: session.appId, + userId: user._id, }); if (exist === null) { // Lookup app const app = await App.findOne({ - _id: session.app_id + _id: session.appId }); // Generate Hash @@ -73,9 +73,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Insert access token doc await AccessToken.insert({ - created_at: new Date(), - app_id: session.app_id, - user_id: user._id, + createdAt: new Date(), + appId: session.appId, + userId: user._id, token: accessToken, hash: hash }); @@ -84,7 +84,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Update session await AuthSess.update(session._id, { $set: { - user_id: user._id + userId: user._id } }); diff --git a/src/api/endpoints/auth/session/generate.ts b/src/api/endpoints/auth/session/generate.ts index 510382247..81db188ee 100644 --- a/src/api/endpoints/auth/session/generate.ts +++ b/src/api/endpoints/auth/session/generate.ts @@ -63,8 +63,8 @@ module.exports = (params) => new Promise(async (res, rej) => { // Create session token document const doc = await AuthSess.insert({ - created_at: new Date(), - app_id: app._id, + createdAt: new Date(), + appId: app._id, token: token }); diff --git a/src/api/endpoints/auth/session/show.ts b/src/api/endpoints/auth/session/show.ts index 73ac3185f..869b714e7 100644 --- a/src/api/endpoints/auth/session/show.ts +++ b/src/api/endpoints/auth/session/show.ts @@ -23,17 +23,17 @@ import AuthSess, { pack } from '../../../models/auth-session'; * schema: * type: object * properties: - * created_at: + * createdAt: * type: string * format: date-time * description: Date and time of the session creation - * app_id: + * appId: * type: string * description: Application ID * token: * type: string * description: Session Token - * user_id: + * userId: * type: string * description: ID of user who create the session * app: diff --git a/src/api/endpoints/auth/session/userkey.ts b/src/api/endpoints/auth/session/userkey.ts index fc989bf8c..74f025c8a 100644 --- a/src/api/endpoints/auth/session/userkey.ts +++ b/src/api/endpoints/auth/session/userkey.ts @@ -71,21 +71,21 @@ module.exports = (params) => new Promise(async (res, rej) => { const session = await AuthSess .findOne({ token: token, - app_id: app._id + appId: app._id }); if (session === null) { return rej('session not found'); } - if (session.user_id == null) { + if (session.userId == null) { return rej('this session is not allowed yet'); } // Lookup access token const accessToken = await AccessToken.findOne({ - app_id: app._id, - user_id: session.user_id + appId: app._id, + userId: session.userId }); // Delete session @@ -101,8 +101,8 @@ module.exports = (params) => new Promise(async (res, rej) => { // Response res({ - access_token: accessToken.token, - user: await pack(session.user_id, null, { + accessToken: accessToken.token, + user: await pack(session.userId, null, { detail: true }) }); diff --git a/src/api/endpoints/channels/create.ts b/src/api/endpoints/channels/create.ts index 695b4515b..1dc453c4a 100644 --- a/src/api/endpoints/channels/create.ts +++ b/src/api/endpoints/channels/create.ts @@ -20,11 +20,11 @@ module.exports = async (params, user) => new Promise(async (res, rej) => { // Create a channel const channel = await Channel.insert({ - created_at: new Date(), - user_id: user._id, + createdAt: new Date(), + userId: user._id, title: title, index: 0, - watching_count: 1 + watchingCount: 1 }); // Response @@ -32,8 +32,8 @@ module.exports = async (params, user) => new Promise(async (res, rej) => { // Create Watching await Watching.insert({ - created_at: new Date(), - user_id: user._id, - channel_id: channel._id + createdAt: new Date(), + userId: user._id, + channelId: channel._id }); }); diff --git a/src/api/endpoints/channels/posts.ts b/src/api/endpoints/channels/posts.ts index d722589c2..753666405 100644 --- a/src/api/endpoints/channels/posts.ts +++ b/src/api/endpoints/channels/posts.ts @@ -30,9 +30,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => { return rej('cannot set since_id and until_id'); } - // Get 'channel_id' parameter - const [channelId, channelIdErr] = $(params.channel_id).id().$; - if (channelIdErr) return rej('invalid channel_id param'); + // Get 'channelId' parameter + const [channelId, channelIdErr] = $(params.channelId).id().$; + if (channelIdErr) return rej('invalid channelId param'); // Fetch channel const channel: IChannel = await Channel.findOne({ @@ -49,7 +49,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { }; const query = { - channel_id: channel._id + channelId: channel._id } as any; if (sinceId) { diff --git a/src/api/endpoints/channels/show.ts b/src/api/endpoints/channels/show.ts index 332da6467..5874ed18a 100644 --- a/src/api/endpoints/channels/show.ts +++ b/src/api/endpoints/channels/show.ts @@ -12,9 +12,9 @@ import Channel, { IChannel, pack } from '../../models/channel'; * @return {Promise} */ module.exports = (params, user) => new Promise(async (res, rej) => { - // Get 'channel_id' parameter - const [channelId, channelIdErr] = $(params.channel_id).id().$; - if (channelIdErr) return rej('invalid channel_id param'); + // Get 'channelId' parameter + const [channelId, channelIdErr] = $(params.channelId).id().$; + if (channelIdErr) return rej('invalid channelId param'); // Fetch channel const channel: IChannel = await Channel.findOne({ diff --git a/src/api/endpoints/channels/unwatch.ts b/src/api/endpoints/channels/unwatch.ts index 19d3be118..709313bc6 100644 --- a/src/api/endpoints/channels/unwatch.ts +++ b/src/api/endpoints/channels/unwatch.ts @@ -13,9 +13,9 @@ import Watching from '../../models/channel-watching'; * @return {Promise} */ module.exports = (params, user) => new Promise(async (res, rej) => { - // Get 'channel_id' parameter - const [channelId, channelIdErr] = $(params.channel_id).id().$; - if (channelIdErr) return rej('invalid channel_id param'); + // Get 'channelId' parameter + const [channelId, channelIdErr] = $(params.channelId).id().$; + if (channelIdErr) return rej('invalid channelId param'); //#region Fetch channel const channel = await Channel.findOne({ @@ -29,9 +29,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => { //#region Check whether not watching const exist = await Watching.findOne({ - user_id: user._id, - channel_id: channel._id, - deleted_at: { $exists: false } + userId: user._id, + channelId: channel._id, + deletedAt: { $exists: false } }); if (exist === null) { @@ -44,7 +44,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { _id: exist._id }, { $set: { - deleted_at: new Date() + deletedAt: new Date() } }); @@ -54,7 +54,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Decrement watching count Channel.update(channel._id, { $inc: { - watching_count: -1 + watchingCount: -1 } }); }); diff --git a/src/api/endpoints/channels/watch.ts b/src/api/endpoints/channels/watch.ts index 030e0dd41..df9e70d5c 100644 --- a/src/api/endpoints/channels/watch.ts +++ b/src/api/endpoints/channels/watch.ts @@ -13,9 +13,9 @@ import Watching from '../../models/channel-watching'; * @return {Promise} */ module.exports = (params, user) => new Promise(async (res, rej) => { - // Get 'channel_id' parameter - const [channelId, channelIdErr] = $(params.channel_id).id().$; - if (channelIdErr) return rej('invalid channel_id param'); + // Get 'channelId' parameter + const [channelId, channelIdErr] = $(params.channelId).id().$; + if (channelIdErr) return rej('invalid channelId param'); //#region Fetch channel const channel = await Channel.findOne({ @@ -29,9 +29,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => { //#region Check whether already watching const exist = await Watching.findOne({ - user_id: user._id, - channel_id: channel._id, - deleted_at: { $exists: false } + userId: user._id, + channelId: channel._id, + deletedAt: { $exists: false } }); if (exist !== null) { @@ -41,9 +41,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Create Watching await Watching.insert({ - created_at: new Date(), - user_id: user._id, - channel_id: channel._id + createdAt: new Date(), + userId: user._id, + channelId: channel._id }); // Send response @@ -52,7 +52,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Increment watching count Channel.update(channel._id, { $inc: { - watching_count: 1 + watchingCount: 1 } }); }); diff --git a/src/api/endpoints/drive.ts b/src/api/endpoints/drive.ts index d92473633..eb2185391 100644 --- a/src/api/endpoints/drive.ts +++ b/src/api/endpoints/drive.ts @@ -14,7 +14,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Calculate drive usage const usage = ((await DriveFile .aggregate([ - { $match: { 'metadata.user_id': user._id } }, + { $match: { 'metadata.userId': user._id } }, { $project: { length: true @@ -31,7 +31,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { }).usage; res({ - capacity: user.drive_capacity, + capacity: user.driveCapacity, usage: usage }); }); diff --git a/src/api/endpoints/drive/files.ts b/src/api/endpoints/drive/files.ts index 89915331e..1ce855932 100644 --- a/src/api/endpoints/drive/files.ts +++ b/src/api/endpoints/drive/files.ts @@ -30,9 +30,9 @@ module.exports = async (params, user, app) => { throw 'cannot set since_id and until_id'; } - // Get 'folder_id' parameter - const [folderId = null, folderIdErr] = $(params.folder_id).optional.nullable.id().$; - if (folderIdErr) throw 'invalid folder_id param'; + // Get 'folderId' parameter + const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.id().$; + if (folderIdErr) throw 'invalid folderId param'; // Get 'type' parameter const [type, typeErr] = $(params.type).optional.string().match(/^[a-zA-Z\/\-\*]+$/).$; @@ -43,8 +43,8 @@ module.exports = async (params, user, app) => { _id: -1 }; const query = { - 'metadata.user_id': user._id, - 'metadata.folder_id': folderId + 'metadata.userId': user._id, + 'metadata.folderId': folderId } as any; if (sinceId) { sort._id = 1; diff --git a/src/api/endpoints/drive/files/create.ts b/src/api/endpoints/drive/files/create.ts index db801b61f..2cd89a8fa 100644 --- a/src/api/endpoints/drive/files/create.ts +++ b/src/api/endpoints/drive/files/create.ts @@ -33,9 +33,9 @@ module.exports = async (file, params, user): Promise => { name = null; } - // Get 'folder_id' parameter - const [folderId = null, folderIdErr] = $(params.folder_id).optional.nullable.id().$; - if (folderIdErr) throw 'invalid folder_id param'; + // Get 'folderId' parameter + const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.id().$; + if (folderIdErr) throw 'invalid folderId param'; try { // Create file diff --git a/src/api/endpoints/drive/files/find.ts b/src/api/endpoints/drive/files/find.ts index e026afe93..47ce89130 100644 --- a/src/api/endpoints/drive/files/find.ts +++ b/src/api/endpoints/drive/files/find.ts @@ -16,16 +16,16 @@ module.exports = (params, user) => new Promise(async (res, rej) => { const [name, nameErr] = $(params.name).string().$; if (nameErr) return rej('invalid name param'); - // Get 'folder_id' parameter - const [folderId = null, folderIdErr] = $(params.folder_id).optional.nullable.id().$; - if (folderIdErr) return rej('invalid folder_id param'); + // Get 'folderId' parameter + const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.id().$; + if (folderIdErr) return rej('invalid folderId param'); // Issue query const files = await DriveFile .find({ filename: name, - 'metadata.user_id': user._id, - 'metadata.folder_id': folderId + 'metadata.userId': user._id, + 'metadata.folderId': folderId }); // Serialize diff --git a/src/api/endpoints/drive/files/show.ts b/src/api/endpoints/drive/files/show.ts index 21664f7ba..63920db7f 100644 --- a/src/api/endpoints/drive/files/show.ts +++ b/src/api/endpoints/drive/files/show.ts @@ -12,15 +12,15 @@ import DriveFile, { pack } from '../../../models/drive-file'; * @return {Promise} */ module.exports = async (params, user) => { - // Get 'file_id' parameter - const [fileId, fileIdErr] = $(params.file_id).id().$; - if (fileIdErr) throw 'invalid file_id param'; + // Get 'fileId' parameter + const [fileId, fileIdErr] = $(params.fileId).id().$; + if (fileIdErr) throw 'invalid fileId param'; // Fetch file const file = await DriveFile .findOne({ _id: fileId, - 'metadata.user_id': user._id + 'metadata.userId': user._id }); if (file === null) { diff --git a/src/api/endpoints/drive/files/update.ts b/src/api/endpoints/drive/files/update.ts index 83da46211..bfad45b0a 100644 --- a/src/api/endpoints/drive/files/update.ts +++ b/src/api/endpoints/drive/files/update.ts @@ -14,15 +14,15 @@ import { publishDriveStream } from '../../../event'; * @return {Promise} */ module.exports = (params, user) => new Promise(async (res, rej) => { - // Get 'file_id' parameter - const [fileId, fileIdErr] = $(params.file_id).id().$; - if (fileIdErr) return rej('invalid file_id param'); + // Get 'fileId' parameter + const [fileId, fileIdErr] = $(params.fileId).id().$; + if (fileIdErr) return rej('invalid fileId param'); // Fetch file const file = await DriveFile .findOne({ _id: fileId, - 'metadata.user_id': user._id + 'metadata.userId': user._id }); if (file === null) { @@ -34,33 +34,33 @@ module.exports = (params, user) => new Promise(async (res, rej) => { if (nameErr) return rej('invalid name param'); if (name) file.filename = name; - // Get 'folder_id' parameter - const [folderId, folderIdErr] = $(params.folder_id).optional.nullable.id().$; - if (folderIdErr) return rej('invalid folder_id param'); + // Get 'folderId' parameter + const [folderId, folderIdErr] = $(params.folderId).optional.nullable.id().$; + if (folderIdErr) return rej('invalid folderId param'); if (folderId !== undefined) { if (folderId === null) { - file.metadata.folder_id = null; + file.metadata.folderId = null; } else { // Fetch folder const folder = await DriveFolder .findOne({ _id: folderId, - user_id: user._id + userId: user._id }); if (folder === null) { return rej('folder-not-found'); } - file.metadata.folder_id = folder._id; + file.metadata.folderId = folder._id; } } await DriveFile.update(file._id, { $set: { filename: file.filename, - 'metadata.folder_id': file.metadata.folder_id + 'metadata.folderId': file.metadata.folderId } }); diff --git a/src/api/endpoints/drive/files/upload_from_url.ts b/src/api/endpoints/drive/files/upload_from_url.ts index 346633c61..1a4ce0bf0 100644 --- a/src/api/endpoints/drive/files/upload_from_url.ts +++ b/src/api/endpoints/drive/files/upload_from_url.ts @@ -18,9 +18,9 @@ module.exports = async (params, user): Promise => { const [url, urlErr] = $(params.url).string().$; if (urlErr) throw 'invalid url param'; - // Get 'folder_id' parameter - const [folderId = null, folderIdErr] = $(params.folder_id).optional.nullable.id().$; - if (folderIdErr) throw 'invalid folder_id param'; + // Get 'folderId' parameter + const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.id().$; + if (folderIdErr) throw 'invalid folderId param'; return pack(await uploadFromUrl(url, user, folderId)); }; diff --git a/src/api/endpoints/drive/folders.ts b/src/api/endpoints/drive/folders.ts index 428bde350..c25964635 100644 --- a/src/api/endpoints/drive/folders.ts +++ b/src/api/endpoints/drive/folders.ts @@ -30,17 +30,17 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => { return rej('cannot set since_id and until_id'); } - // Get 'folder_id' parameter - const [folderId = null, folderIdErr] = $(params.folder_id).optional.nullable.id().$; - if (folderIdErr) return rej('invalid folder_id param'); + // Get 'folderId' parameter + const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.id().$; + if (folderIdErr) return rej('invalid folderId param'); // Construct query const sort = { _id: -1 }; const query = { - user_id: user._id, - parent_id: folderId + userId: user._id, + parentId: folderId } as any; if (sinceId) { sort._id = 1; diff --git a/src/api/endpoints/drive/folders/create.ts b/src/api/endpoints/drive/folders/create.ts index 03f396ddc..564558606 100644 --- a/src/api/endpoints/drive/folders/create.ts +++ b/src/api/endpoints/drive/folders/create.ts @@ -17,9 +17,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => { const [name = '無題のフォルダー', nameErr] = $(params.name).optional.string().pipe(isValidFolderName).$; if (nameErr) return rej('invalid name param'); - // Get 'parent_id' parameter - const [parentId = null, parentIdErr] = $(params.parent_id).optional.nullable.id().$; - if (parentIdErr) return rej('invalid parent_id param'); + // Get 'parentId' parameter + const [parentId = null, parentIdErr] = $(params.parentId).optional.nullable.id().$; + if (parentIdErr) return rej('invalid parentId param'); // If the parent folder is specified let parent = null; @@ -28,7 +28,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { parent = await DriveFolder .findOne({ _id: parentId, - user_id: user._id + userId: user._id }); if (parent === null) { @@ -38,10 +38,10 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Create folder const folder = await DriveFolder.insert({ - created_at: new Date(), + createdAt: new Date(), name: name, - parent_id: parent !== null ? parent._id : null, - user_id: user._id + parentId: parent !== null ? parent._id : null, + userId: user._id }); // Serialize diff --git a/src/api/endpoints/drive/folders/find.ts b/src/api/endpoints/drive/folders/find.ts index fc84766bc..f46aaedd3 100644 --- a/src/api/endpoints/drive/folders/find.ts +++ b/src/api/endpoints/drive/folders/find.ts @@ -16,16 +16,16 @@ module.exports = (params, user) => new Promise(async (res, rej) => { const [name, nameErr] = $(params.name).string().$; if (nameErr) return rej('invalid name param'); - // Get 'parent_id' parameter - const [parentId = null, parentIdErr] = $(params.parent_id).optional.nullable.id().$; - if (parentIdErr) return rej('invalid parent_id param'); + // Get 'parentId' parameter + const [parentId = null, parentIdErr] = $(params.parentId).optional.nullable.id().$; + if (parentIdErr) return rej('invalid parentId param'); // Issue query const folders = await DriveFolder .find({ name: name, - user_id: user._id, - parent_id: parentId + userId: user._id, + parentId: parentId }); // Serialize diff --git a/src/api/endpoints/drive/folders/show.ts b/src/api/endpoints/drive/folders/show.ts index e07d14d20..a6d7e86df 100644 --- a/src/api/endpoints/drive/folders/show.ts +++ b/src/api/endpoints/drive/folders/show.ts @@ -12,15 +12,15 @@ import DriveFolder, { pack } from '../../../models/drive-folder'; * @return {Promise} */ module.exports = (params, user) => new Promise(async (res, rej) => { - // Get 'folder_id' parameter - const [folderId, folderIdErr] = $(params.folder_id).id().$; - if (folderIdErr) return rej('invalid folder_id param'); + // Get 'folderId' parameter + const [folderId, folderIdErr] = $(params.folderId).id().$; + if (folderIdErr) return rej('invalid folderId param'); // Get folder const folder = await DriveFolder .findOne({ _id: folderId, - user_id: user._id + userId: user._id }); if (folder === null) { diff --git a/src/api/endpoints/drive/folders/update.ts b/src/api/endpoints/drive/folders/update.ts index d3df8bdae..fcfd24124 100644 --- a/src/api/endpoints/drive/folders/update.ts +++ b/src/api/endpoints/drive/folders/update.ts @@ -13,15 +13,15 @@ import { publishDriveStream } from '../../../event'; * @return {Promise} */ module.exports = (params, user) => new Promise(async (res, rej) => { - // Get 'folder_id' parameter - const [folderId, folderIdErr] = $(params.folder_id).id().$; - if (folderIdErr) return rej('invalid folder_id param'); + // Get 'folderId' parameter + const [folderId, folderIdErr] = $(params.folderId).id().$; + if (folderIdErr) return rej('invalid folderId param'); // Fetch folder const folder = await DriveFolder .findOne({ _id: folderId, - user_id: user._id + userId: user._id }); if (folder === null) { @@ -33,18 +33,18 @@ module.exports = (params, user) => new Promise(async (res, rej) => { if (nameErr) return rej('invalid name param'); if (name) folder.name = name; - // Get 'parent_id' parameter - const [parentId, parentIdErr] = $(params.parent_id).optional.nullable.id().$; - if (parentIdErr) return rej('invalid parent_id param'); + // Get 'parentId' parameter + const [parentId, parentIdErr] = $(params.parentId).optional.nullable.id().$; + if (parentIdErr) return rej('invalid parentId param'); if (parentId !== undefined) { if (parentId === null) { - folder.parent_id = null; + folder.parentId = null; } else { // Get parent folder const parent = await DriveFolder .findOne({ _id: parentId, - user_id: user._id + userId: user._id }); if (parent === null) { @@ -58,25 +58,25 @@ module.exports = (params, user) => new Promise(async (res, rej) => { _id: folderId }, { _id: true, - parent_id: true + parentId: true }); if (folder2._id.equals(folder._id)) { return true; - } else if (folder2.parent_id) { - return await checkCircle(folder2.parent_id); + } else if (folder2.parentId) { + return await checkCircle(folder2.parentId); } else { return false; } } - if (parent.parent_id !== null) { - if (await checkCircle(parent.parent_id)) { + if (parent.parentId !== null) { + if (await checkCircle(parent.parentId)) { return rej('detected-circular-definition'); } } - folder.parent_id = parent._id; + folder.parentId = parent._id; } } @@ -84,7 +84,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { DriveFolder.update(folder._id, { $set: { name: folder.name, - parent_id: folder.parent_id + parentId: folder.parentId } }); diff --git a/src/api/endpoints/drive/stream.ts b/src/api/endpoints/drive/stream.ts index 8352c7dd4..0f9cea9f1 100644 --- a/src/api/endpoints/drive/stream.ts +++ b/src/api/endpoints/drive/stream.ts @@ -38,7 +38,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { _id: -1 }; const query = { - 'metadata.user_id': user._id + 'metadata.userId': user._id } as any; if (sinceId) { sort._id = 1; diff --git a/src/api/endpoints/following/create.ts b/src/api/endpoints/following/create.ts index 767b837b3..983d8040f 100644 --- a/src/api/endpoints/following/create.ts +++ b/src/api/endpoints/following/create.ts @@ -17,9 +17,9 @@ import event from '../../event'; module.exports = (params, user) => new Promise(async (res, rej) => { const follower = user; - // Get 'user_id' parameter - const [userId, userIdErr] = $(params.user_id).id().$; - if (userIdErr) return rej('invalid user_id param'); + // Get 'userId' parameter + const [userId, userIdErr] = $(params.userId).id().$; + if (userIdErr) return rej('invalid userId param'); // 自分自身 if (user._id.equals(userId)) { @@ -42,9 +42,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Check if already following const exist = await Following.findOne({ - follower_id: follower._id, - followee_id: followee._id, - deleted_at: { $exists: false } + followerId: follower._id, + followeeId: followee._id, + deletedAt: { $exists: false } }); if (exist !== null) { @@ -53,9 +53,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Create following await Following.insert({ - created_at: new Date(), - follower_id: follower._id, - followee_id: followee._id + createdAt: new Date(), + followerId: follower._id, + followeeId: followee._id }); // Send response @@ -64,14 +64,14 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Increment following count User.update(follower._id, { $inc: { - following_count: 1 + followingCount: 1 } }); // Increment followers count User.update({ _id: followee._id }, { $inc: { - followers_count: 1 + followersCount: 1 } }); diff --git a/src/api/endpoints/following/delete.ts b/src/api/endpoints/following/delete.ts index 64b9a8cec..25eba8b26 100644 --- a/src/api/endpoints/following/delete.ts +++ b/src/api/endpoints/following/delete.ts @@ -16,9 +16,9 @@ import event from '../../event'; module.exports = (params, user) => new Promise(async (res, rej) => { const follower = user; - // Get 'user_id' parameter - const [userId, userIdErr] = $(params.user_id).id().$; - if (userIdErr) return rej('invalid user_id param'); + // Get 'userId' parameter + const [userId, userIdErr] = $(params.userId).id().$; + if (userIdErr) return rej('invalid userId param'); // Check if the followee is yourself if (user._id.equals(userId)) { @@ -41,9 +41,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Check not following const exist = await Following.findOne({ - follower_id: follower._id, - followee_id: followee._id, - deleted_at: { $exists: false } + followerId: follower._id, + followeeId: followee._id, + deletedAt: { $exists: false } }); if (exist === null) { @@ -55,7 +55,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { _id: exist._id }, { $set: { - deleted_at: new Date() + deletedAt: new Date() } }); @@ -65,14 +65,14 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Decrement following count User.update({ _id: follower._id }, { $inc: { - following_count: -1 + followingCount: -1 } }); // Decrement followers count User.update({ _id: followee._id }, { $inc: { - followers_count: -1 + followersCount: -1 } }); diff --git a/src/api/endpoints/i.ts b/src/api/endpoints/i.ts index 32b0382fa..f5e92b4de 100644 --- a/src/api/endpoints/i.ts +++ b/src/api/endpoints/i.ts @@ -22,7 +22,7 @@ module.exports = (params, user, _, isSecure) => new Promise(async (res, rej) => // Update lastUsedAt User.update({ _id: user._id }, { $set: { - 'account.last_used_at': new Date() + 'account.lastUsedAt': new Date() } }); }); diff --git a/src/api/endpoints/i/2fa/done.ts b/src/api/endpoints/i/2fa/done.ts index 0f1db7382..d61ebbe6f 100644 --- a/src/api/endpoints/i/2fa/done.ts +++ b/src/api/endpoints/i/2fa/done.ts @@ -12,12 +12,12 @@ module.exports = async (params, user) => new Promise(async (res, rej) => { const _token = token.replace(/\s/g, ''); - if (user.two_factor_temp_secret == null) { + if (user.twoFactorTempSecret == null) { return rej('二段階認証の設定が開始されていません'); } const verified = (speakeasy as any).totp.verify({ - secret: user.two_factor_temp_secret, + secret: user.twoFactorTempSecret, encoding: 'base32', token: _token }); @@ -28,8 +28,8 @@ module.exports = async (params, user) => new Promise(async (res, rej) => { await User.update(user._id, { $set: { - 'account.two_factor_secret': user.two_factor_temp_secret, - 'account.two_factor_enabled': true + 'account.twoFactorSecret': user.twoFactorTempSecret, + 'account.twoFactorEnabled': true } }); diff --git a/src/api/endpoints/i/2fa/register.ts b/src/api/endpoints/i/2fa/register.ts index 24abfcdfc..b498a2414 100644 --- a/src/api/endpoints/i/2fa/register.ts +++ b/src/api/endpoints/i/2fa/register.ts @@ -27,7 +27,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => { await User.update(user._id, { $set: { - two_factor_temp_secret: secret.base32 + twoFactorTempSecret: secret.base32 } }); diff --git a/src/api/endpoints/i/2fa/unregister.ts b/src/api/endpoints/i/2fa/unregister.ts index c43f9ccc4..0221ecb96 100644 --- a/src/api/endpoints/i/2fa/unregister.ts +++ b/src/api/endpoints/i/2fa/unregister.ts @@ -19,8 +19,8 @@ module.exports = async (params, user) => new Promise(async (res, rej) => { await User.update(user._id, { $set: { - 'account.two_factor_secret': null, - 'account.two_factor_enabled': false + 'account.twoFactorSecret': null, + 'account.twoFactorEnabled': false } }); diff --git a/src/api/endpoints/i/appdata/get.ts b/src/api/endpoints/i/appdata/get.ts index 571208d46..0b34643f7 100644 --- a/src/api/endpoints/i/appdata/get.ts +++ b/src/api/endpoints/i/appdata/get.ts @@ -25,8 +25,8 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => { select[`data.${key}`] = true; } const appdata = await Appdata.findOne({ - app_id: app._id, - user_id: user._id + appId: app._id, + userId: user._id }, { fields: select }); diff --git a/src/api/endpoints/i/appdata/set.ts b/src/api/endpoints/i/appdata/set.ts index 2804a14cb..1e3232ce3 100644 --- a/src/api/endpoints/i/appdata/set.ts +++ b/src/api/endpoints/i/appdata/set.ts @@ -43,11 +43,11 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => { } await Appdata.update({ - app_id: app._id, - user_id: user._id + appId: app._id, + userId: user._id }, Object.assign({ - app_id: app._id, - user_id: user._id + appId: app._id, + userId: user._id }, { $set: set }), { diff --git a/src/api/endpoints/i/authorized_apps.ts b/src/api/endpoints/i/authorized_apps.ts index 40ce7a68c..5a38d7c18 100644 --- a/src/api/endpoints/i/authorized_apps.ts +++ b/src/api/endpoints/i/authorized_apps.ts @@ -28,7 +28,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Get tokens const tokens = await AccessToken .find({ - user_id: user._id + userId: user._id }, { limit: limit, skip: offset, @@ -39,5 +39,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Serialize res(await Promise.all(tokens.map(async token => - await pack(token.app_id)))); + await pack(token.appId)))); }); diff --git a/src/api/endpoints/i/favorites.ts b/src/api/endpoints/i/favorites.ts index eb464cf0f..22a439954 100644 --- a/src/api/endpoints/i/favorites.ts +++ b/src/api/endpoints/i/favorites.ts @@ -28,7 +28,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Get favorites const favorites = await Favorite .find({ - user_id: user._id + userId: user._id }, { limit: limit, skip: offset, diff --git a/src/api/endpoints/i/notifications.ts b/src/api/endpoints/i/notifications.ts index 688039a0d..e3447c17e 100644 --- a/src/api/endpoints/i/notifications.ts +++ b/src/api/endpoints/i/notifications.ts @@ -47,15 +47,15 @@ module.exports = (params, user) => new Promise(async (res, rej) => { } const mute = await Mute.find({ - muter_id: user._id, - deleted_at: { $exists: false } + muterId: user._id, + deletedAt: { $exists: false } }); const query = { - notifiee_id: user._id, + notifieeId: user._id, $and: [{ - notifier_id: { - $nin: mute.map(m => m.mutee_id) + notifierId: { + $nin: mute.map(m => m.muteeId) } }] } as any; @@ -69,7 +69,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { const followingIds = await getFriends(user._id); query.$and.push({ - notifier_id: { + notifierId: { $in: followingIds } }); diff --git a/src/api/endpoints/i/pin.ts b/src/api/endpoints/i/pin.ts index ff546fc2b..886a3edeb 100644 --- a/src/api/endpoints/i/pin.ts +++ b/src/api/endpoints/i/pin.ts @@ -14,14 +14,14 @@ import { pack } from '../../models/user'; * @return {Promise} */ module.exports = async (params, user) => new Promise(async (res, rej) => { - // Get 'post_id' parameter - const [postId, postIdErr] = $(params.post_id).id().$; - if (postIdErr) return rej('invalid post_id param'); + // Get 'postId' parameter + const [postId, postIdErr] = $(params.postId).id().$; + if (postIdErr) return rej('invalid postId param'); // Fetch pinee const post = await Post.findOne({ _id: postId, - user_id: user._id + userId: user._id }); if (post === null) { @@ -30,7 +30,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => { await User.update(user._id, { $set: { - pinned_post_id: post._id + pinnedPostId: post._id } }); diff --git a/src/api/endpoints/i/signin_history.ts b/src/api/endpoints/i/signin_history.ts index 859e81653..5b794d0a4 100644 --- a/src/api/endpoints/i/signin_history.ts +++ b/src/api/endpoints/i/signin_history.ts @@ -30,7 +30,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { } const query = { - user_id: user._id + userId: user._id } as any; const sort = { diff --git a/src/api/endpoints/i/update.ts b/src/api/endpoints/i/update.ts index db8a3f25b..664575187 100644 --- a/src/api/endpoints/i/update.ts +++ b/src/api/endpoints/i/update.ts @@ -36,20 +36,20 @@ module.exports = async (params, user, _, isSecure) => new Promise(async (res, re if (birthdayErr) return rej('invalid birthday param'); if (birthday !== undefined) user.account.profile.birthday = birthday; - // Get 'avatar_id' parameter - const [avatarId, avatarIdErr] = $(params.avatar_id).optional.id().$; - if (avatarIdErr) return rej('invalid avatar_id param'); - if (avatarId) user.avatar_id = avatarId; + // Get 'avatarId' parameter + const [avatarId, avatarIdErr] = $(params.avatarId).optional.id().$; + if (avatarIdErr) return rej('invalid avatarId param'); + if (avatarId) user.avatarId = avatarId; - // Get 'banner_id' parameter - const [bannerId, bannerIdErr] = $(params.banner_id).optional.id().$; - if (bannerIdErr) return rej('invalid banner_id param'); - if (bannerId) user.banner_id = bannerId; + // Get 'bannerId' parameter + const [bannerId, bannerIdErr] = $(params.bannerId).optional.id().$; + if (bannerIdErr) return rej('invalid bannerId param'); + if (bannerId) user.bannerId = bannerId; - // Get 'is_bot' parameter - const [isBot, isBotErr] = $(params.is_bot).optional.boolean().$; - if (isBotErr) return rej('invalid is_bot param'); - if (isBot != null) user.account.is_bot = isBot; + // Get 'isBot' parameter + const [isBot, isBotErr] = $(params.isBot).optional.boolean().$; + if (isBotErr) return rej('invalid isBot param'); + if (isBot != null) user.account.isBot = isBot; // Get 'auto_watch' parameter const [autoWatch, autoWatchErr] = $(params.auto_watch).optional.boolean().$; @@ -60,10 +60,10 @@ module.exports = async (params, user, _, isSecure) => new Promise(async (res, re $set: { name: user.name, description: user.description, - avatar_id: user.avatar_id, - banner_id: user.banner_id, + avatarId: user.avatarId, + bannerId: user.bannerId, 'account.profile': user.account.profile, - 'account.is_bot': user.account.is_bot, + 'account.isBot': user.account.isBot, 'account.settings': user.account.settings } }); diff --git a/src/api/endpoints/i/update_client_setting.ts b/src/api/endpoints/i/update_client_setting.ts index c772ed5dc..a0bef5e59 100644 --- a/src/api/endpoints/i/update_client_setting.ts +++ b/src/api/endpoints/i/update_client_setting.ts @@ -22,14 +22,14 @@ module.exports = async (params, user) => new Promise(async (res, rej) => { if (valueErr) return rej('invalid value param'); const x = {}; - x[`account.client_settings.${name}`] = value; + x[`account.clientSettings.${name}`] = value; await User.update(user._id, { $set: x }); // Serialize - user.account.client_settings[name] = value; + user.account.clientSettings[name] = value; const iObj = await pack(user, user, { detail: true, includeSecrets: true diff --git a/src/api/endpoints/i/update_home.ts b/src/api/endpoints/i/update_home.ts index 9ce44e25e..151c3e205 100644 --- a/src/api/endpoints/i/update_home.ts +++ b/src/api/endpoints/i/update_home.ts @@ -26,7 +26,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => { if (home) { await User.update(user._id, { $set: { - 'account.client_settings.home': home + 'account.clientSettings.home': home } }); @@ -38,7 +38,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => { } else { if (id == null && data == null) return rej('you need to set id and data params if home param unset'); - const _home = user.account.client_settings.home; + const _home = user.account.clientSettings.home; const widget = _home.find(w => w.id == id); if (widget == null) return rej('widget not found'); @@ -47,7 +47,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => { await User.update(user._id, { $set: { - 'account.client_settings.home': _home + 'account.clientSettings.home': _home } }); diff --git a/src/api/endpoints/i/update_mobile_home.ts b/src/api/endpoints/i/update_mobile_home.ts index 1daddf42b..a8436b940 100644 --- a/src/api/endpoints/i/update_mobile_home.ts +++ b/src/api/endpoints/i/update_mobile_home.ts @@ -25,7 +25,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => { if (home) { await User.update(user._id, { $set: { - 'account.client_settings.mobile_home': home + 'account.clientSettings.mobile_home': home } }); @@ -37,7 +37,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => { } else { if (id == null && data == null) return rej('you need to set id and data params if home param unset'); - const _home = user.account.client_settings.mobile_home || []; + const _home = user.account.clientSettings.mobile_home || []; const widget = _home.find(w => w.id == id); if (widget == null) return rej('widget not found'); @@ -46,7 +46,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => { await User.update(user._id, { $set: { - 'account.client_settings.mobile_home': _home + 'account.clientSettings.mobile_home': _home } }); diff --git a/src/api/endpoints/messaging/history.ts b/src/api/endpoints/messaging/history.ts index 1683ca7a8..2bf3ed996 100644 --- a/src/api/endpoints/messaging/history.ts +++ b/src/api/endpoints/messaging/history.ts @@ -19,25 +19,25 @@ module.exports = (params, user) => new Promise(async (res, rej) => { if (limitErr) return rej('invalid limit param'); const mute = await Mute.find({ - muter_id: user._id, - deleted_at: { $exists: false } + muterId: user._id, + deletedAt: { $exists: false } }); // Get history const history = await History .find({ - user_id: user._id, - partner: { - $nin: mute.map(m => m.mutee_id) + userId: user._id, + partnerId: { + $nin: mute.map(m => m.muteeId) } }, { limit: limit, sort: { - updated_at: -1 + updatedAt: -1 } }); // Serialize res(await Promise.all(history.map(async h => - await pack(h.message, user)))); + await pack(h.messageId, user)))); }); diff --git a/src/api/endpoints/messaging/messages.ts b/src/api/endpoints/messaging/messages.ts index 67ba5e9d6..ba8ca7d1c 100644 --- a/src/api/endpoints/messaging/messages.ts +++ b/src/api/endpoints/messaging/messages.ts @@ -15,9 +15,9 @@ import read from '../../common/read-messaging-message'; * @return {Promise} */ module.exports = (params, user) => new Promise(async (res, rej) => { - // Get 'user_id' parameter - const [recipientId, recipientIdErr] = $(params.user_id).id().$; - if (recipientIdErr) return rej('invalid user_id param'); + // Get 'userId' parameter + const [recipientId, recipientIdErr] = $(params.userId).id().$; + if (recipientIdErr) return rej('invalid userId param'); // Fetch recipient const recipient = await User.findOne({ @@ -55,11 +55,11 @@ module.exports = (params, user) => new Promise(async (res, rej) => { const query = { $or: [{ - user_id: user._id, - recipient_id: recipient._id + userId: user._id, + recipientId: recipient._id }, { - user_id: recipient._id, - recipient_id: user._id + userId: recipient._id, + recipientId: user._id }] } as any; diff --git a/src/api/endpoints/messaging/messages/create.ts b/src/api/endpoints/messaging/messages/create.ts index 1b8a5f59e..b94a90678 100644 --- a/src/api/endpoints/messaging/messages/create.ts +++ b/src/api/endpoints/messaging/messages/create.ts @@ -21,9 +21,9 @@ import config from '../../../../conf'; * @return {Promise} */ module.exports = (params, user) => new Promise(async (res, rej) => { - // Get 'user_id' parameter - const [recipientId, recipientIdErr] = $(params.user_id).id().$; - if (recipientIdErr) return rej('invalid user_id param'); + // Get 'userId' parameter + const [recipientId, recipientIdErr] = $(params.userId).id().$; + if (recipientIdErr) return rej('invalid userId param'); // Myself if (recipientId.equals(user._id)) { @@ -47,15 +47,15 @@ module.exports = (params, user) => new Promise(async (res, rej) => { const [text, textErr] = $(params.text).optional.string().pipe(isValidText).$; if (textErr) return rej('invalid text'); - // Get 'file_id' parameter - const [fileId, fileIdErr] = $(params.file_id).optional.id().$; - if (fileIdErr) return rej('invalid file_id param'); + // Get 'fileId' parameter + const [fileId, fileIdErr] = $(params.fileId).optional.id().$; + if (fileIdErr) return rej('invalid fileId param'); let file = null; if (fileId !== undefined) { file = await DriveFile.findOne({ _id: fileId, - 'metadata.user_id': user._id + 'metadata.userId': user._id }); if (file === null) { @@ -70,12 +70,12 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // メッセージを作成 const message = await Message.insert({ - created_at: new Date(), - file_id: file ? file._id : undefined, - recipient_id: recipient._id, + createdAt: new Date(), + fileId: file ? file._id : undefined, + recipientId: recipient._id, text: text ? text : undefined, - user_id: user._id, - is_read: false + userId: user._id, + isRead: false }); // Serialize @@ -85,32 +85,32 @@ module.exports = (params, user) => new Promise(async (res, rej) => { res(messageObj); // 自分のストリーム - publishMessagingStream(message.user_id, message.recipient_id, 'message', messageObj); - publishMessagingIndexStream(message.user_id, 'message', messageObj); - publishUserStream(message.user_id, 'messaging_message', messageObj); + publishMessagingStream(message.userId, message.recipientId, 'message', messageObj); + publishMessagingIndexStream(message.userId, 'message', messageObj); + publishUserStream(message.userId, 'messaging_message', messageObj); // 相手のストリーム - publishMessagingStream(message.recipient_id, message.user_id, 'message', messageObj); - publishMessagingIndexStream(message.recipient_id, 'message', messageObj); - publishUserStream(message.recipient_id, 'messaging_message', messageObj); + publishMessagingStream(message.recipientId, message.userId, 'message', messageObj); + publishMessagingIndexStream(message.recipientId, 'message', messageObj); + publishUserStream(message.recipientId, 'messaging_message', messageObj); // 3秒経っても(今回作成した)メッセージが既読にならなかったら「未読のメッセージがありますよ」イベントを発行する setTimeout(async () => { - const freshMessage = await Message.findOne({ _id: message._id }, { is_read: true }); - if (!freshMessage.is_read) { + const freshMessage = await Message.findOne({ _id: message._id }, { isRead: true }); + if (!freshMessage.isRead) { //#region ただしミュートされているなら発行しない const mute = await Mute.find({ - muter_id: recipient._id, - deleted_at: { $exists: false } + muterId: recipient._id, + deletedAt: { $exists: false } }); - const mutedUserIds = mute.map(m => m.mutee_id.toString()); + const mutedUserIds = mute.map(m => m.muteeId.toString()); if (mutedUserIds.indexOf(user._id.toString()) != -1) { return; } //#endregion - publishUserStream(message.recipient_id, 'unread_messaging_message', messageObj); - pushSw(message.recipient_id, 'unread_messaging_message', messageObj); + publishUserStream(message.recipientId, 'unread_messaging_message', messageObj); + pushSw(message.recipientId, 'unread_messaging_message', messageObj); } }, 3000); @@ -130,26 +130,26 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // 履歴作成(自分) History.update({ - user_id: user._id, - partner: recipient._id + userId: user._id, + partnerId: recipient._id }, { - updated_at: new Date(), - user_id: user._id, - partner: recipient._id, - message: message._id + updatedAt: new Date(), + userId: user._id, + partnerId: recipient._id, + messageId: message._id }, { upsert: true }); // 履歴作成(相手) History.update({ - user_id: recipient._id, - partner: user._id + userId: recipient._id, + partnerId: user._id }, { - updated_at: new Date(), - user_id: recipient._id, - partner: user._id, - message: message._id + updatedAt: new Date(), + userId: recipient._id, + partnerId: user._id, + messageId: message._id }, { upsert: true }); diff --git a/src/api/endpoints/messaging/unread.ts b/src/api/endpoints/messaging/unread.ts index c4326e1d2..f7f4047b6 100644 --- a/src/api/endpoints/messaging/unread.ts +++ b/src/api/endpoints/messaging/unread.ts @@ -13,18 +13,18 @@ import Mute from '../../models/mute'; */ module.exports = (params, user) => new Promise(async (res, rej) => { const mute = await Mute.find({ - muter_id: user._id, - deleted_at: { $exists: false } + muterId: user._id, + deletedAt: { $exists: false } }); - const mutedUserIds = mute.map(m => m.mutee_id); + const mutedUserIds = mute.map(m => m.muteeId); const count = await Message .count({ - user_id: { + userId: { $nin: mutedUserIds }, - recipient_id: user._id, - is_read: false + recipientId: user._id, + isRead: false }); res({ diff --git a/src/api/endpoints/mute/create.ts b/src/api/endpoints/mute/create.ts index f99b40d32..e86023508 100644 --- a/src/api/endpoints/mute/create.ts +++ b/src/api/endpoints/mute/create.ts @@ -15,9 +15,9 @@ import Mute from '../../models/mute'; module.exports = (params, user) => new Promise(async (res, rej) => { const muter = user; - // Get 'user_id' parameter - const [userId, userIdErr] = $(params.user_id).id().$; - if (userIdErr) return rej('invalid user_id param'); + // Get 'userId' parameter + const [userId, userIdErr] = $(params.userId).id().$; + if (userIdErr) return rej('invalid userId param'); // 自分自身 if (user._id.equals(userId)) { @@ -40,9 +40,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Check if already muting const exist = await Mute.findOne({ - muter_id: muter._id, - mutee_id: mutee._id, - deleted_at: { $exists: false } + muterId: muter._id, + muteeId: mutee._id, + deletedAt: { $exists: false } }); if (exist !== null) { @@ -51,9 +51,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Create mute await Mute.insert({ - created_at: new Date(), - muter_id: muter._id, - mutee_id: mutee._id, + createdAt: new Date(), + muterId: muter._id, + muteeId: mutee._id, }); // Send response diff --git a/src/api/endpoints/mute/delete.ts b/src/api/endpoints/mute/delete.ts index 36e2fd101..7e361b479 100644 --- a/src/api/endpoints/mute/delete.ts +++ b/src/api/endpoints/mute/delete.ts @@ -15,9 +15,9 @@ import Mute from '../../models/mute'; module.exports = (params, user) => new Promise(async (res, rej) => { const muter = user; - // Get 'user_id' parameter - const [userId, userIdErr] = $(params.user_id).id().$; - if (userIdErr) return rej('invalid user_id param'); + // Get 'userId' parameter + const [userId, userIdErr] = $(params.userId).id().$; + if (userIdErr) return rej('invalid userId param'); // Check if the mutee is yourself if (user._id.equals(userId)) { @@ -40,9 +40,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Check not muting const exist = await Mute.findOne({ - muter_id: muter._id, - mutee_id: mutee._id, - deleted_at: { $exists: false } + muterId: muter._id, + muteeId: mutee._id, + deletedAt: { $exists: false } }); if (exist === null) { @@ -54,7 +54,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { _id: exist._id }, { $set: { - deleted_at: new Date() + deletedAt: new Date() } }); diff --git a/src/api/endpoints/mute/list.ts b/src/api/endpoints/mute/list.ts index 19e3b157e..3401fba64 100644 --- a/src/api/endpoints/mute/list.ts +++ b/src/api/endpoints/mute/list.ts @@ -28,15 +28,15 @@ module.exports = (params, me) => new Promise(async (res, rej) => { // Construct query const query = { - muter_id: me._id, - deleted_at: { $exists: false } + muterId: me._id, + deletedAt: { $exists: false } } as any; if (iknow) { // Get my friends const myFriends = await getFriends(me._id); - query.mutee_id = { + query.muteeId = { $in: myFriends }; } @@ -63,7 +63,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => { // Serialize const users = await Promise.all(mutes.map(async m => - await pack(m.mutee_id, me, { detail: true }))); + await pack(m.muteeId, me, { detail: true }))); // Response res({ diff --git a/src/api/endpoints/my/apps.ts b/src/api/endpoints/my/apps.ts index b23619050..bc1290cac 100644 --- a/src/api/endpoints/my/apps.ts +++ b/src/api/endpoints/my/apps.ts @@ -21,7 +21,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { if (offsetErr) return rej('invalid offset param'); const query = { - user_id: user._id + userId: user._id }; // Execute query diff --git a/src/api/endpoints/notifications/get_unread_count.ts b/src/api/endpoints/notifications/get_unread_count.ts index 845d6b29c..8f9719fff 100644 --- a/src/api/endpoints/notifications/get_unread_count.ts +++ b/src/api/endpoints/notifications/get_unread_count.ts @@ -13,18 +13,18 @@ import Mute from '../../models/mute'; */ module.exports = (params, user) => new Promise(async (res, rej) => { const mute = await Mute.find({ - muter_id: user._id, - deleted_at: { $exists: false } + muterId: user._id, + deletedAt: { $exists: false } }); - const mutedUserIds = mute.map(m => m.mutee_id); + const mutedUserIds = mute.map(m => m.muteeId); const count = await Notification .count({ - notifiee_id: user._id, - notifier_id: { + notifieeId: user._id, + notifierId: { $nin: mutedUserIds }, - is_read: false + isRead: false }); res({ diff --git a/src/api/endpoints/notifications/mark_as_read_all.ts b/src/api/endpoints/notifications/mark_as_read_all.ts index 3550e344c..693de3d0e 100644 --- a/src/api/endpoints/notifications/mark_as_read_all.ts +++ b/src/api/endpoints/notifications/mark_as_read_all.ts @@ -14,11 +14,11 @@ import event from '../../event'; module.exports = (params, user) => new Promise(async (res, rej) => { // Update documents await Notification.update({ - notifiee_id: user._id, - is_read: false + notifieeId: user._id, + isRead: false }, { $set: { - is_read: true + isRead: true } }, { multi: true diff --git a/src/api/endpoints/othello/games.ts b/src/api/endpoints/othello/games.ts index f6e38b8d8..5c71f9882 100644 --- a/src/api/endpoints/othello/games.ts +++ b/src/api/endpoints/othello/games.ts @@ -24,14 +24,14 @@ module.exports = (params, user) => new Promise(async (res, rej) => { } const q: any = my ? { - is_started: true, + isStarted: true, $or: [{ - user1_id: user._id + user1Id: user._id }, { - user2_id: user._id + user2Id: user._id }] } : { - is_started: true + isStarted: true }; const sort = { diff --git a/src/api/endpoints/othello/games/show.ts b/src/api/endpoints/othello/games/show.ts index c7bd74a39..19f5d0fef 100644 --- a/src/api/endpoints/othello/games/show.ts +++ b/src/api/endpoints/othello/games/show.ts @@ -14,9 +14,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => { } const o = new Othello(game.settings.map, { - isLlotheo: game.settings.is_llotheo, - canPutEverywhere: game.settings.can_put_everywhere, - loopedBoard: game.settings.looped_board + isLlotheo: game.settings.isLlotheo, + canPutEverywhere: game.settings.canPutEverywhere, + loopedBoard: game.settings.loopedBoard }); game.logs.forEach(log => { diff --git a/src/api/endpoints/othello/invitations.ts b/src/api/endpoints/othello/invitations.ts index 02fb421fb..f6e0071a6 100644 --- a/src/api/endpoints/othello/invitations.ts +++ b/src/api/endpoints/othello/invitations.ts @@ -3,7 +3,7 @@ import Matching, { pack as packMatching } from '../../models/othello-matching'; module.exports = (params, user) => new Promise(async (res, rej) => { // Find session const invitations = await Matching.find({ - child_id: user._id + childId: user._id }, { sort: { _id: -1 diff --git a/src/api/endpoints/othello/match.ts b/src/api/endpoints/othello/match.ts index f73386ba7..f503c5834 100644 --- a/src/api/endpoints/othello/match.ts +++ b/src/api/endpoints/othello/match.ts @@ -6,19 +6,19 @@ import publishUserStream, { publishOthelloStream } from '../../event'; import { eighteight } from '../../../common/othello/maps'; module.exports = (params, user) => new Promise(async (res, rej) => { - // Get 'user_id' parameter - const [childId, childIdErr] = $(params.user_id).id().$; - if (childIdErr) return rej('invalid user_id param'); + // Get 'userId' parameter + const [childId, childIdErr] = $(params.userId).id().$; + if (childIdErr) return rej('invalid userId param'); // Myself if (childId.equals(user._id)) { - return rej('invalid user_id param'); + return rej('invalid userId param'); } // Find session const exist = await Matching.findOne({ - parent_id: childId, - child_id: user._id + parentId: childId, + childId: user._id }); if (exist) { @@ -29,28 +29,28 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Create game const game = await OthelloGame.insert({ - created_at: new Date(), - user1_id: exist.parent_id, - user2_id: user._id, - user1_accepted: false, - user2_accepted: false, - is_started: false, - is_ended: false, + createdAt: new Date(), + user1Id: exist.parentId, + user2Id: user._id, + user1Accepted: false, + user2Accepted: false, + isStarted: false, + isEnded: false, logs: [], settings: { map: eighteight.data, bw: 'random', - is_llotheo: false + isLlotheo: false } }); // Reponse res(await packGame(game, user)); - publishOthelloStream(exist.parent_id, 'matched', await packGame(game, exist.parent_id)); + publishOthelloStream(exist.parentId, 'matched', await packGame(game, exist.parentId)); const other = await Matching.count({ - child_id: user._id + childId: user._id }); if (other == 0) { @@ -72,14 +72,14 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // 以前のセッションはすべて削除しておく await Matching.remove({ - parent_id: user._id + parentId: user._id }); // セッションを作成 const matching = await Matching.insert({ - created_at: new Date(), - parent_id: user._id, - child_id: child._id + createdAt: new Date(), + parentId: user._id, + childId: child._id }); // Reponse diff --git a/src/api/endpoints/othello/match/cancel.ts b/src/api/endpoints/othello/match/cancel.ts index 6f751ef83..ee0f82a61 100644 --- a/src/api/endpoints/othello/match/cancel.ts +++ b/src/api/endpoints/othello/match/cancel.ts @@ -2,7 +2,7 @@ import Matching from '../../../models/othello-matching'; module.exports = (params, user) => new Promise(async (res, rej) => { await Matching.remove({ - parent_id: user._id + parentId: user._id }); res(); diff --git a/src/api/endpoints/posts.ts b/src/api/endpoints/posts.ts index 7df744d2a..7e9ff3ad7 100644 --- a/src/api/endpoints/posts.ts +++ b/src/api/endpoints/posts.ts @@ -65,15 +65,15 @@ module.exports = (params) => new Promise(async (res, rej) => { } if (reply != undefined) { - query.reply_id = reply ? { $exists: true, $ne: null } : null; + query.replyId = reply ? { $exists: true, $ne: null } : null; } if (repost != undefined) { - query.repost_id = repost ? { $exists: true, $ne: null } : null; + query.repostId = repost ? { $exists: true, $ne: null } : null; } if (media != undefined) { - query.media_ids = media ? { $exists: true, $ne: null } : null; + query.mediaIds = media ? { $exists: true, $ne: null } : null; } if (poll != undefined) { @@ -82,7 +82,7 @@ module.exports = (params) => new Promise(async (res, rej) => { // TODO //if (bot != undefined) { - // query.is_bot = bot; + // query.isBot = bot; //} // Issue query diff --git a/src/api/endpoints/posts/categorize.ts b/src/api/endpoints/posts/categorize.ts index 0c85c2b4e..0436c8e69 100644 --- a/src/api/endpoints/posts/categorize.ts +++ b/src/api/endpoints/posts/categorize.ts @@ -12,13 +12,13 @@ import Post from '../../models/post'; * @return {Promise} */ module.exports = (params, user) => new Promise(async (res, rej) => { - if (!user.account.is_pro) { + if (!user.account.isPro) { return rej('This endpoint is available only from a Pro account'); } - // Get 'post_id' parameter - const [postId, postIdErr] = $(params.post_id).id().$; - if (postIdErr) return rej('invalid post_id param'); + // Get 'postId' parameter + const [postId, postIdErr] = $(params.postId).id().$; + if (postIdErr) return rej('invalid postId param'); // Get categorizee const post = await Post.findOne({ diff --git a/src/api/endpoints/posts/context.ts b/src/api/endpoints/posts/context.ts index 5ba375897..44a77d102 100644 --- a/src/api/endpoints/posts/context.ts +++ b/src/api/endpoints/posts/context.ts @@ -12,9 +12,9 @@ import Post, { pack } from '../../models/post'; * @return {Promise} */ module.exports = (params, user) => new Promise(async (res, rej) => { - // Get 'post_id' parameter - const [postId, postIdErr] = $(params.post_id).id().$; - if (postIdErr) return rej('invalid post_id param'); + // Get 'postId' parameter + const [postId, postIdErr] = $(params.postId).id().$; + if (postIdErr) return rej('invalid postId param'); // Get 'limit' parameter const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$; @@ -48,13 +48,13 @@ module.exports = (params, user) => new Promise(async (res, rej) => { return; } - if (p.reply_id) { - await get(p.reply_id); + if (p.replyId) { + await get(p.replyId); } } - if (post.reply_id) { - await get(post.reply_id); + if (post.replyId) { + await get(post.replyId); } // Serialize diff --git a/src/api/endpoints/posts/create.ts b/src/api/endpoints/posts/create.ts index 286e18bb7..2a3d974fe 100644 --- a/src/api/endpoints/posts/create.ts +++ b/src/api/endpoints/posts/create.ts @@ -33,9 +33,9 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { const [text, textErr] = $(params.text).optional.string().pipe(isValidText).$; if (textErr) return rej('invalid text'); - // Get 'via_mobile' parameter - const [viaMobile = false, viaMobileErr] = $(params.via_mobile).optional.boolean().$; - if (viaMobileErr) return rej('invalid via_mobile'); + // Get 'viaMobile' parameter + const [viaMobile = false, viaMobileErr] = $(params.viaMobile).optional.boolean().$; + if (viaMobileErr) return rej('invalid viaMobile'); // Get 'tags' parameter const [tags = [], tagsErr] = $(params.tags).optional.array('string').unique().eachQ(t => t.range(1, 32)).$; @@ -53,9 +53,9 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { .$; if (geoErr) return rej('invalid geo'); - // Get 'media_ids' parameter - const [mediaIds, mediaIdsErr] = $(params.media_ids).optional.array('id').unique().range(1, 4).$; - if (mediaIdsErr) return rej('invalid media_ids'); + // Get 'mediaIds' parameter + const [mediaIds, mediaIdsErr] = $(params.mediaIds).optional.array('id').unique().range(1, 4).$; + if (mediaIdsErr) return rej('invalid mediaIds'); let files = []; if (mediaIds !== undefined) { @@ -67,7 +67,7 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { // SELECT _id const entity = await DriveFile.findOne({ _id: mediaId, - 'metadata.user_id': user._id + 'metadata.userId': user._id }); if (entity === null) { @@ -80,9 +80,9 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { files = null; } - // Get 'repost_id' parameter - const [repostId, repostIdErr] = $(params.repost_id).optional.id().$; - if (repostIdErr) return rej('invalid repost_id'); + // Get 'repostId' parameter + const [repostId, repostIdErr] = $(params.repostId).optional.id().$; + if (repostIdErr) return rej('invalid repostId'); let repost: IPost = null; let isQuote = false; @@ -94,13 +94,13 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { if (repost == null) { return rej('repostee is not found'); - } else if (repost.repost_id && !repost.text && !repost.media_ids) { + } else if (repost.repostId && !repost.text && !repost.mediaIds) { return rej('cannot repost to repost'); } // Fetch recently post const latestPost = await Post.findOne({ - user_id: user._id + userId: user._id }, { sort: { _id: -1 @@ -111,8 +111,8 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { // 直近と同じRepost対象かつ引用じゃなかったらエラー if (latestPost && - latestPost.repost_id && - latestPost.repost_id.equals(repost._id) && + latestPost.repostId && + latestPost.repostId.equals(repost._id) && !isQuote) { return rej('cannot repost same post that already reposted in your latest post'); } @@ -125,9 +125,9 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { } } - // Get 'reply_id' parameter - const [replyId, replyIdErr] = $(params.reply_id).optional.id().$; - if (replyIdErr) return rej('invalid reply_id'); + // Get 'replyId' parameter + const [replyId, replyIdErr] = $(params.replyId).optional.id().$; + if (replyIdErr) return rej('invalid replyId'); let reply: IPost = null; if (replyId !== undefined) { @@ -141,14 +141,14 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { } // 返信対象が引用でないRepostだったらエラー - if (reply.repost_id && !reply.text && !reply.media_ids) { + if (reply.repostId && !reply.text && !reply.mediaIds) { return rej('cannot reply to repost'); } } - // Get 'channel_id' parameter - const [channelId, channelIdErr] = $(params.channel_id).optional.id().$; - if (channelIdErr) return rej('invalid channel_id'); + // Get 'channelId' parameter + const [channelId, channelIdErr] = $(params.channelId).optional.id().$; + if (channelIdErr) return rej('invalid channelId'); let channel: IChannel = null; if (channelId !== undefined) { @@ -162,12 +162,12 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { } // 返信対象の投稿がこのチャンネルじゃなかったらダメ - if (reply && !channelId.equals(reply.channel_id)) { + if (reply && !channelId.equals(reply.channelId)) { return rej('チャンネル内部からチャンネル外部の投稿に返信することはできません'); } // Repost対象の投稿がこのチャンネルじゃなかったらダメ - if (repost && !channelId.equals(repost.channel_id)) { + if (repost && !channelId.equals(repost.channelId)) { return rej('チャンネル内部からチャンネル外部の投稿をRepostすることはできません'); } @@ -177,12 +177,12 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { } } else { // 返信対象の投稿がチャンネルへの投稿だったらダメ - if (reply && reply.channel_id != null) { + if (reply && reply.channelId != null) { return rej('チャンネル外部からチャンネル内部の投稿に返信することはできません'); } // Repost対象の投稿がチャンネルへの投稿だったらダメ - if (repost && repost.channel_id != null) { + if (repost && repost.channelId != null) { return rej('チャンネル外部からチャンネル内部の投稿をRepostすることはできません'); } } @@ -206,7 +206,7 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { // テキストが無いかつ添付ファイルが無いかつRepostも無いかつ投票も無かったらエラー if (text === undefined && files === null && repost === null && poll === undefined) { - return rej('text, media_ids, repost_id or poll is required'); + return rej('text, mediaIds, repostId or poll is required'); } // 直近の投稿と重複してたらエラー @@ -214,14 +214,14 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { if (user.latest_post) { if (deepEqual({ text: user.latest_post.text, - reply: user.latest_post.reply_id ? user.latest_post.reply_id.toString() : null, - repost: user.latest_post.repost_id ? user.latest_post.repost_id.toString() : null, - media_ids: (user.latest_post.media_ids || []).map(id => id.toString()) + reply: user.latest_post.replyId ? user.latest_post.replyId.toString() : null, + repost: user.latest_post.repostId ? user.latest_post.repostId.toString() : null, + mediaIds: (user.latest_post.mediaIds || []).map(id => id.toString()) }, { text: text, reply: reply ? reply._id.toString() : null, repost: repost ? repost._id.toString() : null, - media_ids: (files || []).map(file => file._id.toString()) + mediaIds: (files || []).map(file => file._id.toString()) })) { return rej('duplicate'); } @@ -246,23 +246,23 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { // 投稿を作成 const post = await Post.insert({ - created_at: new Date(), - channel_id: channel ? channel._id : undefined, + createdAt: new Date(), + channelId: channel ? channel._id : undefined, index: channel ? channel.index + 1 : undefined, - media_ids: files ? files.map(file => file._id) : undefined, - reply_id: reply ? reply._id : undefined, - repost_id: repost ? repost._id : undefined, + mediaIds: files ? files.map(file => file._id) : undefined, + replyId: reply ? reply._id : undefined, + repostId: repost ? repost._id : undefined, poll: poll, text: text, tags: tags, - user_id: user._id, - app_id: app ? app._id : null, - via_mobile: viaMobile, + userId: user._id, + appId: app ? app._id : null, + viaMobile: viaMobile, geo, // 以下非正規化データ - _reply: reply ? { user_id: reply.user_id } : undefined, - _repost: repost ? { user_id: repost.user_id } : undefined, + _reply: reply ? { userId: reply.userId } : undefined, + _repost: repost ? { userId: repost.userId } : undefined, }); // Serialize @@ -293,10 +293,10 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { // Publish event if (!user._id.equals(mentionee)) { const mentioneeMutes = await Mute.find({ - muter_id: mentionee, - deleted_at: { $exists: false } + muterId: mentionee, + deletedAt: { $exists: false } }); - const mentioneesMutedUserIds = mentioneeMutes.map(m => m.mutee_id.toString()); + const mentioneesMutedUserIds = mentioneeMutes.map(m => m.muteeId.toString()); if (mentioneesMutedUserIds.indexOf(user._id.toString()) == -1) { event(mentionee, reason, postObj); pushSw(mentionee, reason, postObj); @@ -312,17 +312,17 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { // Fetch all followers const followers = await Following .find({ - followee_id: user._id, + followeeId: user._id, // 削除されたドキュメントは除く - deleted_at: { $exists: false } + deletedAt: { $exists: false } }, { - follower_id: true, + followerId: true, _id: false }); // Publish event to followers stream followers.forEach(following => - event(following.follower_id, 'post', postObj)); + event(following.followerId, 'post', postObj)); } // チャンネルへの投稿 @@ -339,21 +339,21 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { // Get channel watchers const watches = await ChannelWatching.find({ - channel_id: channel._id, + channelId: channel._id, // 削除されたドキュメントは除く - deleted_at: { $exists: false } + deletedAt: { $exists: false } }); // チャンネルの視聴者(のタイムライン)に配信 watches.forEach(w => { - event(w.user_id, 'post', postObj); + event(w.userId, 'post', postObj); }); } // Increment my posts count User.update({ _id: user._id }, { $inc: { - posts_count: 1 + postsCount: 1 } }); @@ -367,26 +367,26 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { }); // 自分自身へのリプライでない限りは通知を作成 - notify(reply.user_id, user._id, 'reply', { - post_id: post._id + notify(reply.userId, user._id, 'reply', { + postId: post._id }); // Fetch watchers Watching .find({ - post_id: reply._id, - user_id: { $ne: user._id }, + postId: reply._id, + userId: { $ne: user._id }, // 削除されたドキュメントは除く - deleted_at: { $exists: false } + deletedAt: { $exists: false } }, { fields: { - user_id: true + userId: true } }) .then(watchers => { watchers.forEach(watcher => { - notify(watcher.user_id, user._id, 'reply', { - post_id: post._id + notify(watcher.userId, user._id, 'reply', { + postId: post._id }); }); }); @@ -397,33 +397,33 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { } // Add mention - addMention(reply.user_id, 'reply'); + addMention(reply.userId, 'reply'); } // If it is repost if (repost) { // Notify const type = text ? 'quote' : 'repost'; - notify(repost.user_id, user._id, type, { - post_id: post._id + notify(repost.userId, user._id, type, { + postId: post._id }); // Fetch watchers Watching .find({ - post_id: repost._id, - user_id: { $ne: user._id }, + postId: repost._id, + userId: { $ne: user._id }, // 削除されたドキュメントは除く - deleted_at: { $exists: false } + deletedAt: { $exists: false } }, { fields: { - user_id: true + userId: true } }) .then(watchers => { watchers.forEach(watcher => { - notify(watcher.user_id, user._id, type, { - post_id: post._id + notify(watcher.userId, user._id, type, { + postId: post._id }); }); }); @@ -436,18 +436,18 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { // If it is quote repost if (text) { // Add mention - addMention(repost.user_id, 'quote'); + addMention(repost.userId, 'quote'); } else { // Publish event - if (!user._id.equals(repost.user_id)) { - event(repost.user_id, 'repost', postObj); + if (!user._id.equals(repost.userId)) { + event(repost.userId, 'repost', postObj); } } // 今までで同じ投稿をRepostしているか const existRepost = await Post.findOne({ - user_id: user._id, - repost_id: repost._id, + userId: user._id, + repostId: repost._id, _id: { $ne: post._id } @@ -494,15 +494,15 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { if (mentionee == null) return; // 既に言及されたユーザーに対する返信や引用repostの場合も無視 - if (reply && reply.user_id.equals(mentionee._id)) return; - if (repost && repost.user_id.equals(mentionee._id)) return; + if (reply && reply.userId.equals(mentionee._id)) return; + if (repost && repost.userId.equals(mentionee._id)) return; // Add mention addMention(mentionee._id, 'mention'); // Create notification notify(mentionee._id, user._id, 'mention', { - post_id: post._id + postId: post._id }); return; diff --git a/src/api/endpoints/posts/favorites/create.ts b/src/api/endpoints/posts/favorites/create.ts index f9dee271b..6100e10b2 100644 --- a/src/api/endpoints/posts/favorites/create.ts +++ b/src/api/endpoints/posts/favorites/create.ts @@ -13,9 +13,9 @@ import Post from '../../../models/post'; * @return {Promise} */ module.exports = (params, user) => new Promise(async (res, rej) => { - // Get 'post_id' parameter - const [postId, postIdErr] = $(params.post_id).id().$; - if (postIdErr) return rej('invalid post_id param'); + // Get 'postId' parameter + const [postId, postIdErr] = $(params.postId).id().$; + if (postIdErr) return rej('invalid postId param'); // Get favoritee const post = await Post.findOne({ @@ -28,8 +28,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // if already favorited const exist = await Favorite.findOne({ - post_id: post._id, - user_id: user._id + postId: post._id, + userId: user._id }); if (exist !== null) { @@ -38,9 +38,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Create favorite await Favorite.insert({ - created_at: new Date(), - post_id: post._id, - user_id: user._id + createdAt: new Date(), + postId: post._id, + userId: user._id }); // Send response diff --git a/src/api/endpoints/posts/favorites/delete.ts b/src/api/endpoints/posts/favorites/delete.ts index c4fe7d323..b1b4fcebc 100644 --- a/src/api/endpoints/posts/favorites/delete.ts +++ b/src/api/endpoints/posts/favorites/delete.ts @@ -13,9 +13,9 @@ import Post from '../../../models/post'; * @return {Promise} */ module.exports = (params, user) => new Promise(async (res, rej) => { - // Get 'post_id' parameter - const [postId, postIdErr] = $(params.post_id).id().$; - if (postIdErr) return rej('invalid post_id param'); + // Get 'postId' parameter + const [postId, postIdErr] = $(params.postId).id().$; + if (postIdErr) return rej('invalid postId param'); // Get favoritee const post = await Post.findOne({ @@ -28,8 +28,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // if already favorited const exist = await Favorite.findOne({ - post_id: post._id, - user_id: user._id + postId: post._id, + userId: user._id }); if (exist === null) { diff --git a/src/api/endpoints/posts/mentions.ts b/src/api/endpoints/posts/mentions.ts index 7127db0ad..da90583bb 100644 --- a/src/api/endpoints/posts/mentions.ts +++ b/src/api/endpoints/posts/mentions.ts @@ -48,7 +48,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { if (following) { const followingIds = await getFriends(user._id); - query.user_id = { + query.userId = { $in: followingIds }; } diff --git a/src/api/endpoints/posts/polls/recommendation.ts b/src/api/endpoints/posts/polls/recommendation.ts index 4a3fa3f55..19ef0975f 100644 --- a/src/api/endpoints/posts/polls/recommendation.ts +++ b/src/api/endpoints/posts/polls/recommendation.ts @@ -23,22 +23,22 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Get votes const votes = await Vote.find({ - user_id: user._id + userId: user._id }, { fields: { _id: false, - post_id: true + postId: true } }); - const nin = votes && votes.length != 0 ? votes.map(v => v.post_id) : []; + const nin = votes && votes.length != 0 ? votes.map(v => v.postId) : []; const posts = await Post .find({ _id: { $nin: nin }, - user_id: { + userId: { $ne: user._id }, poll: { diff --git a/src/api/endpoints/posts/polls/vote.ts b/src/api/endpoints/posts/polls/vote.ts index 16ce76a6f..e87474ae6 100644 --- a/src/api/endpoints/posts/polls/vote.ts +++ b/src/api/endpoints/posts/polls/vote.ts @@ -17,9 +17,9 @@ import { publishPostStream } from '../../../event'; * @return {Promise} */ module.exports = (params, user) => new Promise(async (res, rej) => { - // Get 'post_id' parameter - const [postId, postIdErr] = $(params.post_id).id().$; - if (postIdErr) return rej('invalid post_id param'); + // Get 'postId' parameter + const [postId, postIdErr] = $(params.postId).id().$; + if (postIdErr) return rej('invalid postId param'); // Get votee const post = await Post.findOne({ @@ -43,8 +43,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // if already voted const exist = await Vote.findOne({ - post_id: post._id, - user_id: user._id + postId: post._id, + userId: user._id }); if (exist !== null) { @@ -53,9 +53,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Create vote await Vote.insert({ - created_at: new Date(), - post_id: post._id, - user_id: user._id, + createdAt: new Date(), + postId: post._id, + userId: user._id, choice: choice }); @@ -73,27 +73,27 @@ module.exports = (params, user) => new Promise(async (res, rej) => { publishPostStream(post._id, 'poll_voted'); // Notify - notify(post.user_id, user._id, 'poll_vote', { - post_id: post._id, + notify(post.userId, user._id, 'poll_vote', { + postId: post._id, choice: choice }); // Fetch watchers Watching .find({ - post_id: post._id, - user_id: { $ne: user._id }, + postId: post._id, + userId: { $ne: user._id }, // 削除されたドキュメントは除く - deleted_at: { $exists: false } + deletedAt: { $exists: false } }, { fields: { - user_id: true + userId: true } }) .then(watchers => { watchers.forEach(watcher => { - notify(watcher.user_id, user._id, 'poll_vote', { - post_id: post._id, + notify(watcher.userId, user._id, 'poll_vote', { + postId: post._id, choice: choice }); }); diff --git a/src/api/endpoints/posts/reactions.ts b/src/api/endpoints/posts/reactions.ts index feb140ab4..f753ba7c2 100644 --- a/src/api/endpoints/posts/reactions.ts +++ b/src/api/endpoints/posts/reactions.ts @@ -13,9 +13,9 @@ import Reaction, { pack } from '../../models/post-reaction'; * @return {Promise} */ module.exports = (params, user) => new Promise(async (res, rej) => { - // Get 'post_id' parameter - const [postId, postIdErr] = $(params.post_id).id().$; - if (postIdErr) return rej('invalid post_id param'); + // Get 'postId' parameter + const [postId, postIdErr] = $(params.postId).id().$; + if (postIdErr) return rej('invalid postId param'); // Get 'limit' parameter const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$; @@ -41,8 +41,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Issue query const reactions = await Reaction .find({ - post_id: post._id, - deleted_at: { $exists: false } + postId: post._id, + deletedAt: { $exists: false } }, { limit: limit, skip: offset, diff --git a/src/api/endpoints/posts/reactions/create.ts b/src/api/endpoints/posts/reactions/create.ts index f77afed40..7031d28e5 100644 --- a/src/api/endpoints/posts/reactions/create.ts +++ b/src/api/endpoints/posts/reactions/create.ts @@ -18,9 +18,9 @@ import { publishPostStream, pushSw } from '../../../event'; * @return {Promise} */ module.exports = (params, user) => new Promise(async (res, rej) => { - // Get 'post_id' parameter - const [postId, postIdErr] = $(params.post_id).id().$; - if (postIdErr) return rej('invalid post_id param'); + // Get 'postId' parameter + const [postId, postIdErr] = $(params.postId).id().$; + if (postIdErr) return rej('invalid postId param'); // Get 'reaction' parameter const [reaction, reactionErr] = $(params.reaction).string().or([ @@ -46,15 +46,15 @@ module.exports = (params, user) => new Promise(async (res, rej) => { } // Myself - if (post.user_id.equals(user._id)) { + if (post.userId.equals(user._id)) { return rej('cannot react to my post'); } // if already reacted const exist = await Reaction.findOne({ - post_id: post._id, - user_id: user._id, - deleted_at: { $exists: false } + postId: post._id, + userId: user._id, + deletedAt: { $exists: false } }); if (exist !== null) { @@ -63,9 +63,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Create reaction await Reaction.insert({ - created_at: new Date(), - post_id: post._id, - user_id: user._id, + createdAt: new Date(), + postId: post._id, + userId: user._id, reaction: reaction }); @@ -83,33 +83,33 @@ module.exports = (params, user) => new Promise(async (res, rej) => { publishPostStream(post._id, 'reacted'); // Notify - notify(post.user_id, user._id, 'reaction', { - post_id: post._id, + notify(post.userId, user._id, 'reaction', { + postId: post._id, reaction: reaction }); - pushSw(post.user_id, 'reaction', { - user: await packUser(user, post.user_id), - post: await packPost(post, post.user_id), + pushSw(post.userId, 'reaction', { + user: await packUser(user, post.userId), + post: await packPost(post, post.userId), reaction: reaction }); // Fetch watchers Watching .find({ - post_id: post._id, - user_id: { $ne: user._id }, + postId: post._id, + userId: { $ne: user._id }, // 削除されたドキュメントは除く - deleted_at: { $exists: false } + deletedAt: { $exists: false } }, { fields: { - user_id: true + userId: true } }) .then(watchers => { watchers.forEach(watcher => { - notify(watcher.user_id, user._id, 'reaction', { - post_id: post._id, + notify(watcher.userId, user._id, 'reaction', { + postId: post._id, reaction: reaction }); }); diff --git a/src/api/endpoints/posts/reactions/delete.ts b/src/api/endpoints/posts/reactions/delete.ts index 922c57ab1..18fdabcdc 100644 --- a/src/api/endpoints/posts/reactions/delete.ts +++ b/src/api/endpoints/posts/reactions/delete.ts @@ -14,9 +14,9 @@ import Post from '../../../models/post'; * @return {Promise} */ module.exports = (params, user) => new Promise(async (res, rej) => { - // Get 'post_id' parameter - const [postId, postIdErr] = $(params.post_id).id().$; - if (postIdErr) return rej('invalid post_id param'); + // Get 'postId' parameter + const [postId, postIdErr] = $(params.postId).id().$; + if (postIdErr) return rej('invalid postId param'); // Fetch unreactee const post = await Post.findOne({ @@ -29,9 +29,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // if already unreacted const exist = await Reaction.findOne({ - post_id: post._id, - user_id: user._id, - deleted_at: { $exists: false } + postId: post._id, + userId: user._id, + deletedAt: { $exists: false } }); if (exist === null) { @@ -43,7 +43,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { _id: exist._id }, { $set: { - deleted_at: new Date() + deletedAt: new Date() } }); diff --git a/src/api/endpoints/posts/replies.ts b/src/api/endpoints/posts/replies.ts index 613c4fa24..db021505f 100644 --- a/src/api/endpoints/posts/replies.ts +++ b/src/api/endpoints/posts/replies.ts @@ -12,9 +12,9 @@ import Post, { pack } from '../../models/post'; * @return {Promise} */ module.exports = (params, user) => new Promise(async (res, rej) => { - // Get 'post_id' parameter - const [postId, postIdErr] = $(params.post_id).id().$; - if (postIdErr) return rej('invalid post_id param'); + // Get 'postId' parameter + const [postId, postIdErr] = $(params.postId).id().$; + if (postIdErr) return rej('invalid postId param'); // Get 'limit' parameter const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$; @@ -39,7 +39,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Issue query const replies = await Post - .find({ reply_id: post._id }, { + .find({ replyId: post._id }, { limit: limit, skip: offset, sort: { diff --git a/src/api/endpoints/posts/reposts.ts b/src/api/endpoints/posts/reposts.ts index 89ab0e3d5..c1645117f 100644 --- a/src/api/endpoints/posts/reposts.ts +++ b/src/api/endpoints/posts/reposts.ts @@ -12,9 +12,9 @@ import Post, { pack } from '../../models/post'; * @return {Promise} */ module.exports = (params, user) => new Promise(async (res, rej) => { - // Get 'post_id' parameter - const [postId, postIdErr] = $(params.post_id).id().$; - if (postIdErr) return rej('invalid post_id param'); + // Get 'postId' parameter + const [postId, postIdErr] = $(params.postId).id().$; + if (postIdErr) return rej('invalid postId param'); // Get 'limit' parameter const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$; @@ -47,7 +47,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { _id: -1 }; const query = { - repost_id: post._id + repostId: post._id } as any; if (sinceId) { sort._id = 1; diff --git a/src/api/endpoints/posts/search.ts b/src/api/endpoints/posts/search.ts index a36d1178a..e7906c95c 100644 --- a/src/api/endpoints/posts/search.ts +++ b/src/api/endpoints/posts/search.ts @@ -21,13 +21,13 @@ module.exports = (params, me) => new Promise(async (res, rej) => { const [text, textError] = $(params.text).optional.string().$; if (textError) return rej('invalid text param'); - // Get 'include_user_ids' parameter - const [includeUserIds = [], includeUserIdsErr] = $(params.include_user_ids).optional.array('id').$; - if (includeUserIdsErr) return rej('invalid include_user_ids param'); + // Get 'include_userIds' parameter + const [includeUserIds = [], includeUserIdsErr] = $(params.include_userIds).optional.array('id').$; + if (includeUserIdsErr) return rej('invalid include_userIds param'); - // Get 'exclude_user_ids' parameter - const [excludeUserIds = [], excludeUserIdsErr] = $(params.exclude_user_ids).optional.array('id').$; - if (excludeUserIdsErr) return rej('invalid exclude_user_ids param'); + // Get 'exclude_userIds' parameter + const [excludeUserIds = [], excludeUserIdsErr] = $(params.exclude_userIds).optional.array('id').$; + if (excludeUserIdsErr) return rej('invalid exclude_userIds param'); // Get 'include_user_usernames' parameter const [includeUserUsernames = [], includeUserUsernamesErr] = $(params.include_user_usernames).optional.array('string').$; @@ -81,7 +81,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => { if (includeUserUsernames != null) { const ids = (await Promise.all(includeUserUsernames.map(async (username) => { const _user = await User.findOne({ - username_lower: username.toLowerCase() + usernameLower: username.toLowerCase() }); return _user ? _user._id : null; }))).filter(id => id != null); @@ -92,7 +92,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => { if (excludeUserUsernames != null) { const ids = (await Promise.all(excludeUserUsernames.map(async (username) => { const _user = await User.findOne({ - username_lower: username.toLowerCase() + usernameLower: username.toLowerCase() }); return _user ? _user._id : null; }))).filter(id => id != null); @@ -143,13 +143,13 @@ async function search( if (includeUserIds && includeUserIds.length != 0) { push({ - user_id: { + userId: { $in: includeUserIds } }); } else if (excludeUserIds && excludeUserIds.length != 0) { push({ - user_id: { + userId: { $nin: excludeUserIds } }); @@ -158,7 +158,7 @@ async function search( if (following != null && me != null) { const ids = await getFriends(me._id, false); push({ - user_id: following ? { + userId: following ? { $in: ids } : { $nin: ids.concat(me._id) @@ -168,45 +168,45 @@ async function search( if (me != null) { const mutes = await Mute.find({ - muter_id: me._id, - deleted_at: { $exists: false } + muterId: me._id, + deletedAt: { $exists: false } }); - const mutedUserIds = mutes.map(m => m.mutee_id); + const mutedUserIds = mutes.map(m => m.muteeId); switch (mute) { case 'mute_all': push({ - user_id: { + userId: { $nin: mutedUserIds }, - '_reply.user_id': { + '_reply.userId': { $nin: mutedUserIds }, - '_repost.user_id': { + '_repost.userId': { $nin: mutedUserIds } }); break; case 'mute_related': push({ - '_reply.user_id': { + '_reply.userId': { $nin: mutedUserIds }, - '_repost.user_id': { + '_repost.userId': { $nin: mutedUserIds } }); break; case 'mute_direct': push({ - user_id: { + userId: { $nin: mutedUserIds } }); break; case 'direct_only': push({ - user_id: { + userId: { $in: mutedUserIds } }); @@ -214,11 +214,11 @@ async function search( case 'related_only': push({ $or: [{ - '_reply.user_id': { + '_reply.userId': { $in: mutedUserIds } }, { - '_repost.user_id': { + '_repost.userId': { $in: mutedUserIds } }] @@ -227,15 +227,15 @@ async function search( case 'all_only': push({ $or: [{ - user_id: { + userId: { $in: mutedUserIds } }, { - '_reply.user_id': { + '_reply.userId': { $in: mutedUserIds } }, { - '_repost.user_id': { + '_repost.userId': { $in: mutedUserIds } }] @@ -247,7 +247,7 @@ async function search( if (reply != null) { if (reply) { push({ - reply_id: { + replyId: { $exists: true, $ne: null } @@ -255,11 +255,11 @@ async function search( } else { push({ $or: [{ - reply_id: { + replyId: { $exists: false } }, { - reply_id: null + replyId: null }] }); } @@ -268,7 +268,7 @@ async function search( if (repost != null) { if (repost) { push({ - repost_id: { + repostId: { $exists: true, $ne: null } @@ -276,11 +276,11 @@ async function search( } else { push({ $or: [{ - repost_id: { + repostId: { $exists: false } }, { - repost_id: null + repostId: null }] }); } @@ -289,7 +289,7 @@ async function search( if (media != null) { if (media) { push({ - media_ids: { + mediaIds: { $exists: true, $ne: null } @@ -297,11 +297,11 @@ async function search( } else { push({ $or: [{ - media_ids: { + mediaIds: { $exists: false } }, { - media_ids: null + mediaIds: null }] }); } @@ -330,7 +330,7 @@ async function search( if (sinceDate) { push({ - created_at: { + createdAt: { $gt: new Date(sinceDate) } }); @@ -338,7 +338,7 @@ async function search( if (untilDate) { push({ - created_at: { + createdAt: { $lt: new Date(untilDate) } }); diff --git a/src/api/endpoints/posts/show.ts b/src/api/endpoints/posts/show.ts index 383949059..bb4bcdb79 100644 --- a/src/api/endpoints/posts/show.ts +++ b/src/api/endpoints/posts/show.ts @@ -12,9 +12,9 @@ import Post, { pack } from '../../models/post'; * @return {Promise} */ module.exports = (params, user) => new Promise(async (res, rej) => { - // Get 'post_id' parameter - const [postId, postIdErr] = $(params.post_id).id().$; - if (postIdErr) return rej('invalid post_id param'); + // Get 'postId' parameter + const [postId, postIdErr] = $(params.postId).id().$; + if (postIdErr) return rej('invalid postId param'); // Get post const post = await Post.findOne({ diff --git a/src/api/endpoints/posts/timeline.ts b/src/api/endpoints/posts/timeline.ts index c41cfdb8b..c7cb8032e 100644 --- a/src/api/endpoints/posts/timeline.ts +++ b/src/api/endpoints/posts/timeline.ts @@ -49,17 +49,17 @@ module.exports = async (params, user, app) => { // Watchしているチャンネルを取得 watchingChannelIds: ChannelWatching.find({ - user_id: user._id, + userId: user._id, // 削除されたドキュメントは除く - deleted_at: { $exists: false } - }).then(watches => watches.map(w => w.channel_id)), + deletedAt: { $exists: false } + }).then(watches => watches.map(w => w.channelId)), // ミュートしているユーザーを取得 mutedUserIds: Mute.find({ - muter_id: user._id, + muterId: user._id, // 削除されたドキュメントは除く - deleted_at: { $exists: false } - }).then(ms => ms.map(m => m.mutee_id)) + deletedAt: { $exists: false } + }).then(ms => ms.map(m => m.muteeId)) }); //#region Construct query @@ -70,31 +70,31 @@ module.exports = async (params, user, app) => { const query = { $or: [{ // フォローしている人のタイムラインへの投稿 - user_id: { + userId: { $in: followingIds }, // 「タイムラインへの」投稿に限定するためにチャンネルが指定されていないもののみに限る $or: [{ - channel_id: { + channelId: { $exists: false } }, { - channel_id: null + channelId: null }] }, { // Watchしているチャンネルへの投稿 - channel_id: { + channelId: { $in: watchingChannelIds } }], // mute - user_id: { + userId: { $nin: mutedUserIds }, - '_reply.user_id': { + '_reply.userId': { $nin: mutedUserIds }, - '_repost.user_id': { + '_repost.userId': { $nin: mutedUserIds }, } as any; @@ -110,11 +110,11 @@ module.exports = async (params, user, app) => { }; } else if (sinceDate) { sort._id = 1; - query.created_at = { + query.createdAt = { $gt: new Date(sinceDate) }; } else if (untilDate) { - query.created_at = { + query.createdAt = { $lt: new Date(untilDate) }; } diff --git a/src/api/endpoints/posts/trend.ts b/src/api/endpoints/posts/trend.ts index caded92bf..3f92f0616 100644 --- a/src/api/endpoints/posts/trend.ts +++ b/src/api/endpoints/posts/trend.ts @@ -38,7 +38,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { if (pollErr) return rej('invalid poll param'); const query = { - created_at: { + createdAt: { $gte: new Date(Date.now() - ms('1days')) }, repost_count: { @@ -47,15 +47,15 @@ module.exports = (params, user) => new Promise(async (res, rej) => { } as any; if (reply != undefined) { - query.reply_id = reply ? { $exists: true, $ne: null } : null; + query.replyId = reply ? { $exists: true, $ne: null } : null; } if (repost != undefined) { - query.repost_id = repost ? { $exists: true, $ne: null } : null; + query.repostId = repost ? { $exists: true, $ne: null } : null; } if (media != undefined) { - query.media_ids = media ? { $exists: true, $ne: null } : null; + query.mediaIds = media ? { $exists: true, $ne: null } : null; } if (poll != undefined) { diff --git a/src/api/endpoints/stats.ts b/src/api/endpoints/stats.ts index a6084cd17..eee6f4870 100644 --- a/src/api/endpoints/stats.ts +++ b/src/api/endpoints/stats.ts @@ -15,7 +15,7 @@ import User from '../models/user'; * schema: * type: object * properties: - * posts_count: + * postsCount: * description: count of all posts of misskey * type: number * users_count: @@ -42,7 +42,7 @@ module.exports = params => new Promise(async (res, rej) => { .count(); res({ - posts_count: postsCount, + postsCount: postsCount, users_count: usersCount }); }); diff --git a/src/api/endpoints/sw/register.ts b/src/api/endpoints/sw/register.ts index 99406138d..1542e1dbe 100644 --- a/src/api/endpoints/sw/register.ts +++ b/src/api/endpoints/sw/register.ts @@ -28,11 +28,11 @@ module.exports = async (params, user, _, isSecure) => new Promise(async (res, re // if already subscribed const exist = await Subscription.findOne({ - user_id: user._id, + userId: user._id, endpoint: endpoint, auth: auth, publickey: publickey, - deleted_at: { $exists: false } + deletedAt: { $exists: false } }); if (exist !== null) { @@ -40,7 +40,7 @@ module.exports = async (params, user, _, isSecure) => new Promise(async (res, re } await Subscription.insert({ - user_id: user._id, + userId: user._id, endpoint: endpoint, auth: auth, publickey: publickey diff --git a/src/api/endpoints/username/available.ts b/src/api/endpoints/username/available.ts index aac7fadf5..f23cdbd85 100644 --- a/src/api/endpoints/username/available.ts +++ b/src/api/endpoints/username/available.ts @@ -20,7 +20,7 @@ module.exports = async (params) => new Promise(async (res, rej) => { const exist = await User .count({ host: null, - username_lower: username.toLowerCase() + usernameLower: username.toLowerCase() }, { limit: 1 }); diff --git a/src/api/endpoints/users.ts b/src/api/endpoints/users.ts index 4acc13c28..393c3479c 100644 --- a/src/api/endpoints/users.ts +++ b/src/api/endpoints/users.ts @@ -29,11 +29,11 @@ module.exports = (params, me) => new Promise(async (res, rej) => { if (sort) { if (sort == '+follower') { _sort = { - followers_count: -1 + followersCount: -1 }; } else if (sort == '-follower') { _sort = { - followers_count: 1 + followersCount: 1 }; } } else { diff --git a/src/api/endpoints/users/followers.ts b/src/api/endpoints/users/followers.ts index b0fb83c68..fc09cfa2c 100644 --- a/src/api/endpoints/users/followers.ts +++ b/src/api/endpoints/users/followers.ts @@ -15,9 +15,9 @@ import getFriends from '../../common/get-friends'; * @return {Promise} */ module.exports = (params, me) => new Promise(async (res, rej) => { - // Get 'user_id' parameter - const [userId, userIdErr] = $(params.user_id).id().$; - if (userIdErr) return rej('invalid user_id param'); + // Get 'userId' parameter + const [userId, userIdErr] = $(params.userId).id().$; + if (userIdErr) return rej('invalid userId param'); // Get 'iknow' parameter const [iknow = false, iknowErr] = $(params.iknow).optional.boolean().$; @@ -46,8 +46,8 @@ module.exports = (params, me) => new Promise(async (res, rej) => { // Construct query const query = { - followee_id: user._id, - deleted_at: { $exists: false } + followeeId: user._id, + deletedAt: { $exists: false } } as any; // ログインしていてかつ iknow フラグがあるとき @@ -55,7 +55,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => { // Get my friends const myFriends = await getFriends(me._id); - query.follower_id = { + query.followerId = { $in: myFriends }; } @@ -82,7 +82,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => { // Serialize const users = await Promise.all(following.map(async f => - await pack(f.follower_id, me, { detail: true }))); + await pack(f.followerId, me, { detail: true }))); // Response res({ diff --git a/src/api/endpoints/users/following.ts b/src/api/endpoints/users/following.ts index 8e88431e9..3387dab36 100644 --- a/src/api/endpoints/users/following.ts +++ b/src/api/endpoints/users/following.ts @@ -15,9 +15,9 @@ import getFriends from '../../common/get-friends'; * @return {Promise} */ module.exports = (params, me) => new Promise(async (res, rej) => { - // Get 'user_id' parameter - const [userId, userIdErr] = $(params.user_id).id().$; - if (userIdErr) return rej('invalid user_id param'); + // Get 'userId' parameter + const [userId, userIdErr] = $(params.userId).id().$; + if (userIdErr) return rej('invalid userId param'); // Get 'iknow' parameter const [iknow = false, iknowErr] = $(params.iknow).optional.boolean().$; @@ -46,8 +46,8 @@ module.exports = (params, me) => new Promise(async (res, rej) => { // Construct query const query = { - follower_id: user._id, - deleted_at: { $exists: false } + followerId: user._id, + deletedAt: { $exists: false } } as any; // ログインしていてかつ iknow フラグがあるとき @@ -55,7 +55,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => { // Get my friends const myFriends = await getFriends(me._id); - query.followee_id = { + query.followeeId = { $in: myFriends }; } @@ -82,7 +82,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => { // Serialize const users = await Promise.all(following.map(async f => - await pack(f.followee_id, me, { detail: true }))); + await pack(f.followeeId, me, { detail: true }))); // Response res({ diff --git a/src/api/endpoints/users/get_frequently_replied_users.ts b/src/api/endpoints/users/get_frequently_replied_users.ts index 87f4f77a5..991c5555b 100644 --- a/src/api/endpoints/users/get_frequently_replied_users.ts +++ b/src/api/endpoints/users/get_frequently_replied_users.ts @@ -6,9 +6,9 @@ import Post from '../../models/post'; import User, { pack } from '../../models/user'; module.exports = (params, me) => new Promise(async (res, rej) => { - // Get 'user_id' parameter - const [userId, userIdErr] = $(params.user_id).id().$; - if (userIdErr) return rej('invalid user_id param'); + // Get 'userId' parameter + const [userId, userIdErr] = $(params.userId).id().$; + if (userIdErr) return rej('invalid userId param'); // Get 'limit' parameter const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$; @@ -29,8 +29,8 @@ module.exports = (params, me) => new Promise(async (res, rej) => { // Fetch recent posts const recentPosts = await Post.find({ - user_id: user._id, - reply_id: { + userId: user._id, + replyId: { $exists: true, $ne: null } @@ -41,7 +41,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => { limit: 1000, fields: { _id: false, - reply_id: true + replyId: true } }); @@ -52,15 +52,15 @@ module.exports = (params, me) => new Promise(async (res, rej) => { const replyTargetPosts = await Post.find({ _id: { - $in: recentPosts.map(p => p.reply_id) + $in: recentPosts.map(p => p.replyId) }, - user_id: { + userId: { $ne: user._id } }, { fields: { _id: false, - user_id: true + userId: true } }); @@ -68,7 +68,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => { // Extract replies from recent posts replyTargetPosts.forEach(post => { - const userId = post.user_id.toString(); + const userId = post.userId.toString(); if (repliedUsers[userId]) { repliedUsers[userId]++; } else { diff --git a/src/api/endpoints/users/posts.ts b/src/api/endpoints/users/posts.ts index 3c84bf0d8..f08be91c4 100644 --- a/src/api/endpoints/users/posts.ts +++ b/src/api/endpoints/users/posts.ts @@ -14,16 +14,16 @@ import User from '../../models/user'; * @return {Promise} */ module.exports = (params, me) => new Promise(async (res, rej) => { - // Get 'user_id' parameter - const [userId, userIdErr] = $(params.user_id).optional.id().$; - if (userIdErr) return rej('invalid user_id param'); + // Get 'userId' parameter + const [userId, userIdErr] = $(params.userId).optional.id().$; + if (userIdErr) return rej('invalid userId param'); // Get 'username' parameter const [username, usernameErr] = $(params.username).optional.string().$; if (usernameErr) return rej('invalid username param'); if (userId === undefined && username === undefined) { - return rej('user_id or pair of username and host is required'); + return rej('userId or pair of username and host is required'); } // Get 'host' parameter @@ -31,7 +31,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => { if (hostErr) return rej('invalid host param'); if (userId === undefined && host === undefined) { - return rej('user_id or pair of username and host is required'); + return rej('userId or pair of username and host is required'); } // Get 'include_replies' parameter @@ -69,7 +69,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => { const q = userId !== undefined ? { _id: userId } - : { username_lower: username.toLowerCase(), host_lower: getHostLower(host) } ; + : { usernameLower: username.toLowerCase(), hostLower: getHostLower(host) } ; // Lookup user const user = await User.findOne(q, { @@ -88,7 +88,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => { }; const query = { - user_id: user._id + userId: user._id } as any; if (sinceId) { @@ -102,21 +102,21 @@ module.exports = (params, me) => new Promise(async (res, rej) => { }; } else if (sinceDate) { sort._id = 1; - query.created_at = { + query.createdAt = { $gt: new Date(sinceDate) }; } else if (untilDate) { - query.created_at = { + query.createdAt = { $lt: new Date(untilDate) }; } if (!includeReplies) { - query.reply_id = null; + query.replyId = null; } if (withMedia) { - query.media_ids = { + query.mediaIds = { $exists: true, $ne: null }; diff --git a/src/api/endpoints/users/recommendation.ts b/src/api/endpoints/users/recommendation.ts index 45d90f422..c5297cdc5 100644 --- a/src/api/endpoints/users/recommendation.ts +++ b/src/api/endpoints/users/recommendation.ts @@ -32,7 +32,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => { }, $or: [ { - 'account.last_used_at': { + 'account.lastUsedAt': { $gte: new Date(Date.now() - ms('7days')) } }, { @@ -43,7 +43,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => { limit: limit, skip: offset, sort: { - followers_count: -1 + followersCount: -1 } }); diff --git a/src/api/endpoints/users/search.ts b/src/api/endpoints/users/search.ts index 39e2ff989..1cc25e61b 100644 --- a/src/api/endpoints/users/search.ts +++ b/src/api/endpoints/users/search.ts @@ -41,7 +41,7 @@ async function byNative(res, rej, me, query, offset, max) { const users = await User .find({ $or: [{ - username_lower: new RegExp(escapedQuery.replace('@', '').toLowerCase()) + usernameLower: new RegExp(escapedQuery.replace('@', '').toLowerCase()) }, { name: new RegExp(escapedQuery) }] diff --git a/src/api/endpoints/users/search_by_username.ts b/src/api/endpoints/users/search_by_username.ts index 9c5e1905a..24e9c98e7 100644 --- a/src/api/endpoints/users/search_by_username.ts +++ b/src/api/endpoints/users/search_by_username.ts @@ -26,7 +26,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => { const users = await User .find({ - username_lower: new RegExp(query.toLowerCase()) + usernameLower: new RegExp(query.toLowerCase()) }, { limit: limit, skip: offset diff --git a/src/api/endpoints/users/show.ts b/src/api/endpoints/users/show.ts index 78df23f33..16411dddc 100644 --- a/src/api/endpoints/users/show.ts +++ b/src/api/endpoints/users/show.ts @@ -56,9 +56,9 @@ function webFingerAndVerify(query, verifier) { module.exports = (params, me) => new Promise(async (res, rej) => { let user; - // Get 'user_id' parameter - const [userId, userIdErr] = $(params.user_id).optional.id().$; - if (userIdErr) return rej('invalid user_id param'); + // Get 'userId' parameter + const [userId, userIdErr] = $(params.userId).optional.id().$; + if (userIdErr) return rej('invalid userId param'); // Get 'username' parameter const [username, usernameErr] = $(params.username).optional.string().$; @@ -69,25 +69,25 @@ module.exports = (params, me) => new Promise(async (res, rej) => { if (hostErr) return rej('invalid username param'); if (userId === undefined && typeof username !== 'string') { - return rej('user_id or pair of username and host is required'); + return rej('userId or pair of username and host is required'); } // Lookup user if (typeof host === 'string') { - const username_lower = username.toLowerCase(); - const host_lower_ascii = toASCII(host).toLowerCase(); - const host_lower = toUnicode(host_lower_ascii); + const usernameLower = username.toLowerCase(); + const hostLower_ascii = toASCII(host).toLowerCase(); + const hostLower = toUnicode(hostLower_ascii); - user = await findUser({ username_lower, host_lower }); + user = await findUser({ usernameLower, hostLower }); if (user === null) { - const acct_lower = `${username_lower}@${host_lower_ascii}`; + const acct_lower = `${usernameLower}@${hostLower_ascii}`; let activityStreams; let finger; - let followers_count; - let following_count; + let followersCount; + let followingCount; let likes_count; - let posts_count; + let postsCount; if (!validateUsername(username)) { return rej('username validation failed'); @@ -122,7 +122,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => { activityStreams['@context'] === 'https://www.w3.org/ns/activitystreams') && activityStreams.type === 'Person' && typeof activityStreams.preferredUsername === 'string' && - activityStreams.preferredUsername.toLowerCase() === username_lower && + activityStreams.preferredUsername.toLowerCase() === usernameLower && isValidName(activityStreams.name) && isValidDescription(activityStreams.summary) )) { @@ -130,7 +130,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => { } try { - [followers_count, following_count, likes_count, posts_count] = await Promise.all([ + [followersCount, followingCount, likes_count, postsCount] = await Promise.all([ getCollectionCount(activityStreams.followers), getCollectionCount(activityStreams.following), getCollectionCount(activityStreams.liked), @@ -145,21 +145,21 @@ module.exports = (params, me) => new Promise(async (res, rej) => { // Create user user = await User.insert({ - avatar_id: null, - banner_id: null, - created_at: new Date(), + avatarId: null, + bannerId: null, + createdAt: new Date(), description: summaryDOM.textContent, - followers_count, - following_count, + followersCount, + followingCount, name: activityStreams.name, - posts_count, + postsCount, likes_count, liked_count: 0, - drive_capacity: 1073741824, // 1GB + driveCapacity: 1073741824, // 1GB username: username, - username_lower, + usernameLower, host: toUnicode(finger.subject.replace(/^.*?@/, '')), - host_lower, + hostLower, account: { uri: activityStreams.id, }, @@ -182,18 +182,18 @@ module.exports = (params, me) => new Promise(async (res, rej) => { User.update({ _id: user._id }, { $set: { - avatar_id: icon._id, - banner_id: image._id, + avatarId: icon._id, + bannerId: image._id, }, }); - user.avatar_id = icon._id; - user.banner_id = icon._id; + user.avatarId = icon._id; + user.bannerId = icon._id; } } else { const q = userId !== undefined ? { _id: userId } - : { username_lower: username.toLowerCase(), host: null }; + : { usernameLower: username.toLowerCase(), host: null }; user = await findUser(q); diff --git a/src/api/models/channel-watching.ts b/src/api/models/channel-watching.ts index 23886d0c7..ec0c8135d 100644 --- a/src/api/models/channel-watching.ts +++ b/src/api/models/channel-watching.ts @@ -9,6 +9,6 @@ export interface IChannelWatching { _id: mongo.ObjectID; createdAt: Date; deletedAt: Date; - channel_id: mongo.ObjectID; + channelId: mongo.ObjectID; userId: mongo.ObjectID; } diff --git a/src/api/models/channel.ts b/src/api/models/channel.ts index a753a4eba..aab21db07 100644 --- a/src/api/models/channel.ts +++ b/src/api/models/channel.ts @@ -63,7 +63,7 @@ export const pack = ( //#region Watchしているかどうか const watch = await Watching.findOne({ userId: meId, - channel_id: _channel.id, + channelId: _channel.id, deletedAt: { $exists: false } }); diff --git a/src/api/models/messaging-message.ts b/src/api/models/messaging-message.ts index 026b23cf3..9a2f81387 100644 --- a/src/api/models/messaging-message.ts +++ b/src/api/models/messaging-message.ts @@ -66,16 +66,16 @@ export const pack = ( } // Populate user - _message.user = await packUser(_message.user_id, me); + _message.user = await packUser(_message.userId, me); - if (_message.file_id) { + if (_message.fileId) { // Populate file - _message.file = await packFile(_message.file_id); + _message.file = await packFile(_message.fileId); } if (opts.populateRecipient) { // Populate recipient - _message.recipient = await packUser(_message.recipient_id, me); + _message.recipient = await packUser(_message.recipientId, me); } resolve(_message); diff --git a/src/api/models/notification.ts b/src/api/models/notification.ts index fa7049d31..910f53947 100644 --- a/src/api/models/notification.ts +++ b/src/api/models/notification.ts @@ -9,7 +9,7 @@ export default Notification; export interface INotification { _id: mongo.ObjectID; - created_at: Date; + createdAt: Date; /** * 通知の受信者 @@ -19,7 +19,7 @@ export interface INotification { /** * 通知の受信者 */ - notifiee_id: mongo.ObjectID; + notifieeId: mongo.ObjectID; /** * イニシエータ(initiator)、Origin。通知を行う原因となったユーザー @@ -29,7 +29,7 @@ export interface INotification { /** * イニシエータ(initiator)、Origin。通知を行う原因となったユーザー */ - notifier_id: mongo.ObjectID; + notifierId: mongo.ObjectID; /** * 通知の種類。 @@ -46,7 +46,7 @@ export interface INotification { /** * 通知が読まれたかどうか */ - is_read: Boolean; + isRead: Boolean; } /** @@ -75,15 +75,15 @@ export const pack = (notification: any) => new Promise(async (resolve, reje _notification.id = _notification._id; delete _notification._id; - // Rename notifier_id to user_id - _notification.user_id = _notification.notifier_id; - delete _notification.notifier_id; + // Rename notifierId to userId + _notification.userId = _notification.notifierId; + delete _notification.notifierId; - const me = _notification.notifiee_id; - delete _notification.notifiee_id; + const me = _notification.notifieeId; + delete _notification.notifieeId; // Populate notifier - _notification.user = await packUser(_notification.user_id, me); + _notification.user = await packUser(_notification.userId, me); switch (_notification.type) { case 'follow': @@ -96,7 +96,7 @@ export const pack = (notification: any) => new Promise(async (resolve, reje case 'reaction': case 'poll_vote': // Populate post - _notification.post = await packPost(_notification.post_id, me); + _notification.post = await packPost(_notification.postId, me); break; default: console.error(`Unknown type: ${_notification.type}`); diff --git a/src/api/models/othello-game.ts b/src/api/models/othello-game.ts index b9e57632d..70e0c696c 100644 --- a/src/api/models/othello-game.ts +++ b/src/api/models/othello-game.ts @@ -97,10 +97,10 @@ export const pack = ( } // Populate user - _game.user1 = await packUser(_game.user1_id, meId); - _game.user2 = await packUser(_game.user2_id, meId); - if (_game.winner_id) { - _game.winner = await packUser(_game.winner_id, meId); + _game.user1 = await packUser(_game.user1Id, meId); + _game.user2 = await packUser(_game.user2Id, meId); + if (_game.winnerId) { + _game.winner = await packUser(_game.winnerId, meId); } else { _game.winner = null; } diff --git a/src/api/models/othello-matching.ts b/src/api/models/othello-matching.ts index 9c84d7fb9..8beedf72c 100644 --- a/src/api/models/othello-matching.ts +++ b/src/api/models/othello-matching.ts @@ -37,8 +37,8 @@ export const pack = ( delete _matching._id; // Populate user - _matching.parent = await packUser(_matching.parent_id, meId); - _matching.child = await packUser(_matching.child_id, meId); + _matching.parent = await packUser(_matching.parentId, meId); + _matching.child = await packUser(_matching.childId, meId); resolve(_matching); }); diff --git a/src/api/models/post-reaction.ts b/src/api/models/post-reaction.ts index f581f0153..82613eb26 100644 --- a/src/api/models/post-reaction.ts +++ b/src/api/models/post-reaction.ts @@ -47,7 +47,7 @@ export const pack = ( delete _reaction._id; // Populate user - _reaction.user = await packUser(_reaction.user_id, me); + _reaction.user = await packUser(_reaction.userId, me); resolve(_reaction); }); diff --git a/src/api/models/post.ts b/src/api/models/post.ts index fc4425651..4ab840b5e 100644 --- a/src/api/models/post.ts +++ b/src/api/models/post.ts @@ -100,21 +100,21 @@ export const pack = async ( } // Populate user - _post.user = packUser(_post.user_id, meId); + _post.user = packUser(_post.userId, meId); // Populate app - if (_post.app_id) { - _post.app = packApp(_post.app_id); + if (_post.appId) { + _post.app = packApp(_post.appId); } // Populate channel - if (_post.channel_id) { - _post.channel = packChannel(_post.channel_id); + if (_post.channelId) { + _post.channel = packChannel(_post.channelId); } // Populate media - if (_post.media_ids) { - _post.media = Promise.all(_post.media_ids.map(fileId => + if (_post.mediaIds) { + _post.media = Promise.all(_post.mediaIds.map(fileId => packFile(fileId) )); } @@ -124,7 +124,7 @@ export const pack = async ( // Get previous post info _post.prev = (async () => { const prev = await Post.findOne({ - user_id: _post.user_id, + userId: _post.userId, _id: { $lt: id } @@ -142,7 +142,7 @@ export const pack = async ( // Get next post info _post.next = (async () => { const next = await Post.findOne({ - user_id: _post.user_id, + userId: _post.userId, _id: { $gt: id } @@ -157,16 +157,16 @@ export const pack = async ( return next ? next._id : null; })(); - if (_post.reply_id) { + if (_post.replyId) { // Populate reply to post - _post.reply = pack(_post.reply_id, meId, { + _post.reply = pack(_post.replyId, meId, { detail: false }); } - if (_post.repost_id) { + if (_post.repostId) { // Populate repost - _post.repost = pack(_post.repost_id, meId, { + _post.repost = pack(_post.repostId, meId, { detail: _post.text == null }); } @@ -176,8 +176,8 @@ export const pack = async ( _post.poll = (async (poll) => { const vote = await Vote .findOne({ - user_id: meId, - post_id: id + userId: meId, + postId: id }); if (vote != null) { @@ -196,9 +196,9 @@ export const pack = async ( _post.my_reaction = (async () => { const reaction = await Reaction .findOne({ - user_id: meId, - post_id: id, - deleted_at: { $exists: false } + userId: meId, + postId: id, + deletedAt: { $exists: false } }); if (reaction) { diff --git a/src/api/models/user.ts b/src/api/models/user.ts index 9aa7c4efa..8c68b06df 100644 --- a/src/api/models/user.ts +++ b/src/api/models/user.ts @@ -47,24 +47,25 @@ export type ILocalAccount = { token: string; twitter: { accessToken: string; - access_token_secret: string; - user_id: string; - screen_name: string; + accessTokenSecret: string; + userId: string; + screenName: string; }; line: { - user_id: string; + userId: string; }; profile: { location: string; birthday: string; // 'YYYY-MM-DD' tags: string[]; }; - last_used_at: Date; - is_bot: boolean; - is_pro: boolean; - two_factor_secret: string; - two_factor_enabled: boolean; - client_settings: any; + lastUsedAt: Date; + isBot: boolean; + isPro: boolean; + twoFactorSecret: string; + twoFactorEnabled: boolean; + twoFactorTempSecret: string; + clientSettings: any; settings: any; }; @@ -74,33 +75,33 @@ export type IRemoteAccount = { export type IUser = { _id: mongo.ObjectID; - created_at: Date; - deleted_at: Date; - followers_count: number; - following_count: number; + createdAt: Date; + deletedAt: Date; + followersCount: number; + followingCount: number; name: string; - posts_count: number; - drive_capacity: number; + postsCount: number; + driveCapacity: number; username: string; - username_lower: string; - avatar_id: mongo.ObjectID; - banner_id: mongo.ObjectID; + usernameLower: string; + avatarId: mongo.ObjectID; + bannerId: mongo.ObjectID; data: any; description: string; latest_post: IPost; - pinned_post_id: mongo.ObjectID; - is_suspended: boolean; + pinnedPostId: mongo.ObjectID; + isSuspended: boolean; keywords: string[]; host: string; - host_lower: string; + hostLower: string; account: ILocalAccount | IRemoteAccount; }; export function init(user): IUser { user._id = new mongo.ObjectID(user._id); - user.avatar_id = new mongo.ObjectID(user.avatar_id); - user.banner_id = new mongo.ObjectID(user.banner_id); - user.pinned_post_id = new mongo.ObjectID(user.pinned_post_id); + user.avatarId = new mongo.ObjectID(user.avatarId); + user.bannerId = new mongo.ObjectID(user.bannerId); + user.pinnedPostId = new mongo.ObjectID(user.pinnedPostId); return user; } @@ -131,7 +132,7 @@ export const pack = ( const fields = opts.detail ? { } : { 'account.settings': false, - 'account.client_settings': false, + 'account.clientSettings': false, 'account.profile': false, 'account.keywords': false, 'account.domains': false @@ -173,12 +174,12 @@ export const pack = ( delete _user.account.keypair; delete _user.account.password; delete _user.account.token; - delete _user.account.two_factor_temp_secret; - delete _user.account.two_factor_secret; - delete _user.username_lower; + delete _user.account.twoFactorTempSecret; + delete _user.account.twoFactorSecret; + delete _user.usernameLower; if (_user.account.twitter) { - delete _user.account.twitter.access_token; - delete _user.account.twitter.access_token_secret; + delete _user.account.twitter.accessToken; + delete _user.account.twitter.accessTokenSecret; } delete _user.account.line; @@ -186,36 +187,36 @@ export const pack = ( if (!opts.includeSecrets) { delete _user.account.email; delete _user.account.settings; - delete _user.account.client_settings; + delete _user.account.clientSettings; } if (!opts.detail) { - delete _user.account.two_factor_enabled; + delete _user.account.twoFactorEnabled; } } - _user.avatar_url = _user.avatar_id != null - ? `${config.drive_url}/${_user.avatar_id}` + _user.avatar_url = _user.avatarId != null + ? `${config.drive_url}/${_user.avatarId}` : `${config.drive_url}/default-avatar.jpg`; - _user.banner_url = _user.banner_id != null - ? `${config.drive_url}/${_user.banner_id}` + _user.banner_url = _user.bannerId != null + ? `${config.drive_url}/${_user.bannerId}` : null; if (!meId || !meId.equals(_user.id) || !opts.detail) { - delete _user.avatar_id; - delete _user.banner_id; + delete _user.avatarId; + delete _user.bannerId; - delete _user.drive_capacity; + delete _user.driveCapacity; } if (meId && !meId.equals(_user.id)) { // Whether the user is following _user.is_following = (async () => { const follow = await Following.findOne({ - follower_id: meId, - followee_id: _user.id, - deleted_at: { $exists: false } + followerId: meId, + followeeId: _user.id, + deletedAt: { $exists: false } }); return follow !== null; })(); @@ -223,9 +224,9 @@ export const pack = ( // Whether the user is followed _user.is_followed = (async () => { const follow2 = await Following.findOne({ - follower_id: _user.id, - followee_id: meId, - deleted_at: { $exists: false } + followerId: _user.id, + followeeId: meId, + deletedAt: { $exists: false } }); return follow2 !== null; })(); @@ -233,18 +234,18 @@ export const pack = ( // Whether the user is muted _user.is_muted = (async () => { const mute = await Mute.findOne({ - muter_id: meId, - mutee_id: _user.id, - deleted_at: { $exists: false } + muterId: meId, + muteeId: _user.id, + deletedAt: { $exists: false } }); return mute !== null; })(); } if (opts.detail) { - if (_user.pinned_post_id) { + if (_user.pinnedPostId) { // Populate pinned post - _user.pinned_post = packPost(_user.pinned_post_id, meId, { + _user.pinnedPost = packPost(_user.pinnedPostId, meId, { detail: true }); } @@ -254,16 +255,16 @@ export const pack = ( // Get following you know count _user.following_you_know_count = Following.count({ - followee_id: { $in: myFollowingIds }, - follower_id: _user.id, - deleted_at: { $exists: false } + followeeId: { $in: myFollowingIds }, + followerId: _user.id, + deletedAt: { $exists: false } }); // Get followers you know count _user.followers_you_know_count = Following.count({ - followee_id: _user.id, - follower_id: { $in: myFollowingIds }, - deleted_at: { $exists: false } + followeeId: _user.id, + followerId: { $in: myFollowingIds }, + deletedAt: { $exists: false } }); } } @@ -322,7 +323,7 @@ export const packForAp = ( "name": _user.name, "summary": _user.description, "icon": [ - `${config.drive_url}/${_user.avatar_id}` + `${config.drive_url}/${_user.avatarId}` ] }); }); diff --git a/src/api/private/signin.ts b/src/api/private/signin.ts index 00dcb8afc..c6b5d19ea 100644 --- a/src/api/private/signin.ts +++ b/src/api/private/signin.ts @@ -32,7 +32,7 @@ export default async (req: express.Request, res: express.Response) => { // Fetch user const user: IUser = await User.findOne({ - username_lower: username.toLowerCase(), + usernameLower: username.toLowerCase(), host: null }, { fields: { @@ -54,9 +54,9 @@ export default async (req: express.Request, res: express.Response) => { const same = await bcrypt.compare(password, account.password); if (same) { - if (account.two_factor_enabled) { + if (account.twoFactorEnabled) { const verified = (speakeasy as any).totp.verify({ - secret: account.two_factor_secret, + secret: account.twoFactorSecret, encoding: 'base32', token: token }); @@ -79,8 +79,8 @@ export default async (req: express.Request, res: express.Response) => { // Append signin history const record = await Signin.insert({ - created_at: new Date(), - user_id: user._id, + createdAt: new Date(), + userId: user._id, ip: req.ip, headers: req.headers, success: same diff --git a/src/api/private/signup.ts b/src/api/private/signup.ts index 29d75b62f..1304ccb54 100644 --- a/src/api/private/signup.ts +++ b/src/api/private/signup.ts @@ -64,7 +64,7 @@ export default async (req: express.Request, res: express.Response) => { // Fetch exist user that same username const usernameExist = await User .count({ - username_lower: username.toLowerCase(), + usernameLower: username.toLowerCase(), host: null }, { limit: 1 @@ -107,19 +107,19 @@ export default async (req: express.Request, res: express.Response) => { // Create account const account: IUser = await User.insert({ - avatar_id: null, - banner_id: null, - created_at: new Date(), + avatarId: null, + bannerId: null, + createdAt: new Date(), description: null, - followers_count: 0, - following_count: 0, + followersCount: 0, + followingCount: 0, name: name, - posts_count: 0, - drive_capacity: 1073741824, // 1GB + postsCount: 0, + driveCapacity: 1073741824, // 1GB username: username, - username_lower: username.toLowerCase(), + usernameLower: username.toLowerCase(), host: null, - host_lower: null, + hostLower: null, account: { keypair: generateKeypair(), token: secret, @@ -139,7 +139,7 @@ export default async (req: express.Request, res: express.Response) => { settings: { auto_watch: true }, - client_settings: { + clientSettings: { home: homeData } } diff --git a/src/api/service/github.ts b/src/api/service/github.ts index 1c78267c0..598f36b0c 100644 --- a/src/api/service/github.ts +++ b/src/api/service/github.ts @@ -9,7 +9,7 @@ module.exports = async (app: express.Application) => { if (config.github_bot == null) return; const bot = await User.findOne({ - username_lower: config.github_bot.username.toLowerCase() + usernameLower: config.github_bot.username.toLowerCase() }); if (bot == null) { diff --git a/src/api/service/twitter.ts b/src/api/service/twitter.ts index c1f2e48a6..67c401efa 100644 --- a/src/api/service/twitter.ts +++ b/src/api/service/twitter.ts @@ -128,7 +128,7 @@ module.exports = (app: express.Application) => { const user = await User.findOne({ host: null, - 'account.twitter.user_id': result.userId + 'account.twitter.userId': result.userId }); if (user == null) { @@ -155,10 +155,10 @@ module.exports = (app: express.Application) => { }, { $set: { 'account.twitter': { - access_token: result.accessToken, - access_token_secret: result.accessTokenSecret, - user_id: result.userId, - screen_name: result.screenName + accessToken: result.accessToken, + accessTokenSecret: result.accessTokenSecret, + userId: result.userId, + screenName: result.screenName } } }); diff --git a/src/api/stream/home.ts b/src/api/stream/home.ts index 1ef0f33b4..291be0824 100644 --- a/src/api/stream/home.ts +++ b/src/api/stream/home.ts @@ -14,10 +14,10 @@ export default async function(request: websocket.request, connection: websocket. subscriber.subscribe(`misskey:user-stream:${user._id}`); const mute = await Mute.find({ - muter_id: user._id, - deleted_at: { $exists: false } + muterId: user._id, + deletedAt: { $exists: false } }); - const mutedUserIds = mute.map(m => m.mutee_id.toString()); + const mutedUserIds = mute.map(m => m.muteeId.toString()); subscriber.on('message', async (channel, data) => { switch (channel.split(':')[1]) { @@ -26,17 +26,17 @@ export default async function(request: websocket.request, connection: websocket. const x = JSON.parse(data); if (x.type == 'post') { - if (mutedUserIds.indexOf(x.body.user_id) != -1) { + if (mutedUserIds.indexOf(x.body.userId) != -1) { return; } - if (x.body.reply != null && mutedUserIds.indexOf(x.body.reply.user_id) != -1) { + if (x.body.reply != null && mutedUserIds.indexOf(x.body.reply.userId) != -1) { return; } - if (x.body.repost != null && mutedUserIds.indexOf(x.body.repost.user_id) != -1) { + if (x.body.repost != null && mutedUserIds.indexOf(x.body.repost.userId) != -1) { return; } } else if (x.type == 'notification') { - if (mutedUserIds.indexOf(x.body.user_id) != -1) { + if (mutedUserIds.indexOf(x.body.userId) != -1) { return; } } @@ -74,7 +74,7 @@ export default async function(request: websocket.request, connection: websocket. // Update lastUsedAt User.update({ _id: user._id }, { $set: { - 'account.last_used_at': new Date() + 'account.lastUsedAt': new Date() } }); break; diff --git a/src/api/stream/othello-game.ts b/src/api/stream/othello-game.ts index 45a931c7e..e48d93cdd 100644 --- a/src/api/stream/othello-game.ts +++ b/src/api/stream/othello-game.ts @@ -62,10 +62,10 @@ export default function(request: websocket.request, connection: websocket.connec async function updateSettings(settings) { const game = await OthelloGame.findOne({ _id: gameId }); - if (game.is_started) return; - if (!game.user1_id.equals(user._id) && !game.user2_id.equals(user._id)) return; - if (game.user1_id.equals(user._id) && game.user1_accepted) return; - if (game.user2_id.equals(user._id) && game.user2_accepted) return; + if (game.isStarted) return; + if (!game.user1Id.equals(user._id) && !game.user2Id.equals(user._id)) return; + if (game.user1Id.equals(user._id) && game.user1Accepted) return; + if (game.user2Id.equals(user._id) && game.user2Accepted) return; await OthelloGame.update({ _id: gameId }, { $set: { @@ -79,10 +79,10 @@ export default function(request: websocket.request, connection: websocket.connec async function initForm(form) { const game = await OthelloGame.findOne({ _id: gameId }); - if (game.is_started) return; - if (!game.user1_id.equals(user._id) && !game.user2_id.equals(user._id)) return; + if (game.isStarted) return; + if (!game.user1Id.equals(user._id) && !game.user2Id.equals(user._id)) return; - const set = game.user1_id.equals(user._id) ? { + const set = game.user1Id.equals(user._id) ? { form1: form } : { form2: form @@ -93,7 +93,7 @@ export default function(request: websocket.request, connection: websocket.connec }); publishOthelloGameStream(gameId, 'init-form', { - user_id: user._id, + userId: user._id, form }); } @@ -101,10 +101,10 @@ export default function(request: websocket.request, connection: websocket.connec async function updateForm(id, value) { const game = await OthelloGame.findOne({ _id: gameId }); - if (game.is_started) return; - if (!game.user1_id.equals(user._id) && !game.user2_id.equals(user._id)) return; + if (game.isStarted) return; + if (!game.user1Id.equals(user._id) && !game.user2Id.equals(user._id)) return; - const form = game.user1_id.equals(user._id) ? game.form2 : game.form1; + const form = game.user1Id.equals(user._id) ? game.form2 : game.form1; const item = form.find(i => i.id == id); @@ -112,7 +112,7 @@ export default function(request: websocket.request, connection: websocket.connec item.value = value; - const set = game.user1_id.equals(user._id) ? { + const set = game.user1Id.equals(user._id) ? { form2: form } : { form1: form @@ -123,7 +123,7 @@ export default function(request: websocket.request, connection: websocket.connec }); publishOthelloGameStream(gameId, 'update-form', { - user_id: user._id, + userId: user._id, id, value }); @@ -132,7 +132,7 @@ export default function(request: websocket.request, connection: websocket.connec async function message(message) { message.id = Math.random(); publishOthelloGameStream(gameId, 'message', { - user_id: user._id, + userId: user._id, message }); } @@ -140,36 +140,36 @@ export default function(request: websocket.request, connection: websocket.connec async function accept(accept: boolean) { const game = await OthelloGame.findOne({ _id: gameId }); - if (game.is_started) return; + if (game.isStarted) return; let bothAccepted = false; - if (game.user1_id.equals(user._id)) { + if (game.user1Id.equals(user._id)) { await OthelloGame.update({ _id: gameId }, { $set: { - user1_accepted: accept + user1Accepted: accept } }); publishOthelloGameStream(gameId, 'change-accepts', { user1: accept, - user2: game.user2_accepted + user2: game.user2Accepted }); - if (accept && game.user2_accepted) bothAccepted = true; - } else if (game.user2_id.equals(user._id)) { + if (accept && game.user2Accepted) bothAccepted = true; + } else if (game.user2Id.equals(user._id)) { await OthelloGame.update({ _id: gameId }, { $set: { - user2_accepted: accept + user2Accepted: accept } }); publishOthelloGameStream(gameId, 'change-accepts', { - user1: game.user1_accepted, + user1: game.user1Accepted, user2: accept }); - if (accept && game.user1_accepted) bothAccepted = true; + if (accept && game.user1Accepted) bothAccepted = true; } else { return; } @@ -178,8 +178,8 @@ export default function(request: websocket.request, connection: websocket.connec // 3秒後、まだacceptされていたらゲーム開始 setTimeout(async () => { const freshGame = await OthelloGame.findOne({ _id: gameId }); - if (freshGame == null || freshGame.is_started || freshGame.is_ended) return; - if (!freshGame.user1_accepted || !freshGame.user2_accepted) return; + if (freshGame == null || freshGame.isStarted || freshGame.isEnded) return; + if (!freshGame.user1Accepted || !freshGame.user2Accepted) return; let bw: number; if (freshGame.settings.bw == 'random') { @@ -198,8 +198,8 @@ export default function(request: websocket.request, connection: websocket.connec await OthelloGame.update({ _id: gameId }, { $set: { - started_at: new Date(), - is_started: true, + startedAt: new Date(), + isStarted: true, black: bw, 'settings.map': map } @@ -207,17 +207,17 @@ export default function(request: websocket.request, connection: websocket.connec //#region 盤面に最初から石がないなどして始まった瞬間に勝敗が決定する場合があるのでその処理 const o = new Othello(map, { - isLlotheo: freshGame.settings.is_llotheo, - canPutEverywhere: freshGame.settings.can_put_everywhere, - loopedBoard: freshGame.settings.looped_board + isLlotheo: freshGame.settings.isLlotheo, + canPutEverywhere: freshGame.settings.canPutEverywhere, + loopedBoard: freshGame.settings.loopedBoard }); if (o.isEnded) { let winner; if (o.winner === true) { - winner = freshGame.black == 1 ? freshGame.user1_id : freshGame.user2_id; + winner = freshGame.black == 1 ? freshGame.user1Id : freshGame.user2Id; } else if (o.winner === false) { - winner = freshGame.black == 1 ? freshGame.user2_id : freshGame.user1_id; + winner = freshGame.black == 1 ? freshGame.user2Id : freshGame.user1Id; } else { winner = null; } @@ -226,13 +226,13 @@ export default function(request: websocket.request, connection: websocket.connec _id: gameId }, { $set: { - is_ended: true, - winner_id: winner + isEnded: true, + winnerId: winner } }); publishOthelloGameStream(gameId, 'ended', { - winner_id: winner, + winnerId: winner, game: await pack(gameId, user) }); } @@ -247,14 +247,14 @@ export default function(request: websocket.request, connection: websocket.connec async function set(pos) { const game = await OthelloGame.findOne({ _id: gameId }); - if (!game.is_started) return; - if (game.is_ended) return; - if (!game.user1_id.equals(user._id) && !game.user2_id.equals(user._id)) return; + if (!game.isStarted) return; + if (game.isEnded) return; + if (!game.user1Id.equals(user._id) && !game.user2Id.equals(user._id)) return; const o = new Othello(game.settings.map, { - isLlotheo: game.settings.is_llotheo, - canPutEverywhere: game.settings.can_put_everywhere, - loopedBoard: game.settings.looped_board + isLlotheo: game.settings.isLlotheo, + canPutEverywhere: game.settings.canPutEverywhere, + loopedBoard: game.settings.loopedBoard }); game.logs.forEach(log => { @@ -262,7 +262,7 @@ export default function(request: websocket.request, connection: websocket.connec }); const myColor = - (game.user1_id.equals(user._id) && game.black == 1) || (game.user2_id.equals(user._id) && game.black == 2) + (game.user1Id.equals(user._id) && game.black == 1) || (game.user2Id.equals(user._id) && game.black == 2) ? true : false; @@ -272,9 +272,9 @@ export default function(request: websocket.request, connection: websocket.connec let winner; if (o.isEnded) { if (o.winner === true) { - winner = game.black == 1 ? game.user1_id : game.user2_id; + winner = game.black == 1 ? game.user1Id : game.user2Id; } else if (o.winner === false) { - winner = game.black == 1 ? game.user2_id : game.user1_id; + winner = game.black == 1 ? game.user2Id : game.user1Id; } else { winner = null; } @@ -293,8 +293,8 @@ export default function(request: websocket.request, connection: websocket.connec }, { $set: { crc32, - is_ended: o.isEnded, - winner_id: winner + isEnded: o.isEnded, + winnerId: winner }, $push: { logs: log @@ -307,7 +307,7 @@ export default function(request: websocket.request, connection: websocket.connec if (o.isEnded) { publishOthelloGameStream(gameId, 'ended', { - winner_id: winner, + winnerId: winner, game: await pack(gameId, user) }); } @@ -316,7 +316,7 @@ export default function(request: websocket.request, connection: websocket.connec async function check(crc32) { const game = await OthelloGame.findOne({ _id: gameId }); - if (!game.is_started) return; + if (!game.isStarted) return; // 互換性のため if (game.crc32 == null) return; diff --git a/src/api/stream/othello.ts b/src/api/stream/othello.ts index bd3b4a763..55c993ec8 100644 --- a/src/api/stream/othello.ts +++ b/src/api/stream/othello.ts @@ -18,11 +18,11 @@ export default function(request: websocket.request, connection: websocket.connec case 'ping': if (msg.id == null) return; const matching = await Matching.findOne({ - parent_id: user._id, - child_id: new mongo.ObjectID(msg.id) + parentId: user._id, + childId: new mongo.ObjectID(msg.id) }); if (matching == null) return; - publishUserStream(matching.child_id, 'othello_invited', await pack(matching, matching.child_id)); + publishUserStream(matching.childId, 'othello_invited', await pack(matching, matching.childId)); break; } }); diff --git a/src/api/streaming.ts b/src/api/streaming.ts index a6759e414..31319fcab 100644 --- a/src/api/streaming.ts +++ b/src/api/streaming.ts @@ -110,7 +110,7 @@ function authenticate(token: string): Promise { // Fetch user const user: IUser = await User - .findOne({ _id: accessToken.user_id }); + .findOne({ _id: accessToken.userId }); resolve(user); } diff --git a/src/common/get-post-summary.ts b/src/common/get-post-summary.ts index 6e8f65708..8d0033064 100644 --- a/src/common/get-post-summary.ts +++ b/src/common/get-post-summary.ts @@ -22,7 +22,7 @@ const summarize = (post: any): string => { } // 返信のとき - if (post.reply_id) { + if (post.replyId) { if (post.reply) { summary += ` RE: ${summarize(post.reply)}`; } else { @@ -31,7 +31,7 @@ const summarize = (post: any): string => { } // Repostのとき - if (post.repost_id) { + if (post.repostId) { if (post.repost) { summary += ` RP: ${summarize(post.repost)}`; } else { diff --git a/src/common/othello/ai/back.ts b/src/common/othello/ai/back.ts index 27dbc3952..52f01ff97 100644 --- a/src/common/othello/ai/back.ts +++ b/src/common/othello/ai/back.ts @@ -44,7 +44,7 @@ process.on('message', async msg => { //#region TLに投稿する const game = msg.body; const url = `${conf.url}/othello/${game.id}`; - const user = game.user1_id == id ? game.user2 : game.user1; + const user = game.user1Id == id ? game.user2 : game.user1; const isSettai = form[0].value === 0; const text = isSettai ? `?[${user.name}](${conf.url}/@${user.username})さんの接待を始めました!` @@ -68,23 +68,23 @@ process.on('message', async msg => { }); //#region TLに投稿する - const user = game.user1_id == id ? game.user2 : game.user1; + const user = game.user1Id == id ? game.user2 : game.user1; const isSettai = form[0].value === 0; const text = isSettai - ? msg.body.winner_id === null + ? msg.body.winnerId === null ? `?[${user.name}](${conf.url}/@${user.username})さんに接待で引き分けました...` - : msg.body.winner_id == id + : msg.body.winnerId == id ? `?[${user.name}](${conf.url}/@${user.username})さんに接待で勝ってしまいました...` : `?[${user.name}](${conf.url}/@${user.username})さんに接待で負けてあげました♪` - : msg.body.winner_id === null + : msg.body.winnerId === null ? `?[${user.name}](${conf.url}/@${user.username})さんと引き分けました~` - : msg.body.winner_id == id + : msg.body.winnerId == id ? `?[${user.name}](${conf.url}/@${user.username})さんに勝ちました♪` : `?[${user.name}](${conf.url}/@${user.username})さんに負けました...`; await request.post(`${conf.api_url}/posts/create`, { json: { i, - repost_id: post.id, + repostId: post.id, text: text } }); @@ -114,9 +114,9 @@ function onGameStarted(g) { // オセロエンジン初期化 o = new Othello(game.settings.map, { - isLlotheo: game.settings.is_llotheo, - canPutEverywhere: game.settings.can_put_everywhere, - loopedBoard: game.settings.looped_board + isLlotheo: game.settings.isLlotheo, + canPutEverywhere: game.settings.canPutEverywhere, + loopedBoard: game.settings.loopedBoard }); // 各マスの価値を計算しておく @@ -141,7 +141,7 @@ function onGameStarted(g) { return count >= 4 ? 1 : 0; }); - botColor = game.user1_id == id && game.black == 1 || game.user2_id == id && game.black == 2; + botColor = game.user1Id == id && game.black == 1 || game.user2Id == id && game.black == 2; if (botColor) { think(); @@ -188,7 +188,7 @@ function think() { }); // ロセオならスコアを反転 - if (game.settings.is_llotheo) score = -score; + if (game.settings.isLlotheo) score = -score; // 接待ならスコアを反転 if (isSettai) score = -score; @@ -234,7 +234,7 @@ function think() { let score; - if (game.settings.is_llotheo) { + if (game.settings.isLlotheo) { // 勝ちは勝ちでも、より自分の石を少なくした方が美しい勝ちだと判定する score = o.winner ? base - (o.blackCount * 100) : base - (o.whiteCount * 100); } else { @@ -317,7 +317,7 @@ function think() { let score; - if (game.settings.is_llotheo) { + if (game.settings.isLlotheo) { // 勝ちは勝ちでも、より自分の石を少なくした方が美しい勝ちだと判定する score = o.winner ? base - (o.blackCount * 100) : base - (o.whiteCount * 100); } else { diff --git a/src/common/othello/ai/front.ts b/src/common/othello/ai/front.ts index d892afbed..e5496132f 100644 --- a/src/common/othello/ai/front.ts +++ b/src/common/othello/ai/front.ts @@ -48,12 +48,12 @@ homeStream.on('message', message => { if (msg.type == 'mention' || msg.type == 'reply') { const post = msg.body; - if (post.user_id == id) return; + if (post.userId == id) return; // リアクションする request.post(`${conf.api_url}/posts/reactions/create`, { json: { i, - post_id: post.id, + postId: post.id, reaction: 'love' } }); @@ -62,12 +62,12 @@ homeStream.on('message', message => { if (post.text.indexOf('オセロ') > -1) { request.post(`${conf.api_url}/posts/create`, { json: { i, - reply_id: post.id, + replyId: post.id, text: '良いですよ~' } }); - invite(post.user_id); + invite(post.userId); } } } @@ -79,12 +79,12 @@ homeStream.on('message', message => { if (message.text.indexOf('オセロ') > -1) { request.post(`${conf.api_url}/messaging/messages/create`, { json: { i, - user_id: message.user_id, + userId: message.userId, text: '良いですよ~' } }); - invite(message.user_id); + invite(message.userId); } } } @@ -94,7 +94,7 @@ homeStream.on('message', message => { function invite(userId) { request.post(`${conf.api_url}/othello/match`, { json: { i, - user_id: userId + userId: userId } }); } @@ -225,7 +225,7 @@ async function onInviteMe(inviter) { const game = await request.post(`${conf.api_url}/othello/match`, { json: { i, - user_id: inviter.id + userId: inviter.id } }); diff --git a/src/common/user/get-summary.ts b/src/common/user/get-summary.ts index f9b7125e3..b314a5cef 100644 --- a/src/common/user/get-summary.ts +++ b/src/common/user/get-summary.ts @@ -7,7 +7,7 @@ import getAcct from './get-acct'; */ export default function(user: IUser): string { let string = `${user.name} (@${getAcct(user)})\n` + - `${user.posts_count}投稿、${user.following_count}フォロー、${user.followers_count}フォロワー\n`; + `${user.postsCount}投稿、${user.followingCount}フォロー、${user.followersCount}フォロワー\n`; if (user.host === null) { const account = user.account as ILocalAccount; diff --git a/src/config.ts b/src/config.ts index 6d3e7740b..0d8df39f4 100644 --- a/src/config.ts +++ b/src/config.ts @@ -80,7 +80,7 @@ type Source = { }; line_bot?: { channel_secret: string; - channel_access_token: string; + channel_accessToken: string; }; analysis?: { mecab_command?: string; diff --git a/src/tools/analysis/extract-user-domains.ts b/src/tools/analysis/extract-user-domains.ts index bc120f5c1..0c4249a1b 100644 --- a/src/tools/analysis/extract-user-domains.ts +++ b/src/tools/analysis/extract-user-domains.ts @@ -50,7 +50,7 @@ function extractDomainsOne(id) { // Fetch recent posts const recentPosts = await Post.find({ - user_id: id, + userId: id, text: { $exists: true } diff --git a/src/tools/analysis/extract-user-keywords.ts b/src/tools/analysis/extract-user-keywords.ts index b99ca9321..08d02e705 100644 --- a/src/tools/analysis/extract-user-keywords.ts +++ b/src/tools/analysis/extract-user-keywords.ts @@ -96,7 +96,7 @@ function extractKeywordsOne(id) { // Fetch recent posts const recentPosts = await Post.find({ - user_id: id, + userId: id, text: { $exists: true } diff --git a/src/tools/analysis/predict-user-interst.ts b/src/tools/analysis/predict-user-interst.ts index 99bdfa420..6904daeb0 100644 --- a/src/tools/analysis/predict-user-interst.ts +++ b/src/tools/analysis/predict-user-interst.ts @@ -6,7 +6,7 @@ export async function predictOne(id) { // TODO: repostなども含める const recentPosts = await Post.find({ - user_id: id, + userId: id, category: { $exists: true } diff --git a/src/web/app/auth/views/form.vue b/src/web/app/auth/views/form.vue index d86ed58b3..9d9e8cdb1 100644 --- a/src/web/app/auth/views/form.vue +++ b/src/web/app/auth/views/form.vue @@ -7,7 +7,7 @@

{{ app.name }}

-

{{ app.name_id }}

+

{{ app.nameId }}

{{ app.description }}

diff --git a/src/web/app/ch/tags/channel.tag b/src/web/app/ch/tags/channel.tag index dc4b8e142..225129088 100644 --- a/src/web/app/ch/tags/channel.tag +++ b/src/web/app/ch/tags/channel.tag @@ -77,7 +77,7 @@ // チャンネル概要読み込み this.$root.$data.os.api('channels/show', { - channel_id: this.id + channelId: this.id }).then(channel => { if (fetched) { Progress.done(); @@ -96,7 +96,7 @@ // 投稿読み込み this.$root.$data.os.api('channels/posts', { - channel_id: this.id + channelId: this.id }).then(posts => { if (fetched) { Progress.done(); @@ -125,7 +125,7 @@ this.posts.unshift(post); this.update(); - if (document.hidden && this.$root.$data.os.isSignedIn && post.user_id !== this.$root.$data.os.i.id) { + if (document.hidden && this.$root.$data.os.isSignedIn && post.userId !== this.$root.$data.os.i.id) { this.unreadCount++; document.title = `(${this.unreadCount}) ${this.channel.title} | Misskey`; } @@ -140,7 +140,7 @@ this.watch = () => { this.$root.$data.os.api('channels/watch', { - channel_id: this.id + channelId: this.id }).then(() => { this.channel.is_watching = true; this.update(); @@ -151,7 +151,7 @@ this.unwatch = () => { this.$root.$data.os.api('channels/unwatch', { - channel_id: this.id + channelId: this.id }).then(() => { this.channel.is_watching = false; this.update(); @@ -166,8 +166,8 @@
{ post.index }: { post.user.name } - - + + ID:{ acct }
@@ -328,9 +328,9 @@ this.$root.$data.os.api('posts/create', { text: this.$refs.text.value == '' ? undefined : this.$refs.text.value, - media_ids: files, - reply_id: this.reply ? this.reply.id : undefined, - channel_id: this.channel.id + mediaIds: files, + replyId: this.reply ? this.reply.id : undefined, + channelId: this.channel.id }).then(data => { this.clear(); }).catch(err => { diff --git a/src/web/app/common/define-widget.ts b/src/web/app/common/define-widget.ts index d8d29873a..27db59b5e 100644 --- a/src/web/app/common/define-widget.ts +++ b/src/web/app/common/define-widget.ts @@ -56,14 +56,14 @@ export default function(data: { id: this.id, data: newProps }).then(() => { - (this as any).os.i.account.client_settings.mobile_home.find(w => w.id == this.id).data = newProps; + (this as any).os.i.account.clientSettings.mobile_home.find(w => w.id == this.id).data = newProps; }); } else { (this as any).api('i/update_home', { id: this.id, data: newProps }).then(() => { - (this as any).os.i.account.client_settings.home.find(w => w.id == this.id).data = newProps; + (this as any).os.i.account.clientSettings.home.find(w => w.id == this.id).data = newProps; }); } }, { diff --git a/src/web/app/common/mios.ts b/src/web/app/common/mios.ts index 2c6c9988e..bcb8b6067 100644 --- a/src/web/app/common/mios.ts +++ b/src/web/app/common/mios.ts @@ -294,12 +294,12 @@ export default class MiOS extends EventEmitter { const fetched = me => { if (me) { // デフォルトの設定をマージ - me.account.client_settings = Object.assign({ + me.account.clientSettings = Object.assign({ fetchOnScroll: true, showMaps: true, showPostFormOnTopOfTl: false, gradientWindowHeader: false - }, me.account.client_settings); + }, me.account.clientSettings); // ローカルストレージにキャッシュ localStorage.setItem('me', JSON.stringify(me)); diff --git a/src/web/app/common/scripts/streaming/home.ts b/src/web/app/common/scripts/streaming/home.ts index ffcf6e536..c19861940 100644 --- a/src/web/app/common/scripts/streaming/home.ts +++ b/src/web/app/common/scripts/streaming/home.ts @@ -16,7 +16,7 @@ export class HomeStream extends Stream { // 最終利用日時を更新するため定期的にaliveメッセージを送信 setInterval(() => { this.send({ type: 'alive' }); - me.account.last_used_at = new Date(); + me.account.lastUsedAt = new Date(); }, 1000 * 60); // 自分の情報が更新されたとき diff --git a/src/web/app/common/views/components/messaging-room.form.vue b/src/web/app/common/views/components/messaging-room.form.vue index 01886b19c..704f2016d 100644 --- a/src/web/app/common/views/components/messaging-room.form.vue +++ b/src/web/app/common/views/components/messaging-room.form.vue @@ -151,9 +151,9 @@ export default Vue.extend({ send() { this.sending = true; (this as any).api('messaging/messages/create', { - user_id: this.user.id, + userId: this.user.id, text: this.text ? this.text : undefined, - file_id: this.file ? this.file.id : undefined + fileId: this.file ? this.file.id : undefined }).then(message => { this.clear(); }).catch(err => { @@ -173,7 +173,7 @@ export default Vue.extend({ const data = JSON.parse(localStorage.getItem('message_drafts') || '{}'); data[this.draftId] = { - updated_at: new Date(), + updatedAt: new Date(), data: { text: this.text, file: this.file diff --git a/src/web/app/common/views/components/messaging-room.message.vue b/src/web/app/common/views/components/messaging-room.message.vue index 5f2eb1ba8..d21cce1a0 100644 --- a/src/web/app/common/views/components/messaging-room.message.vue +++ b/src/web/app/common/views/components/messaging-room.message.vue @@ -5,7 +5,7 @@
-

%i18n:common.tags.mk-messaging-message.is-read%

+

%i18n:common.tags.mk-messaging-message.is-read%

@@ -25,7 +25,7 @@
- +
@@ -43,7 +43,7 @@ export default Vue.extend({ return getAcct(this.message.user); }, isMe(): boolean { - return this.message.user_id == (this as any).os.i.id; + return this.message.userId == (this as any).os.i.id; }, urls(): string[] { if (this.message.ast) { diff --git a/src/web/app/common/views/components/messaging-room.vue b/src/web/app/common/views/components/messaging-room.vue index 6ff808b61..36c53fd3f 100644 --- a/src/web/app/common/views/components/messaging-room.vue +++ b/src/web/app/common/views/components/messaging-room.vue @@ -52,8 +52,8 @@ export default Vue.extend({ computed: { _messages(): any[] { return (this.messages as any).map(message => { - const date = new Date(message.created_at).getDate(); - const month = new Date(message.created_at).getMonth() + 1; + const date = new Date(message.createdAt).getDate(); + const month = new Date(message.createdAt).getMonth() + 1; message._date = date; message._datetext = `${month}月 ${date}日`; return message; @@ -123,7 +123,7 @@ export default Vue.extend({ const max = this.existMoreMessages ? 20 : 10; (this as any).api('messaging/messages', { - user_id: this.user.id, + userId: this.user.id, limit: max + 1, until_id: this.existMoreMessages ? this.messages[0].id : undefined }).then(messages => { @@ -158,7 +158,7 @@ export default Vue.extend({ const isBottom = this.isBottom(); this.messages.push(message); - if (message.user_id != (this as any).os.i.id && !document.hidden) { + if (message.userId != (this as any).os.i.id && !document.hidden) { this.connection.send({ type: 'read', id: message.id @@ -170,7 +170,7 @@ export default Vue.extend({ this.$nextTick(() => { this.scrollToBottom(); }); - } else if (message.user_id != (this as any).os.i.id) { + } else if (message.userId != (this as any).os.i.id) { // Notify this.notify('%i18n:common.tags.mk-messaging-room.new-message%'); } @@ -181,7 +181,7 @@ export default Vue.extend({ ids.forEach(id => { if (this.messages.some(x => x.id == id)) { const exist = this.messages.map(x => x.id).indexOf(id); - this.messages[exist].is_read = true; + this.messages[exist].isRead = true; } }); }, @@ -223,7 +223,7 @@ export default Vue.extend({ onVisibilitychange() { if (document.hidden) return; this.messages.forEach(message => { - if (message.user_id !== (this as any).os.i.id && !message.is_read) { + if (message.userId !== (this as any).os.i.id && !message.isRead) { this.connection.send({ type: 'read', id: message.id diff --git a/src/web/app/common/views/components/messaging.vue b/src/web/app/common/views/components/messaging.vue index 88574b94d..0272c6707 100644 --- a/src/web/app/common/views/components/messaging.vue +++ b/src/web/app/common/views/components/messaging.vue @@ -26,7 +26,7 @@ class="user" :href="`/i/messaging/${getAcct(isMe(message) ? message.recipient : message.user)}`" :data-is-me="isMe(message)" - :data-is-read="message.is_read" + :data-is-read="message.isRead" @click.prevent="navigate(isMe(message) ? message.recipient : message.user)" :key="message.id" > @@ -35,7 +35,7 @@
{{ isMe(message) ? message.recipient.name : message.user.name }} @{{ getAcct(isMe(message) ? message.recipient : message.user) }} - +

%i18n:common.tags.mk-messaging.you%:{{ message.text }}

@@ -95,19 +95,19 @@ export default Vue.extend({ methods: { getAcct, isMe(message) { - return message.user_id == (this as any).os.i.id; + return message.userId == (this as any).os.i.id; }, onMessage(message) { this.messages = this.messages.filter(m => !( - (m.recipient_id == message.recipient_id && m.user_id == message.user_id) || - (m.recipient_id == message.user_id && m.user_id == message.recipient_id))); + (m.recipientId == message.recipientId && m.userId == message.userId) || + (m.recipientId == message.userId && m.userId == message.recipientId))); this.messages.unshift(message); }, onRead(ids) { ids.forEach(id => { const found = this.messages.find(m => m.id == id); - if (found) found.is_read = true; + if (found) found.isRead = true; }); }, search() { diff --git a/src/web/app/common/views/components/othello.game.vue b/src/web/app/common/views/components/othello.game.vue index 414d819a5..8150fe07f 100644 --- a/src/web/app/common/views/components/othello.game.vue +++ b/src/web/app/common/views/components/othello.game.vue @@ -3,19 +3,19 @@
{{ blackUser.name }}(黒) vs {{ whiteUser.name }}(白)
-

{{ turnUser.name }}のターンです

+

{{ turnUser.name }}のターンです

{{ turnUser.name }}のターン

-

相手のターンです

-

あなたのターンです

-

- +

相手のターンです

+

あなたのターンです

+

+

@@ -26,7 +26,7 @@

{{ logPos }}ターン目 黒:{{ o.blackCount }} 白:{{ o.whiteCount }} 合計:{{ o.blackCount + o.whiteCount }}

-
+
%fa:angle-double-left% %fa:angle-left% @@ -62,12 +62,12 @@ export default Vue.extend({ computed: { iAmPlayer(): boolean { if (!(this as any).os.isSignedIn) return false; - return this.game.user1_id == (this as any).os.i.id || this.game.user2_id == (this as any).os.i.id; + return this.game.user1Id == (this as any).os.i.id || this.game.user2Id == (this as any).os.i.id; }, myColor(): Color { if (!this.iAmPlayer) return null; - if (this.game.user1_id == (this as any).os.i.id && this.game.black == 1) return true; - if (this.game.user2_id == (this as any).os.i.id && this.game.black == 2) return true; + if (this.game.user1Id == (this as any).os.i.id && this.game.black == 1) return true; + if (this.game.user2Id == (this as any).os.i.id && this.game.black == 2) return true; return false; }, opColor(): Color { @@ -97,11 +97,11 @@ export default Vue.extend({ watch: { logPos(v) { - if (!this.game.is_ended) return; + if (!this.game.isEnded) return; this.o = new Othello(this.game.settings.map, { - isLlotheo: this.game.settings.is_llotheo, - canPutEverywhere: this.game.settings.can_put_everywhere, - loopedBoard: this.game.settings.looped_board + isLlotheo: this.game.settings.isLlotheo, + canPutEverywhere: this.game.settings.canPutEverywhere, + loopedBoard: this.game.settings.loopedBoard }); this.logs.forEach((log, i) => { if (i < v) { @@ -116,9 +116,9 @@ export default Vue.extend({ this.game = this.initGame; this.o = new Othello(this.game.settings.map, { - isLlotheo: this.game.settings.is_llotheo, - canPutEverywhere: this.game.settings.can_put_everywhere, - loopedBoard: this.game.settings.looped_board + isLlotheo: this.game.settings.isLlotheo, + canPutEverywhere: this.game.settings.canPutEverywhere, + loopedBoard: this.game.settings.loopedBoard }); this.game.logs.forEach(log => { @@ -129,7 +129,7 @@ export default Vue.extend({ this.logPos = this.logs.length; // 通信を取りこぼしてもいいように定期的にポーリングさせる - if (this.game.is_started && !this.game.is_ended) { + if (this.game.isStarted && !this.game.isEnded) { this.pollingClock = setInterval(() => { const crc32 = CRC32.str(this.logs.map(x => x.pos.toString()).join('')); this.connection.send({ @@ -154,7 +154,7 @@ export default Vue.extend({ methods: { set(pos) { - if (this.game.is_ended) return; + if (this.game.isEnded) return; if (!this.iAmPlayer) return; if (!this.isMyTurn) return; if (!this.o.canPut(this.myColor, pos)) return; @@ -194,16 +194,16 @@ export default Vue.extend({ }, checkEnd() { - this.game.is_ended = this.o.isEnded; - if (this.game.is_ended) { + this.game.isEnded = this.o.isEnded; + if (this.game.isEnded) { if (this.o.winner === true) { - this.game.winner_id = this.game.black == 1 ? this.game.user1_id : this.game.user2_id; + this.game.winnerId = this.game.black == 1 ? this.game.user1Id : this.game.user2Id; this.game.winner = this.game.black == 1 ? this.game.user1 : this.game.user2; } else if (this.o.winner === false) { - this.game.winner_id = this.game.black == 1 ? this.game.user2_id : this.game.user1_id; + this.game.winnerId = this.game.black == 1 ? this.game.user2Id : this.game.user1Id; this.game.winner = this.game.black == 1 ? this.game.user2 : this.game.user1; } else { - this.game.winner_id = null; + this.game.winnerId = null; this.game.winner = null; } } @@ -214,9 +214,9 @@ export default Vue.extend({ this.game = game; this.o = new Othello(this.game.settings.map, { - isLlotheo: this.game.settings.is_llotheo, - canPutEverywhere: this.game.settings.can_put_everywhere, - loopedBoard: this.game.settings.looped_board + isLlotheo: this.game.settings.isLlotheo, + canPutEverywhere: this.game.settings.canPutEverywhere, + loopedBoard: this.game.settings.loopedBoard }); this.game.logs.forEach(log => { diff --git a/src/web/app/common/views/components/othello.gameroom.vue b/src/web/app/common/views/components/othello.gameroom.vue index 38a25f668..dba9ccd16 100644 --- a/src/web/app/common/views/components/othello.gameroom.vue +++ b/src/web/app/common/views/components/othello.gameroom.vue @@ -1,6 +1,6 @@ diff --git a/src/web/app/common/views/components/othello.room.vue b/src/web/app/common/views/components/othello.room.vue index 396541483..a32be6b74 100644 --- a/src/web/app/common/views/components/othello.room.vue +++ b/src/web/app/common/views/components/othello.room.vue @@ -41,9 +41,9 @@
ルール
- - - + + + @@ -116,13 +116,13 @@ export default Vue.extend({ return categories.filter((item, pos) => categories.indexOf(item) == pos); }, isAccepted(): boolean { - if (this.game.user1_id == (this as any).os.i.id && this.game.user1_accepted) return true; - if (this.game.user2_id == (this as any).os.i.id && this.game.user2_accepted) return true; + if (this.game.user1Id == (this as any).os.i.id && this.game.user1Accepted) return true; + if (this.game.user2Id == (this as any).os.i.id && this.game.user2Accepted) return true; return false; }, isOpAccepted(): boolean { - if (this.game.user1_id != (this as any).os.i.id && this.game.user1_accepted) return true; - if (this.game.user2_id != (this as any).os.i.id && this.game.user2_accepted) return true; + if (this.game.user1Id != (this as any).os.i.id && this.game.user1Accepted) return true; + if (this.game.user2Id != (this as any).os.i.id && this.game.user2Accepted) return true; return false; } }, @@ -133,8 +133,8 @@ export default Vue.extend({ this.connection.on('init-form', this.onInitForm); this.connection.on('message', this.onMessage); - if (this.game.user1_id != (this as any).os.i.id && this.game.settings.form1) this.form = this.game.settings.form1; - if (this.game.user2_id != (this as any).os.i.id && this.game.settings.form2) this.form = this.game.settings.form2; + if (this.game.user1Id != (this as any).os.i.id && this.game.settings.form1) this.form = this.game.settings.form1; + if (this.game.user2Id != (this as any).os.i.id && this.game.settings.form2) this.form = this.game.settings.form2; }, beforeDestroy() { @@ -162,8 +162,8 @@ export default Vue.extend({ }, onChangeAccepts(accepts) { - this.game.user1_accepted = accepts.user1; - this.game.user2_accepted = accepts.user2; + this.game.user1Accepted = accepts.user1; + this.game.user2Accepted = accepts.user2; this.$forceUpdate(); }, @@ -185,12 +185,12 @@ export default Vue.extend({ }, onInitForm(x) { - if (x.user_id == (this as any).os.i.id) return; + if (x.userId == (this as any).os.i.id) return; this.form = x.form; }, onMessage(x) { - if (x.user_id == (this as any).os.i.id) return; + if (x.userId == (this as any).os.i.id) return; this.messages.unshift(x.message); }, diff --git a/src/web/app/common/views/components/othello.vue b/src/web/app/common/views/components/othello.vue index d65032234..7bdb47100 100644 --- a/src/web/app/common/views/components/othello.vue +++ b/src/web/app/common/views/components/othello.vue @@ -34,7 +34,7 @@ {{ i.parent.name }} @{{ i.parent.username }} - +
@@ -43,7 +43,7 @@ {{ g.user1.name }} vs {{ g.user2.name }} - {{ g.is_ended ? '終了' : '進行中' }} + {{ g.isEnded ? '終了' : '進行中' }}
@@ -52,7 +52,7 @@ {{ g.user1.name }} vs {{ g.user2.name }} - {{ g.is_ended ? '終了' : '進行中' }} + {{ g.isEnded ? '終了' : '進行中' }}
@@ -147,7 +147,7 @@ export default Vue.extend({ username }).then(user => { (this as any).api('othello/match', { - user_id: user.id + userId: user.id }).then(res => { if (res == null) { this.matching = user; @@ -164,7 +164,7 @@ export default Vue.extend({ }, accept(invitation) { (this as any).api('othello/match', { - user_id: invitation.parent.id + userId: invitation.parent.id }).then(game => { if (game) { this.matching = null; diff --git a/src/web/app/common/views/components/poll.vue b/src/web/app/common/views/components/poll.vue index 8156c8bc5..e46e89f55 100644 --- a/src/web/app/common/views/components/poll.vue +++ b/src/web/app/common/views/components/poll.vue @@ -49,7 +49,7 @@ export default Vue.extend({ vote(id) { if (this.poll.choices.some(c => c.is_voted)) return; (this as any).api('posts/polls/vote', { - post_id: this.post.id, + postId: this.post.id, choice: id }).then(() => { this.poll.choices.forEach(c => { diff --git a/src/web/app/common/views/components/post-menu.vue b/src/web/app/common/views/components/post-menu.vue index a53680e55..35116db7e 100644 --- a/src/web/app/common/views/components/post-menu.vue +++ b/src/web/app/common/views/components/post-menu.vue @@ -2,7 +2,7 @@
- +
@@ -51,7 +51,7 @@ export default Vue.extend({ methods: { pin() { (this as any).api('i/pin', { - post_id: this.post.id + postId: this.post.id }).then(() => { this.$destroy(); }); diff --git a/src/web/app/common/views/components/reaction-picker.vue b/src/web/app/common/views/components/reaction-picker.vue index df8100f2f..bcb6b2b96 100644 --- a/src/web/app/common/views/components/reaction-picker.vue +++ b/src/web/app/common/views/components/reaction-picker.vue @@ -69,7 +69,7 @@ export default Vue.extend({ methods: { react(reaction) { (this as any).api('posts/reactions/create', { - post_id: this.post.id, + postId: this.post.id, reaction: reaction }).then(() => { if (this.cb) this.cb(); diff --git a/src/web/app/common/views/components/signin.vue b/src/web/app/common/views/components/signin.vue index 273143262..17154e6b3 100644 --- a/src/web/app/common/views/components/signin.vue +++ b/src/web/app/common/views/components/signin.vue @@ -6,7 +6,7 @@ -