diff --git a/hw7/Claudio_Maggioni/public/js/views.js b/hw7/Claudio_Maggioni/public/js/views.js
index d3e0af0..1bd0158 100644
--- a/hw7/Claudio_Maggioni/public/js/views.js
+++ b/hw7/Claudio_Maggioni/public/js/views.js
@@ -1,6 +1,6 @@
(function(dust){dust.register("500",body_0);function body_0(chk,ctx){return chk.w("
Error 500
").f(ctx.get(["err"], false),ctx,"h").w("
");}body_0.__dustBody=!0;return body_0}(dust));
(function(dust){dust.register("favourite",body_0);function body_0(chk,ctx){return chk.w("").f(ctx.get(["name"], false),ctx,"h").w("").p("favourite_partial",ctx,ctx,{}).w("Favourites list");}body_0.__dustBody=!0;return body_0}(dust));
-(function(dust){dust.register("favourite_partial",body_0);function body_0(chk,ctx){return chk.w("").f(ctx.get(["name"], false),ctx,"h").w("
").x(ctx.get(["b"], false),ctx,{"block":body_1},{}).x(ctx.get(["details"], false),ctx,{"else":body_2,"block":body_5},{});}body_0.__dustBody=!0;function body_1(chk,ctx){return chk.w("Bookmarked
");}body_1.__dustBody=!0;function body_2(chk,ctx){return chk.w("");}body_2.__dustBody=!0;function body_3(chk,ctx){return chk.w("");}body_3.__dustBody=!0;function body_4(chk,ctx){return chk.w("");}body_4.__dustBody=!0;function body_5(chk,ctx){return chk.w("Details");}body_5.__dustBody=!0;return body_0}(dust));
+(function(dust){dust.register("favourite_partial",body_0);function body_0(chk,ctx){return chk.w("").f(ctx.get(["name"], false),ctx,"h").w("
").x(ctx.get(["b"], false),ctx,{"block":body_1},{}).x(ctx.get(["details"], false),ctx,{"else":body_2,"block":body_5},{});}body_0.__dustBody=!0;function body_1(chk,ctx){return chk.w("Bookmarked
");}body_1.__dustBody=!0;function body_2(chk,ctx){return chk.w("");}body_2.__dustBody=!0;function body_3(chk,ctx){return chk.w("");}body_3.__dustBody=!0;function body_4(chk,ctx){return chk.w("");}body_4.__dustBody=!0;function body_5(chk,ctx){return chk.w("Details");}body_5.__dustBody=!0;return body_0}(dust));
(function(dust){dust.register("favourites",body_0);function body_0(chk,ctx){return chk.w("").x(ctx.get(["bookmarked"], false),ctx,{"else":body_1,"block":body_2},{}).w("").x(ctx.get(["bookmarked"], false),ctx,{"else":body_3,"block":body_4},{}).s(ctx.get(["favs"], false),ctx,{"else":body_5,"block":body_6},{}).w("");}body_0.__dustBody=!0;function body_1(chk,ctx){return chk.w("Favourites");}body_1.__dustBody=!0;function body_2(chk,ctx){return chk.w("Bookmarked");}body_2.__dustBody=!0;function body_3(chk,ctx){return chk.w("Favourites
");}body_3.__dustBody=!0;function body_4(chk,ctx){return chk.w("Bookmarked
");}body_4.__dustBody=!0;function body_5(chk,ctx){return chk.w("No favourites.");}body_5.__dustBody=!0;function body_6(chk,ctx){return chk.w("").p("favourite_partial",ctx,ctx,{"name":ctx.get(["name"], false),"dataURL":ctx.get(["dataURL"], false),"_id":ctx.get(["_id"], false),"bookmarked":ctx.get(["bookmarked"], false),"details":"true"}).w("
");}body_6.__dustBody=!0;return body_0}(dust));
(function(dust){dust.register("index",body_0);function body_0(chk,ctx){return chk.w("OO-JS Exercise - Web Atelier 2017OO-JS Exercise: Canvas
");}body_0.__dustBody=!0;return body_0}(dust));
(function(dust){dust.register("server_side",body_0);function body_0(chk,ctx){return chk.s(ctx.get(["favs"], false),ctx,{"block":body_1},{});}body_0.__dustBody=!0;function body_1(chk,ctx){return chk.w("").p("favourite_partial",ctx,ctx,{"name":ctx.get(["name"], false),"dataURL":ctx.get(["dataURL"], false),"_id":ctx.get(["_id"], false),"bookmarked":ctx.get(["bookmarked"], false)}).w("
");}body_1.__dustBody=!0;function body_2(chk,ctx){return chk.w("bookmarked");}body_2.__dustBody=!0;return body_0}(dust));
diff --git a/hw7/Claudio_Maggioni/public/scripts/app.js b/hw7/Claudio_Maggioni/public/scripts/app.js
index 71a6c66..b631e39 100644
--- a/hw7/Claudio_Maggioni/public/scripts/app.js
+++ b/hw7/Claudio_Maggioni/public/scripts/app.js
@@ -29,10 +29,12 @@ class App {
if (replaceToggle.checked) {
replacePanel.classList.remove('hidden');
albumInput.setAttribute('disabled', 'disabled');
+ albumInput.removeAttribute('required');
oldNameInput.setAttribute('required', 'required');
} else {
replacePanel.classList.add('hidden');
albumInput.removeAttribute('disabled');
+ albumInput.setAttribute('required', 'required');
oldNameInput.removeAttribute('required');
}
};
@@ -59,7 +61,7 @@ class App {
.then(e => {
if (e.ordealSuccess === true) {
imgurForm.classList.add('ok');
- if (e.views) {
+ if (e.views !== undefined) {
detailsPanel.innerHTML +=
`Views: ${e.views}
`;
}
@@ -70,6 +72,10 @@ class App {
}
} else {
imgurForm.classList.add('err');
+ if (e.error) {
+ detailsPanel.innerHTML += `
+ Error: ${e.error}
`;
+ }
}
}).catch(e => {
console.error(e);
diff --git a/hw7/Claudio_Maggioni/routes/root/router.js b/hw7/Claudio_Maggioni/routes/root/router.js
index e0af6cc..c1dd0e9 100644
--- a/hw7/Claudio_Maggioni/routes/root/router.js
+++ b/hw7/Claudio_Maggioni/routes/root/router.js
@@ -67,6 +67,12 @@ async function fetchImgur(req, res, method, url, body) {
router.post('/imgur/ordeal', async (req, res) => {
try {
+ if ((!req.body.replace && (!req.body.name || !req.body.album)) ||
+ (req.body.replace && (!req.body.name || !req.body.oldName))) {
+ res.status(400).json({ error: "Malformed ordeal request" });
+ return;
+ }
+
const ordealResponse = { ordealSuccess: true };
const uploadData = {
diff --git a/hw7/Claudio_Maggioni/views/favourite_partial.dust b/hw7/Claudio_Maggioni/views/favourite_partial.dust
index 015948f..ebf0217 100644
--- a/hw7/Claudio_Maggioni/views/favourite_partial.dust
+++ b/hw7/Claudio_Maggioni/views/favourite_partial.dust
@@ -28,7 +28,7 @@ formaction="/favorites/{_id}/bookmarked?_method=PUT">Add bookmark