96 lines
2.6 KiB
TypeScript
96 lines
2.6 KiB
TypeScript
import axios, {type AxiosResponse} from "axios";
|
|
import {cleanOptions} from "@/helpers/AxiosHelper.ts";
|
|
|
|
export interface Webstream {
|
|
id?: number;
|
|
name: string;
|
|
description: string;
|
|
url: string;
|
|
length?: string;
|
|
creator_id?: number;
|
|
mtime?: Date;
|
|
utime?: Date;
|
|
lptime?: Date;
|
|
mime?: string;
|
|
}
|
|
|
|
export const baseWebstream = (): Webstream => {
|
|
return {
|
|
id: null,
|
|
name: 'test',
|
|
description: '',
|
|
url: '',
|
|
length: '00:00:00',
|
|
creator_id: null,
|
|
mtime: null,
|
|
utime: null,
|
|
lptime: null,
|
|
mime: null
|
|
}
|
|
}
|
|
|
|
export const webstreamTableHeader = [
|
|
{title: 'Nome', value: 'name'},
|
|
{title: 'Descrizione', value: 'description'},
|
|
{title: 'URL', value: 'url'},
|
|
{title: 'Durata', value: 'length'},
|
|
{title: 'Azioni', value: 'actions'}
|
|
]
|
|
|
|
export const getWebstreams = async (options: {
|
|
name?: string | null;
|
|
description?: string | null;
|
|
url?: string | null;
|
|
mime?: string | null;
|
|
page?: Number | null;
|
|
per_page?: Number | null;
|
|
}): Promise<Webstream[]> => {
|
|
const filteredParams = cleanOptions(options);
|
|
return await axios.get(`/webstream`, {params: filteredParams})
|
|
.then((response: AxiosResponse) => {
|
|
return response.data
|
|
}).catch((error: Error) => {
|
|
console.log("Error: " + error);
|
|
})
|
|
}
|
|
|
|
export const getWebstream = async (id: number): Promise<Webstream> => {
|
|
return await axios.get(`/webstream/${id}`)
|
|
.then((response: AxiosResponse) => {
|
|
return response.data
|
|
}).catch((error: Error) => {
|
|
console.log("Error: " + error);
|
|
throw error;
|
|
})
|
|
}
|
|
|
|
export const createWebstream = async (webstream: Webstream): Promise<Webstream> => {
|
|
return await axios.post('/webstream', webstream)
|
|
.then((response: AxiosResponse) => {
|
|
return response.data
|
|
}).catch((error: Error) => {
|
|
console.log("Error: " + error);
|
|
throw error;
|
|
})
|
|
}
|
|
|
|
export const updateWebstream = async (webstream: Webstream): Promise<Webstream> => {
|
|
return await axios.put(`/webstream/${webstream.id}`, webstream)
|
|
.then((response: AxiosResponse) => {
|
|
return response.data
|
|
}).catch((error: Error) => {
|
|
console.log("Error: " + error);
|
|
throw error;
|
|
})
|
|
}
|
|
|
|
export const deleteWebstream = async (webstreamIds: Number[]) => {
|
|
try {
|
|
for (const webstreamId of webstreamIds) {
|
|
await axios.delete(`/webstream/${webstreamId}`)
|
|
}
|
|
} catch (error) {
|
|
console.error('Error deleting webstream:', error);
|
|
throw error;
|
|
}
|
|
}
|