try adding playlists list to context menu - unsuccsessfully

This commit is contained in:
geoffrey45
2022-03-25 20:51:22 +03:00
parent 642c524a08
commit e2544dbbdc
21 changed files with 394 additions and 75 deletions
+3 -29
View File
@@ -1,42 +1,18 @@
import axios from "axios";
import { Folder, Track } from "../interfaces";
import state from "./state";
import { Track, Folder } from "../interfaces";
let base_uri = "http://127.0.0.1:9876/";
const getTracksAndDirs = async (path) => {
let url;
const encoded_path = encodeURIComponent(path.replaceAll("/", "|"));
url = url = `${base_uri}/f/${encoded_path}`;
const res = await fetch(url);
if (!res.ok) {
const message = `An error has occurred: ${res.status}`;
throw new Error(message);
}
const data = await res.json();
const songs = data.files;
const folders = data.folders;
return { songs, folders };
};
async function fetchThat(path: string) {
export default async function (path: string) {
let tracks = Array<Track>();
let folders = Array<Folder>();
await axios
.post(state.settings.uri + "/folder", {
.post(`${state.settings.uri}/folder`, {
folder: path,
})
.then((res) => {
tracks = res.data.tracks;
folders = res.data.folders;
console.log(tracks)
})
.catch((err) => {
console.error(err);
@@ -44,5 +20,3 @@ async function fetchThat(path: string) {
return { tracks, folders };
}
export default fetchThat;
+45
View File
@@ -0,0 +1,45 @@
import axios from "axios";
import { Playlist } from "../interfaces";
import { Notification } from "../stores/notification";
import state from "./state";
/**
* Creates a new playlist on the server.
* @param playlist_name The name of the playlist to create.
*/
async function createNewPlaylist(playlist_name: string) {
await axios
.post(state.settings.uri + "/playlist/new", {
name: playlist_name,
})
.then((res) => {
console.log(res.data);
new Notification("Playlist created!");
})
.catch((err) => {
console.error(err);
});
}
/**
* Fetches all playlists from the server.
* @returns {Promise<Playlist[]>} A promise that resolves to an array of playlists.
*/
async function getAllPlaylists(): Promise<Playlist[]> {
let playlists = <Playlist[]>[];
const newLocal = `${state.settings.uri}/playlists`;
await axios
.get(newLocal)
.then((res) => {
playlists = res.data.data;
})
.catch((err) => {
console.error(err);
});
return playlists;
}
export { createNewPlaylist, getAllPlaylists };