-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
display image attachments as image instead of chip
- Loading branch information
Showing
7 changed files
with
106 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package controller | ||
|
||
import ( | ||
"fmt" | ||
"github.com/gabriel-vasile/mimetype" | ||
"io" | ||
"net/http" | ||
"os" | ||
) | ||
|
||
type AssetMeta struct { | ||
Path string | ||
MimeType string | ||
} | ||
|
||
func (c *Controller) GetAssetMeta(path string) (AssetMeta, error) { | ||
file, err := os.Open(path) | ||
if err != nil { | ||
println("error open asset file: " + err.Error()) | ||
return AssetMeta{}, fmt.Errorf("error open asset file: %w", err) | ||
} | ||
defer file.Close() | ||
|
||
mime, err := mimetype.DetectReader(file) | ||
if err != nil { | ||
return AssetMeta{}, fmt.Errorf("error detecting mimetype: %w", err) | ||
} | ||
|
||
result := AssetMeta{ | ||
Path: path, | ||
MimeType: mime.String(), | ||
} | ||
|
||
return result, nil | ||
} | ||
|
||
func (c *Controller) handleAsset(resp http.ResponseWriter, req *http.Request) { | ||
file, err := os.Open(req.URL.Path) | ||
if err != nil { | ||
resp.WriteHeader(http.StatusNotFound) | ||
return | ||
} | ||
defer file.Close() | ||
|
||
resp.WriteHeader(http.StatusOK) | ||
io.Copy(resp, file) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters