File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99namespace OCA \Richdocuments ;
1010
1111use OCA \Richdocuments \Service \CapabilitiesService ;
12+ use OCA \Richdocuments \Service \DiscoveryService ;
1213use OCP \App \IAppManager ;
1314use OCP \Capabilities \ICapability ;
1415use OCP \IURLGenerator ;
@@ -97,6 +98,7 @@ public function __construct(
9798 private IAppManager $ appManager ,
9899 private ?string $ userId ,
99100 private IURLGenerator $ urlGenerator ,
101+ private DiscoveryService $ discoveryService ,
100102 ) {
101103 }
102104
@@ -141,7 +143,7 @@ public function getCapabilities() {
141143 * @return list<string>
142144 */
143145 public function getDefaultMimetypes (): array {
144- $ defaultMimetypes = self ::MIMETYPES ;
146+ $ defaultMimetypes = $ this -> discoveryService -> getSupportedMimeTypes () ?: self ::MIMETYPES ;
145147
146148 if (!$ this ->capabilitiesService ->hasOtherOOXMLApps ()) {
147149 array_push ($ defaultMimetypes , ...self ::MIMETYPES_MSOFFICE );
@@ -151,7 +153,7 @@ public function getDefaultMimetypes(): array {
151153 $ defaultMimetypes [] = 'application/pdf ' ;
152154 }
153155
154- return $ defaultMimetypes ;
156+ return array_unique ( $ defaultMimetypes) ;
155157 }
156158
157159 /**
Original file line number Diff line number Diff line change @@ -127,4 +127,35 @@ private function getParsed(): SimpleXMLElement {
127127 throw new \Exception ('Could not parse discovery XML ' );
128128 }
129129 }
130+
131+ /**
132+ * Dynamically get all supported mime types out of the discovery XML
133+ * @todo Currently no categories given from endpoint
134+ *
135+ * @return array
136+ * @throws \Exception
137+ */
138+ public function getSupportedMimeTypes (): array
139+ {
140+ $ mimeTypes = [];
141+
142+ try {
143+ $ parsed = $ this ->getParsed ();
144+ } catch (\Exception $ e ) {
145+ // @todo fallback to a default set instead of empty array
146+ return $ mimeTypes ;
147+ }
148+
149+ foreach ($ parsed ->xpath ('//net-zone/app ' ) as $ app ) {
150+ $ mimeTypeName = (string )$ app ['name ' ]; // (e.g. "application/pdf")
151+
152+ // Filter (Settings, Capabilities, etc.)
153+ if (!str_contains ($ mimeTypeName , '/ ' )) {
154+ continue ;
155+ }
156+ $ mimeTypes [] = $ mimeTypeName ;
157+ }
158+
159+ return array_unique ($ mimeTypes );
160+ }
130161}
You can’t perform that action at this time.
0 commit comments