MCPcopy Create free account
hub / github.com/CoderOpen/waimai / download

Method download

front/utils/luch-request/core/Request.js:369–410  ·  view source on GitHub ↗
(url, options = {})

Source from the content-addressed store, hash-verified

367 }
368
369 download(url, options = {}) {
370 return new Promise((resolve, reject) => {
371 let next = true
372 const pubConfig = {
373 baseUrl: this.config.baseUrl,
374 url,
375 method: 'DOWNLOAD',
376 header: {...this.config.header, ...(options.header || {})},
377 params: options.params || {},
378 custom: {...this.config.custom, ...(options.custom || {})},
379 getTask: options.getTask || this.config.getTask
380 }
381 const cancel = (t = 'handle cancel', config = pubConfig) => {
382 const err = {
383 errMsg: t,
384 config: config
385 }
386 reject(err)
387 next = false
388 }
389
390 const handleRe = {...this.requestBeforeFun(pubConfig, cancel)}
391 if (!next) return
392 const requestTask = uni.downloadFile({
393 url: buildURL(buildFullPath(handleRe.baseUrl, handleRe.url), handleRe.params),
394 header: handleRe.header,
395 complete: (response) => {
396 response.config = handleRe
397 if (this.validateStatus(response.statusCode)) { // 成功
398 response = this.requestComFun(response)
399 resolve(response)
400 } else {
401 response = this.requestComFail(response)
402 reject(response)
403 }
404 }
405 })
406 if (handleRe.getTask) {
407 handleRe.getTask(requestTask, handleRe)
408 }
409 })
410 }
411}
412
413

Callers

nothing calls this directly

Calls 3

validateStatusMethod · 0.95
buildURLFunction · 0.85
buildFullPathFunction · 0.85

Tested by

no test coverage detected