@@ -39,131 +39,131 @@ |
||
39 | 39 | |
40 | 40 | class APIController extends OCSController { |
41 | 41 | |
42 | - /** @var IConfig */ |
|
43 | - protected $config; |
|
44 | - |
|
45 | - /** @var IAppManager */ |
|
46 | - protected $appManager; |
|
47 | - |
|
48 | - /** @var AppFetcher */ |
|
49 | - protected $appFetcher; |
|
50 | - |
|
51 | - /** @var IFactory */ |
|
52 | - protected $l10nFactory; |
|
53 | - |
|
54 | - /** @var IUserSession */ |
|
55 | - protected $userSession; |
|
56 | - |
|
57 | - /** @var string */ |
|
58 | - protected $language; |
|
59 | - |
|
60 | - /** |
|
61 | - * List of apps that were in the appstore but are now shipped and don't have |
|
62 | - * a compatible update available. |
|
63 | - * |
|
64 | - * @var array<string, int> |
|
65 | - */ |
|
66 | - protected array $appsShippedInFutureVersion = [ |
|
67 | - 'bruteforcesettings' => 25, |
|
68 | - 'suspicious_login' => 25, |
|
69 | - 'twofactor_totp' => 25, |
|
70 | - ]; |
|
71 | - |
|
72 | - public function __construct(string $appName, |
|
73 | - IRequest $request, |
|
74 | - IConfig $config, |
|
75 | - IAppManager $appManager, |
|
76 | - AppFetcher $appFetcher, |
|
77 | - IFactory $l10nFactory, |
|
78 | - IUserSession $userSession) { |
|
79 | - parent::__construct($appName, $request); |
|
80 | - |
|
81 | - $this->config = $config; |
|
82 | - $this->appManager = $appManager; |
|
83 | - $this->appFetcher = $appFetcher; |
|
84 | - $this->l10nFactory = $l10nFactory; |
|
85 | - $this->userSession = $userSession; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * @param string $newVersion |
|
90 | - * @return DataResponse |
|
91 | - */ |
|
92 | - public function getAppList(string $newVersion): DataResponse { |
|
93 | - if (!$this->config->getSystemValue('appstoreenabled', true)) { |
|
94 | - return new DataResponse([ |
|
95 | - 'appstore_disabled' => true, |
|
96 | - ], Http::STATUS_NOT_FOUND); |
|
97 | - } |
|
98 | - |
|
99 | - // Get list of installed custom apps |
|
100 | - $installedApps = $this->appManager->getInstalledApps(); |
|
101 | - $installedApps = array_filter($installedApps, function ($app) { |
|
102 | - try { |
|
103 | - $this->appManager->getAppPath($app); |
|
104 | - } catch (AppPathNotFoundException $e) { |
|
105 | - return false; |
|
106 | - } |
|
107 | - return !$this->appManager->isShipped($app) && !isset($this->appsShippedInFutureVersion[$app]); |
|
108 | - }); |
|
109 | - |
|
110 | - if (empty($installedApps)) { |
|
111 | - return new DataResponse([ |
|
112 | - 'missing' => [], |
|
113 | - 'available' => [], |
|
114 | - ]); |
|
115 | - } |
|
116 | - |
|
117 | - $this->appFetcher->setVersion($newVersion, 'future-apps.json', false); |
|
118 | - |
|
119 | - // Apps available on the app store for that version |
|
120 | - $availableApps = array_map(static function (array $app) { |
|
121 | - return $app['id']; |
|
122 | - }, $this->appFetcher->get()); |
|
123 | - |
|
124 | - if (empty($availableApps)) { |
|
125 | - return new DataResponse([ |
|
126 | - 'appstore_disabled' => false, |
|
127 | - 'already_on_latest' => false, |
|
128 | - ], Http::STATUS_NOT_FOUND); |
|
129 | - } |
|
130 | - |
|
131 | - $this->language = $this->l10nFactory->getUserLanguage($this->userSession->getUser()); |
|
132 | - |
|
133 | - // Ignore apps that are deployed from git |
|
134 | - $installedApps = array_filter($installedApps, function(string $appId) { |
|
135 | - try { |
|
136 | - return !file_exists($this->appManager->getAppPath($appId) . '/.git'); |
|
137 | - } catch (AppPathNotFoundException $e) { |
|
138 | - return true; |
|
139 | - } |
|
140 | - }); |
|
141 | - |
|
142 | - $missing = array_diff($installedApps, $availableApps); |
|
143 | - $missing = array_map([$this, 'getAppDetails'], $missing); |
|
144 | - sort($missing); |
|
145 | - |
|
146 | - $available = array_intersect($installedApps, $availableApps); |
|
147 | - $available = array_map([$this, 'getAppDetails'], $available); |
|
148 | - sort($available); |
|
149 | - |
|
150 | - return new DataResponse([ |
|
151 | - 'missing' => $missing, |
|
152 | - 'available' => $available, |
|
153 | - ]); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Get translated app name |
|
158 | - * |
|
159 | - * @param string $appId |
|
160 | - * @return string[] |
|
161 | - */ |
|
162 | - protected function getAppDetails(string $appId): array { |
|
163 | - $app = $this->appManager->getAppInfo($appId, false, $this->language); |
|
164 | - return [ |
|
165 | - 'appId' => $appId, |
|
166 | - 'appName' => $app['name'] ?? $appId, |
|
167 | - ]; |
|
168 | - } |
|
42 | + /** @var IConfig */ |
|
43 | + protected $config; |
|
44 | + |
|
45 | + /** @var IAppManager */ |
|
46 | + protected $appManager; |
|
47 | + |
|
48 | + /** @var AppFetcher */ |
|
49 | + protected $appFetcher; |
|
50 | + |
|
51 | + /** @var IFactory */ |
|
52 | + protected $l10nFactory; |
|
53 | + |
|
54 | + /** @var IUserSession */ |
|
55 | + protected $userSession; |
|
56 | + |
|
57 | + /** @var string */ |
|
58 | + protected $language; |
|
59 | + |
|
60 | + /** |
|
61 | + * List of apps that were in the appstore but are now shipped and don't have |
|
62 | + * a compatible update available. |
|
63 | + * |
|
64 | + * @var array<string, int> |
|
65 | + */ |
|
66 | + protected array $appsShippedInFutureVersion = [ |
|
67 | + 'bruteforcesettings' => 25, |
|
68 | + 'suspicious_login' => 25, |
|
69 | + 'twofactor_totp' => 25, |
|
70 | + ]; |
|
71 | + |
|
72 | + public function __construct(string $appName, |
|
73 | + IRequest $request, |
|
74 | + IConfig $config, |
|
75 | + IAppManager $appManager, |
|
76 | + AppFetcher $appFetcher, |
|
77 | + IFactory $l10nFactory, |
|
78 | + IUserSession $userSession) { |
|
79 | + parent::__construct($appName, $request); |
|
80 | + |
|
81 | + $this->config = $config; |
|
82 | + $this->appManager = $appManager; |
|
83 | + $this->appFetcher = $appFetcher; |
|
84 | + $this->l10nFactory = $l10nFactory; |
|
85 | + $this->userSession = $userSession; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * @param string $newVersion |
|
90 | + * @return DataResponse |
|
91 | + */ |
|
92 | + public function getAppList(string $newVersion): DataResponse { |
|
93 | + if (!$this->config->getSystemValue('appstoreenabled', true)) { |
|
94 | + return new DataResponse([ |
|
95 | + 'appstore_disabled' => true, |
|
96 | + ], Http::STATUS_NOT_FOUND); |
|
97 | + } |
|
98 | + |
|
99 | + // Get list of installed custom apps |
|
100 | + $installedApps = $this->appManager->getInstalledApps(); |
|
101 | + $installedApps = array_filter($installedApps, function ($app) { |
|
102 | + try { |
|
103 | + $this->appManager->getAppPath($app); |
|
104 | + } catch (AppPathNotFoundException $e) { |
|
105 | + return false; |
|
106 | + } |
|
107 | + return !$this->appManager->isShipped($app) && !isset($this->appsShippedInFutureVersion[$app]); |
|
108 | + }); |
|
109 | + |
|
110 | + if (empty($installedApps)) { |
|
111 | + return new DataResponse([ |
|
112 | + 'missing' => [], |
|
113 | + 'available' => [], |
|
114 | + ]); |
|
115 | + } |
|
116 | + |
|
117 | + $this->appFetcher->setVersion($newVersion, 'future-apps.json', false); |
|
118 | + |
|
119 | + // Apps available on the app store for that version |
|
120 | + $availableApps = array_map(static function (array $app) { |
|
121 | + return $app['id']; |
|
122 | + }, $this->appFetcher->get()); |
|
123 | + |
|
124 | + if (empty($availableApps)) { |
|
125 | + return new DataResponse([ |
|
126 | + 'appstore_disabled' => false, |
|
127 | + 'already_on_latest' => false, |
|
128 | + ], Http::STATUS_NOT_FOUND); |
|
129 | + } |
|
130 | + |
|
131 | + $this->language = $this->l10nFactory->getUserLanguage($this->userSession->getUser()); |
|
132 | + |
|
133 | + // Ignore apps that are deployed from git |
|
134 | + $installedApps = array_filter($installedApps, function(string $appId) { |
|
135 | + try { |
|
136 | + return !file_exists($this->appManager->getAppPath($appId) . '/.git'); |
|
137 | + } catch (AppPathNotFoundException $e) { |
|
138 | + return true; |
|
139 | + } |
|
140 | + }); |
|
141 | + |
|
142 | + $missing = array_diff($installedApps, $availableApps); |
|
143 | + $missing = array_map([$this, 'getAppDetails'], $missing); |
|
144 | + sort($missing); |
|
145 | + |
|
146 | + $available = array_intersect($installedApps, $availableApps); |
|
147 | + $available = array_map([$this, 'getAppDetails'], $available); |
|
148 | + sort($available); |
|
149 | + |
|
150 | + return new DataResponse([ |
|
151 | + 'missing' => $missing, |
|
152 | + 'available' => $available, |
|
153 | + ]); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Get translated app name |
|
158 | + * |
|
159 | + * @param string $appId |
|
160 | + * @return string[] |
|
161 | + */ |
|
162 | + protected function getAppDetails(string $appId): array { |
|
163 | + $app = $this->appManager->getAppInfo($appId, false, $this->language); |
|
164 | + return [ |
|
165 | + 'appId' => $appId, |
|
166 | + 'appName' => $app['name'] ?? $appId, |
|
167 | + ]; |
|
168 | + } |
|
169 | 169 | } |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | |
99 | 99 | // Get list of installed custom apps |
100 | 100 | $installedApps = $this->appManager->getInstalledApps(); |
101 | - $installedApps = array_filter($installedApps, function ($app) { |
|
101 | + $installedApps = array_filter($installedApps, function($app) { |
|
102 | 102 | try { |
103 | 103 | $this->appManager->getAppPath($app); |
104 | 104 | } catch (AppPathNotFoundException $e) { |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | $this->appFetcher->setVersion($newVersion, 'future-apps.json', false); |
118 | 118 | |
119 | 119 | // Apps available on the app store for that version |
120 | - $availableApps = array_map(static function (array $app) { |
|
120 | + $availableApps = array_map(static function(array $app) { |
|
121 | 121 | return $app['id']; |
122 | 122 | }, $this->appFetcher->get()); |
123 | 123 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | // Ignore apps that are deployed from git |
134 | 134 | $installedApps = array_filter($installedApps, function(string $appId) { |
135 | 135 | try { |
136 | - return !file_exists($this->appManager->getAppPath($appId) . '/.git'); |
|
136 | + return !file_exists($this->appManager->getAppPath($appId).'/.git'); |
|
137 | 137 | } catch (AppPathNotFoundException $e) { |
138 | 138 | return true; |
139 | 139 | } |