mirror of
https://github.com/20kaushik02/spotify-manager.git
synced 2026-01-25 06:04:05 +00:00
CJS -> ESM
This commit is contained in:
@@ -1,18 +1,19 @@
|
||||
const { authInstance } = require("../api/axios");
|
||||
import { authInstance } from "../api/axios.js";
|
||||
|
||||
const typedefs = require("../typedefs");
|
||||
const { scopes, stateKey, accountsAPIURL, sessionName } = require("../constants");
|
||||
import * as typedefs from "../typedefs.js";
|
||||
import { scopes, stateKey, accountsAPIURL, sessionName } from "../constants.js";
|
||||
|
||||
const generateRandString = require("../utils/generateRandString");
|
||||
const { getUserProfile } = require("../api/spotify");
|
||||
const logger = require("../utils/logger")(module);
|
||||
import generateRandString from "../utils/generateRandString.js";
|
||||
import { getUserProfile } from "../api/spotify.js";
|
||||
import curriedLogger from "../utils/logger.js";
|
||||
const logger = curriedLogger(import.meta);
|
||||
|
||||
/**
|
||||
* Stateful redirect to Spotify login with credentials
|
||||
* @param {typedefs.Req} req
|
||||
* @param {typedefs.Res} res
|
||||
*/
|
||||
const login = (_req, res) => {
|
||||
export const login = (_req, res) => {
|
||||
try {
|
||||
const state = generateRandString(16);
|
||||
res.cookie(stateKey, state);
|
||||
@@ -41,7 +42,7 @@ const login = (_req, res) => {
|
||||
* @param {typedefs.Req} req
|
||||
* @param {typedefs.Res} res
|
||||
*/
|
||||
const callback = async (req, res) => {
|
||||
export const callback = async (req, res) => {
|
||||
try {
|
||||
const { code, state, error } = req.query;
|
||||
const storedState = req.cookies ? req.cookies[stateKey] : null;
|
||||
@@ -104,7 +105,7 @@ const callback = async (req, res) => {
|
||||
* @param {typedefs.Req} req
|
||||
* @param {typedefs.Res} res
|
||||
*/
|
||||
const refresh = async (req, res) => {
|
||||
export const refresh = async (req, res) => {
|
||||
try {
|
||||
const authForm = {
|
||||
refresh_token: req.session.refreshToken,
|
||||
@@ -139,10 +140,10 @@ const refresh = async (req, res) => {
|
||||
* @param {typedefs.Req} req
|
||||
* @param {typedefs.Res} res
|
||||
*/
|
||||
const logout = async (req, res) => {
|
||||
export const logout = async (req, res) => {
|
||||
try {
|
||||
const delSession = req.session.destroy((error) => {
|
||||
if(Object.keys(error).length) {
|
||||
if (Object.keys(error).length) {
|
||||
res.status(500).send({ message: "Internal Server Error" });
|
||||
logger.error("Error while logging out", { error });
|
||||
return;
|
||||
@@ -160,10 +161,3 @@ const logout = async (req, res) => {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
login,
|
||||
callback,
|
||||
refresh,
|
||||
logout
|
||||
};
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
const typedefs = require("../typedefs");
|
||||
const logger = require("../utils/logger")(module);
|
||||
import * as typedefs from "../typedefs.js";
|
||||
import curriedLogger from "../utils/logger.js";
|
||||
const logger = curriedLogger(import.meta);
|
||||
|
||||
const { getUserPlaylistsFirstPage, getUserPlaylistsNextPage, getPlaylistDetailsFirstPage, getPlaylistDetailsNextPage, addItemsToPlaylist, removeItemsFromPlaylist, checkPlaylistEditable } = require("../api/spotify");
|
||||
import { getUserPlaylistsFirstPage, getUserPlaylistsNextPage, getPlaylistDetailsFirstPage, getPlaylistDetailsNextPage, addItemsToPlaylist, removeItemsFromPlaylist, checkPlaylistEditable } from "../api/spotify.js";
|
||||
|
||||
const { parseSpotifyLink } = require("../utils/spotifyURITransformer");
|
||||
const { randomBool, sleep } = require("../utils/flake");
|
||||
const myGraph = require("../utils/graph");
|
||||
import { parseSpotifyLink } from "../utils/spotifyURITransformer.js";
|
||||
import { randomBool, sleep } from "../utils/flake.js";
|
||||
import myGraph from "../utils/graph.js";
|
||||
|
||||
const { Op } = require("sequelize");
|
||||
const { sequelize } = require("../models");
|
||||
/** @type {typedefs.Model} */
|
||||
const Playlists = require("../models").playlists;
|
||||
/** @type {typedefs.Model} */
|
||||
const Links = require("../models").links;
|
||||
import { Op } from "sequelize";
|
||||
|
||||
import models, { sequelize } from "../models/index.js";
|
||||
const Playlists = models.playlists;
|
||||
const Links = models.links;
|
||||
|
||||
/**
|
||||
* Sync user's Spotify data
|
||||
* @param {typedefs.Req} req
|
||||
* @param {typedefs.Res} res
|
||||
*/
|
||||
const updateUser = async (req, res) => {
|
||||
export const updateUser = async (req, res) => {
|
||||
try {
|
||||
let currentPlaylists = [];
|
||||
const uID = req.session.user.id;
|
||||
@@ -177,7 +177,7 @@ const updateUser = async (req, res) => {
|
||||
* @param {typedefs.Req} req
|
||||
* @param {typedefs.Res} res
|
||||
*/
|
||||
const fetchUser = async (req, res) => {
|
||||
export const fetchUser = async (req, res) => {
|
||||
try {
|
||||
// if (randomBool(0.5)) {
|
||||
// res.status(404).send({ message: "Not Found" });
|
||||
@@ -219,7 +219,7 @@ const fetchUser = async (req, res) => {
|
||||
* @param {typedefs.Req} req
|
||||
* @param {typedefs.Res} res
|
||||
*/
|
||||
const createLink = async (req, res) => {
|
||||
export const createLink = async (req, res) => {
|
||||
try {
|
||||
// await sleep(1000);
|
||||
const uID = req.session.user.id;
|
||||
@@ -310,7 +310,7 @@ const createLink = async (req, res) => {
|
||||
* @param {typedefs.Req} req
|
||||
* @param {typedefs.Res} res
|
||||
*/
|
||||
const removeLink = async (req, res) => {
|
||||
export const removeLink = async (req, res) => {
|
||||
try {
|
||||
const uID = req.session.user.id;
|
||||
|
||||
@@ -475,7 +475,7 @@ const _populateSingleLinkCore = async (req, res, link) => {
|
||||
* @param {typedefs.Req} req
|
||||
* @param {typedefs.Res} res
|
||||
*/
|
||||
const populateSingleLink = async (req, res) => {
|
||||
export const populateSingleLink = async (req, res) => {
|
||||
try {
|
||||
const uID = req.session.user.id;
|
||||
const link = { from: req.body.from, to: req.body.to };
|
||||
@@ -591,7 +591,7 @@ const _pruneSingleLinkCore = async (req, res, link) => {
|
||||
* @param {typedefs.Req} req
|
||||
* @param {typedefs.Res} res
|
||||
*/
|
||||
const pruneSingleLink = async (req, res) => {
|
||||
export const pruneSingleLink = async (req, res) => {
|
||||
try {
|
||||
const uID = req.session.user.id;
|
||||
const link = { from: req.body.from, to: req.body.to };
|
||||
@@ -643,12 +643,3 @@ const pruneSingleLink = async (req, res) => {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
updateUser,
|
||||
fetchUser,
|
||||
createLink,
|
||||
removeLink,
|
||||
populateSingleLink,
|
||||
pruneSingleLink,
|
||||
};
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
const logger = require("../utils/logger")(module);
|
||||
import curriedLogger from "../utils/logger.js";
|
||||
const logger = curriedLogger(import.meta);
|
||||
|
||||
const typedefs = require("../typedefs");
|
||||
const { getUserPlaylistsFirstPage, getUserPlaylistsNextPage, getPlaylistDetailsFirstPage, getPlaylistDetailsNextPage } = require("../api/spotify");
|
||||
const { parseSpotifyLink } = require("../utils/spotifyURITransformer");
|
||||
import * as typedefs from "../typedefs.js";
|
||||
import { getUserPlaylistsFirstPage, getUserPlaylistsNextPage, getPlaylistDetailsFirstPage, getPlaylistDetailsNextPage } from "../api/spotify.js";
|
||||
import { parseSpotifyLink } from "../utils/spotifyURITransformer.js";
|
||||
|
||||
/**
|
||||
* Retrieve list of all of user's playlists
|
||||
* @param {typedefs.Req} req
|
||||
* @param {typedefs.Res} res
|
||||
*/
|
||||
const fetchUserPlaylists = async (req, res) => {
|
||||
export const fetchUserPlaylists = async (req, res) => {
|
||||
try {
|
||||
let userPlaylists = {};
|
||||
|
||||
@@ -65,7 +66,7 @@ const fetchUserPlaylists = async (req, res) => {
|
||||
* @param {typedefs.Req} req
|
||||
* @param {typedefs.Res} res
|
||||
*/
|
||||
const fetchPlaylistDetails = async (req, res) => {
|
||||
export const fetchPlaylistDetails = async (req, res) => {
|
||||
try {
|
||||
let playlist = {};
|
||||
/** @type {typedefs.URIObject} */
|
||||
@@ -152,8 +153,3 @@ const fetchPlaylistDetails = async (req, res) => {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
fetchUserPlaylists,
|
||||
fetchPlaylistDetails
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user