HW7: done task 6
This commit is contained in:
parent
b8fad52ebe
commit
d50ce187f7
3 changed files with 21 additions and 7 deletions
|
@ -19,6 +19,7 @@ class App {
|
|||
const albumInput = imgurForm.querySelector('input[name=album]');
|
||||
const oldNameInput = imgurForm.querySelector('input[name=old_name]');
|
||||
const replacePanel = imgurForm.querySelector('.replace');
|
||||
const detailsPanel = imgurForm.querySelector('.details');
|
||||
|
||||
dom.querySelector('button.imgur').onclick = () => {
|
||||
imgurForm.classList.toggle('hidden');
|
||||
|
@ -39,9 +40,11 @@ class App {
|
|||
imgurForm.onsubmit = e => {
|
||||
imgurForm.classList.remove('ok');
|
||||
imgurForm.classList.remove('err');
|
||||
e.preventDefault();
|
||||
const data = new FormData(imgurForm);
|
||||
detailsPanel.innerHTML = '';
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
const data = new FormData(imgurForm);
|
||||
const obj = {
|
||||
dataURL: data.get('dataURL'),
|
||||
name: dom.querySelector('form.data input[name=name]').value,
|
||||
|
@ -56,6 +59,15 @@ class App {
|
|||
.then(e => {
|
||||
if (e.ordealSuccess === true) {
|
||||
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 {
|
||||
imgurForm.classList.add('err');
|
||||
}
|
||||
|
|
|
@ -154,10 +154,12 @@ router.post('/imgur/ordeal', async (req, res) => {
|
|||
|
||||
ordealResponse.views = result.image.views;
|
||||
ordealResponse.votes = await fetchImgur(req, res, 'GET', '/gallery/'
|
||||
+ result.album.id + '/votes');
|
||||
+ result.image.id + '/votes');
|
||||
|
||||
if (!ordealResponse.votes) {
|
||||
return;
|
||||
} else {
|
||||
ordealResponse.votes = ordealResponse.votes.data;
|
||||
}
|
||||
|
||||
console.log('votes', ordealResponse.votes);
|
||||
|
@ -172,9 +174,8 @@ router.post('/imgur/ordeal', async (req, res) => {
|
|||
}
|
||||
}
|
||||
|
||||
if (!await fetchImgur(req, res, 'POST', '/gallery/album/' +
|
||||
albumJson.data.id, { title: req.body.album ? req.body.album :
|
||||
req.body.name })) {
|
||||
if (!await fetchImgur(req, res, 'POST', '/gallery/image/' +
|
||||
uploadJson.data.id, { title: req.body.name })) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -184,7 +185,7 @@ router.post('/imgur/ordeal', async (req, res) => {
|
|||
};
|
||||
|
||||
if (!await fetchImgur(req, res, 'POST', '/gallery/tags/' +
|
||||
albumJson.data.id, tagsData)) {
|
||||
uploadJson.data.id, tagsData)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -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>
|
||||
</div>
|
||||
<button type="submit">Submit to Imgur</button>
|
||||
<div class="details"></div>
|
||||
</form>
|
||||
{/details}
|
||||
|
|
Reference in a new issue