Skip to content

Commit f641af8

Browse files
mahsashadimahsa shadi
authored andcommitted
Improve unserialization of VFS URL query parameters
1 parent cde5db7 commit f641af8

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/vfs.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ const createMiddleware = core => {
111111
};
112112

113113
const createOptions = req => {
114-
const options = req.fields.options;
114+
const options = req.fields.options ? req.fields.options : decodeOptions(req.fields);
115115
const range = req.headers && req.headers.range;
116116
const session = {...req.session || {}};
117117
let result = options || {};
@@ -134,6 +134,30 @@ const createOptions = req => {
134134
};
135135
};
136136

137+
const decodeOptions = (reqFileds) => {
138+
let options = {};
139+
let keyPath = [];
140+
Object.keys(reqFileds).map((item) => {
141+
keyPath = item.split('.');
142+
assignObject(options, keyPath, reqFileds[item]);
143+
});
144+
console.log(options)
145+
return options;
146+
};
147+
148+
const assignObject = (obj, keyPath, value) => {
149+
let lastKeyIndex = keyPath.length - 1;
150+
let key;
151+
for (let i = 0; i < lastKeyIndex; i++) {
152+
key = keyPath[i];
153+
if (!(key in obj)) {
154+
obj[key] = {};
155+
}
156+
obj = obj[key];
157+
}
158+
obj[keyPath[lastKeyIndex]] = value;
159+
};
160+
137161
// Standard request with only a target
138162
const createRequestFactory = findMountpoint => (getter, method, readOnly, respond) => async (req, res) => {
139163
const options = createOptions(req);

0 commit comments

Comments
 (0)