mirror of
https://github.com/paricafe/misskey.git
synced 2024-11-29 11:16:44 -06:00
45e8331e26
Closes #12, #227 and #58
40 lines
718 B
TypeScript
40 lines
718 B
TypeScript
/**
|
|
* Module dependencies
|
|
*/
|
|
import * as mongo from 'mongodb';
|
|
import deepcopy = require('deepcopy');
|
|
import serializeApp from './app';
|
|
|
|
/**
|
|
* Serialize an auth session
|
|
*
|
|
* @param {any} session
|
|
* @param {any} me?
|
|
* @return {Promise<any>}
|
|
*/
|
|
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);
|
|
});
|