body method

  1. @override
String body(
  1. String path,
  2. String baseName,
  3. String className
)
override

Defines the actual body code. path is passed relative to lib, baseName is the filename, and className is the filename converted to Pascal case.

実際の本体コードを定義します。pathlibからの相対パス、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;
  }
}
}
""";
}