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

Function getMockInfo

Rewrite-Parser.beta.js:2581–2749  ·  view source on GitHub ↗
(x, mark, y)

Source from the content-addressed store, hash-verified

2579
2580//获取mock参数
2581function getMockInfo(x, mark, y) {
2582 let noteK = isNoteK(x)
2583 let mockptn, mockurl, mockheader, mocktype, mockstatus, oritype, datapath, data, mockbase64
2584 if (/url\s+echo-response\s/.test(x)) {
2585 mockptn = x.split(/\s+url\s+/)[0]
2586 mockurl = x.split(/\s+echo-response\s+/)[2]
2587 mocktype = 'file'
2588 mockheader = '&contentType=' + encodeURIComponent(x.split(/\s+echo-response\s+/)[1])
2589 oritype = mocktype
2590 }
2591
2592 if (/\sdata\s*=\s*"|\sdata-type=/.test(x)) {
2593 mockptn = x
2594 .split(/\s+/)[0]
2595 .replace(/^#/g, '')
2596 .replace(/^"(.+)"$/, '$1')
2597 datapath = getJsInfo(x, /\s+data-path\s*=\s*/).replace(/^"(.*)"$/, '$1')
2598 data = getJsInfo(x, /\s+data\s*=\s*/).replace(/^"(.*)"$/, '$1')
2599 mockurl = data || datapath
2600 mockbase64 = getJsInfo(x, /\s+mock-data-is-base64\s*=\s*/)
2601 mocktype = getJsInfo(x, /\s+data-type\s*=\s*/) || 'file'
2602 oritype = mocktype
2603 mockstatus = getJsInfo(x, /\s+status-code\s*=\s*/)
2604 mockheader = getJsInfo(x, /\s+header\s*=\s*/).replace(/^"(.+)"$/, '$1')
2605 if (/\smock-response-body\s/.test(x)) {
2606 // Loon data-type: body的类型,json,text,css,html,javascript,plain,png,gif,jpeg,tiff,svg,mp4,form-data 应该设置对应的 Content-Type
2607 switch (mocktype) {
2608 case 'json':
2609 mockheader = 'Content-Type:application/json'
2610 break
2611 case 'text':
2612 mockheader = 'Content-Type:text/plain'
2613 break
2614 case 'css':
2615 mockheader = 'Content-Type:text/css'
2616 break
2617 case 'html':
2618 mockheader = 'Content-Type:text/html'
2619 break
2620 case 'javascript':
2621 mockheader = 'Content-Type:text/javascript'
2622 break
2623 case 'plain':
2624 mockheader = 'Content-Type:text/plain'
2625 break
2626 case 'png':
2627 mockheader = 'Content-Type:image/png'
2628 break
2629 case 'gif':
2630 mockheader = 'Content-Type:image/gif'
2631 break
2632 case 'jpeg':
2633 mockheader = 'Content-Type:image/jpeg'
2634 break
2635 case 'tiff':
2636 mockheader = 'Content-Type:image/tiff'
2637 break
2638 case 'svg':

Callers 1

Calls 4

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

Tested by

no test coverage detected