This commit is contained in:
Joris Bertomeu
2024-11-19 12:01:15 +01:00
commit dfb0846b79
40 changed files with 16403 additions and 0 deletions

View 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 [];
}
}
}