Skip to content

Commit

Permalink
#89
Browse files Browse the repository at this point in the history
  • Loading branch information
kaangiray26 committed Mar 1, 2023
1 parent 4d516ac commit 7292a11
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 73 deletions.
35 changes: 29 additions & 6 deletions server/js/db.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// db.js
import path from "path";
import glob from "glob";
import glob from 'glob'
import chokidar from "chokidar";
import { parseFile } from 'music-metadata';
import pgPromise from 'pg-promise';
Expand Down Expand Up @@ -251,7 +251,11 @@ async function update_album_cover(id, album, artist_id) {

async function check_library() {
// Check if the library is empty
let items = glob.sync(library_path + "/**/*");
let items = await glob("**/*", {
cwd: library_path,
absolute: true,
});

if (!items.length) {
console.log("=> The library is empty.");
return;
Expand All @@ -264,7 +268,7 @@ async function check_library() {
db.none("UPDATE library SET items = $1", [items]);

// If the library is empty, add all the folders
if (!library) {
if (!library.items.length) {
console.log("=> The library is empty. Adding all the items...");
items.map(item => add_item(item));
return;
Expand Down Expand Up @@ -625,7 +629,15 @@ async function handle_artist(item, artist_name = null) {
}

// Get the artist cover
let cover = glob.sync(item + "/cover.*")[0];
let covers = await glob("cover.*", {
cwd: item,
absolute: true,
})

let cover = null;
if (covers) {
cover = covers[0];
}

// Copy the cover to the uploads folder
let cover_id = null;
Expand Down Expand Up @@ -655,7 +667,10 @@ async function handle_album(item,
}
}) {
// Get number of tracks
let tracks = glob.sync(item + `/**/*.{${audio_extensions.join()}}`);
let tracks = await glob(`**/*.{${audio_extensions.join()}}`, {
cwd: item,
absolute: true,
});

// Get metadata
if (tracks.length) {
Expand All @@ -669,7 +684,15 @@ async function handle_album(item,
let artist = await handle_artist(path.dirname(item), metadata.common.artist);

// Get the album cover
let cover = glob.sync(item + "/cover.*")[0];
let covers = await glob("cover.*", {
cwd: item,
absolute: true,
});

let cover = null;
if (covers) {
cover = covers[0];
}

// Copy the cover to the uploads folder
let cover_id = null;
Expand Down
139 changes: 73 additions & 66 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"cors": "^2.8.5",
"express": "^4.18.2",
"express-session": "^1.17.3",
"glob": "^8.1.0",
"glob": "^9.0.2",
"greenlock": "^4.0.4",
"greenlock-express": "^4.0.3",
"mime-types": "^2.1.35",
Expand Down

0 comments on commit 7292a11

Please sign in to comment.