Skip to content

Commit 8600636

Browse files
authored
Merge pull request #48912 from nextcloud/bugfix/exception-appscreenshot-notstring
fix(apps-store): Fix exception on generating preview url for installed app screenshot
2 parents 5efb175 + 220bd34 commit 8600636

7 files changed

Lines changed: 97 additions & 3 deletions

File tree

apps/settings/lib/Controller/AppSettingsController.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,15 @@ private function fetchApps() {
245245
$apps = $appClass->listAllApps();
246246
foreach ($apps as $app) {
247247
$app['installed'] = true;
248-
// locally installed apps have a flatted screenshot property
248+
249249
if (isset($app['screenshot'][0])) {
250-
$app['screenshot'] = $this->createProxyPreviewUrl($app['screenshot'][0]);
250+
$appScreenshot = $app['screenshot'][0] ?? null;
251+
if (is_array($appScreenshot)) {
252+
// Screenshot with thumbnail
253+
$appScreenshot = $appScreenshot['@value'];
254+
}
255+
256+
$app['screenshot'] = $this->createProxyPreviewUrl($appScreenshot);
251257
}
252258
$this->allApps[$app['id']] = $app;
253259
}

lib/private/App/InfoParser.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,17 @@ public function parse($file) {
190190
$array['dependencies']['backend'] = [$array['dependencies']['backend']];
191191
}
192192

193+
// Ensure some fields are always arrays
194+
if (isset($array['screenshot']) && !is_array($array['screenshot'])) {
195+
$array['screenshot'] = [$array['screenshot']];
196+
}
197+
if (isset($array['author']) && !is_array($array['author'])) {
198+
$array['author'] = [$array['author']];
199+
}
200+
if (isset($array['category']) && !is_array($array['category'])) {
201+
$array['category'] = [$array['category']];
202+
}
203+
193204
if ($this->cache !== null) {
194205
$this->cache->set($fileCacheKey, json_encode($array));
195206
}

tests/data/app/expected-info.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"name": "Server-side Encryption",
77
"description": "\n\tThis application encrypts all files accessed by ownCloud at rest, wherever they are stored. As an example, with this application enabled, external cloud based Amazon S3 storage will be encrypted, protecting this data on storage outside of the control of the Admin. When this application is enabled for the first time, all files are encrypted as users log in and are prompted for their password. The recommended recovery key option enables recovery of files in case the key is lost. \n\tNote that this app encrypts all files that are touched by ownCloud, so external storage providers and applications such as SharePoint will see new files encrypted when they are accessed. Encryption is based on AES 128 or 256 bit keys. More information is available in the Encryption documentation \n\t",
88
"licence": "AGPL",
9-
"author": "Sam Tuke, Bjoern Schiessle, Florin Peter",
9+
"author": [
10+
"Sam Tuke, Bjoern Schiessle, Florin Peter"
11+
],
1012
"requiremin": "4",
1113
"shipped": "true",
1214
"documentation": {
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"id": "notifications",
3+
"name": "Notifications",
4+
"description": "A single screenshot should be an array",
5+
"version": "1.0.0",
6+
"licence": "agpl",
7+
"author": [
8+
"Joas Schilling"
9+
],
10+
"dependencies": {
11+
"nextcloud": {
12+
"@attributes": {
13+
"min-version": "16",
14+
"max-version": "16"
15+
}
16+
},
17+
"backend": []
18+
},
19+
"screenshot": [
20+
"https://raw.githubusercontent.com/nextcloud/notifications/refs/heads/master/docs/screenshot.png"
21+
],
22+
"category": [
23+
"monitoring"
24+
],
25+
"info": [],
26+
"background-jobs": [],
27+
"activity": {
28+
"filters": [],
29+
"settings": [],
30+
"providers": []
31+
},
32+
"commands": [],
33+
"remote": [],
34+
"public": [],
35+
"repair-steps": {
36+
"install": [],
37+
"pre-migration": [],
38+
"post-migration": [],
39+
"live-migration": [],
40+
"uninstall": []
41+
},
42+
"settings": {
43+
"admin": [],
44+
"admin-section": [],
45+
"personal": [],
46+
"personal-section": []
47+
},
48+
"two-factor-providers": [],
49+
"types": []
50+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
2+
SPDX-License-Identifier: AGPL-3.0-or-later
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
- SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
4+
- SPDX-License-Identifier: AGPL-3.0-or-later
5+
-->
6+
<info xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
7+
xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/info.xsd">
8+
<id>notifications</id>
9+
<name>Notifications</name>
10+
<description>A single screenshot should be an array</description>
11+
<version>1.0.0</version>
12+
<licence>agpl</licence>
13+
<author>Joas Schilling</author>
14+
15+
<category>monitoring</category>
16+
17+
<screenshot>https://raw.githubusercontent.com/nextcloud/notifications/refs/heads/master/docs/screenshot.png</screenshot>
18+
19+
<dependencies>
20+
<nextcloud min-version="16" max-version="16"/>
21+
</dependencies>
22+
</info>

tests/lib/App/InfoParserTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function providesInfoXml(): array {
5353
[null, 'invalid-info.xml'],
5454
['navigation-one-item.json', 'navigation-one-item.xml'],
5555
['navigation-two-items.json', 'navigation-two-items.xml'],
56+
['various-single-item.json', 'various-single-item.xml'],
5657
];
5758
}
5859
}

0 commit comments

Comments
 (0)