MCPcopy Create free account
hub / github.com/Script-Hub-Org/Script-Hub / getMockInfo

Function getMockInfo

Rewrite-Parser.js:2177–2345  ·  view source on GitHub ↗
(x, mark, y)

Source from the content-addressed store, hash-verified

2175
2176//获取mock参数
2177function getMockInfo(x, mark, y) {
2178 let noteK = isNoteK(x)
2179 let mockptn, mockurl, mockheader, mocktype, mockstatus, oritype, datapath, data, mockbase64
2180 if (/url\s+echo-response\s/.test(x)) {
2181 mockptn = x.split(/\s+url\s+/)[0]
2182 mockurl = x.split(/\s+echo-response\s+/)[2]
2183 mocktype = 'file'
2184 mockheader = '&contentType=' + encodeURIComponent(x.split(/\s+echo-response\s+/)[1])
2185 oritype = mocktype
2186 }
2187
2188 if (/\sdata\s*=\s*"|\sdata-type=/.test(x)) {
2189 mockptn = x
2190 .split(/\s+/)[0]
2191 .replace(/^#/g, '')
2192 .replace(/^"(.+)"$/, '$1')
2193 datapath = getJsInfo(x, /\s+data-path\s*=\s*/).replace(/^"(.*)"$/, '$1')
2194 data = getJsInfo(x, /\s+data\s*=\s*/).replace(/^"(.*)"$/, '$1')
2195 mockurl = data || datapath
2196 mockbase64 = getJsInfo(x, /\s+mock-data-is-base64\s*=\s*/)
2197 mocktype = getJsInfo(x, /\s+data-type\s*=\s*/) || 'file'
2198 oritype = mocktype
2199 mockstatus = getJsInfo(x, /\s+status-code\s*=\s*/)
2200 mockheader = getJsInfo(x, /\s+header\s*=\s*/).replace(/^"(.+)"$/, '$1')
2201 if (/\smock-response-body\s/.test(x)) {
2202 // Loon data-type: body的类型,json,text,css,html,javascript,plain,png,gif,jpeg,tiff,svg,mp4,form-data 应该设置对应的 Content-Type
2203 switch (mocktype) {
2204 case 'json':
2205 mockheader = 'Content-Type:application/json'
2206 break
2207 case 'text':
2208 mockheader = 'Content-Type:text/plain'
2209 break
2210 case 'css':
2211 mockheader = 'Content-Type:text/css'
2212 break
2213 case 'html':
2214 mockheader = 'Content-Type:text/html'
2215 break
2216 case 'javascript':
2217 mockheader = 'Content-Type:text/javascript'
2218 break
2219 case 'plain':
2220 mockheader = 'Content-Type:text/plain'
2221 break
2222 case 'png':
2223 mockheader = 'Content-Type:image/png'
2224 break
2225 case 'gif':
2226 mockheader = 'Content-Type:image/gif'
2227 break
2228 case 'jpeg':
2229 mockheader = 'Content-Type:image/jpeg'
2230 break
2231 case 'tiff':
2232 mockheader = 'Content-Type:image/tiff'
2233 break
2234 case 'svg':

Callers 1

Rewrite-Parser.jsFile · 0.70

Calls 4

isNoteKFunction · 0.70
getJsInfoFunction · 0.70
shNotifyFunction · 0.70
logMethod · 0.45

Tested by

no test coverage detected