mirror of
https://codeberg.org/PLG-Development/PLG-MuDiCS
synced 2026-07-06 00:47:09 +00:00
chore: more error handling
This commit is contained in:
@@ -27,26 +27,30 @@ func OpenFile(path string) error {
|
||||
|
||||
mType, err := mimetype.DetectFile(path)
|
||||
if err != nil {
|
||||
slog.Error("Failed to detect mime type", "file", path, "error", err)
|
||||
return fmt.Errorf("detect mime type of file %q: %w", path, err)
|
||||
}
|
||||
|
||||
switch mType.String() {
|
||||
case "video/mp4":
|
||||
var templateBuffer bytes.Buffer
|
||||
videoTemplate(path).Render(context.Background(), &templateBuffer)
|
||||
browser.Browser.OpenHTML(templateBuffer.String())
|
||||
_ = videoTemplate(path).Render(context.Background(), &templateBuffer)
|
||||
err = browser.Browser.OpenHTML(templateBuffer.String())
|
||||
case "image/jpeg", "image/png", "image/gif":
|
||||
var templateBuffer bytes.Buffer
|
||||
imageTemplate(path).Render(context.Background(), &templateBuffer)
|
||||
browser.Browser.OpenHTML(templateBuffer.String())
|
||||
_ = imageTemplate(path).Render(context.Background(), &templateBuffer)
|
||||
err = browser.Browser.OpenHTML(templateBuffer.String())
|
||||
case "application/pdf":
|
||||
browser.Browser.OpenPDF(path)
|
||||
err = browser.Browser.OpenPDF(path)
|
||||
case "application/vnd.openxmlformats-officedocument.presentationml.presentation", "application/vnd.oasis.opendocument.presentation":
|
||||
err = fileHandler.openFileWithApp(path)
|
||||
default:
|
||||
return fmt.Errorf("unsupported file type: %s", mType.String())
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open file: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user