You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.2 KiB
35 lines
1.2 KiB
import db from './db.services.js'
|
|
|
|
export async function getAllMusics() {
|
|
const query = "SELECT * FROM music_files";
|
|
const values = [];
|
|
return await db(query, values);
|
|
}
|
|
|
|
export async function getMusicMetadata(file) {
|
|
|
|
const filename = file.split(".")[0];
|
|
const name = filename.split("---")[0];
|
|
const artist = filename.split("---")[1];
|
|
|
|
const endpoint = encodeURI(`https://api.discogs.com/database/search?q=${name}${(artist && artist.length > 0) ? "&artist=" + artist : ""}&type=track&track=${name}&token=EyYNWEgsvjQWwDrLPeRkkgjnUNdFxyNfimkbPqCn`);
|
|
|
|
const req = await fetch(endpoint, {});
|
|
const res = await req.json();
|
|
console.log(endpoint);
|
|
console.log(res);
|
|
return res;
|
|
|
|
}
|
|
|
|
export async function insertMusicFile(filename) {
|
|
const query = "INSERT INTO music_files (file) VALUES ($1) RETURNING *";
|
|
const values = [filename];
|
|
return await db(query, values);
|
|
}
|
|
|
|
export async function insertMusicMetadata(metadata) {
|
|
const query = "INSERT INTO music_metadatas (name, artist, album, cover, file) VALUES ($1, $2, $3, $4, $5) RETURNING *";
|
|
const values = [metadata.name, metadata.artist, metadata.album, metadata.cover, metadata.file];
|
|
return await db(query, values);
|
|
}
|