@@ -100,9 +100,22 @@ const createMiddleware = core => {
100
100
} ) ;
101
101
} ;
102
102
103
+ const createOptions = req => {
104
+ const options = req . fields . options ;
105
+ if ( typeof options === 'string' ) {
106
+ try {
107
+ return JSON . parse ( req . fields . options ) || { } ;
108
+ } catch ( e ) {
109
+ // Allow to fall through
110
+ }
111
+ }
112
+
113
+ return options || { } ;
114
+ } ;
115
+
103
116
// Standard request with only a target
104
117
const createRequestFactory = findMountpoint => ( getter , method , readOnly , respond ) => async ( req , res ) => {
105
- const options = req . fields . options || { } ;
118
+ const options = createOptions ( req ) ;
106
119
const args = [ ...getter ( req , res ) , options ] ;
107
120
108
121
const found = await findMountpoint ( args [ 0 ] ) ;
@@ -125,7 +138,7 @@ const createRequestFactory = findMountpoint => (getter, method, readOnly, respon
125
138
126
139
// Request that has a source and target
127
140
const createCrossRequestFactory = findMountpoint => ( getter , method , respond ) => async ( req , res ) => {
128
- const [ from , to , options ] = [ ...getter ( req , res ) , req . fields . options || { } ] ;
141
+ const [ from , to , options ] = [ ...getter ( req , res ) , createOptions ( req ) ] ;
129
142
130
143
const srcMount = await findMountpoint ( from ) ;
131
144
const destMount = await findMountpoint ( to ) ;
0 commit comments