mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-09-29 13:25:50 +02:00
Google Drive Plaintext Types (#2371)
This commit is contained in:
@@ -317,27 +317,23 @@ def extract_text(file: dict[str, str], service: discovery.Resource) -> str:
|
|||||||
GDriveMimeType.DOC.value,
|
GDriveMimeType.DOC.value,
|
||||||
GDriveMimeType.PPT.value,
|
GDriveMimeType.PPT.value,
|
||||||
GDriveMimeType.SPREADSHEET.value,
|
GDriveMimeType.SPREADSHEET.value,
|
||||||
GDriveMimeType.PLAIN_TEXT.value,
|
|
||||||
GDriveMimeType.MARKDOWN.value,
|
|
||||||
]:
|
]:
|
||||||
export_mime_type = "text/plain"
|
export_mime_type = (
|
||||||
if mime_type == GDriveMimeType.SPREADSHEET.value:
|
"text/plain"
|
||||||
export_mime_type = "text/csv"
|
if mime_type != GDriveMimeType.SPREADSHEET.value
|
||||||
elif mime_type == GDriveMimeType.PPT.value:
|
else "text/csv"
|
||||||
export_mime_type = "text/plain"
|
)
|
||||||
elif mime_type in [
|
return (
|
||||||
GDriveMimeType.PLAIN_TEXT.value,
|
|
||||||
GDriveMimeType.MARKDOWN.value,
|
|
||||||
]:
|
|
||||||
export_mime_type = mime_type
|
|
||||||
|
|
||||||
response = (
|
|
||||||
service.files()
|
service.files()
|
||||||
.export(fileId=file["id"], mimeType=export_mime_type)
|
.export(fileId=file["id"], mimeType=export_mime_type)
|
||||||
.execute()
|
.execute()
|
||||||
|
.decode("utf-8")
|
||||||
)
|
)
|
||||||
return response.decode("utf-8")
|
elif mime_type in [
|
||||||
|
GDriveMimeType.PLAIN_TEXT.value,
|
||||||
|
GDriveMimeType.MARKDOWN.value,
|
||||||
|
]:
|
||||||
|
return service.files().get_media(fileId=file["id"]).execute().decode("utf-8")
|
||||||
elif mime_type == GDriveMimeType.WORD_DOC.value:
|
elif mime_type == GDriveMimeType.WORD_DOC.value:
|
||||||
response = service.files().get_media(fileId=file["id"]).execute()
|
response = service.files().get_media(fileId=file["id"]).execute()
|
||||||
return docx_to_text(file=io.BytesIO(response))
|
return docx_to_text(file=io.BytesIO(response))
|
||||||
|
Reference in New Issue
Block a user