Skip to content

Commit 20e836c

Browse files
authored
Merge pull request #4464 from codewithvk/private/codewithvk/caching
fix: send etag for settings URLs and update etag on file changes
2 parents fc1bbd0 + c9b774d commit 20e836c

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

lib/Controller/WopiController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ public function checkFileInfo(string $fileId, string $access_token): JSONRespons
177177
];
178178

179179
if ($this->capabilitiesService->hasSettingIframeSupport()) {
180-
181180
if (!$isPublic) {
182181
$response['UserSettings'] = $this->generateSettings($userId, 'userconfig');
183182
}
@@ -993,9 +992,10 @@ private function generateSettingToken(string $userId): string {
993992
private function generateSettings(string $userId, string $type): array {
994993
$nextcloudUrl = $this->appConfig->getNextcloudUrl() ?: trim($this->urlGenerator->getAbsoluteURL(''), '/');
995994
$uri = $nextcloudUrl . '/index.php/apps/richdocuments/wopi/settings' . '?type=' . $type . '&access_token=' . $this->generateSettingToken($userId) . '&fileId=' . '-1';
995+
$etag = $this->settingsService->getFolderEtag($type);
996996
return [
997997
'uri' => $uri,
998-
'stamp' => time()
998+
'stamp' => $etag
999999
];
10001000
}
10011001
}

lib/Service/SettingsService.php

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public function uploadFile(SettingsUrl $settingsUrl, string $fileData, string $u
9797
$fileName = $settingsUrl->getFileName();
9898
$newFile = $categoryFolder->newFile($fileName, $fileData);
9999
$fileUri = $this->generateFileUri($settingsUrl->getType(), $settingsUrl->getCategory(), $fileName, $userId);
100+
$this->refreshFolderEtag($settingsUrl->getType());
100101

101102
return [
102103
'stamp' => $newFile->getETag(),
@@ -154,6 +155,15 @@ public function generateIframeToken(string $type, string $userId): array {
154155
throw $e;
155156
}
156157
}
158+
159+
/**
160+
*
161+
* @param string $type
162+
* @return string
163+
*/
164+
public function getFolderEtag($type) : string {
165+
return $this->getTypeFolder($type)->getEtag();
166+
}
157167

158168
/**
159169
* generate setting config
@@ -210,12 +220,7 @@ private function getAllCategories(string $type): array {
210220
*/
211221
private function getCategoryDirFolderList(string $type) : array {
212222
try {
213-
$instanceId = $this->config->getSystemValue('instanceid', null);
214-
if ($instanceId === null) {
215-
throw new NotFoundException('Instance ID not found');
216-
}
217-
$rootFolder = $this->rootFolder;
218-
$folder = $rootFolder->get('appdata_' . $instanceId . '/richdocuments' . '/' . $type);
223+
$folder = $this->getTypeFolder($type);
219224
if (!$folder instanceof Folder) {
220225
return [];
221226
}
@@ -225,6 +230,36 @@ private function getCategoryDirFolderList(string $type) : array {
225230
}
226231
}
227232

233+
/**
234+
* extract folder of $type
235+
*
236+
* @param string $type
237+
* @return Folder
238+
*/
239+
private function getTypeFolder($type) {
240+
$instanceId = $this->config->getSystemValue('instanceid', null);
241+
if ($instanceId === null) {
242+
throw new NotFoundException('Instance ID not found');
243+
}
244+
$rootFolder = $this->rootFolder;
245+
try {
246+
$folder = $rootFolder->get('appdata_' . $instanceId . '/richdocuments' . '/' . $type);
247+
} catch (NotFoundException $e) {
248+
$baseFolder = $this->appData->newFolder($type);
249+
$folder = $rootFolder->get('appdata_' . $instanceId . '/richdocuments' . '/' . $type);
250+
}
251+
return $folder;
252+
}
253+
254+
/**
255+
*
256+
* @param string $type
257+
*/
258+
private function refreshFolderEtag($type) {
259+
$folder = $this->getTypeFolder($type);
260+
$folder->getStorage()->getCache()->update($folder->getId(), [ 'etag' => uniqid() ]);
261+
}
262+
228263
/**
229264
* Generate file URL.
230265
*
@@ -314,6 +349,7 @@ public function deleteSettingsFile(string $type, string $category, string $name,
314349
throw new NotFoundException("File '{$name}' not found in category '{$category}' for type '{$type}'.");
315350
}
316351
$categoryFolder->getFile($name)->delete();
352+
$this->refreshFolderEtag($type);
317353
} catch (NotFoundException $e) {
318354
throw $e;
319355
} catch (NotPermittedException $e) {

0 commit comments

Comments
 (0)