2
import type { AxiosRequestConfig, AxiosResponse } from 'axios'
4
export const httpClientActions = {
5
get<T = unknown, R = AxiosResponse<T>, D = unknown> (url: string, options?: AxiosRequestConfig) {
6
return Vue.$httpClient.get<T, R, D>(url, options)
9
post<T = unknown, R = AxiosResponse<T>, D = unknown> (url: string, data: D, options?: AxiosRequestConfig) {
10
return Vue.$httpClient.post<T, R, D>(url, data, options)
13
postForm<T = unknown, R = AxiosResponse<T>, D = unknown> (url: string, data: D, options?: AxiosRequestConfig) {
14
return Vue.$httpClient.postForm<T, R, D>(url, data, options)
17
delete<T = unknown, R = AxiosResponse<T>, D = unknown> (url: string, options?: AxiosRequestConfig) {
18
return Vue.$httpClient.delete<T, R, D>(url, options)
22
return Vue.$httpClient.defaults
25
accessInfoGet (options?: AxiosRequestConfig) {
28
default_source: string,
29
available_sources: string[]
31
}>('/access/info', options)
34
accessRefreshJwtPost (refresh_token: string, options?: AxiosRequestConfig) {
42
}>('/access/refresh_jwt', { refresh_token }, options)
45
accessLoginPost (username: string, password: string, source = 'moonraker', options?: AxiosRequestConfig) {
50
refresh_token: string,
61
accessLogoutPost (options?: AxiosRequestConfig) {
67
}>('access/logout', undefined, options)
70
accessOneshotTokenGet (options?: AxiosRequestConfig) {
73
}>('/access/oneshot_token', options)
76
accessCurrentUserGet (options?: AxiosRequestConfig) {
83
}>('/access/user', options)
86
accessUsersListGet (options?: AxiosRequestConfig) {
95
}>('/access/users/list', options)
98
accessUserPost (username: string, password: string, options?: AxiosRequestConfig) {
103
refresh_token: string,
113
accessUserDelete (username: string, options?: AxiosRequestConfig) {
125
accessUserPasswordPost (password: string, new_password: string, options?: AxiosRequestConfig) {
131
}>('/access/user/password', {
137
accessApiKeyGet (options?: AxiosRequestConfig) {
140
}>('/access/api_key', options)
143
accessApiKeyPost (options?: AxiosRequestConfig) {
146
}>('/access/api_key', undefined, options)
149
serverDatabaseItemGet<T = unknown> (namespace: string, options?: AxiosRequestConfig) {
156
}>(`/server/database/item?namespace=${namespace}`, options)
159
serverDatabaseItemPost<T = unknown> (namespace: string, key: string, value: T, options?: AxiosRequestConfig) {
166
}>('/server/database/item', {
173
serverDatabaseItemDelete<T = unknown> (namespace: string, key: string, options?: AxiosRequestConfig) {
180
}>(`/server/database/item?namespace=${namespace}&key=${key}`, options)
183
serverFilesUploadPost (file: File, path: string, root: string, print?: boolean, options?: AxiosRequestConfig) {
184
const formData = new FormData()
186
formData.append('file', file, file.name)
187
formData.append('path', path)
188
formData.append('root', root)
190
formData.append('print', 'true')
193
return this.postForm<{
199
print_started?: boolean,
202
}>('/server/files/upload', formData, options)
205
serverFilesGet<T = unknown> (filepath: string, options?: AxiosRequestConfig) {
206
return this.get<T>(`/server/files/${encodeURI(filepath)}?date=${Date.now()}`, options)