'use server' export async function getAlbums() { return fetch('https://api.anatid.net/album', { method: "GET", headers: { "Content-Type": "application/json" }, next: { revalidate: 3600 } }).then(response => { if (response.ok) { return response.json(); } return Promise.reject(response); }).catch(error => { console.log(error); }); } export async function getAlbum(id: number) { return fetch(`https://api.anatid.net/album/${id}`, { method: "GET", headers: { "Content-Type": "application/json" }, next: { revalidate: 3600 } }).then(response => { if (response.ok) { return response.json(); } return Promise.reject(response); }).catch(error => { console.log(error); }); } export async function createAlbum(formData: FormData) { const title = formData.get('title'); const artist = formData.get('artist'); const genre = formData.get('genre'); return fetch("https://api.anatid.net/album", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ title: title, artist: artist, genre: genre, }) }).then(response => { if (response.ok) { return response.json(); } return Promise.reject(response); }).catch(error => { console.log(error); }); } export async function updateAlbum(formData: FormData) { const id = formData.get('id'); const title = formData.get('title'); const artist = formData.get('artist'); const genre = formData.get('genre'); console.log(id,title,artist,genre); return fetch(`https://api.anatid.net/album/${id}`, { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ id: id, title: title, artist: artist, genre: genre, }) }).then(response => { if (response.ok) { return response.json(); } return Promise.reject(response); }).catch(error => { console.log(error); }); } export async function deleteAlbum(id: number) { return fetch(`https://api.anatid.net/album/${id}`, { method: "DELETE", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ id: id, }) }).then(response => { if (response.ok) { return response.json(); } return Promise.reject(response); }).catch(error => { console.log(error); }); } export async function getSongs() { return fetch("https://api.anatid.net/song/", { method: "GET", headers: { "Content-Type": "application/json" }, next: { revalidate: 3600 } }).then(response => { if (response.ok) { return response.json(); } return Promise.reject(response); }).catch(error => { console.log(error); }); } export async function getSong(id: number) { return fetch(`https://api.anatid.net/song/${id}`, { method: "GET", headers: { "Content-Type": "application/json" }, next: { revalidate: 3600 } }).then(response => { if (response.ok) { return response.json(); } return Promise.reject(response); }).catch(error => { console.log(error); }); } export async function createSong(formData: FormData) { const albumId = formData.get('album-id'); const title = formData.get('title'); const duration = formData.get('duration'); const trackNumber = formData.get('trackNumber'); return fetch("https://api.anatid.net/song", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ albumId: albumId, title: title, duration: duration, trackNumber: trackNumber, }) }).then(response => { if (response.ok) { return response.json(); } return Promise.reject(response); }).catch(error => { console.log(error); }); } export async function updateSong(formData: FormData) { const id = formData.get('id'); const albumId = formData.get('album-id'); const title = formData.get('title'); const duration = formData.get('duration'); const trackNumber = formData.get('trackNumber'); return fetch(`https://api.anatid.net/song/${albumId}`, { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ id: id, albumId: albumId, title: title, duration: duration, trackNumber: trackNumber, }), next: { revalidate: 3600 } }).then(response => { if (response.ok) { return response.json(); } return Promise.reject(response); }).catch(error => { console.log(error); }); } export async function deleteSong(id: number) { return fetch(`https://api.anatid.net/song/${id}`, { method: "DELETE", headers: { "Content-Type": "application/json" } }).then(response => { if (response.ok) { return response.json(); } return Promise.reject(response); }).catch(error => { console.log(error); }); }