Skip to content

Commit

Permalink
fixup! feat: Implement assetconfiguration endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusknorr committed Dec 4, 2024
1 parent 481c3df commit 0898a02
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 85 deletions.
4 changes: 0 additions & 4 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
['name' => 'settings#checkSettings', 'url' => 'settings/check', 'verb' => 'GET'],
['name' => 'settings#demoServers', 'url' => 'settings/demo', 'verb' => 'GET'],
['name' => 'settings#getFontNames', 'url' => 'settings/fonts', 'verb' => 'GET'],
['name' => 'settings#remoteAssetConfig', 'url' => 'settings/assets', 'verb' => 'GET'],
['name' => 'settings#remoteAssetConfigGet', 'url' => 'settings/assets/{path}', 'verb' => 'GET'],
['name' => 'settings#getJsonFontList', 'url' => 'settings/fonts.json', 'verb' => 'GET'],
['name' => 'settings#getFontFile', 'url' => 'settings/fonts/{name}', 'verb' => 'GET'],
['name' => 'settings#getFontFileOverview', 'url' => 'settings/fonts/{name}/overview', 'verb' => 'GET'],
['name' => 'settings#deleteFontFile', 'url' => 'settings/fonts/{name}', 'verb' => 'DELETE'],
['name' => 'settings#uploadFontFile', 'url' => 'settings/fonts', 'verb' => 'POST'],
Expand Down
1 change: 1 addition & 0 deletions composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
'OCA\\Richdocuments\\Controller\\FederationController' => $baseDir . '/../lib/Controller/FederationController.php',
'OCA\\Richdocuments\\Controller\\MentionController' => $baseDir . '/../lib/Controller/MentionController.php',
'OCA\\Richdocuments\\Controller\\OCSController' => $baseDir . '/../lib/Controller/OCSController.php',
'OCA\\Richdocuments\\Controller\\RemoteAssetController' => $baseDir . '/../lib/Controller/RemoteAssetController.php',
'OCA\\Richdocuments\\Controller\\SettingsController' => $baseDir . '/../lib/Controller/SettingsController.php',
'OCA\\Richdocuments\\Controller\\TargetController' => $baseDir . '/../lib/Controller/TargetController.php',
'OCA\\Richdocuments\\Controller\\TemplateFieldController' => $baseDir . '/../lib/Controller/TemplateFieldController.php',
Expand Down
1 change: 1 addition & 0 deletions composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class ComposerStaticInitRichdocuments
'OCA\\Richdocuments\\Controller\\FederationController' => __DIR__ . '/..' . '/../lib/Controller/FederationController.php',
'OCA\\Richdocuments\\Controller\\MentionController' => __DIR__ . '/..' . '/../lib/Controller/MentionController.php',
'OCA\\Richdocuments\\Controller\\OCSController' => __DIR__ . '/..' . '/../lib/Controller/OCSController.php',
'OCA\\Richdocuments\\Controller\\RemoteAssetController' => __DIR__ . '/..' . '/../lib/Controller/RemoteAssetController.php',
'OCA\\Richdocuments\\Controller\\SettingsController' => __DIR__ . '/..' . '/../lib/Controller/SettingsController.php',
'OCA\\Richdocuments\\Controller\\TargetController' => __DIR__ . '/..' . '/../lib/Controller/TargetController.php',
'OCA\\Richdocuments\\Controller\\TemplateFieldController' => __DIR__ . '/..' . '/../lib/Controller/TemplateFieldController.php',
Expand Down
74 changes: 48 additions & 26 deletions lib/Controller/RemoteAssetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,7 @@ public function __construct(
#[RestrictToWopiServer]
#[FrontpageRoute(verb: 'GET', url: '/settings/assets')]
public function getRemoteAssets(): DataResponse {
$data = [
'kind' => 'assetconfiguration',
'server' => $this->request->getServerHost(),
'templates' => [
'presentation' => array_values(array_map(function ($template) {
return [
'uri' => $this->urlGenerator->linkToRouteAbsolute('richdocuments.remoteasset.downloadRemoteAsset', [
'type' => 'template-presentation',
'identifier' => $template->getId(),
]),
'version' => $template->getEtag(),
];
}, $this->templateManager->getSystem('presentation'))),
],
'fonts' => array_values(array_map(function ($font) {
return [
'uri' => $this->urlGenerator->linkToRouteAbsolute('richdocuments.remoteasset.downloadRemoteAsset', [
'type' => 'font',
'identifier' => $font->getName(),
]),
'version' => $font->getEtag(),
];
}, $this->fontService->getFontFiles())),
];

return new DataResponse($data);
return new DataResponse($this->getRemoteAssetData());
}

#[NoAdminRequired]
Expand Down Expand Up @@ -98,4 +73,51 @@ public function downloadRemoteAsset(string $type, string $identifier): DataRespo
}


/**
* @deprecated To remove once collabora no longer supports a searate remote font config (also cleanup fontsOnly param then)
*/
#[NoAdminRequired]
#[PublicPage]
#[NoCSRFRequired]
#[RestrictToWopiServer]
#[FrontpageRoute(verb: 'GET', url: '/settings/fonts.json')]
public function getJsonFontList(): DataResponse {
return new DataResponse($this->getRemoteAssetData(true));
}

private function getRemoteAssetData(bool $fontsOnly = false): array {
$data = [
'kind' => 'assetconfiguration',
'server' => $this->request->getServerHost(),

'fonts' => array_values(array_map(function ($font) {
return [
'uri' => $this->urlGenerator->linkToRouteAbsolute('richdocuments.remoteasset.downloadRemoteAsset', [
'type' => 'font',
'identifier' => $font->getName(),
]),
'version' => $font->getEtag(),
];
}, $this->fontService->getFontFiles())),
];

if ($fontsOnly) {
return $data;
}

$data['templates'] = [
'presentation' => array_values(array_map(function ($template) {
return [
'uri' => $this->urlGenerator->linkToRouteAbsolute('richdocuments.remoteasset.downloadRemoteAsset', [
'type' => 'template-presentation',
'identifier' => $template->getId(),
]),
'version' => $template->getEtag(),
];
}, $this->templateManager->getSystem('presentation'))),
];

return $data;
}

}
55 changes: 0 additions & 55 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use OCP\AppFramework\Http\JSONResponse;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
Expand Down Expand Up @@ -313,60 +312,6 @@ public function getFontNames() {
return $response;
}

/**
* @NoAdminRequired
* @PublicPage
* @NoCSRFRequired
*
* @return JSONResponse|DataResponse
* @throws \OCP\Files\NotPermittedException
*/
public function getJsonFontList() {
$files = $this->fontService->getFontFiles();
$etags = array_map(
static fn (ISimpleFile $f) => $f->getETag(),
$files
);
$etag = md5(implode(',', $etags));
$ifNoneMatchHeader = $this->request->getHeader('If-None-Match');
if ($ifNoneMatchHeader && $ifNoneMatchHeader === $etag) {
return new DataResponse([], HTTP::STATUS_NOT_MODIFIED);
}

$fontList = $this->fontService->getFontList($files);
$response = new JSONResponse($fontList);
$response->addHeader('Etag', $etag);
return $response;
}

/**
* @NoAdminRequired
* @PublicPage
* @NoCSRFRequired
*
* @param string $name
* @return DataDisplayResponse|DataResponse
* @throws \OCP\Files\NotPermittedException
*/
public function getFontFile(string $name) {
try {
$fontFile = $this->fontService->getFontFile($name);
$etag = $fontFile->getETag();
$ifNoneMatchHeader = $this->request->getHeader('If-None-Match');
if ($ifNoneMatchHeader && $ifNoneMatchHeader === $etag) {
return new DataResponse([], HTTP::STATUS_NOT_MODIFIED);
}

return new DataDisplayResponse(
$fontFile->getContent(),
Http::STATUS_OK,
['Content-Type' => $fontFile->getMimeType(), 'Etag' => $etag]
);
} catch (NotFoundException) {
return new DataDisplayResponse('', Http::STATUS_NOT_FOUND);
}
}

/**
* @NoAdminRequired
* @PublicPage
Expand Down

0 comments on commit 0898a02

Please sign in to comment.