Fixes relative to fresh unsplash conf

This commit is contained in:
Joris Bertomeu
2024-11-19 16:11:40 +01:00
parent fd0b1395f7
commit e8d68d0b7e
3 changed files with 8 additions and 4 deletions

View File

@@ -18,7 +18,7 @@ export class PhotoController {
collections = Array.isArray(collections) ? collections : [collections]; 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) { if (!photo) {
return res.status(500).json({ error: 'Failed to fetch photo' }); return res.status(500).json({ error: 'Failed to fetch photo' });

View File

@@ -6,7 +6,7 @@ export class PhotoService {
this.fileService = fileService; this.fileService = fileService;
} }
async pickPictureFromFile(collections = [], burnPic = true) { async pickPictureFromFile(collections = [], burnPic = true, unsplashCreds = null) {
try { try {
const filename = generatePictureFilename(collections.join(',')); const filename = generatePictureFilename(collections.join(','));
let pics = this.fileService.readJsonFile(filename); let pics = this.fileService.readJsonFile(filename);
@@ -22,7 +22,11 @@ export class PhotoService {
return pic; 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) { if (newPics.length === 0) {
return null; return null;
} }

View File

@@ -10,7 +10,7 @@ export class UnsplashService {
}); });
} }
async getRandomPhotos(collections = [], count = DEFAULT_PHOTO_COUNT) { async getRandomPhotos(collections = [], count = 30) {
try { try {
const { response } = await this.api.photos.getRandom({ const { response } = await this.api.photos.getRandom({
orientation: 'landscape', orientation: 'landscape',