This repository has been archived by the owner on May 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathstorage.rules
50 lines (46 loc) · 1.79 KB
/
storage.rules
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
// Returns true if the uploaded file is an image and its size is below the given number of MB.
function isImageBelowMaxSize(maxSizeMB) {
return request.resource.size < maxSizeMB * 1024 * 1024
&& request.resource.contentType.matches('image/.*');
}
// Returns true if the uploaded file is an video and its size is below the given number of MB.
function isVideoBelowMaxSize(maxSizeMB) {
return request.resource.size < maxSizeMB * 1024 * 1024
&& request.resource.contentType.matches('video/.*');
}
// Returns true if the user that initiated the request is an admin.
function isAdmin() {
return request.auth.token != null && request.auth.token.admin == true;
}
// Returns true if the resource is being deleted.
function isResourceBeingDeleted() {
return request.resource == null;
}
// Returns true if the user is the owner of the file.
function isOwner(uid) {
return request.auth.uid == uid;
}
service firebase.storage {
match /b/{bucket}/o {
match /images/{userId}/{fileName} {
allow read;
allow write: if isAdmin() || isOwner(userId) && (isResourceBeingDeleted() || isImageBelowMaxSize(5));
}
match /videos/{userId}/{fileName} {
allow read;
allow write: if isAdmin() || isOwner(userId) && (isResourceBeingDeleted() || isVideoBelowMaxSize(20));
}
match /thumbnail/{userId}/{fileName} {
allow read;
allow write: if isAdmin() || isOwner(userId) && (isResourceBeingDeleted() || isImageBelowMaxSize(5));
}
match /avatar/{userId}/{fileName} {
allow read;
allow write: if isAdmin() || isOwner(userId) && (isResourceBeingDeleted() || isImageBelowMaxSize(5));
}
match /cover/{userId}/{fileName} {
allow read;
allow write: if isAdmin() || isOwner(userId) && (isResourceBeingDeleted() || isImageBelowMaxSize(5));
}
}
}