forked from dbroqua/MusicTopus
54 lines
1.3 KiB
JavaScript
54 lines
1.3 KiB
JavaScript
|
import express from "express";
|
||
|
import { ensureLoggedIn } from "connect-ensure-login";
|
||
|
|
||
|
import Albums from "../middleware/Albums";
|
||
|
|
||
|
import render from "../libs/format";
|
||
|
|
||
|
// eslint-disable-next-line new-cap
|
||
|
const router = express.Router();
|
||
|
|
||
|
router.route("/").get(ensureLoggedIn("/connexion"), async (req, res, next) => {
|
||
|
try {
|
||
|
const page = new Albums(req, "mon-compte/ma-collection");
|
||
|
|
||
|
await page.loadMyCollection();
|
||
|
|
||
|
if (page.getPageContent("artists").length > 0) {
|
||
|
render(res, page);
|
||
|
} else {
|
||
|
res.redirect("/ajouter-un-album");
|
||
|
}
|
||
|
} catch (err) {
|
||
|
next(err);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
router
|
||
|
.route("/exporter")
|
||
|
.get(ensureLoggedIn("/connexion"), async (req, res, next) => {
|
||
|
try {
|
||
|
const page = new Albums(req, "mon-compte/ma-collection/exporter");
|
||
|
|
||
|
render(res, page);
|
||
|
} catch (err) {
|
||
|
next(err);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
router
|
||
|
.route("/:itemId")
|
||
|
.get(ensureLoggedIn("/connexion"), async (req, res, next) => {
|
||
|
try {
|
||
|
const page = new Albums(req, "mon-compte/ma-collection/details");
|
||
|
|
||
|
await page.loadItem();
|
||
|
|
||
|
render(res, page);
|
||
|
} catch (err) {
|
||
|
next(err);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
export default router;
|