implemented attachment downloading
This commit is contained in:
@@ -33,6 +33,7 @@ import (
|
||||
|
||||
// AmContext is the interface for Amsterdam's wrapper context that exposes the required functionality.
|
||||
type AmContext interface {
|
||||
AddHeader(string, string)
|
||||
ClearCommunityContext()
|
||||
ClearLoginCookie()
|
||||
ClearSession()
|
||||
@@ -59,6 +60,7 @@ type AmContext interface {
|
||||
ReplaceUser(*database.User)
|
||||
SaveSession() error
|
||||
SetCommunityContext(string) error
|
||||
SetHeader(string, string)
|
||||
SetLeftMenu(string)
|
||||
SetLoginCookie(string)
|
||||
SetOutputType(string)
|
||||
@@ -96,6 +98,11 @@ type amContext struct {
|
||||
isMemberLocked bool
|
||||
}
|
||||
|
||||
// AddHeader adds a header to the response.
|
||||
func (c *amContext) AddHeader(key, value string) {
|
||||
c.echoContext.Response().Header().Add(key, value)
|
||||
}
|
||||
|
||||
// ClearCommunityContext clears the community context so changes will be reflected.
|
||||
func (c *amContext) ClearCommunityContext() {
|
||||
c.community = nil
|
||||
@@ -343,6 +350,11 @@ func (c *amContext) SetCommunityContext(param string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetHeader sets a header on the output.
|
||||
func (c *amContext) SetHeader(key, value string) {
|
||||
c.echoContext.Response().Header().Set(key, value)
|
||||
}
|
||||
|
||||
// SetLeftMenu sets the current topmost left menu name value.
|
||||
func (c *amContext) SetLeftMenu(name string) {
|
||||
c.session.Set("leftMenu", name)
|
||||
|
||||
@@ -13,7 +13,9 @@ package ui
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/klauspost/lctime"
|
||||
"github.com/labstack/echo/v4"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
@@ -89,6 +91,9 @@ func ErrorPage(ctxt AmContext, input_err error) (string, any, error) {
|
||||
return "framed_template", "error.jet", nil
|
||||
}
|
||||
|
||||
// expireTime is the expiration time sent in the dynamic headers.
|
||||
var expireTime string = lctime.Strftime("%c", time.Unix(1, 0))
|
||||
|
||||
/* AmWrap wraps the Amsterdam handler function in a wrapper that implements the spec for
|
||||
* Echo handler functions.
|
||||
* Parameters:
|
||||
@@ -99,6 +104,12 @@ func ErrorPage(ctxt AmContext, input_err error) (string, any, error) {
|
||||
func AmWrap(myfunc func(AmContext) (string, any, error)) echo.HandlerFunc {
|
||||
return func(ctxt echo.Context) error {
|
||||
amctxt := AmContextFromEchoContext(ctxt)
|
||||
|
||||
// Add the dynamic headers.
|
||||
ctxt.Response().Header().Set("Pragma", "No-cache")
|
||||
ctxt.Response().Header().Set("Cache-Control", "no-cache")
|
||||
ctxt.Response().Header().Set("Expires", expireTime)
|
||||
|
||||
// Exec the wrapped function.
|
||||
what, rc, err := myfunc(amctxt)
|
||||
if err == nil {
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<a href="/user/{{ post_userName }}" target="_blank" class="text-blue-700 hover:text-blue-900">{{ post_userName }}</a>,
|
||||
{{ DisplayDateTime(post_cur.Posted, .) }}</em>)
|
||||
{{ if post_attach.Filename != "" }}
|
||||
<a href="/TODO" title="(Attachment {{ post_attach.Filename }} - {{ post_attach.Length }} bytes)"
|
||||
<a href="/attachment/{{ post_cur.PostId }}" title="(Attachment {{ post_attach.Filename }} - {{ post_attach.Length }} bytes)"
|
||||
{{ if hasPrefix(post_attach.MIMEType, "text/") || hasPrefix(post_attach.MIMEType, "image/" )}}
|
||||
target="_blank"
|
||||
{{ end }}
|
||||
|
||||
Reference in New Issue
Block a user