diff --git a/api/src/controllers/PhotoController.js b/api/src/controllers/PhotoController.js index b49432b..4545bcc 100644 --- a/api/src/controllers/PhotoController.js +++ b/api/src/controllers/PhotoController.js @@ -18,7 +18,7 @@ export class PhotoController { collections = Array.isArray(collections) ? collections : [collections]; } - const photo = await this.photoService.pickPictureFromFile(collections, false); + const photo = await this.photoService.pickPictureFromFile(collections, false, settings.unsplash); if (!photo) { return res.status(500).json({ error: 'Failed to fetch photo' }); diff --git a/api/src/services/PhotoService.js b/api/src/services/PhotoService.js index eeff3ed..4c0bfdf 100644 --- a/api/src/services/PhotoService.js +++ b/api/src/services/PhotoService.js @@ -6,7 +6,7 @@ export class PhotoService { this.fileService = fileService; } - async pickPictureFromFile(collections = [], burnPic = true) { + async pickPictureFromFile(collections = [], burnPic = true, unsplashCreds = null) { try { const filename = generatePictureFilename(collections.join(',')); let pics = this.fileService.readJsonFile(filename); @@ -22,7 +22,11 @@ export class PhotoService { return pic; } - const newPics = await UnsplashService.getRandomPhotos(collections); + const unsplashService = new UnsplashService({ + accessKey: unsplashCreds?.accessKey || '', + secretKey: unsplashCreds?.secretKey || '' + }); + const newPics = await unsplashService.getRandomPhotos(collections); if (newPics.length === 0) { return null; } diff --git a/api/src/services/UnsplashService.js b/api/src/services/UnsplashService.js index 5f7fb73..63c41ad 100644 --- a/api/src/services/UnsplashService.js +++ b/api/src/services/UnsplashService.js @@ -10,7 +10,7 @@ export class UnsplashService { }); } - async getRandomPhotos(collections = [], count = DEFAULT_PHOTO_COUNT) { + async getRandomPhotos(collections = [], count = 30) { try { const { response } = await this.api.photos.getRandom({ orientation: 'landscape',