Files
wticreatorstudio/Modules/Livestream/Resources/client/api/useRestream.js
2024-04-25 16:48:43 +08:00

42 lines
1.2 KiB
JavaScript

import { toValue } from "vue";
import { toast } from "vue3-toastify";
import { request } from "@/helpers/axios";
export function useRestream() {
function updateRestreamSettings(clientId, clientSecret) {
return new Promise(async (resolve, reject) => {
try {
const response = await request().put(route("restream.update-settings"), {
client_id: toValue(clientId),
client_secret: toValue(clientSecret),
});
const { data } = response;
const { message, item } = data;
toast(message, {
type: toast.TYPE.SUCCESS,
position: toast.POSITION.TOP_RIGHT,
});
resolve(item);
} catch (error) {
handleError(error);
reject(error);
}
});
}
function handleError(error) {
const { response } = error;
const { data } = response;
const { message } = data;
toast(message, {
type: toast.TYPE.ERROR,
position: toast.POSITION.TOP_RIGHT,
});
}
return {
updateRestreamSettings,
};
}