Skip to content

Commit

Permalink
Make the accessor return a buffer rather than saving on a specific fo…
Browse files Browse the repository at this point in the history
…lder
  • Loading branch information
pdulvp committed May 13, 2023
1 parent b44a697 commit 71edb61
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ A domain adaptor must provides this following API:

`getArchives: (code) => [ code, date ]`

`fetchImage (imageFile, idPage)`
`getImage (idPage)`

### Installation

Expand Down
13 changes: 4 additions & 9 deletions accessorh/sampleh.js
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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));
});
}
}
Expand Down
31 changes: 17 additions & 14 deletions domainh.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit 71edb61

Please sign in to comment.