mirror of
https://github.com/rustfs/console.git
synced 2026-09-19 01:47:44 +08:00
feat: login
This commit is contained in:
+19
-10
@@ -1,42 +1,51 @@
|
||||
import type { AwsClient } from "aws4fetch"
|
||||
import { joinURL } from "ufo"
|
||||
|
||||
type FetchType = typeof $fetch
|
||||
class ApiClient {
|
||||
private $api: any
|
||||
private config?: { baseUrl?: string, headers?: Record<string, string> }
|
||||
|
||||
constructor(api: FetchType) {
|
||||
constructor(api: AwsClient, options?: any) {
|
||||
this.$api = api
|
||||
this.config = options
|
||||
}
|
||||
|
||||
async request(url: string, options?: any) {
|
||||
url = this.config?.baseUrl ? joinURL(this.config?.baseUrl, url) : url
|
||||
options.headers = { ...this.config?.headers, ...options.headers }
|
||||
return this.$api.fetch(url, options)
|
||||
}
|
||||
|
||||
async get(url: string, options?: any) {
|
||||
return this.$api(url, { method: 'GET', ...options })
|
||||
return this.request(url, { method: 'GET', ...options })
|
||||
}
|
||||
|
||||
async post(url: string, body: any, options?: any) {
|
||||
return this.$api(url, { method: 'POST', body, ...options })
|
||||
return this.request(url, { method: 'POST', body, ...options })
|
||||
}
|
||||
|
||||
async delete(url: string, options?: any) {
|
||||
return this.$api(url, { method: 'DELETE', ...options })
|
||||
return this.request(url, { method: 'DELETE', ...options })
|
||||
}
|
||||
|
||||
async put(url: string, body: any, options?: any) {
|
||||
return this.$api(url, { method: 'PUT', body, ...options })
|
||||
return this.request(url, { method: 'PUT', body, ...options })
|
||||
}
|
||||
|
||||
async patch(url: string, body: any, options?: any) {
|
||||
return this.$api(url, { method: 'PATCH', body, ...options })
|
||||
return this.request(url, { method: 'PATCH', body, ...options })
|
||||
}
|
||||
|
||||
async head(url: string, options?: any) {
|
||||
return this.$api(url, { method: 'HEAD', ...options })
|
||||
return this.request(url, { method: 'HEAD', ...options })
|
||||
}
|
||||
|
||||
async options(url: string, options?: any) {
|
||||
return this.$api(url, { method: 'OPTIONS', ...options })
|
||||
return this.request(url, { method: 'OPTIONS', ...options })
|
||||
}
|
||||
|
||||
async trace(url: string, options?: any) {
|
||||
return this.$api(url, { method: 'TRACE', ...options })
|
||||
return this.request(url, { method: 'TRACE', ...options })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user