-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding in mob data editing and exporting
- Loading branch information
1 parent
5aaef5a
commit 2803af9
Showing
5 changed files
with
73 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,53 @@ | ||
import axios from 'axios'; | ||
import {GetJwtToken} from './session-service'; | ||
import axios, {type AxiosRequestConfig, type AxiosResponse} from 'axios'; | ||
import { GetJwtToken } from './session-service'; | ||
import { toast } from "@zerodevx/svelte-toast"; | ||
|
||
export class HttpService { | ||
private static instance: HttpService; | ||
|
||
constructor() { | ||
private constructor() { | ||
axios.defaults.baseURL = import.meta.env.VITE_API_BASE_URL; | ||
axios.interceptors.request.use((config) => { | ||
if (GetJwtToken()) { | ||
config.headers['Authorization'] = `Bearer ${GetJwtToken()}`; | ||
} | ||
return config; | ||
}, (error) => { | ||
// Do something with request error | ||
return Promise.reject(error); | ||
}); | ||
|
||
axios.interceptors.response.use(function (response) { | ||
return response; | ||
}, function (error) { | ||
toast.push('Failed to fetch'); | ||
return Promise.reject(error); | ||
}); | ||
} | ||
|
||
public static getInstance(): HttpService { | ||
if (!HttpService.instance) { | ||
HttpService.instance = new HttpService(); | ||
} | ||
return HttpService.instance; | ||
} | ||
|
||
public async get(url: string): Promise<any> { | ||
public async get(url: string): Promise<AxiosResponse> { | ||
return await axios.get(url); | ||
} | ||
|
||
public async post(url: string, data: any): Promise<any> { | ||
return await axios.post(url, data); | ||
public async post(url: string, data: any, options?: AxiosRequestConfig): Promise<AxiosResponse> { | ||
return await axios.post(url, data, options); | ||
} | ||
|
||
public async put(url: string, data: any): Promise<any> { | ||
public async put(url: string, data: any): Promise<AxiosResponse> { | ||
return await axios.put(url, data); | ||
} | ||
|
||
public async delete(url: string): Promise<any> { | ||
public async delete(url: string): Promise<AxiosResponse> { | ||
return await axios.delete(url); | ||
} | ||
|
||
public async patch(url: string, data: any): Promise<any> { | ||
public async patch(url: string, data: any): Promise<AxiosResponse> { | ||
return await axios.patch(url, data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters