diff --git a/README.md b/README.md index 2900f98..72f1bbf 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ A domain adaptor must provides this following API: `getArchives: (code) => [ code, date ]` -`fetchImage (imageFile, idPage)` +`getImage (idPage)` ### Installation diff --git a/accessorh/sampleh.js b/accessorh/sampleh.js index c682572..01dedf7 100644 --- a/accessorh/sampleh.js +++ b/accessorh/sampleh.js @@ -74,7 +74,7 @@ var sampleDomainh = { return Promise.resolve(result); }, - fetchImage: (imageFile, imageId) => { + getImage: (imageId) => { let id = imageId; return fetch(`https://picsum.photos/id/${id}/200/300`, { "headers": { @@ -98,14 +98,9 @@ var sampleDomainh = { "mode": "cors", "credentials": "include" }).then(response => { - return response.arrayBuffer() - }).then((arrayBuffer) => { - return fsh.write(imageFile, Buffer.from(arrayBuffer)).then(e => { - console.log('The file has been saved!'); - }).catch(e => { - console.log(e); - console.log(err); - }) + return response.arrayBuffer(); + }).then(arrayBuffer => { + return Promise.resolve(Buffer.from(arrayBuffer)); }); } } diff --git a/domainh.js b/domainh.js index 46a3176..be73f0e 100644 --- a/domainh.js +++ b/domainh.js @@ -183,20 +183,23 @@ function downloadComplet(code, date, type = null) { download.current++; console.log(download); - return accessorh.fetchImage(imageFile, imageId).then(tt => { - if (e[0] == imageId) { - return new Promise((resolve2, reject) => { - if (fsh.fileExists(imageFile)) { - let thumb = `${folder}/thumbnail.png`; - fs.copyFileSync(imageFile, thumb); - let mainThumb = `${folder}/../thumbnail.png`; - fs.copyFileSync(imageFile, mainThumb); - } - resolve2(true); - }); - } else { - return Promise.resolve(true); - } + return accessorh.getImage(imageId).then(tt => { + return fsh.write(imageFile, tt).then(e => { + console.log('The file has been saved!'); + if (e[0] == imageId) { + return new Promise((resolve2, reject) => { + if (fsh.fileExists(imageFile)) { + let thumb = `${folder}/thumbnail.png`; + fs.copyFileSync(imageFile, thumb); + let mainThumb = `${folder}/../thumbnail.png`; + fs.copyFileSync(imageFile, mainThumb); + } + resolve2(true); + }); + } else { + return Promise.resolve(true); + } + }); }).then(promiseh.wait); }).then(ee => {