Skip to content

Commit

Permalink
2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jaumesegarra committed Mar 13, 2019
1 parent a760d16 commit 31cedf1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ Download latest version from [here](https://github.com/jaumesegarra/ranwall2-app
## Thanks to:
* [picsum.photos](https://picsum.photos)
* [unsplash.com](https://unsplash.com)
* [desktoppr.co](https://www.desktoppr.co)
* [loremFlickr.com](https://loremFlickr.com)
* [splashbase.co](http://www.splashbase.co)
* [desktoppr.co](https://www.desktoppr.co): Now are down 😥
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ranwall",
"version": "2.0.0",
"version": "2.0.1",
"description": "App for set random wallpapers",
"homepage": "./",
"repository": "https://github.com/jaumesegarra/ranwall2-app",
Expand Down
8 changes: 8 additions & 0 deletions src/constants/providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ export default [{
"name": "unsplash.com",
"url": res => `https://source.unsplash.com/random/${res[0]}x${res[1]}`
},
{
"code": "DSKPR",
"name": "desktoppr.co *",
"url": res => `https://api.desktoppr.co/1/wallpapers/random`,
"get": {
"imgPath": data => data.response.image.url
}
},
{
"code": "FLCK",
"name": "loremFlickr.com *",
Expand Down
9 changes: 7 additions & 2 deletions src/utils/wallpapermanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export function createWallpaperObject () {
let tmpBinImage = null;
function downloadWallpaper(provider, size, name){

let times = 0;
function getRequest(url, obs, auth = null){
let params = {url: url, encoding: null};

Expand All @@ -41,15 +42,19 @@ function downloadWallpaper(provider, size, name){
if(res.statusCode !== 200)
return obs.error(res.statusCode);

if((res.headers['content-type'] && res.headers['content-type'].indexOf('application/json') >= 0) || (provider.get && provider.get.type === 'json')){
let data = JSON.parse(body);
if((res.headers['content-type'] && res.headers['content-type'].indexOf('application/json') >= 0) || (times === 0 && provider.get && provider.get.type === 'json')){
let data;
try{
data = JSON.parse(body);
}catch(e) { return obs.error('Invalid JSON returned'); }

if(!provider.get || !provider.get.imgPath)
return obs.error('Not defined function to obtain the image path...');

return getRequest(provider.get.imgPath(data), obs);
}

times++;
tmpBinImage = body;
obs.next(body);
obs.complete();
Expand Down

0 comments on commit 31cedf1

Please sign in to comment.