66 * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
77 * SPDX-License-Identifier: AGPL-3.0-only
88 */
9+
910namespace OCA \Files_Sharing \External ;
1011
12+ use GuzzleHttp \Exception \ClientException ;
13+ use GuzzleHttp \Exception \ConnectException ;
14+ use GuzzleHttp \Exception \RequestException ;
15+ use OC \Files \Storage \BearerAuthAwareSabreClient ;
16+ use OC \Files \Storage \DAV ;
17+ use OC \ForbiddenException ;
18+ use OCA \Files_Sharing \External \Manager as ExternalShareManager ;
19+ use OCA \Files_Sharing \ISharedStorage ;
20+ use OCP \AppFramework \Http ;
21+ use OCP \Constants ;
22+ use OCP \Federation \ICloudId ;
1123use OCP \Files \Cache \ICache ;
1224use OCP \Files \Cache \IScanner ;
1325use OCP \Files \Cache \IWatcher ;
26+ use OCP \Files \NotFoundException ;
1427use OCP \Files \Storage \IDisableEncryptionStorage ;
1528use OCP \Files \Storage \IReliableEtagStorage ;
1629use OCP \Files \Storage \IStorage ;
30+ use OCP \Files \StorageInvalidException ;
31+ use OCP \Files \StorageNotAvailableException ;
32+ use OCP \Http \Client \IClientService ;
33+ use OCP \Http \Client \LocalServerException ;
34+ use OCP \IAppConfig ;
35+ use OCP \ICacheFactory ;
36+ use OCP \IConfig ;
37+ use OCP \IUserSession ;
38+ use OCP \OCM \Exceptions \OCMArgumentException ;
39+ use OCP \OCM \Exceptions \OCMProviderException ;
40+ use OCP \OCM \IOCMDiscoveryService ;
41+ use OCP \Server ;
42+ use OCP \Share \IManager as IShareManager ;
43+ use Psr \Log \LoggerInterface ;
44+
45+ class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage, IReliableEtagStorage {
46+ protected IAppConfig $ appConfig ;
47+
48+ private const int REFRESH_MAX_ATTEMPTS = 3 ;
49+ private const int REFRESH_BACKOFF_SECONDS = 5 ;
1750
18- class Storage implements IDisableEncryptionStorage, IReliableEtagStorage {
19- public function getWatcher (string $ path = '' , ?IStorage $ storage = null ): IWatcher {
20- }
21-
22- public function getRemoteUser (): string {
23- }
24-
25- public function getRemote (): string {
26- }
27-
28- public function getMountPoint (): string {
29- }
30-
31- public function getToken (): string {
32- }
33-
34- public function getPassword (): ?string {
35- }
36-
37- public function getId (): string {
38- }
39-
40- public function getCache (string $ path = '' , ?IStorage $ storage = null ): ICache {
41- }
42-
43- public function getScanner (string $ path = '' , ?IStorage $ storage = null ): IScanner {
44- }
45-
46- public function hasUpdated (string $ path , int $ time ): bool {
47- }
51+ /**
52+ * @param array{HttpClientService: IClientService, manager: ExternalShareManager, cloudId: ICloudId, mountpoint: string, token: string, access_token: ?string, access_token_expires: ?int}|array $options
53+ */
54+ public function __construct ($ options )
55+ {
56+ }
4857
49- public function test (): bool {
50- }
58+ /**
59+ * Refresh the access token. Extends parent to also persist to database.
60+ *
61+ * Uses expiry timestamps instead of a boolean flag so that concurrent
62+ * processes can detect that another process already obtained a fresh token
63+ * and reuse it rather than performing a redundant exchange.
64+ *
65+ * After a failed exchange, a 60-second backoff is applied so that
66+ * subsequent file operations do not hammer the remote token endpoint.
67+ * The DB is still consulted during backoff in case a concurrent process
68+ * succeeded; only the outgoing exchange call is suppressed.
69+ *
70+ * @return string|null the access token (freshly exchanged or reused from
71+ * DB), or null if refresh is currently not possible
72+ */
73+ #[\Override]
74+ protected function refreshAccessToken (): ?string
75+ {
76+ }
77+
78+ #[\Override]
79+ public function getWatcher (string $ path = '' , ?IStorage $ storage = null ): IWatcher
80+ {
81+ }
82+
83+ public function getRemoteUser (): string
84+ {
85+ }
86+
87+ public function getRemote (): string
88+ {
89+ }
90+
91+ public function getMountPoint (): string
92+ {
93+ }
94+
95+ public function getToken (): string
96+ {
97+ }
98+
99+ public function getPassword (): ?string
100+ {
101+ }
102+
103+ #[\Override]
104+ public function getId (): string
105+ {
106+ }
107+
108+ #[\Override]
109+ public function getCache (string $ path = '' , ?IStorage $ storage = null ): ICache
110+ {
111+ }
112+
113+ #[\Override]
114+ public function getScanner (string $ path = '' , ?IStorage $ storage = null ): IScanner
115+ {
116+ }
117+
118+ #[\Override]
119+ public function hasUpdated (string $ path , int $ time ): bool
120+ {
121+ }
122+
123+ #[\Override]
124+ public function test (): bool
125+ {
126+ }
51127
52128 /**
53129 * Check whether this storage is permanently or temporarily
@@ -56,28 +132,82 @@ public function test(): bool {
56132 * @throws StorageNotAvailableException
57133 * @throws StorageInvalidException
58134 */
59- public function checkStorageAvailability (): void {
60- }
135+ public function checkStorageAvailability (): void
136+ {
137+ }
61138
62- public function file_exists (string $ path ): bool {
63- }
139+ #[\Override]
140+ public function file_exists (string $ path ): bool
141+ {
142+ }
64143
65- public function getShareInfo (int $ depth = -1 ) {
66- }
67-
68- public function getOwner (string $ path ): string |false {
69- }
144+ /**
145+ * Check if the configured remote is a valid-federated share provider
146+ */
147+ protected function testRemote (): bool
148+ {
149+ }
70150
71- public function isSharable (string $ path ): bool {
72- }
151+ /**
152+ * Check whether the remote is an ownCloud/Nextcloud. This is needed since some sharing
153+ * features are not standardized.
154+ *
155+ * @throws LocalServerException
156+ */
157+ public function remoteIsOwnCloud (): bool
158+ {
159+ }
73160
74- public function getPermissions (string $ path ): int {
75- }
161+ /**
162+ * @return mixed
163+ * @throws ForbiddenException
164+ * @throws NotFoundException
165+ * @throws \Exception
166+ */
167+ public function getShareInfo (int $ depth = -1 )
168+ {
169+ }
170+
171+ #[\Override]
172+ public function getOwner (string $ path ): string |false
173+ {
174+ }
175+
176+ #[\Override]
177+ public function isSharable (string $ path ): bool
178+ {
179+ }
180+
181+ #[\Override]
182+ public function getPermissions (string $ path ): int
183+ {
184+ }
185+
186+ #[\Override]
187+ public function needsPartFile (): bool
188+ {
189+ }
76190
77- public function needsPartFile (): bool {
78- return false ;
79- }
191+ /**
192+ * Translate OCM Permissions to Nextcloud permissions
193+ *
194+ * @param string $ocmPermissions json encoded OCM permissions
195+ * @param string $path path to file
196+ * @return int
197+ */
198+ protected function ocmPermissions2ncPermissions (string $ ocmPermissions , string $ path ): int
199+ {
200+ }
80201
81- public function free_space (string $ path ): int |float |false {
82- }
202+ /**
203+ * Calculate the default permissions in case no permissions are provided
204+ */
205+ protected function getDefaultPermissions (string $ path ): int
206+ {
207+ }
208+
209+ #[\Override]
210+ public function free_space (string $ path ): int |float |false
211+ {
212+ }
83213}
0 commit comments