mirror of
https://github.com/jorisbertomeu/web-screensaver.git
synced 2026-04-20 00:37:40 +02:00
first
This commit is contained in:
26
api/src/services/UnsplashService.js
Normal file
26
api/src/services/UnsplashService.js
Normal file
@@ -0,0 +1,26 @@
|
||||
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 = DEFAULT_PHOTO_COUNT) {
|
||||
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 [];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user