diff options
Diffstat (limited to 'src/server/api/common')
| -rw-r--r-- | src/server/api/common/read-messaging-message.ts | 9 | ||||
| -rw-r--r-- | src/server/api/common/read-notification.ts | 7 | ||||
| -rw-r--r-- | src/server/api/common/signin.ts | 4 |
3 files changed, 12 insertions, 8 deletions
diff --git a/src/server/api/common/read-messaging-message.ts b/src/server/api/common/read-messaging-message.ts index 075e369832..63080d22a4 100644 --- a/src/server/api/common/read-messaging-message.ts +++ b/src/server/api/common/read-messaging-message.ts @@ -1,4 +1,5 @@ import * as mongo from 'mongodb'; +import isObjectId from '../../../misc/is-objectid'; import Message from '../../../models/messaging-message'; import { IMessagingMessage as IMessage } from '../../../models/messaging-message'; import { publishMainStream } from '../../../stream'; @@ -15,21 +16,21 @@ export default ( message: string | string[] | IMessage | IMessage[] | mongo.ObjectID | mongo.ObjectID[] ) => new Promise<any>(async (resolve, reject) => { - const userId = mongo.ObjectID.prototype.isPrototypeOf(user) + const userId = isObjectId(user) ? user : new mongo.ObjectID(user); - const otherpartyId = mongo.ObjectID.prototype.isPrototypeOf(otherparty) + const otherpartyId = isObjectId(otherparty) ? otherparty : new mongo.ObjectID(otherparty); const ids: mongo.ObjectID[] = Array.isArray(message) - ? mongo.ObjectID.prototype.isPrototypeOf(message[0]) + ? isObjectId(message[0]) ? (message as mongo.ObjectID[]) : typeof message[0] === 'string' ? (message as string[]).map(m => new mongo.ObjectID(m)) : (message as IMessage[]).map(m => m._id) - : mongo.ObjectID.prototype.isPrototypeOf(message) + : isObjectId(message) ? [(message as mongo.ObjectID)] : typeof message === 'string' ? [new mongo.ObjectID(message)] diff --git a/src/server/api/common/read-notification.ts b/src/server/api/common/read-notification.ts index 2d58ada4ce..27d3f1be32 100644 --- a/src/server/api/common/read-notification.ts +++ b/src/server/api/common/read-notification.ts @@ -1,4 +1,5 @@ import * as mongo from 'mongodb'; +import isObjectId from '../../../misc/is-objectid'; import { default as Notification, INotification } from '../../../models/notification'; import { publishMainStream } from '../../../stream'; import Mute from '../../../models/mute'; @@ -12,17 +13,17 @@ export default ( message: string | string[] | INotification | INotification[] | mongo.ObjectID | mongo.ObjectID[] ) => new Promise<any>(async (resolve, reject) => { - const userId = mongo.ObjectID.prototype.isPrototypeOf(user) + const userId = isObjectId(user) ? user : new mongo.ObjectID(user); const ids: mongo.ObjectID[] = Array.isArray(message) - ? mongo.ObjectID.prototype.isPrototypeOf(message[0]) + ? isObjectId(message[0]) ? (message as mongo.ObjectID[]) : typeof message[0] === 'string' ? (message as string[]).map(m => new mongo.ObjectID(m)) : (message as INotification[]).map(m => m._id) - : mongo.ObjectID.prototype.isPrototypeOf(message) + : isObjectId(message) ? [(message as mongo.ObjectID)] : typeof message === 'string' ? [new mongo.ObjectID(message)] diff --git a/src/server/api/common/signin.ts b/src/server/api/common/signin.ts index 44e1336f27..8d44b377fe 100644 --- a/src/server/api/common/signin.ts +++ b/src/server/api/common/signin.ts @@ -8,7 +8,9 @@ export default function(ctx: Koa.Context, user: ILocalUser, redirect = false) { ctx.cookies.set('i', user.token, { path: '/', domain: config.hostname, - secure: config.url.startsWith('https'), + // SEE: https://github.com/koajs/koa/issues/974 + //secure: config.url.startsWith('https'), + secure: false, httpOnly: false, expires: new Date(Date.now() + expires), maxAge: expires |