mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-02-20 17:34:10 +01:00
feat: add data-provider
This commit is contained in:
parent
21920dd864
commit
2589754171
7 changed files with 578 additions and 0 deletions
66
client/src/data-provider/request.ts
Normal file
66
client/src/data-provider/request.ts
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
import axios, { AxiosRequestConfig } from "axios";
|
||||
|
||||
async function _get<T>(url: string, options?: AxiosRequestConfig): Promise<T> {
|
||||
const response = await axios.get(url, { withCredentials: true, ...options});
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async function _post(url: string, data?: any) {
|
||||
const response = await axios.post(url, JSON.stringify(data), {
|
||||
withCredentials: true,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async function _postMultiPart(
|
||||
url: string,
|
||||
formData: FormData,
|
||||
options?: AxiosRequestConfig
|
||||
) {
|
||||
const response = await axios.post(url, formData, {
|
||||
withCredentials: true,
|
||||
...options,
|
||||
headers: { "Content-Type": "multipart/form-data" },
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async function _put(url: string, data?: any) {
|
||||
const response = await axios.put(url, JSON.stringify(data), {
|
||||
withCredentials: true,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async function _delete<T>(url: string): Promise<T> {
|
||||
const response = await axios.delete(url, { withCredentials: true });
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async function _deleteWithOptions<T>(
|
||||
url: string,
|
||||
options?: AxiosRequestConfig
|
||||
): Promise<T> {
|
||||
const response = await axios.delete(url, { withCredentials: true, ...options});
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async function _patch(url: string, data?: any) {
|
||||
const response = await axios.patch(url, JSON.stringify(data), {
|
||||
withCredentials: true,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export default {
|
||||
get: _get,
|
||||
post: _post,
|
||||
postMultiPart: _postMultiPart,
|
||||
put: _put,
|
||||
delete: _delete,
|
||||
deleteWithOptions: _deleteWithOptions,
|
||||
patch: _patch,
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue