4
4
5
5
use DateTime ;
6
6
use Html2Text \Html2Text ;
7
+ use OC \User \NoUserException ;
7
8
use OCA \Assistant \AppInfo \Application ;
8
9
use OCA \Assistant \Db \TaskNotificationMapper ;
9
10
use OCA \Assistant \ResponseDefinitions ;
14
15
use OCP \Files \File ;
15
16
use OCP \Files \Folder ;
16
17
use OCP \Files \GenericFileException ;
18
+ use OCP \Files \InvalidPathException ;
17
19
use OCP \Files \IRootFolder ;
18
20
use OCP \Files \NotPermittedException ;
19
21
use OCP \IConfig ;
20
22
use OCP \IL10N ;
21
23
use OCP \ITempManager ;
22
24
use OCP \Lock \LockedException ;
25
+ use OCP \PreConditionNotMetException ;
23
26
use OCP \Share \IManager as IShareManager ;
24
27
use OCP \Share \IShare ;
25
28
use OCP \TaskProcessing \EShapeType ;
@@ -201,15 +204,33 @@ public function getAvailableTaskTypes(): array {
201
204
return $ types ;
202
205
}
203
206
207
+ /**
208
+ * @param string $userId
209
+ * @param string|null $taskTypeId
210
+ * @return array
211
+ * @throws NotFoundException
212
+ * @throws TaskProcessingException
213
+ */
204
214
public function getUserTasks (string $ userId , ?string $ taskTypeId = null ): array {
205
215
return $ this ->taskProcessingManager ->getUserTasks ($ userId , $ taskTypeId );
206
216
}
207
217
218
+ /**
219
+ * @param string $userId
220
+ * @param string $tempFileLocation
221
+ * @param string|null $filename
222
+ * @return array
223
+ * @throws NotPermittedException
224
+ * @throws InvalidPathException
225
+ * @throws \OCP\Files\NotFoundException
226
+ */
208
227
public function storeInputFile (string $ userId , string $ tempFileLocation , ?string $ filename = null ): array {
209
228
$ assistantDataFolder = $ this ->getAssistantDataFolder ($ userId );
210
229
211
- $ date = (new DateTime ())->format ('Y-m-d_H:i:s ' );
212
- $ targetFileName = $ filename === null ? $ date : ($ date . ' ' . $ filename );
230
+ $ formattedDate = (new DateTime ())->format ('Y-m-d_H.i.s ' );
231
+ $ targetFileName = $ filename === null
232
+ ? $ formattedDate
233
+ : ($ formattedDate . ' ' . str_replace (': ' , '. ' , $ filename ));
213
234
$ targetFile = $ assistantDataFolder ->newFile ($ targetFileName , fopen ($ tempFileLocation , 'rb ' ));
214
235
215
236
return [
@@ -218,6 +239,14 @@ public function storeInputFile(string $userId, string $tempFileLocation, ?string
218
239
];
219
240
}
220
241
242
+ /**
243
+ * @param string $userId
244
+ * @return Folder
245
+ * @throws NotPermittedException
246
+ * @throws \OCP\Files\NotFoundException
247
+ * @throws PreConditionNotMetException
248
+ * @throws NoUserException
249
+ */
221
250
public function getAssistantDataFolder (string $ userId ): Folder {
222
251
$ userFolder = $ this ->rootFolder ->getUserFolder ($ userId );
223
252
@@ -235,6 +264,13 @@ public function getAssistantDataFolder(string $userId): Folder {
235
264
return $ dataFolder ;
236
265
}
237
266
267
+ /**
268
+ * @param string $userId
269
+ * @param int $try
270
+ * @return Folder
271
+ * @throws NoUserException
272
+ * @throws NotPermittedException
273
+ */
238
274
private function createAssistantDataFolder (string $ userId , int $ try = 0 ): Folder {
239
275
$ userFolder = $ this ->rootFolder ->getUserFolder ($ userId );
240
276
if ($ try === 0 ) {
@@ -254,6 +290,13 @@ private function createAssistantDataFolder(string $userId, int $try = 0): Folder
254
290
return $ userFolder ->newFolder ($ folderPath );
255
291
}
256
292
293
+ /**
294
+ * @param string $userId
295
+ * @param int $fileId
296
+ * @return File|null
297
+ * @throws NoUserException
298
+ * @throws NotPermittedException
299
+ */
257
300
public function getUserFile (string $ userId , int $ fileId ): ?File {
258
301
$ userFolder = $ this ->rootFolder ->getUserFolder ($ userId );
259
302
$ file = $ userFolder ->getFirstNodeById ($ fileId );
@@ -266,6 +309,15 @@ public function getUserFile(string $userId, int $fileId): ?File {
266
309
return null ;
267
310
}
268
311
312
+ /**
313
+ * @param string $userId
314
+ * @param int $fileId
315
+ * @return array|null
316
+ * @throws InvalidPathException
317
+ * @throws NoUserException
318
+ * @throws NotPermittedException
319
+ * @throws \OCP\Files\NotFoundException
320
+ */
269
321
public function getUserFileInfo (string $ userId , int $ fileId ): ?array {
270
322
$ userFolder = $ this ->rootFolder ->getUserFolder ($ userId );
271
323
$ file = $ userFolder ->getFirstNodeById ($ fileId );
@@ -316,6 +368,21 @@ public function getTaskOutputFile(string $userId, int $ocpTaskId, int $fileId):
316
368
return $ node ;
317
369
}
318
370
371
+ /**
372
+ * @param string $userId
373
+ * @param int $ocpTaskId
374
+ * @param int $fileId
375
+ * @return string
376
+ * @throws Exception
377
+ * @throws InvalidPathException
378
+ * @throws LockedException
379
+ * @throws NoUserException
380
+ * @throws NotFoundException
381
+ * @throws NotPermittedException
382
+ * @throws PreConditionNotMetException
383
+ * @throws TaskProcessingException
384
+ * @throws \OCP\Files\NotFoundException
385
+ */
319
386
public function shareOutputFile (string $ userId , int $ ocpTaskId , int $ fileId ): string {
320
387
$ taskOutputFile = $ this ->getTaskOutputFile ($ userId , $ ocpTaskId , $ fileId );
321
388
$ assistantDataFolder = $ this ->getAssistantDataFolder ($ userId );
@@ -346,6 +413,12 @@ public function shareOutputFile(string $userId, int $ocpTaskId, int $fileId): st
346
413
return $ shareToken ;
347
414
}
348
415
416
+ /**
417
+ * @param File $file
418
+ * @return string
419
+ * @throws LockedException
420
+ * @throws NotPermittedException
421
+ */
349
422
private function getTargetFileName (File $ file ): string {
350
423
$ mime = mime_content_type ($ file ->fopen ('rb ' ));
351
424
$ name = $ file ->getName ();
@@ -362,6 +435,11 @@ private function getTargetFileName(File $file): string {
362
435
return $ name . $ ext ;
363
436
}
364
437
438
+ /**
439
+ * @param Task $task
440
+ * @return array
441
+ * @throws NotFoundException
442
+ */
365
443
private function extractFileIdsFromTask (Task $ task ): array {
366
444
$ ids = [];
367
445
$ taskTypes = $ this ->taskProcessingManager ->getAvailableTaskTypes ();
@@ -415,6 +493,7 @@ public function getOutputFilePreviewFile(string $userId, int $taskId, int $fileI
415
493
416
494
/**
417
495
* Sanitize inputs for storage based on the input type
496
+ *
418
497
* @param string $type
419
498
* @param array $inputs
420
499
* @return array
@@ -587,6 +666,10 @@ private function parseDocument(string $filePath, string $mimeType): string {
587
666
return $ outText ;
588
667
}
589
668
669
+ /**
670
+ * @param string $content
671
+ * @return string
672
+ */
590
673
private function parseRtfDocument (string $ content ): string {
591
674
// henck/rtf-to-html
592
675
$ document = new Document ($ content );
0 commit comments