MCPcopy Create free account
hub / github.com/6dylan6/jdm / curl

Method curl

function/common.js:78–119  ·  view source on GitHub ↗
(params, extra = '')

Source from the content-addressed store, hash-verified

76 }
77 }
78 curl(params, extra = '') {
79 if (typeof(params) != 'object') {
80 params = {
81 'url': params
82 }
83 }
84 params = Object.assign({ ...this.options
85 }, params);
86 params.method = params.body ? 'POST' : 'GET';
87 if (params.hasOwnProperty('cookie')) {
88 params.headers.cookie = params.cookie
89 }
90 if (params.hasOwnProperty('ua') || params.hasOwnProperty('useragent')) {
91 params.headers['user-agent'] = params.ua
92 }
93 if (params.hasOwnProperty('referer')) {
94 params.headers.referer = params.referer
95 }
96 if (params.hasOwnProperty('params')) {
97 params.url += '?' + qs.stringify(params.params)
98 }
99 if (params.hasOwnProperty('form')) {
100 params.method = 'POST'
101 }
102 return new Promise(resolve => {
103 request(params, async (err, resp, data) => {
104 try {
105 if (params.console) {
106 console.log(data)
107 }
108 this.source = this.jsonParse(data);
109 if (extra) {
110 this[extra] = this.source
111 }
112 } catch (e) {
113 console.log(e, resp)
114 } finally {
115 resolve(data);
116 }
117 })
118 })
119 }
120 dumps(dict) {
121 return JSON.stringify(dict)
122 }

Callers

nothing calls this directly

Calls 2

jsonParseMethod · 0.95
logMethod · 0.45

Tested by

no test coverage detected