volumes: update route
This commit is contained in:
@@ -6,7 +6,7 @@ exports = module.exports = {
|
||||
del,
|
||||
list,
|
||||
load,
|
||||
setMountConfig,
|
||||
update,
|
||||
getMountStatus
|
||||
};
|
||||
|
||||
@@ -61,13 +61,13 @@ async function list(req, res, next) {
|
||||
next(new HttpSuccess(200, { volumes: result }));
|
||||
}
|
||||
|
||||
async function setMountConfig(req, res, next) {
|
||||
async function update(req, res, next) {
|
||||
assert.strictEqual(typeof req.params.id, 'string');
|
||||
|
||||
if (typeof req.body.mountType !== 'string') return next(new HttpError(400, 'mountType must be a string'));
|
||||
if (typeof req.body.mountOptions !== 'object') return next(new HttpError(400, 'mountOptions must be a object'));
|
||||
|
||||
const [error] = await safe(volumes.setMountConfig(req.resource, req.body.mountType, req.body.mountOptions));
|
||||
const [error] = await safe(volumes.update(req.resource, req.body.mountType, req.body.mountOptions));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
next(new HttpSuccess(200, {}));
|
||||
}
|
||||
|
||||
+1
-1
@@ -310,7 +310,7 @@ function initializeExpressSync() {
|
||||
router.get ('/api/v1/volumes', token, authorizeAdmin, routes.volumes.list);
|
||||
router.get ('/api/v1/volumes/:id', token, authorizeAdmin, routes.volumes.load, routes.volumes.get);
|
||||
router.del ('/api/v1/volumes/:id', token, authorizeAdmin, routes.volumes.load, routes.volumes.del);
|
||||
router.post('/api/v1/volumes/:id/mount_config', token, authorizeAdmin, routes.volumes.load, routes.volumes.setMountConfig);
|
||||
router.post('/api/v1/volumes/:id', json, token, authorizeAdmin, routes.volumes.load, routes.volumes.update);
|
||||
router.get ('/api/v1/volumes/:id/mount_status', token, authorizeAdmin, routes.volumes.load, routes.volumes.getMountStatus);
|
||||
router.use ('/api/v1/volumes/:id/files/*', token, authorizeAdmin, routes.filemanager.proxy);
|
||||
|
||||
|
||||
+9
-3
@@ -5,7 +5,7 @@ exports = module.exports = {
|
||||
get,
|
||||
del,
|
||||
list,
|
||||
setMountConfig,
|
||||
update,
|
||||
getMountStatus,
|
||||
};
|
||||
|
||||
@@ -136,7 +136,7 @@ async function removeMountFile(volume) {
|
||||
await safe(shell.promises.sudo('generateMountFile', [ RM_MOUNT_CMD, volume.hostPath ], {})); // ignore any error
|
||||
}
|
||||
|
||||
async function setMountConfig(volume, mountType, mountOptions) {
|
||||
async function update(volume, mountType, mountOptions) {
|
||||
assert.strictEqual(typeof volume, 'object');
|
||||
assert.strictEqual(typeof mountType, 'string');
|
||||
assert.strictEqual(typeof mountOptions, 'object');
|
||||
@@ -144,8 +144,14 @@ async function setMountConfig(volume, mountType, mountOptions) {
|
||||
let error = validateMountOptions(mountType, mountOptions);
|
||||
if (error) throw error;
|
||||
|
||||
if (mountType === 'noop') {
|
||||
await safe(removeMountFile(Object.assign({}, volume, { mountType, mountOptions })));
|
||||
} else {
|
||||
await safe(writeMountFile(Object.assign({}, volume, { mountType, mountOptions })));
|
||||
}
|
||||
|
||||
let result;
|
||||
[error, result] = await safe(database.query('UPDATE volumes SET mountType=? AND mountOptionsJson=? WHERE id=?', [ mountType, JSON.stringify(mountOptions), volume.id ]));
|
||||
[error, result] = await safe(database.query('UPDATE volumes SET mountType=?, mountOptionsJson=? WHERE id=?', [ mountType, JSON.stringify(mountOptions), volume.id ]));
|
||||
if (error) throw error;
|
||||
if (result.affectedRows !== 1) throw new BoxError(BoxError.NOT_FOUND, 'Volume not found');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user