Allow customisation of preview generation (#673)

* Add generate-specific options
* Include no-cache in preview response
This commit is contained in:
WithoutPants
2020-07-23 12:51:35 +10:00
committed by GitHub
parent 37be146a9d
commit a2341f0819
18 changed files with 509 additions and 53 deletions

View File

@@ -3,13 +3,15 @@ package utils
import (
"archive/zip"
"fmt"
"github.com/h2non/filetype"
"github.com/h2non/filetype/types"
"io/ioutil"
"math"
"net/http"
"os"
"os/user"
"path/filepath"
"github.com/h2non/filetype"
"github.com/h2non/filetype/types"
)
// FileType uses the filetype package to determine the given file path's type
@@ -219,3 +221,11 @@ func GetParent(path string) *string {
return &parentPath
}
}
// ServeFileNoCache serves the provided file, ensuring that the response
// contains headers to prevent caching.
func ServeFileNoCache(w http.ResponseWriter, r *http.Request, filepath string) {
w.Header().Add("Cache-Control", "no-cache")
http.ServeFile(w, r, filepath)
}