parent
32b546a212
commit
8671c4d220
2 changed files with 2 additions and 10 deletions
|
@ -15,6 +15,7 @@ type Store interface {
|
||||||
type File interface {
|
type File interface {
|
||||||
io.ReadCloser
|
io.ReadCloser
|
||||||
io.ReaderAt
|
io.ReaderAt
|
||||||
|
io.Seeker
|
||||||
Stat() (fi os.FileInfo, err error)
|
Stat() (fi os.FileInfo, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
package trantor
|
package trantor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
|
|
||||||
log "github.com/cihub/seelog"
|
log "github.com/cihub/seelog"
|
||||||
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -115,14 +112,8 @@ func downloadHandler(h handler) {
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
headers := h.w.Header()
|
|
||||||
headers["Content-Type"] = []string{"application/epub+zip"}
|
|
||||||
headers["Content-Disposition"] = []string{fmt.Sprintf("attachment; filename=\"%s - %s.epub\"", strings.Join(book.Authors, ", "), book.Title)}
|
|
||||||
headers["Content-Length"] = []string{fmt.Sprint(book.FileSize)}
|
|
||||||
headers["Last-Modified"] = []string{fmt.Sprint(book.UploadDate.Format(time.RFC1123))}
|
|
||||||
addCacheControlHeader(h.w, false)
|
addCacheControlHeader(h.w, false)
|
||||||
|
http.ServeContent(h.w, h.r, fmt.Sprintf("%s - %s.epub", strings.Join(book.Authors, ", "), book.Title), book.UploadDate, f)
|
||||||
io.Copy(h.w, f)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type indexData struct {
|
type indexData struct {
|
||||||
|
|
Reference in a new issue