support for video and improvements
parent
3430488b58
commit
d96bbff550
|
@ -33,6 +33,10 @@ video {
|
|||
display: inline-block
|
||||
}
|
||||
|
||||
video {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
audio:not([controls]) {
|
||||
display: none;
|
||||
height: 0
|
||||
|
|
|
@ -6,7 +6,11 @@
|
|||
{{ else if eq .Type "audio" }}
|
||||
<audio src="{{ .URL }}?raw=true"></audio>
|
||||
{{ else if eq .Type "video" }}
|
||||
<!-- TODO: SHOW VIDEO ? -->
|
||||
<video src="{{ .URL }}?raw=true" controls>
|
||||
Sorry, your browser doesn't support embedded videos,
|
||||
but don't worry, you can <a href="?download=true">download it</a>
|
||||
and watch it with your favorite video player!
|
||||
</video>
|
||||
{{ else if eq .Type "blob" }}
|
||||
<a href="?download=true">Download</a>
|
||||
{{ else}}
|
||||
|
|
32
file/info.go
32
file/info.go
|
@ -16,7 +16,6 @@ import (
|
|||
// Info contains the information about a particular file or directory
|
||||
type Info struct {
|
||||
os.FileInfo
|
||||
File *os.File
|
||||
URL string
|
||||
Path string // Relative path to Caddyfile
|
||||
VirtualPath string // Relative path to u.FileSystem
|
||||
|
@ -40,36 +39,41 @@ func GetInfo(url *url.URL, c *config.Config, u *config.User) (*Info, int, error)
|
|||
i.Path = strings.Replace(i.Path, "\\", "/", -1)
|
||||
i.Path = filepath.Clean(i.Path)
|
||||
|
||||
i.File, err = os.Open(i.Path)
|
||||
if err != nil {
|
||||
return i, errors.ErrorToHTTPCode(err, false), err
|
||||
}
|
||||
|
||||
i.FileInfo, err = i.File.Stat()
|
||||
i.FileInfo, err = os.Stat(i.Path)
|
||||
if err != nil {
|
||||
return i, errors.ErrorToHTTPCode(err, true), err
|
||||
}
|
||||
|
||||
p := make([]byte, 512)
|
||||
_, err = i.File.Read(p)
|
||||
return i, 0, nil
|
||||
}
|
||||
|
||||
// RetrieveFileType obtains the mimetype and a simplified internal Type
|
||||
// using the first 512 bytes from the file.
|
||||
func (i *Info) RetrieveFileType() error {
|
||||
file, err := os.Open(i.Path)
|
||||
if err != nil {
|
||||
return i, errors.ErrorToHTTPCode(err, false), err
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
p := make([]byte, 512)
|
||||
_, err = file.Read(p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
i.Mimetype = http.DetectContentType(p)
|
||||
i.Type = simplifyMediaType(i.Mimetype)
|
||||
return i, 0, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reads the file.
|
||||
func (i *Info) Read() error {
|
||||
var err error
|
||||
i.Content, err = ioutil.ReadFile(i.Path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
i.Mimetype = http.DetectContentType(i.Content)
|
||||
i.Type = simplifyMediaType(i.Mimetype)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -12,11 +12,18 @@ import (
|
|||
// ServeSingle serves a single file in an editor (if it is editable), shows the
|
||||
// plain file, or downloads it if it can't be shown.
|
||||
func ServeSingle(w http.ResponseWriter, r *http.Request, c *config.Config, u *config.User, i *file.Info) (int, error) {
|
||||
err := i.Read()
|
||||
if err != nil {
|
||||
var err error
|
||||
|
||||
if err = i.RetrieveFileType(); err != nil {
|
||||
return errors.ErrorToHTTPCode(err, true), err
|
||||
}
|
||||
|
||||
if i.Type == "text" {
|
||||
if err = i.Read(); err != nil {
|
||||
return errors.ErrorToHTTPCode(err, true), err
|
||||
}
|
||||
}
|
||||
|
||||
p := &page.Page{
|
||||
Info: &page.Info{
|
||||
Name: i.Name(),
|
||||
|
|
Loading…
Reference in New Issue