HW7: done task 6

This commit is contained in:
Claudio Maggioni 2019-11-14 16:26:10 +01:00
parent b8fad52ebe
commit d50ce187f7
3 changed files with 21 additions and 7 deletions

View file

@ -19,6 +19,7 @@ class App {
const albumInput = imgurForm.querySelector('input[name=album]'); const albumInput = imgurForm.querySelector('input[name=album]');
const oldNameInput = imgurForm.querySelector('input[name=old_name]'); const oldNameInput = imgurForm.querySelector('input[name=old_name]');
const replacePanel = imgurForm.querySelector('.replace'); const replacePanel = imgurForm.querySelector('.replace');
const detailsPanel = imgurForm.querySelector('.details');
dom.querySelector('button.imgur').onclick = () => { dom.querySelector('button.imgur').onclick = () => {
imgurForm.classList.toggle('hidden'); imgurForm.classList.toggle('hidden');
@ -39,9 +40,11 @@ class App {
imgurForm.onsubmit = e => { imgurForm.onsubmit = e => {
imgurForm.classList.remove('ok'); imgurForm.classList.remove('ok');
imgurForm.classList.remove('err'); imgurForm.classList.remove('err');
e.preventDefault(); detailsPanel.innerHTML = '';
const data = new FormData(imgurForm);
e.preventDefault();
const data = new FormData(imgurForm);
const obj = { const obj = {
dataURL: data.get('dataURL'), dataURL: data.get('dataURL'),
name: dom.querySelector('form.data input[name=name]').value, name: dom.querySelector('form.data input[name=name]').value,
@ -56,6 +59,15 @@ class App {
.then(e => { .then(e => {
if (e.ordealSuccess === true) { if (e.ordealSuccess === true) {
imgurForm.classList.add('ok'); imgurForm.classList.add('ok');
if (e.views) {
detailsPanel.innerHTML +=
`<strong>Views:</strong> ${e.views}<br>`;
}
if (e.votes) {
detailsPanel.innerHTML +=
`<strong>Upvotes:</strong> ${e.votes.ups}<br>
<strong>Downvotes:</strong> ${e.votes.downs}<br>`;
}
} else { } else {
imgurForm.classList.add('err'); imgurForm.classList.add('err');
} }

View file

@ -154,10 +154,12 @@ router.post('/imgur/ordeal', async (req, res) => {
ordealResponse.views = result.image.views; ordealResponse.views = result.image.views;
ordealResponse.votes = await fetchImgur(req, res, 'GET', '/gallery/' ordealResponse.votes = await fetchImgur(req, res, 'GET', '/gallery/'
+ result.album.id + '/votes'); + result.image.id + '/votes');
if (!ordealResponse.votes) { if (!ordealResponse.votes) {
return; return;
} else {
ordealResponse.votes = ordealResponse.votes.data;
} }
console.log('votes', ordealResponse.votes); console.log('votes', ordealResponse.votes);
@ -172,9 +174,8 @@ router.post('/imgur/ordeal', async (req, res) => {
} }
} }
if (!await fetchImgur(req, res, 'POST', '/gallery/album/' + if (!await fetchImgur(req, res, 'POST', '/gallery/image/' +
albumJson.data.id, { title: req.body.album ? req.body.album : uploadJson.data.id, { title: req.body.name })) {
req.body.name })) {
return; return;
} }
@ -184,7 +185,7 @@ router.post('/imgur/ordeal', async (req, res) => {
}; };
if (!await fetchImgur(req, res, 'POST', '/gallery/tags/' + if (!await fetchImgur(req, res, 'POST', '/gallery/tags/' +
albumJson.data.id, tagsData)) { uploadJson.data.id, tagsData)) {
return; return;
} }

View file

@ -38,5 +38,6 @@ formaction="/favorites/{_id}/bookmarked?_method=PUT">Add bookmark</button>
<input type="text" name="old_name" placeholder="Imgur image name to replace"><br> <input type="text" name="old_name" placeholder="Imgur image name to replace"><br>
</div> </div>
<button type="submit">Submit to Imgur</button> <button type="submit">Submit to Imgur</button>
<div class="details"></div>
</form> </form>
{/details} {/details}