mirror of
https://github.com/20kaushik02/spotify-manager.git
synced 2026-01-25 06:04:05 +00:00
back
small improvements, bug fixes, ocd formatting,
This commit is contained in:
@@ -4,8 +4,8 @@
|
||||
* @return {string} The generated string
|
||||
*/
|
||||
module.exports = (length) => {
|
||||
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
let text = '';
|
||||
const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
let text = "";
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
||||
|
||||
@@ -9,13 +9,13 @@ const typedefs = require("../typedefs");
|
||||
*
|
||||
* Example:
|
||||
* ```javascript
|
||||
* let nodes = ['a', 'b', 'c', 'd', 'e'];
|
||||
* let nodes = ["a", "b", "c", "d", "e"];
|
||||
* let edges = [
|
||||
* { from: 'a', to: 'b' },
|
||||
* { from: 'b', to: 'c' },
|
||||
* { from: 'c', to: 'd' },
|
||||
* { from: 'd', to: 'a' },
|
||||
* { from: 'e', to: 'a' }
|
||||
* { from: "a", to: "b" },
|
||||
* { from: "b", to: "c" },
|
||||
* { from: "c", to: "d" },
|
||||
* { from: "d", to: "a" },
|
||||
* { from: "e", to: "a" }
|
||||
* ];
|
||||
* let g = new myGraph(nodes, edges);
|
||||
* console.log(g.detectCycle()); // true
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* @param {string} delimiter Delimiter of final string
|
||||
* @returns {string}
|
||||
*/
|
||||
const getNestedValuesString = (obj, delimiter = ', ') => {
|
||||
const getNestedValuesString = (obj, delimiter = ", ") => {
|
||||
let values = [];
|
||||
for (key in obj) {
|
||||
if (typeof obj[key] !== "object") {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const path = require("path");
|
||||
|
||||
const { createLogger, transports, config, format } = require('winston');
|
||||
const { createLogger, transports, config, format } = require("winston");
|
||||
const { combine, label, timestamp, printf, errors } = format;
|
||||
|
||||
const typedefs = require("../typedefs");
|
||||
@@ -15,8 +15,8 @@ const allowedErrorKeys = ["name", "code", "message", "stack"];
|
||||
|
||||
const metaFormat = (meta) => {
|
||||
if (Object.keys(meta).length > 0)
|
||||
return '\n' + JSON.stringify(meta, null, "\t");
|
||||
return '';
|
||||
return "\n" + JSON.stringify(meta, null, "\t");
|
||||
return "";
|
||||
}
|
||||
|
||||
const logFormat = printf(({ level, message, label, timestamp, ...meta }) => {
|
||||
@@ -28,7 +28,7 @@ const logFormat = printf(({ level, message, label, timestamp, ...meta }) => {
|
||||
}
|
||||
const { stack, ...rest } = meta.error;
|
||||
return `${timestamp} [${label}] ${level}: ${message}${metaFormat(rest)}\n` +
|
||||
`${stack ?? ''}`;
|
||||
`${stack ?? ""}`;
|
||||
}
|
||||
return `${timestamp} [${label}] ${level}: ${message}${metaFormat(meta)}`;
|
||||
});
|
||||
@@ -43,24 +43,24 @@ const curriedLogger = (callingModule) => {
|
||||
format: combine(
|
||||
errors({ stack: true }),
|
||||
label({ label: getLabel(callingModule) }),
|
||||
timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
|
||||
timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
|
||||
logFormat,
|
||||
),
|
||||
transports: [
|
||||
new transports.Console({ level: 'info' }),
|
||||
new transports.Console({ level: "info" }),
|
||||
new transports.File({
|
||||
filename: __dirname + '/../logs/debug.log',
|
||||
level: 'debug',
|
||||
filename: __dirname + "/../logs/debug.log",
|
||||
level: "debug",
|
||||
maxsize: 10485760,
|
||||
}),
|
||||
new transports.File({
|
||||
filename: __dirname + '/../logs/error.log',
|
||||
level: 'error',
|
||||
filename: __dirname + "/../logs/error.log",
|
||||
level: "error",
|
||||
maxsize: 1048576,
|
||||
}),
|
||||
]
|
||||
});
|
||||
winstonLogger.on('error', (error) => winstonLogger.error("Error inside logger", { error }));
|
||||
winstonLogger.on("error", (error) => winstonLogger.error("Error inside logger", { error }));
|
||||
return winstonLogger;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,8 @@ const parseSpotifyURI = (uri) => {
|
||||
}
|
||||
|
||||
// URL decode artist, album, and title
|
||||
const artist = decodeURIComponent(idParts[0] || '');
|
||||
const album = decodeURIComponent(idParts[1] || '');
|
||||
const artist = decodeURIComponent(idParts[0] || "");
|
||||
const album = decodeURIComponent(idParts[1] || "");
|
||||
const title = decodeURIComponent(idParts[2]);
|
||||
const duration = parseInt(idParts[3], 10);
|
||||
|
||||
@@ -71,8 +71,8 @@ const parseSpotifyLink = (link) => {
|
||||
}
|
||||
|
||||
// URL decode artist, album, and title
|
||||
const artist = decodeURIComponent(matches[1] || '');
|
||||
const album = decodeURIComponent(matches[2] || '');
|
||||
const artist = decodeURIComponent(matches[1] || "");
|
||||
const album = decodeURIComponent(matches[2] || "");
|
||||
const title = decodeURIComponent(matches[3]);
|
||||
const duration = parseInt(matches[4], 10);
|
||||
|
||||
@@ -108,10 +108,10 @@ const parseSpotifyLink = (link) => {
|
||||
*/
|
||||
const buildSpotifyURI = (uriObj) => {
|
||||
if (uriObj.is_local) {
|
||||
const artist = encodeURIComponent(uriObj.artist ?? '');
|
||||
const album = encodeURIComponent(uriObj.album ?? '');
|
||||
const title = encodeURIComponent(uriObj.title ?? '');
|
||||
const duration = uriObj.duration ? uriObj.duration.toString() : '';
|
||||
const artist = encodeURIComponent(uriObj.artist ?? "");
|
||||
const album = encodeURIComponent(uriObj.album ?? "");
|
||||
const title = encodeURIComponent(uriObj.title ?? "");
|
||||
const duration = uriObj.duration ? uriObj.duration.toString() : "";
|
||||
return `spotify:local:${artist}:${album}:${title}:${duration}`;
|
||||
}
|
||||
return `spotify:${uriObj.type}:${uriObj.id}`;
|
||||
@@ -124,10 +124,10 @@ const buildSpotifyURI = (uriObj) => {
|
||||
*/
|
||||
const buildSpotifyLink = (uriObj) => {
|
||||
if (uriObj.is_local) {
|
||||
const artist = encodeURIComponent(uriObj.artist ?? '');
|
||||
const album = encodeURIComponent(uriObj.album ?? '');
|
||||
const title = encodeURIComponent(uriObj.title ?? '');
|
||||
const duration = uriObj.duration ? uriObj.duration.toString() : '';
|
||||
const artist = encodeURIComponent(uriObj.artist ?? "");
|
||||
const album = encodeURIComponent(uriObj.album ?? "");
|
||||
const title = encodeURIComponent(uriObj.title ?? "");
|
||||
const duration = uriObj.duration ? uriObj.duration.toString() : "";
|
||||
return `https://open.spotify.com/local/${artist}/${album}/${title}/${duration}`;
|
||||
}
|
||||
return `https://open.spotify.com/${uriObj.type}/${uriObj.id}`
|
||||
|
||||
Reference in New Issue
Block a user