chore: Refactor getBackgroundImages to improve image URL generation

This commit is contained in:
Sean Morley
2024-06-12 19:59:53 +00:00
parent 8eb9f11708
commit 71363026b2
5 changed files with 50 additions and 2 deletions

View File

@@ -1,6 +1,13 @@
import { ensureBucketExists, getObjectUrl, s3Client } from "$lib/server/s3";
import { ListObjectsV2Command } from "@aws-sdk/client-s3";
/**
* Retrieves a random background image URL from the "backgrounds" bucket.
* If the randomly selected image is ".emptyFolderPlaceholder", it recursively calls itself to get another image.
* If no images are found in the bucket, a default image URL is returned.
*
* @returns A Promise that resolves to a string representing the URL of the background image.
*/
export const getBackgroundImages = async (): Promise<string> => {
await ensureBucketExists("backgrounds");