Fix server-side linting erros
This commit is contained in:
parent
1107f7352a
commit
9de8257464
3 changed files with 42 additions and 43 deletions
|
@ -60,14 +60,14 @@ export function deleteObjectsFromS3(keyList, callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deleteObjectFromS3(req, res) {
|
export function deleteObjectFromS3(req, res) {
|
||||||
const { object_key, user_id } = req.params;
|
const { objectKey, userId } = req.params;
|
||||||
let objectKey;
|
let fullObjectKey;
|
||||||
if (user_id) {
|
if (userId) {
|
||||||
objectKey = `${user_id}/${object_key}`
|
fullObjectKey = `${userId}/${objectKey}`;
|
||||||
} else {
|
} else {
|
||||||
objectKey = object_key;
|
fullObjectKey = objectKey;
|
||||||
}
|
}
|
||||||
deleteObjectsFromS3([objectKey], () => {
|
deleteObjectsFromS3([fullObjectKey], () => {
|
||||||
res.json({ success: true });
|
res.json({ success: true });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ export function deleteObjectFromS3(req, res) {
|
||||||
export function signS3(req, res) {
|
export function signS3(req, res) {
|
||||||
const limit = process.env.UPLOAD_LIMIT || 250000000;
|
const limit = process.env.UPLOAD_LIMIT || 250000000;
|
||||||
if (req.user.totalSize > limit) {
|
if (req.user.totalSize > limit) {
|
||||||
res.status(403).send({message: 'user has uploaded the maximum size of assets.'});
|
res.status(403).send({ message: 'user has uploaded the maximum size of assets.' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const fileExtension = getExtension(req.body.name);
|
const fileExtension = getExtension(req.body.name);
|
||||||
|
@ -95,7 +95,7 @@ export function signS3(req, res) {
|
||||||
policy: p.policy,
|
policy: p.policy,
|
||||||
signature: p.signature
|
signature: p.signature
|
||||||
};
|
};
|
||||||
return res.json(result);
|
res.json(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function copyObjectInS3(req, res) {
|
export function copyObjectInS3(req, res) {
|
||||||
|
@ -135,43 +135,41 @@ export function listObjectsInS3ForUser(userId) {
|
||||||
.on('end', () => {
|
.on('end', () => {
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
}).then(() => {
|
}).then(() => getProjectsForUserId(userId)).then((projects) => {
|
||||||
return getProjectsForUserId(userId);
|
const projectAssets = [];
|
||||||
}).then((projects) => {
|
let totalSize = 0;
|
||||||
const projectAssets = [];
|
assets.forEach((asset) => {
|
||||||
let totalSize = 0;
|
const name = asset.key.split('/').pop();
|
||||||
assets.forEach((asset) => {
|
const foundAsset = {
|
||||||
const name = asset.key.split('/').pop();
|
key: asset.key,
|
||||||
const foundAsset = {
|
name,
|
||||||
key: asset.key,
|
size: asset.size,
|
||||||
name,
|
url: `${process.env.S3_BUCKET_URL_BASE}${asset.key}`
|
||||||
size: asset.size,
|
};
|
||||||
url: `${process.env.S3_BUCKET_URL_BASE}${asset.key}`
|
totalSize += asset.size;
|
||||||
};
|
projects.some((project) => {
|
||||||
totalSize += asset.size;
|
let found = false;
|
||||||
projects.some((project) => {
|
project.files.some((file) => {
|
||||||
let found = false;
|
if (!file.url) return false;
|
||||||
project.files.some((file) => {
|
if (file.url.includes(asset.key)) {
|
||||||
if (!file.url) return false;
|
found = true;
|
||||||
if (file.url.includes(asset.key)) {
|
foundAsset.name = file.name;
|
||||||
found = true;
|
foundAsset.sketchName = project.name;
|
||||||
foundAsset.name = file.name;
|
foundAsset.sketchId = project.id;
|
||||||
foundAsset.sketchName = project.name;
|
foundAsset.url = file.url;
|
||||||
foundAsset.sketchId = project.id;
|
return true;
|
||||||
foundAsset.url = file.url;
|
}
|
||||||
return true;
|
return false;
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
return found;
|
|
||||||
});
|
});
|
||||||
projectAssets.push(foundAsset);
|
return found;
|
||||||
});
|
});
|
||||||
return Promise.resolve({ assets: projectAssets, totalSize});
|
projectAssets.push(foundAsset);
|
||||||
}).catch((err) => {
|
|
||||||
console.log('got an error');
|
|
||||||
console.log(err);
|
|
||||||
});
|
});
|
||||||
|
return Promise.resolve({ assets: projectAssets, totalSize });
|
||||||
|
}).catch((err) => {
|
||||||
|
console.log('got an error');
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function listObjectsInS3ForUserRequestHandler(req, res) {
|
export function listObjectsInS3ForUserRequestHandler(req, res) {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
/* eslint-disable */
|
||||||
import mongoose from 'mongoose';
|
import mongoose from 'mongoose';
|
||||||
|
|
||||||
import User from '../models/user';
|
import User from '../models/user';
|
||||||
|
|
|
@ -6,7 +6,7 @@ const router = new Router();
|
||||||
|
|
||||||
router.post('/S3/sign', isAuthenticated, AWSController.signS3);
|
router.post('/S3/sign', isAuthenticated, AWSController.signS3);
|
||||||
router.post('/S3/copy', isAuthenticated, AWSController.copyObjectInS3);
|
router.post('/S3/copy', isAuthenticated, AWSController.copyObjectInS3);
|
||||||
router.delete('/S3/:user_id?/:object_key', isAuthenticated, AWSController.deleteObjectFromS3);
|
router.delete('/S3/:userId?/:objectKey', isAuthenticated, AWSController.deleteObjectFromS3);
|
||||||
router.get('/S3/objects', AWSController.listObjectsInS3ForUserRequestHandler);
|
router.get('/S3/objects', AWSController.listObjectsInS3ForUserRequestHandler);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|
Loading…
Reference in a new issue