1515use \OCP \IL10N ;
1616use \OCP \IRequest ;
1717use OCA \Richdocuments \AppConfig ;
18- use OCA \Richdocuments \Service \CapabilitiesService ;
18+ use OCA \Richdocuments \Service \ConnectivityService ;
1919use OCA \Richdocuments \Service \DemoService ;
2020use OCA \Richdocuments \Service \FontService ;
2121use OCA \Richdocuments \UploadException ;
22- use OCA \Richdocuments \WOPI \DiscoveryManager ;
2322use OCA \Richdocuments \WOPI \Parser ;
2423use OCP \AppFramework \Http ;
2524use OCP \AppFramework \Http \DataDisplayResponse ;
2625use OCP \AppFramework \Http \DataResponse ;
2726use OCP \AppFramework \Http \JSONResponse ;
28- use OCP \AppFramework \Http \NotFoundResponse ;
2927use OCP \Files \NotFoundException ;
3028use OCP \Files \NotPermittedException ;
3129use OCP \Files \SimpleFS \ISimpleFile ;
3230use OCP \IConfig ;
33- use OCP \ILogger ;
3431use OCP \PreConditionNotMetException ;
3532use OCP \Util ;
33+ use Psr \Log \LoggerInterface ;
3634
3735class SettingsController extends Controller {
3836 // TODO adapt overview generation if we add more font mimetypes
@@ -44,81 +42,37 @@ class SettingsController extends Controller {
4442 'application/vnd.oasis.opendocument.formula-template ' ,
4543 ];
4644
47- /** @var IL10N */
48- private $ l10n ;
49- /** @var AppConfig */
50- private $ appConfig ;
51- /** @var IConfig */
52- private $ config ;
53- /** @var DiscoveryManager */
54- private $ discoveryManager ;
55- /** @var Parser */
56- private $ wopiParser ;
57- /** @var string */
58- private $ userId ;
59- /** @var CapabilitiesService */
60- private $ capabilitiesService ;
61- /** @var DemoService */
62- private $ demoService ;
63- /** @var ILogger */
64- private $ logger ;
65- /**
66- * @var FontService
67- */
68- private $ fontService ;
69-
70- public function __construct ($ appName ,
45+ public function __construct (
46+ string $ appName ,
7147 IRequest $ request ,
72- IL10N $ l10n ,
73- AppConfig $ appConfig ,
74- IConfig $ config ,
75- DiscoveryManager $ discoveryManager ,
76- Parser $ wopiParser ,
77- CapabilitiesService $ capabilitiesService ,
78- DemoService $ demoService ,
79- FontService $ fontService ,
80- ILogger $ logger ,
81- $ userId
48+ private IL10N $ l10n ,
49+ private AppConfig $ appConfig ,
50+ private IConfig $ config ,
51+ private ConnectivityService $ connectivityService ,
52+ private Parser $ wopiParser ,
53+ private DemoService $ demoService ,
54+ private FontService $ fontService ,
55+ private LoggerInterface $ logger ,
56+ private ?string $ userId
8257 ) {
8358 parent ::__construct ($ appName , $ request );
84- $ this ->l10n = $ l10n ;
85- $ this ->appConfig = $ appConfig ;
86- $ this ->config = $ config ;
87- $ this ->discoveryManager = $ discoveryManager ;
88- $ this ->wopiParser = $ wopiParser ;
89- $ this ->capabilitiesService = $ capabilitiesService ;
90- $ this ->demoService = $ demoService ;
91- $ this ->logger = $ logger ;
92- $ this ->userId = $ userId ;
93- $ this ->fontService = $ fontService ;
94- $ this ->request = $ request ;
9559 }
9660
9761 /**
9862 * @PublicPage
9963 * @NoCSRFRequired
100- * @throws \Exception
10164 */
102- public function checkSettings () {
103- try {
104- $ response = $ this ->discoveryManager ->fetchFromRemote ();
105- } catch (\Exception $ e ) {
106- $ this ->logger ->logException ($ e , ['app ' => 'richdocuments ' ]);
107- return new DataResponse ([
108- 'status ' => $ e ->getCode (),
109- 'message ' => 'Could not fetch discovery details '
110- ], Http::STATUS_INTERNAL_SERVER_ERROR );
111- }
112-
113- return new DataResponse ();
65+ public function checkSettings (): DataResponse {
66+ $ this ->connectivityService ->verifyConnection ();
67+ return new DataResponse ($ this ->connectivityService ->getStatus ());
11468 }
11569
116- public function demoServers () {
70+ public function demoServers (): DataResponse {
11771 $ demoServers = $ this ->demoService ->fetchDemoServers (true );
11872 if (count ($ demoServers ) > 0 ) {
11973 return new DataResponse ($ demoServers );
12074 }
121- return new NotFoundResponse ([]);
75+ return new DataResponse ([], Http:: STATUS_NOT_FOUND );
12276 }
12377
12478 /**
@@ -193,44 +147,31 @@ public function setSettings($wopi_url,
193147 $ this ->appConfig ->setAppValue ('canonical_webroot ' , $ canonical_webroot );
194148 }
195149
196- $ this ->discoveryManager ->refetch ();
197- $ this ->capabilitiesService ->clear ();
198- try {
199- $ capaUrlSrc = $ this ->wopiParser ->getUrlSrc ('Capabilities ' );
200- if (is_array ($ capaUrlSrc ) && $ capaUrlSrc ['action ' ] === 'getinfo ' ) {
201- $ public_wopi_url = str_replace ('/hosting/capabilities ' , '' , $ capaUrlSrc ['urlsrc ' ]);
202- if ($ public_wopi_url !== null ) {
203- $ this ->appConfig ->setAppValue ('public_wopi_url ' , $ public_wopi_url );
204- $ colon = strpos ($ public_wopi_url , ': ' , 0 );
205- if ($ this ->request ->getServerProtocol () !== substr ($ public_wopi_url , 0 , $ colon )) {
206- $ message = $ this ->l10n ->t ('Saved with error: Collabora Online should expose the same protocol as the server installation. Please check the ssl.enable and ssl.termination settings of your Collabora Online server. ' );
207- }
208- }
209- }
210- } catch (\Exception $ e ) {
211- if ($ wopi_url !== null ) {
212- return new JSONResponse ([
213- 'status ' => 'error ' ,
214- 'data ' => ['message ' => 'Failed to connect to the remote server ' ]
215- ], 500 );
216- }
150+ $ this ->connectivityService ->verifyConnection (true );
151+
152+ $ publicUrl = $ this ->wopiParser ->getDetectedPublicUrl ();
153+ if ($ publicUrl ) {
154+ $ this ->appConfig ->setAppValue ('public_wopi_url ' , $ publicUrl );
155+ $ this ->connectivityService ->verifyConnection (true );
217156 }
218157
219- $ this ->capabilitiesService ->clear ();
220- $ this ->capabilitiesService ->refetch ();
221- if ($ this ->capabilitiesService ->getCapabilities () === []) {
158+ if (!$ this ->connectivityService ->isDiscoveryReachable ()) {
222159 return new JSONResponse ([
223160 'status ' => 'error ' ,
224- 'data ' => ['message ' => 'Failed to connect to the remote server ' , 'hint ' => 'missing_capabilities ' ]
161+ 'data ' => [
162+ 'message ' => 'Failed to connect to the remote server ' ,
163+ 'status ' => $ this ->connectivityService ->getStatus (),]
225164 ], 500 );
226165 }
227166
228- $ response = [
167+ return new JSONResponse ( [
229168 'status ' => 'success ' ,
230- 'data ' => ['message ' => $ message ]
231- ];
232-
233- return new JSONResponse ($ response );
169+ 'data ' => [
170+ 'discovery ' => $ this ->wopiParser ->getUrlSrc ('application/vnd.oasis.opendocument.text ' )['urlsrc ' ],
171+ 'message ' => $ message ,
172+ 'status ' => $ this ->connectivityService ->getStatus (),
173+ ]
174+ ]);
234175 }
235176
236177 public function updateWatermarkSettings ($ settings = []) {
0 commit comments