Skip to content

Commit

Permalink
Improve unserialization of VFS URL query parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
mahsashadi authored and mahsa shadi committed Sep 3, 2021
1 parent cde5db7 commit f641af8
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/vfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const createMiddleware = core => {
};

const createOptions = req => {
const options = req.fields.options;
const options = req.fields.options ? req.fields.options : decodeOptions(req.fields);
const range = req.headers && req.headers.range;
const session = {...req.session || {}};
let result = options || {};
Expand All @@ -134,6 +134,30 @@ const createOptions = req => {
};
};

const decodeOptions = (reqFileds) => {
let options = {};
let keyPath = [];
Object.keys(reqFileds).map((item) => {
keyPath = item.split('.');
assignObject(options, keyPath, reqFileds[item]);
});
console.log(options)
return options;
};

const assignObject = (obj, keyPath, value) => {
let lastKeyIndex = keyPath.length - 1;
let key;
for (let i = 0; i < lastKeyIndex; i++) {
key = keyPath[i];
if (!(key in obj)) {
obj[key] = {};
}
obj = obj[key];
}
obj[keyPath[lastKeyIndex]] = value;
};

// Standard request with only a target
const createRequestFactory = findMountpoint => (getter, method, readOnly, respond) => async (req, res) => {
const options = createOptions(req);
Expand Down

0 comments on commit f641af8

Please sign in to comment.