Build an in-memory cloud storage system across four incremental levels. Model the system as a class that fulfills the CloudStorage interface described below, along with any internal data structures you need.
Implement these methods:
add_file(name: str, size: int) -> bool
name is already present, return False. Otherwise store the file with its size and return True.copy_file(name_from: str, name_to: str) -> bool
False when the source file is missing or the destination name is already taken. Otherwise duplicate the file (copy only its size) and return True.get_file_size(name: str) -> int | None
None.Constraints:
size is strictly positive.Add:
find_file(prefix: str, suffix: str) -> list[str]
prefix and ends with suffix."{name}({size})".Extend the model so that every file belongs to a user. Each user has a capacity and a current usage. The built-in user "admin" has unlimited capacity.
New and changed methods:
add_user(user_id: str, capacity: int) -> bool
add_file_by(user_id: str, name: str, size: int) -> int | None
None) when the user does not exist, the file name is already taken, or adding the file would exceed the user's capacity.user_id, update that user's usage, and return their remaining capacity.add_file(name: str, size: int) -> bool
"admin" is adding the file.copy_file(name_from: str, name_to: str) -> bool
update_capacity(user_id: str, capacity: int) -> int | None
Only the file's owner may perform these operations.
compress_file(user_id: str, name: str) -> int | None
name with name + ".COMPRESSED".floor(old_size / 2).decompress_file(user_id: str, name: str) -> int | None
name must exist and be owned by user_id.".COMPRESSED" suffix to obtain original_name.original_name already exists.current_size * 2; fail if the owner's quota would be exceeded.Input:
add_file /a 10
add_file /a 10
copy_file /a /b
get_file_size /b
Output:
True
False
True
10