2020use OCP \Files \Config \IUserMountCache ;
2121use OCP \Files \Folder ;
2222use OCP \Files \IMimeTypeLoader ;
23- use OCP \Files \IRootFolder ;
2423use OCP \Files \Node ;
2524use OCP \FilesMetadata \IFilesMetadataManager ;
2625use OCP \IDBConnection ;
@@ -44,8 +43,8 @@ public function __construct(
4443 private IMimeTypeLoader $ mimeTypes ,
4544 private IUserMountCache $ userMountCache ,
4645 private IFilesMetadataManager $ metadataManager ,
47- private IRootFolder $ rootFolder ,
4846 private IFileAccess $ fileAccess ,
47+ private TaskTypeService $ taskTypeService ,
4948 ) {
5049 }
5150
@@ -84,7 +83,8 @@ public function countFilesInMount(int $storageId, int $rootId): int {
8483 return 0 ;
8584 }
8685
87- $ mimeTypes = array_map (fn ($ mimeType ) => $ this ->mimeTypes ->getId ($ mimeType ), Application::MIMETYPES );
86+ $ mimeTypes = $ this ->taskTypeService ->getMultimodalMimetypes ();
87+ $ mimeTypesIds = array_map (fn ($ mimeType ) => $ this ->mimeTypes ->getId ($ mimeType ), $ mimeTypes );
8888
8989 $ qb = $ this ->getCacheQueryBuilder ();
9090
@@ -110,7 +110,7 @@ public function countFilesInMount(int $storageId, int $rootId): int {
110110 ->andWhere ($ qb ->expr ()->notLike ('filecache.path ' , $ qb ->createNamedParameter ('files_versions/% ' )))
111111 ->andWhere ($ qb ->expr ()->notLike ('filecache.path ' , $ qb ->createNamedParameter ('files_trashbin/% ' )))
112112 ->andWhere ($ qb ->expr ()->eq ('filecache.storage ' , $ qb ->createNamedParameter ($ storageId )))
113- ->andWhere ($ qb ->expr ()->in ('filecache.mimetype ' , $ qb ->createNamedParameter ($ mimeTypes , IQueryBuilder::PARAM_INT_ARRAY )))
113+ ->andWhere ($ qb ->expr ()->in ('filecache.mimetype ' , $ qb ->createNamedParameter ($ mimeTypesIds , IQueryBuilder::PARAM_INT_ARRAY )))
114114 ->andWhere ($ qb ->expr ()->lte ('filecache.size ' , $ qb ->createNamedParameter (Application::CC_MAX_SIZE , IQueryBuilder::PARAM_INT )))
115115 ->andWhere ($ qb ->expr ()->gt ('filecache.size ' , $ qb ->createNamedParameter (0 , IQueryBuilder::PARAM_INT )));
116116 $ result = $ qb ->executeQuery ();
@@ -199,25 +199,42 @@ private function getMountsOld(): \Generator {
199199 * @param int $rootId
200200 * @param int $lastFileId
201201 * @param int $maxResults
202+ * @param list<string> $mimeTypes
202203 * @return \Generator<int,int,mixed,void>
203204 */
204- public function getFilesInMount (int $ storageId , int $ rootId , int $ lastFileId = 0 , int $ maxResults = 100 ): \Generator {
205+ public function getFilesInMount (
206+ int $ storageId ,
207+ int $ rootId ,
208+ int $ lastFileId = 0 ,
209+ int $ maxResults = 100 ,
210+ array $ mimeTypes = [],
211+ ): \Generator {
212+ if ($ mimeTypes === []) {
213+ $ mimeTypes = $ this ->taskTypeService ->getMultimodalMimetypes ();
214+ }
205215 if (!$ this ->isFileAccessAvailable ()) {
206- return $ this ->getFilesInMountOld ($ storageId , $ rootId , $ lastFileId , $ maxResults );
216+ return $ this ->getFilesInMountOld ($ storageId , $ rootId , $ lastFileId , $ maxResults, $ mimeTypes );
207217 }
208218
209- return $ this ->getFilesInMountUsingFileAccess ($ storageId , $ rootId , $ lastFileId , $ maxResults );
219+ return $ this ->getFilesInMountUsingFileAccess ($ storageId , $ rootId , $ lastFileId , $ maxResults, $ mimeTypes );
210220 }
211221
212222 /**
213223 * @param int $storageId
214224 * @param int $rootId
215225 * @param int $lastFileId
216226 * @param int $maxResults
227+ * @param list<string> $mimeTypes
217228 * @return \Generator<int,int,mixed,void>
218229 */
219- private function getFilesInMountUsingFileAccess (int $ storageId , int $ rootId , int $ lastFileId = 0 , int $ maxResults = 100 ): \Generator {
220- $ mimeTypeIds = array_map (fn ($ mimeType ) => $ this ->mimeTypes ->getId ($ mimeType ), Application::MIMETYPES );
230+ private function getFilesInMountUsingFileAccess (
231+ int $ storageId ,
232+ int $ rootId ,
233+ int $ lastFileId = 0 ,
234+ int $ maxResults = 100 ,
235+ array $ mimeTypes = Application::MIMETYPES ,
236+ ): \Generator {
237+ $ mimeTypeIds = array_map (fn ($ mimeType ) => $ this ->mimeTypes ->getId ($ mimeType ), $ mimeTypes );
221238 foreach ($ this ->fileAccess ->getByAncestorInStorage ($ storageId , $ rootId , $ lastFileId , $ maxResults , $ mimeTypeIds , false , true ) as $ cacheEntry ) {
222239 yield $ cacheEntry ['fileid ' ];
223240 }
@@ -228,9 +245,16 @@ private function getFilesInMountUsingFileAccess(int $storageId, int $rootId, int
228245 * @param int $rootId
229246 * @param int $lastFileId
230247 * @param int $maxResults
248+ * @param list<string> $mimeTypes
231249 * @return \Generator<int,int,mixed,void>
232250 */
233- private function getFilesInMountOld (int $ storageId , int $ rootId , int $ lastFileId = 0 , int $ maxResults = 100 ): \Generator {
251+ private function getFilesInMountOld (
252+ int $ storageId ,
253+ int $ rootId ,
254+ int $ lastFileId = 0 ,
255+ int $ maxResults = 100 ,
256+ array $ mimeTypes = Application::MIMETYPES ,
257+ ): \Generator {
234258 $ qb = $ this ->getCacheQueryBuilder ();
235259 try {
236260 $ qb ->selectFileCache ();
@@ -249,7 +273,7 @@ private function getFilesInMountOld(int $storageId, int $rootId, int $lastFileId
249273 return ;
250274 }
251275
252- $ mimeTypes = array_map (fn ($ mimeType ) => $ this ->mimeTypes ->getId ($ mimeType ), Application:: MIMETYPES );
276+ $ mimeTypesIds = array_map (fn ($ mimeType ) => $ this ->mimeTypes ->getId ($ mimeType ), $ mimeTypes );
253277
254278 $ qb = $ this ->getCacheQueryBuilder ();
255279
@@ -272,7 +296,7 @@ private function getFilesInMountOld(int $storageId, int $rootId, int $lastFileId
272296 ->andWhere ($ qb ->expr ()->like ('filecache.path ' , $ qb ->createNamedParameter ($ path . '% ' )))
273297 ->andWhere ($ qb ->expr ()->eq ('filecache.storage ' , $ qb ->createNamedParameter ($ storageId )))
274298 ->andWhere ($ qb ->expr ()->gt ('filecache.fileid ' , $ qb ->createNamedParameter ($ lastFileId )))
275- ->andWhere ($ qb ->expr ()->in ('filecache.mimetype ' , $ qb ->createNamedParameter ($ mimeTypes , IQueryBuilder::PARAM_INT_ARRAY )));
299+ ->andWhere ($ qb ->expr ()->in ('filecache.mimetype ' , $ qb ->createNamedParameter ($ mimeTypesIds , IQueryBuilder::PARAM_INT_ARRAY )));
276300
277301 if ($ maxResults !== 0 ) {
278302 $ qb ->setMaxResults ($ maxResults );
0 commit comments