MCPcopy
hub / github.com/1Panel-dev/MaxKB / promise

Function promise

ui/src/request/index.ts:98–125  ·  view source on GitHub ↗
(request, loading = ref(false))

Source from the content-addressed store, hash-verified

96 request: Promise<any>,
97 loading?: NProgress | Ref<boolean> | WritableComputedRef<boolean>,
98) => Promise<Result<any>> = (request, loading = ref(false)) => {
99 return new Promise((resolve, reject) => {
100 if ((loading as NProgress).start) {
101 ;(loading as NProgress).start()
102 } else {
103 ;(loading as Ref).value = true
104 }
105 request
106 .then((response) => {
107 // blob类型的返回状态是response.status
108 if (response.status === 200) {
109 resolve(response?.data || response)
110 } else {
111 reject(response?.data || response)
112 }
113 })
114 .catch((error) => {
115 reject(error)
116 })
117 .finally(() => {
118 if ((loading as NProgress).start) {
119 ;(loading as NProgress).done()
120 } else {
121 ;(loading as Ref).value = false
122 }
123 })
124 })
125}
126
127/**
128 * 发送get请求 一般用来请求资源

Callers 9

getFunction · 0.70
postFunction · 0.70
putFunction · 0.70
delFunction · 0.70
exportExcelFunction · 0.70
exportFileFunction · 0.70
exportExcelPostFunction · 0.70
exportFilePostFunction · 0.70
downloadFunction · 0.70

Calls 1

startMethod · 0.45

Tested by

no test coverage detected