File size: 2,964 Bytes
2fe2727
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2642f13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2fe2727
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
"""Storage interface for DocVault."""

from abc import ABC, abstractmethod
from typing import Any, Dict, List, Optional


class StorageInterface(ABC):
    """Contract implemented by the active storage backend."""

    @abstractmethod
    def create_folder(self, user_id: str, folder_path: str) -> Dict[str, Any]:
        pass

    @abstractmethod
    def upload_file(
        self, user_id: str, folder_path: str, filename: str, file_obj: Any
    ) -> Dict[str, Any]:
        pass

    @abstractmethod
    def delete_file(self, user_id: str, file_path: str) -> Dict[str, Any]:
        pass

    @abstractmethod
    def rename_file(
        self, user_id: str, file_path: str, new_name: str
    ) -> Dict[str, Any]:
        pass

    @abstractmethod
    def delete_folder(self, user_id: str, folder_path: str) -> Dict[str, Any]:
        pass

    @abstractmethod
    def rename_folder(
        self, user_id: str, folder_path: str, new_name: str
    ) -> Dict[str, Any]:
        pass

    @abstractmethod
    def download(self, user_id: str, file_path: str) -> Dict[str, Any]:
        pass

    @abstractmethod
    def list(self, user_id: str, prefix: str = "") -> Dict[str, List[Dict[str, Any]]]:
        pass

    @abstractmethod
    def exists(self, user_id: str, path: str) -> bool:
        pass

    @abstractmethod
    def get_stats(self, user_id: str) -> Dict[str, Any]:
        pass

    @abstractmethod
    def get_history(self, user_id: str, path: str) -> List[Dict[str, Any]]:
        pass

    @abstractmethod
    def restore(
        self, user_id: str, path: str, revision: str, as_copy: bool = False
    ) -> Dict[str, Any]:
        pass

    @abstractmethod
    def add_link(
        self, user_id: str, url: str, title: str, description: str = ""
    ) -> Dict[str, Any]:
        pass

    @abstractmethod
    def get_links(self, user_id: str) -> Dict[str, Any]:
        pass

    @abstractmethod
    def delete_link(self, user_id: str, link_id: str) -> Dict[str, Any]:
        pass

    @abstractmethod
    def update_link(
        self, user_id: str, link_id: str, url: str = "", title: str = "", description: str = ""
    ) -> Dict[str, Any]:
        pass

    def standardize_file(
        self,
        name: str,
        path: str,
        size: int,
        created_at: str,
        storage_type: str,
        modified_at: Optional[str] = None,
    ) -> Dict[str, Any]:
        return {
            "name": name,
            "path": path,
            "size": size,
            "type": "file",
            "created_at": created_at,
            "modified_at": modified_at or created_at,
            "storage": storage_type,
        }

    def standardize_folder(
        self, name: str, path: str, created_at: str, storage_type: str
    ) -> Dict[str, Any]:
        return {
            "name": name,
            "path": path,
            "type": "folder",
            "created_at": created_at,
            "storage": storage_type,
        }