Kevin Hu commited on
Commit
016dc40
·
1 Parent(s): 2082761

fix ppt file from filemanager error (#2470)

Browse files

### What problem does this PR solve?

#2467

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

api/apps/file2document_app.py CHANGED
@@ -85,6 +85,7 @@ def convert():
85
  "location": file.location,
86
  "size": file.size
87
  })
 
88
  file2document = File2DocumentService.insert({
89
  "id": get_uuid(),
90
  "file_id": id,
 
85
  "location": file.location,
86
  "size": file.size
87
  })
88
+ FileService.set_constant_parser(doc, file.name)
89
  file2document = File2DocumentService.insert({
90
  "id": get_uuid(),
91
  "file_id": id,
api/db/services/file_service.py CHANGED
@@ -366,14 +366,7 @@ class FileService(CommonService):
366
  "size": len(blob),
367
  "thumbnail": thumbnail(filename, blob)
368
  }
369
- if doc["type"] == FileType.VISUAL:
370
- doc["parser_id"] = ParserType.PICTURE.value
371
- if doc["type"] == FileType.AURAL:
372
- doc["parser_id"] = ParserType.AUDIO.value
373
- if re.search(r"\.(ppt|pptx|pages)$", filename):
374
- doc["parser_id"] = ParserType.PRESENTATION.value
375
- if re.search(r"\.(eml)$", filename):
376
- doc["parser_id"] = ParserType.EMAIL.value
377
  DocumentService.insert(doc)
378
 
379
  FileService.add_file_from_kb(doc, kb_folder["id"], kb.tenant_id)
@@ -381,4 +374,15 @@ class FileService(CommonService):
381
  except Exception as e:
382
  err.append(file.filename + ": " + str(e))
383
 
384
- return err, files
 
 
 
 
 
 
 
 
 
 
 
 
366
  "size": len(blob),
367
  "thumbnail": thumbnail(filename, blob)
368
  }
369
+ self.set_constant_parser(doc, filename)
 
 
 
 
 
 
 
370
  DocumentService.insert(doc)
371
 
372
  FileService.add_file_from_kb(doc, kb_folder["id"], kb.tenant_id)
 
374
  except Exception as e:
375
  err.append(file.filename + ": " + str(e))
376
 
377
+ return err, files
378
+
379
+ @staticmethod
380
+ def set_constant_parser(doc, filename):
381
+ if doc["type"] == FileType.VISUAL:
382
+ doc["parser_id"] = ParserType.PICTURE.value
383
+ if doc["type"] == FileType.AURAL:
384
+ doc["parser_id"] = ParserType.AUDIO.value
385
+ if re.search(r"\.(ppt|pptx|pages)$", filename):
386
+ doc["parser_id"] = ParserType.PRESENTATION.value
387
+ if re.search(r"\.(eml)$", filename):
388
+ doc["parser_id"] = ParserType.EMAIL.value