@edgedev/firebase 2.1.42 → 2.1.43
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 +14 -14
- package/package.json +1 -1
package/edgeFirebase.ts
CHANGED
|
@@ -2077,7 +2077,6 @@ export const EdgeFirebase = class {
|
|
|
2077
2077
|
};
|
|
2078
2078
|
|
|
2079
2079
|
|
|
2080
|
-
// File functions
|
|
2081
2080
|
// File functions
|
|
2082
2081
|
public uploadFile = async (filePath: string, file: Blob, isPublic: boolean): Promise<actionResponse> => {
|
|
2083
2082
|
|
|
@@ -2089,7 +2088,7 @@ export const EdgeFirebase = class {
|
|
|
2089
2088
|
meta: {}
|
|
2090
2089
|
});
|
|
2091
2090
|
}
|
|
2092
|
-
|
|
2091
|
+
|
|
2093
2092
|
// Check if the user has write permission to the filePath
|
|
2094
2093
|
let hasWritePermission = await this.permissionCheck("write", filePath);
|
|
2095
2094
|
if (isPublic) {
|
|
@@ -2103,45 +2102,47 @@ export const EdgeFirebase = class {
|
|
|
2103
2102
|
meta: {}
|
|
2104
2103
|
});
|
|
2105
2104
|
}
|
|
2106
|
-
|
|
2105
|
+
|
|
2107
2106
|
try {
|
|
2108
2107
|
const chunkSize = 5 * 1024 * 1024; // 5 MB per chunk
|
|
2109
2108
|
const totalChunks = Math.ceil(file.size / chunkSize);
|
|
2110
2109
|
const uploadPath = `${filePath.replaceAll('/', '-')}/${file.name}`;
|
|
2111
2110
|
const chunkPromises = [];
|
|
2112
|
-
|
|
2111
|
+
let totalBytesTransferred = 0;
|
|
2112
|
+
|
|
2113
2113
|
for (let i = 0; i < totalChunks; i++) {
|
|
2114
2114
|
const chunkStart = i * chunkSize;
|
|
2115
2115
|
const chunkEnd = Math.min(chunkStart + chunkSize, file.size);
|
|
2116
2116
|
const chunk = file.slice(chunkStart, chunkEnd);
|
|
2117
|
-
|
|
2117
|
+
|
|
2118
2118
|
const chunkFilePath = `${uploadPath}.part-${i + 1}`;
|
|
2119
2119
|
const fileRef = ref(this.storage, chunkFilePath);
|
|
2120
2120
|
const uploadTask = uploadBytesResumable(fileRef, chunk, { contentType: file.type });
|
|
2121
|
-
|
|
2121
|
+
|
|
2122
2122
|
chunkPromises.push(new Promise((resolve, reject) => {
|
|
2123
2123
|
uploadTask.on(
|
|
2124
2124
|
'state_changed',
|
|
2125
2125
|
(snapshot) => {
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2126
|
+
const chunkProgress = (snapshot.bytesTransferred / snapshot.totalBytes) * (chunkEnd - chunkStart);
|
|
2127
|
+
totalBytesTransferred += chunkProgress;
|
|
2128
|
+
const overallProgress = (totalBytesTransferred / file.size) * 100;
|
|
2129
|
+
console.log(`Upload is ${overallProgress.toFixed(2)}% done`);
|
|
2129
2130
|
},
|
|
2130
2131
|
(error) => reject(error),
|
|
2131
2132
|
() => resolve(uploadTask.snapshot)
|
|
2132
2133
|
);
|
|
2133
2134
|
}));
|
|
2134
2135
|
}
|
|
2135
|
-
|
|
2136
|
+
|
|
2136
2137
|
// Wait for all chunks to finish uploading
|
|
2137
2138
|
await Promise.all(chunkPromises);
|
|
2138
|
-
|
|
2139
|
+
|
|
2139
2140
|
return this.sendResponse({
|
|
2140
2141
|
success: true,
|
|
2141
2142
|
message: "File uploaded successfully in chunks.",
|
|
2142
2143
|
meta: {file: uploadPath}
|
|
2143
2144
|
});
|
|
2144
|
-
|
|
2145
|
+
|
|
2145
2146
|
} catch (error) {
|
|
2146
2147
|
return this.sendResponse({
|
|
2147
2148
|
success: false,
|
|
@@ -2150,8 +2151,7 @@ export const EdgeFirebase = class {
|
|
|
2150
2151
|
});
|
|
2151
2152
|
}
|
|
2152
2153
|
};
|
|
2153
|
-
|
|
2154
|
-
|
|
2154
|
+
|
|
2155
2155
|
public deleteFile = async (filePath: string): Promise<actionResponse> => {
|
|
2156
2156
|
let hasDeletePermission = await this.permissionCheck("write", filePath);
|
|
2157
2157
|
if (filePath.substring(0, 6) === 'public') {
|