1
0

Replaced templates to a generated ones.

This commit is contained in:
Alexander Andreev 2022-06-13 21:07:33 +04:00
parent dc9b66cae4
commit 2cdd27d249
Signed by: Arav
GPG Key ID: 0388CC8FAA51063F

View File

@ -51,8 +51,6 @@ type UploadHandlers struct {
}
func NewUploadHandlers(conf *configuration.Configuration, lErr, lUp, lDown *logging.Logger, uploadDirSize *int64) *UploadHandlers {
web.CompileTemplates(lErr)
return &UploadHandlers{
conf: conf,
logErr: lErr,
@ -74,20 +72,7 @@ func (h *UploadHandlers) Index(w http.ResponseWriter, r *http.Request) {
_, _, availStr := utils.ConvertFileSize(storCapacity - *h.uploadDirSize)
_, _, fMaxSzStr := utils.ConvertFileSize(fMaxSize)
if err := web.Template("index").Execute(w, &IndexData{
MainSite: utils.MainSite(r.Host),
FileMaxSz: fMaxSzStr,
StorageCapacity: storCapacity,
StorageCapStr: capStr,
StorageAvailable: storCapacity - *h.uploadDirSize,
StorageAvailStr: availStr,
StorageUsed: *h.uploadDirSize,
StorageUsedStr: usedStr,
KeepForHours: h.conf.Uploads.Limits.KeepForHours,
}); err != nil {
w.WriteHeader(http.StatusInternalServerError)
h.logErr.Fatalln("failed to execute Index template:", err)
}
web.Index(utils.MainSite(r.Host), storCapacity, *h.uploadDirSize, h.conf.Uploads.Limits.KeepForHours, fMaxSzStr, usedStr, capStr, availStr, w)
}
func (h *UploadHandlers) Upload(w http.ResponseWriter, r *http.Request) {
@ -119,12 +104,7 @@ func (h *UploadHandlers) Upload(w http.ResponseWriter, r *http.Request) {
if leftSpace < fHandler.Size {
h.logErr.Println("not enough space left in storage, only", leftSpace>>20, "MiB left")
w.WriteHeader(http.StatusInternalServerError)
if err := web.Template("nospace").Execute(w, &NotFoundData{
MainSite: utils.MainSite(r.Host),
}); err != nil {
h.logErr.Fatalln("failed to execute NoSpace template:", err)
http.Error(w, "cannot execute a NoSpace template. But error was that there's no space for uploads left", http.StatusInternalServerError)
}
web.ErrorNoSpace(utils.MainSite(r.Host), w)
}
s256 := sha256.New()
@ -187,14 +167,7 @@ func (h *UploadHandlers) Upload(w http.ResponseWriter, r *http.Request) {
return
}
if err := web.Template("uploaded").Execute(w, &UploadedData{
MainSite: utils.MainSite(r.Host),
DownloadURL: downloadURLParsed.String(),
KeepForHours: h.conf.Uploads.Limits.KeepForHours,
}); err != nil {
h.logErr.Fatalln("failed to execute Uploaded template:", err)
http.Error(w, "cannot execute Uploaded template, but here is your download link: "+downloadURLParsed.String(), http.StatusInternalServerError)
}
web.Uploaded(utils.MainSite(r.Host), downloadURLParsed.String(), h.conf.Uploads.Limits.KeepForHours, w)
}
func (h *UploadHandlers) Download(w http.ResponseWriter, r *http.Request) {
@ -229,10 +202,5 @@ func (h *UploadHandlers) Download(w http.ResponseWriter, r *http.Request) {
func (h *UploadHandlers) NotFound(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
if err := web.Template("404").Execute(w, NotFoundData{
MainSite: utils.MainSite(r.Host),
}); err != nil {
w.WriteHeader(http.StatusInternalServerError)
h.logErr.Fatalln("failed to execute 404 template:", err)
}
web.Error404(utils.MainSite(r.Host), w)
}