feat: add MimeType detection to StatFile #10

Merged
iwilltry42 merged 2 commits from feat/statfile-mimetype into main 2024-11-20 20:17:00 +00:00
iwilltry42 commented 2024-11-20 18:42:12 +00:00 (Migrated from github.com)

This improves experience with knowledge, as we don't have to pull a whole file from S3 just to detect the mimetype from the first few bytes.
Other options would require us to add extra subtools and touch too many other pieces of code, so this is the easiest to implement and clean solution.

This improves experience with knowledge, as we don't have to pull a whole file from S3 just to detect the mimetype from the first few bytes. Other options would require us to add extra subtools and touch too many other pieces of code, so this is the easiest to implement and clean solution.
StrongMonkey (Migrated from github.com) reviewed 2024-11-20 18:42:12 +00:00
g-linville (Migrated from github.com) reviewed 2024-11-20 18:42:12 +00:00
njhale (Migrated from github.com) reviewed 2024-11-20 19:21:16 +00:00
@ -145,3 +152,4 @@
return FileInfo{
WorkspaceID: DirectoryProvider + "://" + d.dataHome,
Name: stat.Name(),
njhale (Migrated from github.com) commented 2024-11-20 19:19:41 +00:00

This returns application/octet-stream when it fails to identify the mime type. I think we may want some logic to increase the read limit -- as per the mimetype README -- and try again when that happens.

This returns `application/octet-stream` when it fails to identify the mime type. I think we may want some logic to increase the read limit -- as per the `mimetype` [README](https://github.com/gabriel-vasile/mimetype?tab=readme-ov-file#faq) -- and try again when that happens.
njhale (Migrated from github.com) approved these changes 2024-11-20 19:28:03 +00:00
iwilltry42 (Migrated from github.com) reviewed 2024-11-20 19:35:15 +00:00
@ -145,3 +152,4 @@
return FileInfo{
WorkspaceID: DirectoryProvider + "://" + d.dataHome,
Name: stat.Name(),
iwilltry42 (Migrated from github.com) commented 2024-11-20 19:35:14 +00:00

Yeah.. I don't know how sophisticated we want to get here, as for the current use case this is good enough.
The mentioned office documents are included by extension on knowledge side, so we won't care about the mimetype.
But I agree, that we need to have some more sophisticated approach here if we want to be 100% sure.

Yeah.. I don't know how sophisticated we want to get here, as for the current use case this is good enough. The mentioned office documents are included by extension on knowledge side, so we won't care about the mimetype. But I agree, that we need to have some more sophisticated approach here if we want to be 100% sure.
thedadams (Migrated from github.com) approved these changes 2024-11-20 19:47:55 +00:00
@ -142,11 +143,19 @@ func (d *directoryProvider) StatFile(_ context.Context, s string) (FileInfo, err
return FileInfo{}, err
thedadams (Migrated from github.com) commented 2024-11-20 19:47:18 +00:00

nit:

	mt, err := mimetype.DetectReader(f)
	if err != nil {
		return FileInfo{}, err
	}
	mime := strings.Split(mt.String(), ";")[0]
nit: ```suggestion mt, err := mimetype.DetectReader(f) if err != nil { return FileInfo{}, err } mime := strings.Split(mt.String(), ";")[0] ```
njhale (Migrated from github.com) reviewed 2024-11-20 20:15:14 +00:00
@ -145,3 +152,4 @@
return FileInfo{
WorkspaceID: DirectoryProvider + "://" + d.dataHome,
Name: stat.Name(),
njhale (Migrated from github.com) commented 2024-11-20 20:15:14 +00:00

That's fair enough!

That's fair enough!
Sign in to join this conversation.
No description provided.