@edgedev/firebase 2.1.36 → 2.1.37
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 +16 -4
- package/package.json +1 -1
- package/src/storage.rules +5 -0
package/edgeFirebase.ts
CHANGED
|
@@ -2053,7 +2053,7 @@ export const EdgeFirebase = class {
|
|
|
2053
2053
|
|
|
2054
2054
|
|
|
2055
2055
|
// File functions
|
|
2056
|
-
public uploadFile = async (filePath: string, file: Blob): Promise<actionResponse> => {
|
|
2056
|
+
public uploadFile = async (filePath: string, file: Blob, isPublic: boolean): Promise<actionResponse> => {
|
|
2057
2057
|
|
|
2058
2058
|
// Validate if file is provided
|
|
2059
2059
|
if (!file) {
|
|
@@ -2065,7 +2065,11 @@ export const EdgeFirebase = class {
|
|
|
2065
2065
|
}
|
|
2066
2066
|
|
|
2067
2067
|
// Check if the user has write permission to the filePath
|
|
2068
|
-
|
|
2068
|
+
let hasWritePermission = await this.permissionCheck("write", filePath);
|
|
2069
|
+
if (isPublic) {
|
|
2070
|
+
hasWritePermission = true;
|
|
2071
|
+
filePath = "public";
|
|
2072
|
+
}
|
|
2069
2073
|
if (!hasWritePermission) {
|
|
2070
2074
|
return this.sendResponse({
|
|
2071
2075
|
success: false,
|
|
@@ -2075,13 +2079,21 @@ export const EdgeFirebase = class {
|
|
|
2075
2079
|
}
|
|
2076
2080
|
|
|
2077
2081
|
try {
|
|
2078
|
-
|
|
2082
|
+
let randomId = ''
|
|
2083
|
+
if (isPublic) {
|
|
2084
|
+
randomId = Math.random().toString(36).substring(2, 6) + '-'
|
|
2085
|
+
}
|
|
2086
|
+
const tempFilePath = `${filePath.replaceAll('/', '-')}` + '/' + randomId + file.name;
|
|
2079
2087
|
const fileRef = ref(this.storage, tempFilePath);
|
|
2088
|
+
if (isPublic) {
|
|
2089
|
+
await uploadBytes(fileRef, file, { contentType: file.type, cacheControl: 'public, max-age=31536000' });
|
|
2090
|
+
} else {
|
|
2080
2091
|
await uploadBytes(fileRef, file);
|
|
2092
|
+
}
|
|
2081
2093
|
return this.sendResponse({
|
|
2082
2094
|
success: true,
|
|
2083
2095
|
message: "File uploaded successfully.",
|
|
2084
|
-
meta: {}
|
|
2096
|
+
meta: {file: tempFilePath}
|
|
2085
2097
|
});
|
|
2086
2098
|
} catch (error) {
|
|
2087
2099
|
return this.sendResponse({
|
package/package.json
CHANGED
package/src/storage.rules
CHANGED
|
@@ -36,6 +36,11 @@ service firebase.storage {
|
|
|
36
36
|
)
|
|
37
37
|
);
|
|
38
38
|
}
|
|
39
|
+
match /public/{fileId} {
|
|
40
|
+
// Public directory with special rules
|
|
41
|
+
allow read: if true; // Unrestricted read access
|
|
42
|
+
allow write, delete: if request.auth != null; // Write and delete require authentication
|
|
43
|
+
}
|
|
39
44
|
match /{dir}/{fileId} {
|
|
40
45
|
// General read permission check based on Firestore data
|
|
41
46
|
allow read: if checkPermission("read", dir);
|