Merge pull request 'Removing toaster at every request' (#160) from tonitch/del/toast into master
Some checks failed
Some checks failed
Reviewed-on: #160
This commit is contained in:
commit
061f329020
@ -3,25 +3,25 @@ import { toast } from 'vue3-toastify'
|
|||||||
|
|
||||||
const restURL = import.meta.env.VITE_CLYDE_MODE === 'container' ? "http://localhost:8080": import.meta.env.DEV ? "http://localhost:8080" : "https://clyde.herisson.ovh/api"
|
const restURL = import.meta.env.VITE_CLYDE_MODE === 'container' ? "http://localhost:8080": import.meta.env.DEV ? "http://localhost:8080" : "https://clyde.herisson.ovh/api"
|
||||||
|
|
||||||
export async function restGet(endPoint) {
|
export function restGet(endPoint) {
|
||||||
return await _rest(endPoint, {method: "GET"});
|
return _rest(endPoint, {method: "GET"});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function restPost(endPoint, data) {
|
export function restPost(endPoint, data) {
|
||||||
return await _rest(endPoint, {method: "POST", credentials: 'include', body: JSON.stringify(data)});
|
return _rest(endPoint, {method: "POST", credentials: 'include', body: JSON.stringify(data)});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function restPostFile(endPoint, file){
|
export function restPostFile(endPoint, file){
|
||||||
let headers = new Headers();
|
let headers = new Headers();
|
||||||
return await _rest(endPoint, {method: "POST", credentials: 'include', body: file, headers: headers });
|
return _rest(endPoint, {method: "POST", credentials: 'include', body: file, headers: headers });
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function restDelete(endPoint) {
|
export function restDelete(endPoint) {
|
||||||
return await _rest(endPoint, {method: "DELETE"});
|
return _rest(endPoint, {method: "DELETE"});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function restPatch(endPoint, data) {
|
export function restPatch(endPoint, data) {
|
||||||
return await _rest(endPoint, {method: "PATCH", credentials: 'include', body: JSON.stringify(data)});
|
return _rest(endPoint, {method: "PATCH", credentials: 'include', body: JSON.stringify(data)});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -33,7 +33,7 @@ export async function restPatch(endPoint, data) {
|
|||||||
*
|
*
|
||||||
* @Example _rest("/ping", {user: data}) -> {id:0, txt:"pong"}
|
* @Example _rest("/ping", {user: data}) -> {id:0, txt:"pong"}
|
||||||
*/
|
*/
|
||||||
async function _rest(endPoint, config){
|
function _rest(endPoint, config){
|
||||||
endPoint.at(0) != "/" ? console.error("Carefull, you certainly should put a / at the begenning of your endPoint ") : true;
|
endPoint.at(0) != "/" ? console.error("Carefull, you certainly should put a / at the begenning of your endPoint ") : true;
|
||||||
let session_token = getCookie("session_token");
|
let session_token = getCookie("session_token");
|
||||||
let headers = new Headers({
|
let headers = new Headers({
|
||||||
@ -41,13 +41,16 @@ async function _rest(endPoint, config){
|
|||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
});
|
});
|
||||||
config['headers'] = config['headers'] == null ? headers : config['headers'];
|
config['headers'] = config['headers'] == null ? headers : config['headers'];
|
||||||
return toast.promise(fetch(restURL + endPoint, config),
|
|
||||||
|
let ret = fetch(restURL + endPoint, config);
|
||||||
|
if(config['toast']){
|
||||||
|
ret = toast.promise(ret,
|
||||||
{
|
{
|
||||||
pending: config['pending'] != null ? config['pending'] : 'pending',
|
pending: config['pending'] != null ? config['pending'] : 'pending',
|
||||||
error: config['error'] != null ? config['error'] : 'Network Failure...',
|
error: config['error'] != null ? config['error'] : 'Network Failure...',
|
||||||
success: config['success'] != null ? config['success'] : {render(res){
|
success: config['success'] != null ? config['success'] : {render(res){
|
||||||
return res.data.ok ? "Success" : "error";
|
return res.data.ok ? "Success" : "error";
|
||||||
}},
|
}}})
|
||||||
})
|
}
|
||||||
.then( e => e.json()).catch( e => e );
|
return ret.then( e => e.json()).catch( e => e );
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user