Make PhotoPanel bound

This commit is contained in:
John Lyon-Smith
2018-04-26 14:11:12 -07:00
parent 109e9f4d3d
commit 71cec6088a
10 changed files with 327 additions and 190 deletions

View File

@@ -65,7 +65,14 @@ export class AssetRoutes {
}
async getAsset(req, res, next) {
const assetId = req.params._id
let assetId = req.params._id
const extIndex = assetId.indexOf(".")
if (extIndex !== -1) {
// TODO: Should really check the index against the requested extension...
assetId = assetId.slice(0, extIndex)
}
const file = await this.db.gridfs.findOneAsync({ _id: assetId })
if (!file) {
@@ -112,13 +119,17 @@ export class AssetRoutes {
chunkContentType,
} = req.body
if (!fileName || !uploadSize || !numberOfChunks || !contentType) {
if (!uploadSize || !numberOfChunks || !contentType) {
throw createError.BadRequest(
"Must specify fileName, uploadSize, numberOfChunks, contentType"
"Must specify uploadSize, numberOfChunks, contentType"
)
}
fileName = uploadId + "-" + path.basename(fileName)
if (fileName) {
fileName = uploadId + "-" + path.basename(fileName)
} else {
fileName = uploadId
}
if (chunkContentType) {
if (
@@ -159,9 +170,11 @@ export class AssetRoutes {
const contentRange = req.get("Content-Range")
const contentLength = req.get("Content-Length")
console.log(uploadData)
if (!uploadData) {
throw createError.BadRequest(`Bad upload id ${uploadId}`)
}
if (contentType !== uploadData.chunkContentType) {
if (!contentType.startsWith(uploadData.chunkContentType)) {
throw createError.BadRequest(
`Content-Type ${contentType} does not match chunk type ${
uploadData.chunkContentType
@@ -211,7 +224,7 @@ export class AssetRoutes {
}
try {
const [uploadedChunks] = await Promise.all([
const [, uploadedChunks] = await Promise.all([
this.rs.setrangeAsync(uploadDataId, offset, req.body),
this.rs.incrAsync(uploadCountId),
])