Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions stores/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { acceptHMRUpdate, defineStore } from "pinia";

import {
deleteObject,
FullMetadata,
getBlob,
getDownloadURL,
getMetadata as getMetadataStorage,
Expand All @@ -14,7 +15,7 @@ import { useFirebase } from "./firebase";

export const useStorage = defineStore("Storage", () => {
const storage = useFirebase().storage;
const cached = {};
const cached = {}, cachedMetadata: {[key: string]: Promise<FullMetadata>} = {};

const upload = async (file: File | Blob, path: string, fileName?: string) => {
const pathName = path + "/" + (fileName ?? uuid());
Expand Down Expand Up @@ -74,8 +75,13 @@ export const useStorage = defineStore("Storage", () => {
}

async function getMetadata(url: string) {
if (cachedMetadata[url] !== undefined) {
return cachedMetadata[url];
}
const refFile = refStorage(storage, url);
return getMetadataStorage(refFile);
cachedMetadata[url] = getMetadataStorage(refFile);

return cachedMetadata[url];
}

return {
Expand Down
Loading