This commit is contained in:
syuilo 2018-02-02 08:21:30 +09:00
parent 2f645d59db
commit 8462a74938
61 changed files with 132 additions and 119 deletions

View file

@ -12,7 +12,7 @@ import prominence = require('prominence');
import DriveFile, { getGridFSBucket } from '../models/drive-file';
import DriveFolder from '../models/drive-folder';
import serialize from '../serializers/drive-file';
import { pack } from '../models/drive-file';
import event, { publishDriveStream } from '../event';
import config from '../../conf';
@ -282,7 +282,7 @@ export default (user: any, file: string | stream.Readable, ...args) => new Promi
log(`drive file has been created ${file._id}`);
resolve(file);
serialize(file).then(serializedFile => {
pack(file).then(serializedFile => {
// Publish drive_file_created event
event(user._id, 'drive_file_created', serializedFile);
publishDriveStream(user._id, 'file_created', serializedFile);

View file

@ -2,7 +2,7 @@ import * as mongo from 'mongodb';
import Notification from '../models/notification';
import Mute from '../models/mute';
import event from '../event';
import serialize from '../serializers/notification';
import { pack } from '../models/notification';
export default (
notifiee: mongo.ObjectID,
@ -27,7 +27,7 @@ export default (
// Publish notification event
event(notifiee, 'notification',
await serialize(notification));
await pack(notification));
// 3秒経っても(今回作成した)通知が既読にならなかったら「未読の通知がありますよ」イベントを発行する
setTimeout(async () => {
@ -44,7 +44,7 @@ export default (
}
//#endregion
event(notifiee, 'unread_notification', await serialize(notification));
event(notifiee, 'unread_notification', await pack(notification));
}
}, 3000);
});

View file

@ -5,7 +5,7 @@ import rndstr from 'rndstr';
import $ from 'cafy';
import App from '../../models/app';
import { isValidNameId } from '../../models/app';
import serialize from '../../serializers/app';
import { pack } from '../../models/app';
/**
* @swagger
@ -106,5 +106,5 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
});
// Response
res(await serialize(app));
res(await pack(app));
});

View file

@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import App from '../../models/app';
import serialize from '../../serializers/app';
import { pack } from '../../models/app';
/**
* @swagger
@ -67,7 +67,7 @@ module.exports = (params, user, _, isSecure) => new Promise(async (res, rej) =>
}
// Send response
res(await serialize(app, user, {
res(await pack(app, user, {
includeSecret: isSecure && app.user_id.equals(user._id)
}));
});

View file

@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import AuthSess from '../../../models/auth-session';
import serialize from '../../../serializers/auth-session';
import { pack } from '../../../models/auth-session';
/**
* @swagger
@ -67,5 +67,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
}
// Response
res(await serialize(session, user));
res(await pack(session, user));
});

View file

@ -5,7 +5,7 @@ import $ from 'cafy';
import App from '../../../models/app';
import AuthSess from '../../../models/auth-session';
import AccessToken from '../../../models/access-token';
import serialize from '../../../serializers/user';
import { pack } from '../../../models/user';
/**
* @swagger
@ -102,7 +102,7 @@ module.exports = (params) => new Promise(async (res, rej) => {
// Response
res({
access_token: accessToken.token,
user: await serialize(session.user_id, null, {
user: await pack(session.user_id, null, {
detail: true
})
});

View file

@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import Channel from '../models/channel';
import serialize from '../serializers/channel';
import { pack } from '../models/channel';
/**
* Get all channels
@ -55,5 +55,5 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(channels.map(async channel =>
await serialize(channel, me))));
await pack(channel, me))));
});

View file

@ -4,7 +4,7 @@
import $ from 'cafy';
import Channel from '../../models/channel';
import Watching from '../../models/channel-watching';
import serialize from '../../serializers/channel';
import { pack } from '../../models/channel';
/**
* Create a channel
@ -28,7 +28,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
});
// Response
res(await serialize(channel));
res(await pack(channel));
// Create Watching
await Watching.insert({

View file

@ -4,7 +4,7 @@
import $ from 'cafy';
import { default as Channel, IChannel } from '../../models/channel';
import Post from '../../models/post';
import serialize from '../../serializers/post';
import { pack } from '../../models/post';
/**
* Show a posts of a channel
@ -74,6 +74,6 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(posts.map(async (post) =>
await serialize(post, user)
await pack(post, user)
)));
});

View file

@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import { default as Channel, IChannel } from '../../models/channel';
import serialize from '../../serializers/channel';
import { pack } from '../../models/channel';
/**
* Show a channel
@ -27,5 +27,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
}
// Serialize
res(await serialize(channel, user));
res(await pack(channel, user));
});

View file

@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import DriveFile from '../../models/drive-file';
import serialize from '../../serializers/drive-file';
import { pack } from '../../models/drive-file';
/**
* Get drive files
@ -69,6 +69,6 @@ module.exports = async (params, user, app) => {
});
// Serialize
const _files = await Promise.all(files.map(file => serialize(file)));
const _files = await Promise.all(files.map(file => pack(file)));
return _files;
};

View file

@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import { validateFileName } from '../../../models/drive-file';
import serialize from '../../../serializers/drive-file';
import { pack } from '../../../models/drive-file';
import create from '../../../common/add-file-to-drive';
/**
@ -43,7 +43,7 @@ module.exports = async (file, params, user): Promise<any> => {
const driveFile = await create(user, file.path, name, null, folderId);
// Serialize
return serialize(driveFile);
return pack(driveFile);
} catch (e) {
console.error(e);

View file

@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import DriveFile from '../../../models/drive-file';
import serialize from '../../../serializers/drive-file';
import { pack } from '../../../models/drive-file';
/**
* Find a file(s)
@ -31,5 +31,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(files.map(async file =>
await serialize(file))));
await pack(file))));
});

View file

@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import DriveFile from '../../../models/drive-file';
import serialize from '../../../serializers/drive-file';
import { pack } from '../../../models/drive-file';
/**
* Show a file
@ -29,7 +29,7 @@ module.exports = async (params, user) => {
}
// Serialize
const _file = await serialize(file, {
const _file = await pack(file, {
detail: true
});

View file

@ -5,7 +5,7 @@ import $ from 'cafy';
import DriveFolder from '../../../models/drive-folder';
import DriveFile from '../../../models/drive-file';
import { validateFileName } from '../../../models/drive-file';
import serialize from '../../../serializers/drive-file';
import { pack } from '../../../models/drive-file';
import { publishDriveStream } from '../../../event';
/**
@ -67,7 +67,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
});
// Serialize
const fileObj = await serialize(file);
const fileObj = await pack(file);
// Response
res(fileObj);

View file

@ -4,7 +4,7 @@
import * as URL from 'url';
import $ from 'cafy';
import { validateFileName } from '../../../models/drive-file';
import serialize from '../../../serializers/drive-file';
import { pack } from '../../../models/drive-file';
import create from '../../../common/add-file-to-drive';
import * as debug from 'debug';
import * as tmp from 'tmp';
@ -63,5 +63,5 @@ module.exports = async (params, user): Promise<any> => {
if (e) log(e.stack);
});
return serialize(driveFile);
return pack(driveFile);
};

View file

@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import DriveFolder from '../../models/drive-folder';
import serialize from '../../serializers/drive-folder';
import { pack } from '../../models/drive-folder';
/**
* Get drive folders
@ -63,5 +63,5 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(folders.map(async folder =>
await serialize(folder))));
await pack(folder))));
});

View file

@ -4,7 +4,7 @@
import $ from 'cafy';
import DriveFolder from '../../../models/drive-folder';
import { isValidFolderName } from '../../../models/drive-folder';
import serialize from '../../../serializers/drive-folder';
import { pack } from '../../../models/drive-folder';
import { publishDriveStream } from '../../../event';
/**
@ -47,7 +47,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
});
// Serialize
const folderObj = await serialize(folder);
const folderObj = await pack(folder);
// Response
res(folderObj);

View file

@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import DriveFolder from '../../../models/drive-folder';
import serialize from '../../../serializers/drive-folder';
import { pack } from '../../../models/drive-folder';
/**
* Find a folder(s)
@ -30,5 +30,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
});
// Serialize
res(await Promise.all(folders.map(folder => serialize(folder))));
res(await Promise.all(folders.map(folder => pack(folder))));
});

View file

@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import DriveFolder from '../../../models/drive-folder';
import serialize from '../../../serializers/drive-folder';
import { pack } from '../../../models/drive-folder';
/**
* Show a folder
@ -29,7 +29,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
}
// Serialize
res(await serialize(folder, {
res(await pack(folder, {
detail: true
}));
});

View file

@ -4,7 +4,7 @@
import $ from 'cafy';
import DriveFolder from '../../../models/drive-folder';
import { isValidFolderName } from '../../../models/drive-folder';
import serialize from '../../../serializers/drive-folder';
import { pack } from '../../../models/drive-folder';
import { publishDriveStream } from '../../../event';
/**
@ -91,7 +91,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
});
// Serialize
const folderObj = await serialize(folder);
const folderObj = await pack(folder);
// Response
res(folderObj);

View file

@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import DriveFile from '../../models/drive-file';
import serialize from '../../serializers/drive-file';
import { pack } from '../../models/drive-file';
/**
* Get drive stream
@ -64,5 +64,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(files.map(async file =>
await serialize(file))));
await pack(file))));
});

View file

@ -2,7 +2,7 @@
* Module dependencies
*/
import User from '../models/user';
import serialize from '../serializers/user';
import { pack } from '../models/user';
/**
* Show myself
@ -15,7 +15,7 @@ import serialize from '../serializers/user';
*/
module.exports = (params, user, _, isSecure) => new Promise(async (res, rej) => {
// Serialize
res(await serialize(user, user, {
res(await pack(user, user, {
detail: true,
includeSecrets: isSecure
}));

View file

@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import AccessToken from '../../models/access-token';
import serialize from '../../serializers/app';
import { pack } from '../../models/app';
/**
* Get authorized apps of my account
@ -39,5 +39,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(tokens.map(async token =>
await serialize(token.app_id))));
await pack(token.app_id))));
});

View file

@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import Favorite from '../../models/favorite';
import serialize from '../../serializers/post';
import { pack } from '../../models/post';
/**
* Get followers of a user
@ -39,6 +39,6 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(favorites.map(async favorite =>
await serialize(favorite.post)
await pack(favorite.post)
)));
});

View file

@ -4,7 +4,7 @@
import $ from 'cafy';
import Notification from '../../models/notification';
import Mute from '../../models/mute';
import serialize from '../../serializers/notification';
import { pack } from '../../models/notification';
import getFriends from '../../common/get-friends';
import read from '../../common/read-notification';
@ -101,7 +101,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(notifications.map(async notification =>
await serialize(notification))));
await pack(notification))));
// Mark as read all
if (notifications.length > 0 && markAsRead) {

View file

@ -4,7 +4,7 @@
import $ from 'cafy';
import User from '../../models/user';
import Post from '../../models/post';
import serialize from '../../serializers/user';
import { pack } from '../../models/user';
/**
* Pin post
@ -35,7 +35,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
});
// Serialize
const iObj = await serialize(user, user, {
const iObj = await pack(user, user, {
detail: true
});

View file

@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import Signin from '../../models/signin';
import serialize from '../../serializers/signin';
import { pack } from '../../models/signin';
/**
* Get signin history of my account
@ -58,5 +58,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(history.map(async record =>
await serialize(record))));
await pack(record))));
});

View file

@ -4,7 +4,7 @@
import $ from 'cafy';
import User from '../../models/user';
import { isValidName, isValidDescription, isValidLocation, isValidBirthday } from '../../models/user';
import serialize from '../../serializers/user';
import { pack } from '../../models/user';
import event from '../../event';
import config from '../../../conf';
@ -65,7 +65,7 @@ module.exports = async (params, user, _, isSecure) => new Promise(async (res, re
});
// Serialize
const iObj = await serialize(user, user, {
const iObj = await pack(user, user, {
detail: true,
includeSecrets: isSecure
});

View file

@ -4,7 +4,7 @@
import $ from 'cafy';
import History from '../../models/messaging-history';
import Mute from '../../models/mute';
import serialize from '../../serializers/messaging-message';
import { pack } from '../../models/messaging-message';
/**
* Show messaging history
@ -39,5 +39,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(history.map(async h =>
await serialize(h.message, user))));
await pack(h.message, user))));
});

View file

@ -4,7 +4,7 @@
import $ from 'cafy';
import Message from '../../models/messaging-message';
import User from '../../models/user';
import serialize from '../../serializers/messaging-message';
import { pack } from '../../models/messaging-message';
import read from '../../common/read-messaging-message';
/**
@ -87,7 +87,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(messages.map(async message =>
await serialize(message, user, {
await pack(message, user, {
populateRecipient: false
}))));

View file

@ -8,7 +8,7 @@ import History from '../../../models/messaging-history';
import User from '../../../models/user';
import Mute from '../../../models/mute';
import DriveFile from '../../../models/drive-file';
import serialize from '../../../serializers/messaging-message';
import { pack } from '../../../models/messaging-message';
import publishUserStream from '../../../event';
import { publishMessagingStream, publishMessagingIndexStream, pushSw } from '../../../event';
import config from '../../../../conf';
@ -79,7 +79,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
});
// Serialize
const messageObj = await serialize(message);
const messageObj = await pack(message);
// Reponse
res(messageObj);

View file

@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import Mute from '../../models/mute';
import serialize from '../../serializers/user';
import { pack } from '../../models/user';
import getFriends from '../../common/get-friends';
/**
@ -63,7 +63,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// Serialize
const users = await Promise.all(mutes.map(async m =>
await serialize(m.mutee_id, me, { detail: true })));
await pack(m.mutee_id, me, { detail: true })));
// Response
res({

View file

@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import App from '../../models/app';
import serialize from '../../serializers/app';
import { pack } from '../../models/app';
/**
* Get my apps
@ -37,5 +37,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Reply
res(await Promise.all(apps.map(async app =>
await serialize(app))));
await pack(app))));
});

View file

@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import Post from '../models/post';
import serialize from '../serializers/post';
import { pack } from '../models/post';
/**
* Lists all posts
@ -85,5 +85,5 @@ module.exports = (params) => new Promise(async (res, rej) => {
});
// Serialize
res(await Promise.all(posts.map(async post => await serialize(post))));
res(await Promise.all(posts.map(async post => await pack(post))));
});

View file

@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import Post from '../../models/post';
import serialize from '../../serializers/post';
import { pack } from '../../models/post';
/**
* Show a context of a post
@ -60,5 +60,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(context.map(async post =>
await serialize(post, user))));
await pack(post, user))));
});

View file

@ -12,7 +12,7 @@ import Mute from '../../models/mute';
import DriveFile from '../../models/drive-file';
import Watching from '../../models/post-watching';
import ChannelWatching from '../../models/channel-watching';
import serialize from '../../serializers/post';
import { pack } from '../../models/post';
import notify from '../../common/notify';
import watch from '../../common/watch-post';
import event, { pushSw, publishChannelStream } from '../../event';
@ -224,7 +224,7 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
});
// Serialize
const postObj = await serialize(post);
const postObj = await pack(post);
// Reponse
res({

View file

@ -4,7 +4,7 @@
import $ from 'cafy';
import Post from '../../models/post';
import getFriends from '../../common/get-friends';
import serialize from '../../serializers/post';
import { pack } from '../../models/post';
/**
* Get mentions of myself
@ -73,6 +73,6 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(mentions.map(async mention =>
await serialize(mention, user)
await pack(mention, user)
)));
});

View file

@ -4,7 +4,7 @@
import $ from 'cafy';
import Vote from '../../../models/poll-vote';
import Post from '../../../models/post';
import serialize from '../../../serializers/post';
import { pack } from '../../../models/post';
/**
* Get recommended polls
@ -56,5 +56,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(posts.map(async post =>
await serialize(post, user, { detail: true }))));
await pack(post, user, { detail: true }))));
});

View file

@ -4,7 +4,7 @@
import $ from 'cafy';
import Post from '../../models/post';
import Reaction from '../../models/post-reaction';
import serialize from '../../serializers/post-reaction';
import { pack } from '../../models/post-reaction';
/**
* Show reactions of a post
@ -54,5 +54,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(reactions.map(async reaction =>
await serialize(reaction, user))));
await pack(reaction, user))));
});

View file

@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import Post from '../../models/post';
import serialize from '../../serializers/post';
import { pack } from '../../models/post';
/**
* Show a replies of a post
@ -50,5 +50,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(replies.map(async post =>
await serialize(post, user))));
await pack(post, user))));
});

View file

@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import Post from '../../models/post';
import serialize from '../../serializers/post';
import { pack } from '../../models/post';
/**
* Show a reposts of a post
@ -70,5 +70,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(reposts.map(async post =>
await serialize(post, user))));
await pack(post, user))));
});

View file

@ -7,7 +7,7 @@ import Post from '../../models/post';
import User from '../../models/user';
import Mute from '../../models/mute';
import getFriends from '../../common/get-friends';
import serialize from '../../serializers/post';
import { pack } from '../../models/post';
/**
* Search a post
@ -351,5 +351,5 @@ async function search(
// Serialize
res(await Promise.all(posts.map(async post =>
await serialize(post, me))));
await pack(post, me))));
}

View file

@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import Post from '../../models/post';
import serialize from '../../serializers/post';
import { pack } from '../../models/post';
/**
* Show a post
@ -27,7 +27,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
}
// Serialize
res(await serialize(post, user, {
res(await pack(post, user, {
detail: true
}));
});

View file

@ -7,7 +7,7 @@ import Post from '../../models/post';
import Mute from '../../models/mute';
import ChannelWatching from '../../models/channel-watching';
import getFriends from '../../common/get-friends';
import serialize from '../../serializers/post';
import { pack } from '../../models/post';
/**
* Get timeline of myself
@ -128,5 +128,5 @@ module.exports = async (params, user, app) => {
});
// Serialize
return await Promise.all(timeline.map(post => serialize(post, user)));
return await Promise.all(timeline.map(post => pack(post, user)));
};

View file

@ -4,7 +4,7 @@
const ms = require('ms');
import $ from 'cafy';
import Post from '../../models/post';
import serialize from '../../serializers/post';
import { pack } from '../../models/post';
/**
* Get trend posts
@ -76,5 +76,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(posts.map(async post =>
await serialize(post, user, { detail: true }))));
await pack(post, user, { detail: true }))));
});

View file

@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import User from '../models/user';
import serialize from '../serializers/user';
import { pack } from '../models/user';
/**
* Lists all users
@ -55,5 +55,5 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(users.map(async user =>
await serialize(user, me))));
await pack(user, me))));
});

View file

@ -4,7 +4,7 @@
import $ from 'cafy';
import User from '../../models/user';
import Following from '../../models/following';
import serialize from '../../serializers/user';
import { pack } from '../../models/user';
import getFriends from '../../common/get-friends';
/**
@ -82,7 +82,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// Serialize
const users = await Promise.all(following.map(async f =>
await serialize(f.follower_id, me, { detail: true })));
await pack(f.follower_id, me, { detail: true })));
// Response
res({

View file

@ -4,7 +4,7 @@
import $ from 'cafy';
import User from '../../models/user';
import Following from '../../models/following';
import serialize from '../../serializers/user';
import { pack } from '../../models/user';
import getFriends from '../../common/get-friends';
/**
@ -82,7 +82,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// Serialize
const users = await Promise.all(following.map(async f =>
await serialize(f.followee_id, me, { detail: true })));
await pack(f.followee_id, me, { detail: true })));
// Response
res({

View file

@ -4,7 +4,7 @@
import $ from 'cafy';
import Post from '../../models/post';
import User from '../../models/user';
import serialize from '../../serializers/user';
import { pack } from '../../models/user';
module.exports = (params, me) => new Promise(async (res, rej) => {
// Get 'user_id' parameter
@ -91,7 +91,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// Make replies object (includes weights)
const repliesObj = await Promise.all(topRepliedUsers.map(async (user) => ({
user: await serialize(user, me, { detail: true }),
user: await pack(user, me, { detail: true }),
weight: repliedUsers[user] / peak
})));

View file

@ -4,7 +4,7 @@
import $ from 'cafy';
import Post from '../../models/post';
import User from '../../models/user';
import serialize from '../../serializers/post';
import { pack } from '../../models/post';
/**
* Get posts of a user
@ -124,6 +124,6 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(posts.map(async (post) =>
await serialize(post, me)
await pack(post, me)
)));
});

View file

@ -4,7 +4,7 @@
const ms = require('ms');
import $ from 'cafy';
import User from '../../models/user';
import serialize from '../../serializers/user';
import { pack } from '../../models/user';
import getFriends from '../../common/get-friends';
/**
@ -44,5 +44,5 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(users.map(async user =>
await serialize(user, me, { detail: true }))));
await pack(user, me, { detail: true }))));
});

View file

@ -4,7 +4,7 @@
import * as mongo from 'mongodb';
import $ from 'cafy';
import User from '../../models/user';
import serialize from '../../serializers/user';
import { pack } from '../../models/user';
import config from '../../../conf';
const escapeRegexp = require('escape-regexp');
@ -94,6 +94,6 @@ async function byElasticsearch(res, rej, me, query, offset, max) {
// Serialize
res(await Promise.all(users.map(async user =>
await serialize(user, me, { detail: true }))));
await pack(user, me, { detail: true }))));
});
}

View file

@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import User from '../../models/user';
import serialize from '../../serializers/user';
import { pack } from '../../models/user';
/**
* Search a user by username
@ -35,5 +35,5 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(users.map(async user =>
await serialize(user, me, { detail: true }))));
await pack(user, me, { detail: true }))));
});

View file

@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import User from '../../models/user';
import serialize from '../../serializers/user';
import { pack } from '../../models/user';
/**
* Show a user
@ -41,7 +41,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
}
// Send response
res(await serialize(user, me, {
res(await pack(user, me, {
detail: true
}));
});

View file

@ -20,8 +20,14 @@ export { getGridFSBucket };
export type IDriveFile = {
_id: mongodb.ObjectID;
created_at: Date;
user_id: mongodb.ObjectID;
uploadDate: Date;
md5: string;
filename: string;
metadata: {
properties: any;
user_id: mongodb.ObjectID;
folder_id: mongodb.ObjectID;
}
};
export function validateFileName(name: string): boolean {

View file

@ -9,7 +9,9 @@ export default DriveFolder;
export type IDriveFolder = {
_id: mongo.ObjectID;
created_at: Date;
name: string;
user_id: mongo.ObjectID;
parent_id: mongo.ObjectID;
};
export function isValidFolderName(name: string): boolean {

View file

@ -10,6 +10,11 @@ export default MessagingMessage;
export interface IMessagingMessage {
_id: mongo.ObjectID;
created_at: Date;
text: string;
user_id: mongo.ObjectID;
recipient_id: mongo.ObjectID;
is_read: boolean;
}
export function isValidText(text: string): boolean {

View file

@ -3,7 +3,7 @@ import * as bcrypt from 'bcryptjs';
import * as speakeasy from 'speakeasy';
import { default as User, IUser } from '../models/user';
import Signin from '../models/signin';
import serialize from '../serializers/signin';
import { pack } from '../models/signin';
import event from '../event';
import signin from '../common/signin';
import config from '../../conf';
@ -85,5 +85,5 @@ export default async (req: express.Request, res: express.Response) => {
});
// Publish signin event
event(user._id, 'signin', await serialize(record));
event(user._id, 'signin', await pack(record));
};

View file

@ -4,7 +4,7 @@ import * as bcrypt from 'bcryptjs';
import recaptcha = require('recaptcha-promise');
import { default as User, IUser } from '../models/user';
import { validateUsername, validatePassword } from '../models/user';
import serialize from '../serializers/user';
import { pack } from '../models/user';
import generateUserToken from '../common/generate-native-user-token';
import config from '../../conf';
@ -142,7 +142,7 @@ export default async (req: express.Request, res: express.Response) => {
});
// Response
res.send(await serialize(account));
res.send(await pack(account));
// Create search index
if (config.elasticsearch.enable) {

View file

@ -6,7 +6,7 @@ import * as uuid from 'uuid';
import autwh from 'autwh';
import redis from '../../db/redis';
import User from '../models/user';
import serialize from '../serializers/user';
import { pack } from '../models/user';
import event from '../event';
import config from '../../conf';
import signin from '../common/signin';
@ -50,7 +50,7 @@ module.exports = (app: express.Application) => {
res.send(`Twitterの連携を解除しました :v:`);
// Publish i updated event
event(user._id, 'i_updated', await serialize(user, user, {
event(user._id, 'i_updated', await pack(user, user, {
detail: true,
includeSecrets: true
}));