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 ;
@@ -96,6 +97,7 @@ public function __construct(
9697 private IAppManager $ appManager ,
9798 private ?string $ userId ,
9899 private IURLGenerator $ urlGenerator ,
100+ private DiscoveryService $ discoveryService ,
99101 ) {
100102 }
101103
@@ -140,7 +142,7 @@ public function getCapabilities() {
140142 * @return list<string>
141143 */
142144 public function getDefaultMimetypes (): array {
143- $ defaultMimetypes = self ::MIMETYPES ;
145+ $ defaultMimetypes = $ this -> discoveryService -> getSupportedMimeTypes () ?: self ::MIMETYPES ;
144146
145147 if (!$ this ->capabilitiesService ->hasOtherOOXMLApps ()) {
146148 array_push ($ defaultMimetypes , ...self ::MIMETYPES_MSOFFICE );
@@ -150,7 +152,7 @@ public function getDefaultMimetypes(): array {
150152 $ defaultMimetypes [] = 'application/pdf ' ;
151153 }
152154
153- return $ defaultMimetypes ;
155+ return array_unique ( $ defaultMimetypes) ;
154156 }
155157
156158 /**
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