Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/**
* Note: even though most APIs don't, unsplash specifically recommends
* hotlinking their images, which makes our integration easier.
*/
'use strict'
// ugly hack required for unsplash client to work
global.fetch = require('node-fetch')
const { toJson, default: Unsplash } = require('unsplash-js')
const unsplash = new Unsplash({
accessKey: process.env.UNSPLASH_ACCESS_KEY,
secret: process.env.UNSPLASH_SECRET_KEY
})
const utm = '?utm_source=saasify&utm_medium=referral&utm_campaign=api-credit'
module.exports = async (opts) => {
const { query, offset, limit } = opts
const response = await unsplash.search.photos(
query,
1 + Math.ceil(offset / limit),
limit
)
if (!response.ok) {
}
if(offlineTestPath) {
console.info('Unsplash: found offline test path', offlineTestPath)
return {
random: () => Promise.resolve(require(offlineTestPath).search)
.then(formatUnsplashResult),
search: (query) => Promise.resolve(require(offlineTestPath).search)
.then(formatUnsplashResult),
};
}
if(!accessKey || !appName) throw 'Unsplash bank image requires options: accessKey, appName.';
const fetch = require('node-fetch');
global.fetch = fetch;
const Unsplash = require('unsplash-js').default;
const {toJson} = require('unsplash-js');
const unsplash = new Unsplash({ accessKey })
return {
random: () => unsplash.photos.listPhotos(1, 50)
.then(toJson)
.then(json => { return {
total: json.length,
pages: 1,
results: json,
}})
.then(formatUnsplashResult),
search: (query) => unsplash.search.photos(query, 1, 50)
.then(toJson)
.then(formatUnsplashResult),
};
}
require('isomorphic-fetch');
const { default: Unsplash, toJson } = require('unsplash-js');
const WALLPAPER_COLLECTION_ID = 136026;
const client = new Unsplash({
applicationId: process.env.UNSPLASH_ACCESS_KEY,
secret: process.env.UNSPLASH_SECRET_KEY,
callbackUrl: process.env.UNSPLASH_CALLBACK_URL,
});
const parseImageResult = img => ({
id: img.id,
photographer: {
name: img.user.name,
profile_url: img.user.links.html,
},
url: img.urls.small,
});
const getRandomImages = () =>
client.photos
const Unsplash = require('unsplash-js').default;
const fetch = require('node-fetch');
global.fetch = fetch;
const fs = require('fs');
require('dotenv').config();
let all = [];
const unsplash = new Unsplash({
applicationId: process.env.API_KEY,
secret: process.env.API_SECRET
});
async function download(url, name) {
const response = await fetch(url);
const dest = fs.createWriteStream(`./images/regular/${name}.png`);
response.body.pipe(dest);
}
getAll();
async function getAll() {
for (let i = 1; i < 328; i++) {
//let i = 300;
try {
const response = await unsplash.search.photos('rainbow', i, 20);