/
storage.rules
44 lines (37 loc) · 1.07 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
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /users/{userId} {
// match /{allPaths=**} {
// }
match /photo {
allow read: if true;
allow write: if isAuthUid(userId) && isImageMb(request.resource, 5);
allow delete: if isAuthUid(userId);
}
}
match /posts/{postId}/{imageId} {
allow read: if isPublic(resource);
allow create: if
isAuthUid(request.resource.metadata['userId']) &&
isImageMb(request.resource, 5) &&
(imageId == '1' || imageId == '2' || imageId == '3' || imageId == '4');
}
function isAuthUid(uid) {
return request.auth.uid == uid;
}
function isPublic(res) {
return res.metadata['visibility'] == 'public';
}
function isImageMb(res, mb) {
return isImage(res) && isLtMb(res, mb);
}
// is the request file size less than in MB
function isLtMb(res, mb) {
return res.size < mb * 1024 * 1024;
}
function isImage(res) {
return res.contentType.matches('image/.*');
}
}
}