forked from excalidraw/excalidraw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.ts
54 lines (46 loc) · 1.57 KB
/
config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import {
isSavedToFirebase,
loadFilesFromFirebase,
loadFromFirebase,
saveFilesToFirebase,
saveToFirebase,
} from "./firebase";
import {
isSavedToHttpStorage,
loadFilesFromHttpStorage,
loadFromHttpStorage,
saveFilesToHttpStorage,
saveToHttpStorage,
} from "./httpStorage";
import { StorageBackend } from "./StorageBackend";
const firebaseStorage: StorageBackend = {
isSaved: isSavedToFirebase,
saveToStorageBackend: saveToFirebase,
loadFromStorageBackend: loadFromFirebase,
saveFilesToStorageBackend: saveFilesToFirebase,
loadFilesFromStorageBackend: loadFilesFromFirebase,
};
const httpStorage: StorageBackend = {
isSaved: isSavedToHttpStorage,
saveToStorageBackend: saveToHttpStorage,
loadFromStorageBackend: loadFromHttpStorage,
saveFilesToStorageBackend: saveFilesToHttpStorage,
loadFilesFromStorageBackend: loadFilesFromHttpStorage,
};
const storageBackends = new Map<string, StorageBackend>()
.set("firebase", firebaseStorage)
.set("http", httpStorage);
export let storageBackend: StorageBackend | null = null;
export async function getStorageBackend() {
if (storageBackend) {
return storageBackend;
}
const storageBackendName = import.meta.env.VITE_APP_STORAGE_BACKEND || '';
if (storageBackends.has(storageBackendName)) {
storageBackend = storageBackends.get(storageBackendName) as StorageBackend;
} else {
console.warn("No storage backend found, default to firebase");
storageBackend = firebaseStorage;
}
return storageBackend;
}