photo.ts 700 B

1234567891011121314151617181920212223242526272829
  1. import { ref, getDownloadURL, listAll } from "firebase/storage";
  2. import { storage } from "../firebase";
  3. export async function getPhotoUrl(filePath: string): Promise<string> {
  4. const storageRef = ref(storage, filePath);
  5. try {
  6. const url = await getDownloadURL(storageRef);
  7. return url;
  8. } catch (error) {
  9. throw error;
  10. }
  11. }
  12. export async function listPhotos(folderPath: string): Promise<string[]> {
  13. const folderRef = ref(storage, folderPath);
  14. try {
  15. const res = await listAll(folderRef);
  16. const urlPromises = res.items.map((itemRef) => getDownloadURL(itemRef));
  17. const urls = await Promise.all(urlPromises);
  18. return urls;
  19. } catch (error) {
  20. throw error;
  21. }
  22. }