@edgedev/firebase 2.1.44 → 2.1.46
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 +81 -58
- package/package.json +1 -1
package/edgeFirebase.ts
CHANGED
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
arrayRemove,
|
|
26
26
|
arrayUnion,
|
|
27
27
|
connectFirestoreEmulator,
|
|
28
|
+
getCountFromServer,
|
|
28
29
|
} from "firebase/firestore";
|
|
29
30
|
|
|
30
31
|
import {
|
|
@@ -60,6 +61,7 @@ import { getStorage, ref, uploadBytesResumable, getDownloadURL, connectStorageEm
|
|
|
60
61
|
import { getFunctions, httpsCallable, connectFunctionsEmulator } from "firebase/functions";
|
|
61
62
|
|
|
62
63
|
import { getAnalytics, logEvent } from "firebase/analytics";
|
|
64
|
+
import { get } from "http";
|
|
63
65
|
|
|
64
66
|
interface FirestoreQuery {
|
|
65
67
|
field: string;
|
|
@@ -1285,9 +1287,22 @@ export const EdgeFirebase = class {
|
|
|
1285
1287
|
return { data, next: nextLast };
|
|
1286
1288
|
};
|
|
1287
1289
|
|
|
1290
|
+
private getTotalCount = async (
|
|
1291
|
+
collectionPath: string,
|
|
1292
|
+
queryList: FirestoreQuery[] = []
|
|
1293
|
+
): Promise<number> => {
|
|
1294
|
+
console.log('getTotalCount')
|
|
1295
|
+
console.log(collectionPath )
|
|
1296
|
+
console.log(queryList)
|
|
1297
|
+
const q = this.getQuery(collectionPath, queryList);
|
|
1298
|
+
const snapshot = await getCountFromServer(q);
|
|
1299
|
+
return snapshot.data().count;
|
|
1300
|
+
};
|
|
1301
|
+
|
|
1288
1302
|
get SearchStaticData() {
|
|
1289
1303
|
const getStaticData = this.getStaticData;
|
|
1290
1304
|
const permissionCheckOnly = this.permissionCheckOnly;
|
|
1305
|
+
const getTotalCount = this.getTotalCount;
|
|
1291
1306
|
const sendResponse = this.sendResponse;
|
|
1292
1307
|
return class {
|
|
1293
1308
|
private collectionPath = "";
|
|
@@ -1300,7 +1315,8 @@ export const EdgeFirebase = class {
|
|
|
1300
1315
|
pagination: [],
|
|
1301
1316
|
staticIsLastPage: true,
|
|
1302
1317
|
staticIsFirstPage: true,
|
|
1303
|
-
staticCurrentPage: ""
|
|
1318
|
+
staticCurrentPage: "",
|
|
1319
|
+
total: 0
|
|
1304
1320
|
});
|
|
1305
1321
|
|
|
1306
1322
|
public prev = async (): Promise<void> => {
|
|
@@ -1408,6 +1424,7 @@ export const EdgeFirebase = class {
|
|
|
1408
1424
|
orderList,
|
|
1409
1425
|
max
|
|
1410
1426
|
);
|
|
1427
|
+
this.results.total = await getTotalCount(this.collectionPath, this.queryList);
|
|
1411
1428
|
if (Object.keys(results.data).length > 0) {
|
|
1412
1429
|
this.results.staticIsLastPage = false;
|
|
1413
1430
|
this.results.data = results.data;
|
|
@@ -2082,76 +2099,82 @@ export const EdgeFirebase = class {
|
|
|
2082
2099
|
|
|
2083
2100
|
// Validate if file is provided
|
|
2084
2101
|
if (!file) {
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2102
|
+
return this.sendResponse({
|
|
2103
|
+
success: false,
|
|
2104
|
+
message: "No file provided for upload.",
|
|
2105
|
+
meta: {}
|
|
2106
|
+
});
|
|
2090
2107
|
}
|
|
2091
|
-
|
|
2108
|
+
|
|
2092
2109
|
// Check if the user has write permission to the filePath
|
|
2093
2110
|
let hasWritePermission = await this.permissionCheck("write", filePath);
|
|
2094
2111
|
if (isPublic) {
|
|
2095
|
-
|
|
2096
|
-
|
|
2112
|
+
hasWritePermission = true;
|
|
2113
|
+
filePath = "public";
|
|
2097
2114
|
}
|
|
2098
2115
|
if (!hasWritePermission) {
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2116
|
+
return this.sendResponse({
|
|
2117
|
+
success: false,
|
|
2118
|
+
message: "You do not have permission to upload files to this path.",
|
|
2119
|
+
meta: {}
|
|
2120
|
+
});
|
|
2104
2121
|
}
|
|
2105
|
-
|
|
2122
|
+
|
|
2106
2123
|
try {
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
+
let randomId = '';
|
|
2125
|
+
if (isPublic) {
|
|
2126
|
+
randomId = Math.random().toString(36).substring(2, 6) + '-';
|
|
2127
|
+
}
|
|
2128
|
+
const tempFilePath = `${filePath.replaceAll('/', '-')}` + '/' + randomId + file.name;
|
|
2129
|
+
const storage = getStorage();
|
|
2130
|
+
const fileRef = ref(storage, tempFilePath);
|
|
2131
|
+
|
|
2132
|
+
const metadata = {
|
|
2133
|
+
contentType: file.type,
|
|
2134
|
+
cacheControl: isPublic ? 'public, max-age=31536000' : undefined,
|
|
2135
|
+
};
|
|
2136
|
+
|
|
2137
|
+
// Resumable upload
|
|
2138
|
+
const uploadTask = uploadBytesResumable(fileRef, file, metadata);
|
|
2139
|
+
|
|
2140
|
+
// Wrap the upload task in a Promise
|
|
2141
|
+
const uploadPromise = new Promise<actionResponse>((resolve, reject) => {
|
|
2124
2142
|
uploadTask.on('state_changed',
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2143
|
+
(snapshot) => {
|
|
2144
|
+
// Progress, pause, and resume events
|
|
2145
|
+
const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
|
|
2146
|
+
console.log('Upload is ' + progress + '% done');
|
|
2147
|
+
},
|
|
2148
|
+
(error) => {
|
|
2149
|
+
// Handle unsuccessful uploads
|
|
2150
|
+
reject(this.sendResponse({
|
|
2151
|
+
success: false,
|
|
2152
|
+
message: "An error occurred during file upload.",
|
|
2153
|
+
meta: { error: error.message }
|
|
2154
|
+
}));
|
|
2155
|
+
},
|
|
2156
|
+
() => {
|
|
2157
|
+
// Handle successful uploads on complete
|
|
2158
|
+
resolve(this.sendResponse({
|
|
2159
|
+
success: true,
|
|
2160
|
+
message: "File uploaded successfully.",
|
|
2161
|
+
meta: { file: tempFilePath }
|
|
2162
|
+
}));
|
|
2163
|
+
}
|
|
2146
2164
|
);
|
|
2165
|
+
});
|
|
2166
|
+
|
|
2167
|
+
return await uploadPromise;
|
|
2168
|
+
|
|
2147
2169
|
} catch (error) {
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2170
|
+
return this.sendResponse({
|
|
2171
|
+
success: false,
|
|
2172
|
+
message: "An error occurred during file upload.",
|
|
2173
|
+
meta: { error: error.message }
|
|
2174
|
+
});
|
|
2153
2175
|
}
|
|
2154
2176
|
};
|
|
2177
|
+
|
|
2155
2178
|
|
|
2156
2179
|
public deleteFile = async (filePath: string): Promise<actionResponse> => {
|
|
2157
2180
|
let hasDeletePermission = await this.permissionCheck("write", filePath);
|