Fix admin/user login issues

This commit is contained in:
John Lyon-Smith
2018-05-25 10:16:28 -07:00
parent a33ca57d58
commit 587052a509
22 changed files with 255 additions and 92 deletions

View File

@@ -8,22 +8,7 @@ import config from "config"
import autobind from "autobind-decorator"
import { PassThrough } from "stream"
import { catchAll } from "."
function pipeToGridFS(readable, writeable) {
const promise = new Promise((resolve, reject) => {
readable.on("error", (error) => {
reject(error)
})
writeable.on("error", (error) => {
reject(error)
})
writeable.on("finish", (file) => {
resolve(file)
})
})
readable.pipe(writeable)
return promise
}
import { pipeToPromise } from "../../util"
@autobind
export class AssetRoutes {
@@ -109,7 +94,7 @@ export class AssetRoutes {
}
async beginAssetUpload(req, res, next) {
const uploadId = this.db.newObjectId()
const uploadId = this.db.newObjectId().toString()
let {
fileName,
uploadSize,
@@ -224,12 +209,12 @@ export class AssetRoutes {
if (uploadedChunks >= uploadData.numberOfChunks) {
let readable = redisReadStream(this.rs.client, uploadDataId)
let writeable = this.db.gridfs.openUploadStreamWithId(
uploadId,
this.db.newObjectId(uploadId),
uploadData.fileName,
{ contentType: uploadData.contentType }
)
const file = await pipeToGridFS(readable, writeable)
const file = await pipeToPromise(readable, writeable)
await Promise.all([
this.rs.del(uploadId),