body method
Defines the actual body code. path
is passed relative to lib
, baseName
is the filename, and className
is the filename converted to Pascal case.
実際の本体コードを定義します。path
にlib
からの相対パス、baseName
にファイル名が渡され、className
にファイル名をパスカルケースに変換した値が渡されます。
Implementation
@override
String body(String path, String baseName, String className) {
return """
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /public/{userId}/{allPaths=**} {
allow read: if isAssets(resource);
allow create, update: if isSpecifiedUser(userId) && isAssets(request.resource) && isNotTooLarge(request.resource);
allow delete: if isSpecifiedUser(userId);
}
match /private/{userId}/{allPaths=**} {
allow read, write: if isSpecifiedUser(userId);
}
match /{allPaths=**} {
allow read, write: if false;
}
function isSpecifiedUser(userId) {
return isAuthUser() && request.auth.uid == userId;
}
function isAssets(data) {
return data != null && (data.contentType.matches('image/.*') || data.contentType.matches('video/.*') || data.contentType.matches('audio/.*') || data.contentType == 'application/vnd.apple.mpegurl');
}
function isAuthUser() {
return request.auth != null;
}
function isNotTooLarge(data) {
return data.size <= 2 * 1024 * 1024;
}
}
}
""";
}