diff --git a/lib/file.go b/lib/file.go index 8501fb6d..38cf4f97 100644 --- a/lib/file.go +++ b/lib/file.go @@ -1,7 +1,6 @@ package lib import ( - "bytes" "crypto/md5" "crypto/sha1" "crypto/sha256" @@ -19,7 +18,6 @@ import ( "strings" "time" - "github.com/gohugoio/hugo/parser" "github.com/maruel/natural" ) @@ -178,33 +176,6 @@ func (i *File) GetListing(u *User, r *http.Request) error { return nil } -// GetEditor gets the editor based on a Info struct -func (i *File) GetEditor() error { - i.Language = editorLanguage(i.Extension) - // If the editor will hold only content, leave now. - if editorMode(i.Language) == "content" { - return nil - } - - // If the file doesn't have any kind of metadata, leave now. - if !hasRune(i.Content) { - return nil - } - - buffer := bytes.NewBuffer([]byte(i.Content)) - page, err := parser.ReadFrom(buffer) - - // If there is an error, just ignore it and return nil. - // This way, the file can be served for editing. - if err != nil { - return nil - } - - i.Content = strings.TrimSpace(string(page.Content())) - i.Metadata = strings.TrimSpace(string(page.FrontMatter())) - return nil -} - // GetFileType obtains the mimetype and converts it to a simple // type nomenclature. func (i *File) GetFileType(checkContent bool) error { diff --git a/lib/http/download.go b/lib/http/download.go index d2143646..84099570 100644 --- a/lib/http/download.go +++ b/lib/http/download.go @@ -45,21 +45,21 @@ func downloadHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int var ( extension string - ar archiver.Archiver + ar archiver.Writer ) switch query { // If the format is true, just set it to "zip". case "zip", "true", "": - extension, ar = ".zip", archiver.Zip + extension, ar = ".zip", &archiver.Zip{} case "tar": - extension, ar = ".tar", archiver.Tar + extension, ar = ".tar", &archiver.Tar{} case "targz": - extension, ar = ".tar.gz", archiver.TarGz + extension, ar = ".tar.gz", &archiver.TarGz{} case "tarbz2": - extension, ar = ".tar.bz2", archiver.TarBz2 + extension, ar = ".tar.bz2", &archiver.TarBz2{} case "tarxz": - extension, ar = ".tar.xz", archiver.TarXZ + extension, ar = ".tar.xz", &archiver.TarXz{} default: return http.StatusNotImplemented, nil } @@ -72,7 +72,34 @@ func downloadHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int name += extension w.Header().Set("Content-Disposition", "attachment; filename*=utf-8''"+url.PathEscape(name)) - err := ar.Write(w, files) + + err := ar.Create(w) + if err != nil { + return 0, err + } + defer ar.Close() + + for _, f := range files { + file, err := os.Open(f) + if err != nil { + return 0, err + } + + info, err := file.Stat() + if err != nil { + return 0, err + } + + // ... open file and get the name for it within the archive ... + err = ar.Write(archiver.File{ + FileInfo: info, + ReadCloser: file, + }) + + if err != nil { + return 0, err + } + } return 0, err } diff --git a/lib/http/resource.go b/lib/http/resource.go index af39962d..e2cb0dda 100644 --- a/lib/http/resource.go +++ b/lib/http/resource.go @@ -95,12 +95,6 @@ func resourceGetHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) ( } f.Kind = "editor" - - // Tries to get the editor data. - if err = f.GetEditor(); err != nil { - return http.StatusInternalServerError, err - } - return renderJSON(w, f) }