misskey/src/api/serializers/auth-session.ts

41 lines
718 B
TypeScript
Raw Normal View History

2016-12-29 07:49:51 +09:00
/**
* Module dependencies
*/
import * as mongo from 'mongodb';
2017-01-03 06:03:19 +09:00
import deepcopy = require('deepcopy');
2016-12-29 07:49:51 +09:00
import serializeApp from './app';
/**
* Serialize an auth session
*
2017-03-01 17:37:01 +09:00
* @param {any} session
* @param {any} me?
* @return {Promise<any>}
2016-12-29 07:49:51 +09:00
*/
export default (
session: any,
me?: any
) => new Promise<any>(async (resolve, reject) => {
let _session: any;
// TODO: Populate session if it ID
_session = deepcopy(session);
// Me
if (me && !mongo.ObjectID.prototype.isPrototypeOf(me)) {
if (typeof me === 'string') {
me = new mongo.ObjectID(me);
} else {
me = me._id;
}
}
delete _session._id;
// Populate app
_session.app = await serializeApp(_session.app_id, me);
resolve(_session);
});