Skip to content

Commit

Permalink
feat: Remove Unsplash; Add Lorem Flickr and Lorem Picsum
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwilson committed Jul 7, 2024
1 parent d822eaa commit bbaef53
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 9 deletions.
19 changes: 11 additions & 8 deletions src/provider/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@

const providers = {
'custom-v1': require('./custom-v1'),
s3: require('./s3'),
unsplash: require('./unsplash')
}
"custom-v1": require("./custom-v1"),
s3: require("./s3"),
"lorem-flickr": require("./lorem-flickr"),
picsum: require("./picsum"),
unsplash: require("./unsplash"),
};

module.exports = {
providers,
defaultableProviders: Object.keys(providers).filter(providerName => providers[providerName].defaultable)
}
providers,
defaultableProviders: Object.keys(providers).filter(
(providerName) => providers[providerName].defaultable,
),
};
29 changes: 29 additions & 0 deletions src/provider/lorem-flickr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const BaseProvider = require("./base-provider");

class LoremFlickr extends BaseProvider {
constructor(provider) {
super(provider);
this._defaultResponseBody.provider = "LoremFlickr";
this._defaultResponseBody.license = "Creative Commons";
this._defaultResponseBody.terms = "https://loremflickr.com/";
}

static get defaultable() {
return true;
}

randomImage(query) {
const height = query.size.height || 1080;
const width = query.size.width || 1920;
return fetch(
`https://loremflickr.com/${width}/${height}/${query.category}`,
).then((res) =>
this._normalizeResponse({
url: res.url,
size: { height, width },
}),
);
}
}

module.exports = LoremFlickr;
27 changes: 27 additions & 0 deletions src/provider/picsum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const BaseProvider = require("./base-provider");

class Picsum extends BaseProvider {
constructor(provider) {
super(provider);
this._defaultResponseBody.provider = "LoremPicsum";
this._defaultResponseBody.license = "CC0";
this._defaultResponseBody.terms = "https://picsum.photos/";
}

static get defaultable() {
return true;
}

randomImage(query) {
const height = query.size.height || 1080;
const width = query.size.width || 1920;
return fetch(`https://picsum.photos/${width}/${height}`).then((res) =>
this._normalizeResponse({
url: res.url,
size: { height, width },
}),
);
}
}

module.exports = Picsum;
2 changes: 1 addition & 1 deletion src/provider/unsplash.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Unsplash extends BaseProvider {
}

static get defaultable() {
return true;
return false;
}

randomImage(query) {
Expand Down

0 comments on commit bbaef53

Please sign in to comment.