@edgedev/firebase 2.0.28 → 2.0.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/edgeFirebase.ts +55 -3
- package/package.json +1 -1
package/edgeFirebase.ts
CHANGED
|
@@ -59,6 +59,9 @@ import {
|
|
|
59
59
|
updateProfile,
|
|
60
60
|
} from "firebase/auth";
|
|
61
61
|
|
|
62
|
+
import { getStorage, ref as storageRef, uploadBytes, listAll, getDownloadURL, deleteObject } from "firebase/storage";
|
|
63
|
+
|
|
64
|
+
|
|
62
65
|
import { getFunctions, httpsCallable, connectFunctionsEmulator } from "firebase/functions";
|
|
63
66
|
|
|
64
67
|
import { getAnalytics, logEvent } from "firebase/analytics";
|
|
@@ -226,21 +229,25 @@ export const EdgeFirebase = class {
|
|
|
226
229
|
}
|
|
227
230
|
|
|
228
231
|
if (this.firebaseConfig.emulatorAuth) {
|
|
229
|
-
connectAuthEmulator(this.auth, `http://
|
|
232
|
+
connectAuthEmulator(this.auth, `http://127.0.0.1:${this.firebaseConfig.emulatorAuth}`)
|
|
230
233
|
}
|
|
231
234
|
|
|
232
235
|
this.db = getFirestore(this.app);
|
|
233
236
|
if (this.firebaseConfig.emulatorFirestore) {
|
|
234
|
-
connectFirestoreEmulator(this.db, "
|
|
237
|
+
connectFirestoreEmulator(this.db, "127.0.0.1", this.firebaseConfig.emulatorFirestore)
|
|
235
238
|
}
|
|
236
239
|
|
|
237
240
|
if (this.firebaseConfig.measurementId) {
|
|
238
241
|
this.anaytics = getAnalytics(this.app);
|
|
239
242
|
}
|
|
240
243
|
|
|
244
|
+
if (this.firebaseConfig.storageBucket) {
|
|
245
|
+
this.storage = getStorage(this.app);
|
|
246
|
+
}
|
|
247
|
+
|
|
241
248
|
this.functions = getFunctions(this.app);
|
|
242
249
|
if (this.firebaseConfig.emulatorFunctions) {
|
|
243
|
-
connectFunctionsEmulator(this.functions, "
|
|
250
|
+
connectFunctionsEmulator(this.functions, "127.0.0.1", this.firebaseConfig.emulatorFunctions)
|
|
244
251
|
}
|
|
245
252
|
this.setOnAuthStateChanged();
|
|
246
253
|
}
|
|
@@ -250,6 +257,7 @@ export const EdgeFirebase = class {
|
|
|
250
257
|
public app = null;
|
|
251
258
|
public auth = null;
|
|
252
259
|
public db = null;
|
|
260
|
+
public storage = null;
|
|
253
261
|
|
|
254
262
|
private anaytics = null;
|
|
255
263
|
|
|
@@ -2119,4 +2127,48 @@ export const EdgeFirebase = class {
|
|
|
2119
2127
|
this.unsubscribe[collectionPath] = null;
|
|
2120
2128
|
}
|
|
2121
2129
|
};
|
|
2130
|
+
// Firestore Storage
|
|
2131
|
+
// Upload a file
|
|
2132
|
+
async uploadFileToStorage(filePath, file) {
|
|
2133
|
+
const canWrite = await this.permissionCheck("write", filePath);
|
|
2134
|
+
if (!canWrite) {
|
|
2135
|
+
return { success: false, message: "Permission denied" };
|
|
2136
|
+
}
|
|
2137
|
+
const storagePath = storageRef(this.storage, filePath);
|
|
2138
|
+
await uploadBytes(storagePath, file);
|
|
2139
|
+
return { success: true, message: "File uploaded successfully" };
|
|
2140
|
+
}
|
|
2141
|
+
|
|
2142
|
+
// List all files in a directory
|
|
2143
|
+
async listFilesInStorage(directoryPath) {
|
|
2144
|
+
const canRead = await this.permissionCheck("read", directoryPath);
|
|
2145
|
+
if (!canRead) {
|
|
2146
|
+
return { success: false, message: "Permission denied" };
|
|
2147
|
+
}
|
|
2148
|
+
const dirRef = storageRef(this.storage, directoryPath);
|
|
2149
|
+
const fileList = await listAll(dirRef);
|
|
2150
|
+
return { success: true, files: fileList.items.map(item => item.fullPath) };
|
|
2151
|
+
}
|
|
2152
|
+
|
|
2153
|
+
// Download a file
|
|
2154
|
+
async downloadFileFromStorage(filePath) {
|
|
2155
|
+
const canRead = await this.permissionCheck("read", filePath);
|
|
2156
|
+
if (!canRead) {
|
|
2157
|
+
return { success: false, message: "Permission denied" };
|
|
2158
|
+
}
|
|
2159
|
+
const fileRef = storageRef(this.storage, filePath);
|
|
2160
|
+
const downloadUrl = await getDownloadURL(fileRef);
|
|
2161
|
+
return { success: true, url: downloadUrl };
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2164
|
+
// Delete a fileå
|
|
2165
|
+
async deleteFileFromStorage(filePath) {
|
|
2166
|
+
const canDelete = await this.permissionCheck("delete", filePath);
|
|
2167
|
+
if (!canDelete) {
|
|
2168
|
+
return { success: false, message: "Permission denied" };
|
|
2169
|
+
}
|
|
2170
|
+
const fileRef = storageRef(this.storage, filePath);
|
|
2171
|
+
await deleteObject(fileRef);
|
|
2172
|
+
return { success: true, message: "File deleted successfully" };
|
|
2173
|
+
}
|
|
2122
2174
|
};
|