mirror of
https://github.com/jorisbertomeu/web-screensaver.git
synced 2026-04-19 16:27:40 +02:00
26 lines
762 B
JavaScript
26 lines
762 B
JavaScript
import { createApi } from 'unsplash-js';
|
|
import * as nodeFetch from 'node-fetch';
|
|
|
|
export class UnsplashService {
|
|
constructor(credentials) {
|
|
this.api = createApi({
|
|
accessKey: credentials.accessKey,
|
|
secretKey: credentials.secretKey,
|
|
fetch: nodeFetch.default
|
|
});
|
|
}
|
|
|
|
async getRandomPhotos(collections = [], count = 30) {
|
|
try {
|
|
const { response } = await this.api.photos.getRandom({
|
|
orientation: 'landscape',
|
|
collectionIds: collections,
|
|
count
|
|
});
|
|
return response || [];
|
|
} catch (error) {
|
|
console.error("Error fetching photos from Unsplash:", error);
|
|
return [];
|
|
}
|
|
}
|
|
} |