From 80663061d8f361ae4bcea1307a10a40c41174ebe Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Sat, 8 Oct 2022 14:00:39 +0200 Subject: [feature] Add opt-in RSS feed for account's latest Public posts (#897) * start adding rss functionality * add gorilla/feeds dependency * first bash at building rss feed still needs work, this is an interim commit * tidy up a bit * add publicOnly option to GetAccountLastPosted * implement rss endpoint * fix test * add initial user docs for rss * update rss logo * docs update * add rssFeed to frontend * feed -> feed.rss * enableRSS * increase rss logo size a lil bit * add rss toggle * move emojify to text package * fiddle with rss feed formatting * add Text field to test statuses * move status to rss item to typeconverter * update bun schema for enablerss * simplify 304 checking * assume account not rss * update tests * update swagger docs * allow more characters in title, trim nicer * update last posted to be more consistent --- internal/web/web.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'internal/web/web.go') diff --git a/internal/web/web.go b/internal/web/web.go index a816f3f08..cdcf7422f 100644 --- a/internal/web/web.go +++ b/internal/web/web.go @@ -21,7 +21,6 @@ package web import ( "errors" "net/http" - "time" "codeberg.org/gruf/go-cache/v2" "github.com/gin-gonic/gin" @@ -36,6 +35,7 @@ const ( confirmEmailPath = "/" + uris.ConfirmEmailPath profilePath = "/@:" + usernameKey customCSSPath = profilePath + "/custom.css" + rssFeedPath = profilePath + "/feed.rss" statusPath = profilePath + "/statuses/:" + statusIDKey assetsPathPrefix = "/assets" userPanelPath = "/settings/user" @@ -44,23 +44,26 @@ const ( tokenParam = "token" usernameKey = "username" statusIDKey = "status" + + cacheControlHeader = "Cache-Control" // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control + cacheControlNoCache = "no-cache" // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#response_directives + ifModifiedSinceHeader = "If-Modified-Since" // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Modified-Since + ifNoneMatchHeader = "If-None-Match" // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-None-Match + eTagHeader = "ETag" // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag + lastModifiedHeader = "Last-Modified" // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Last-Modified ) // Module implements the api.ClientModule interface for web pages. type Module struct { - processor processing.Processor - assetsETagCache cache.Cache[string, eTagCacheEntry] + processor processing.Processor + eTagCache cache.Cache[string, eTagCacheEntry] } // New returns a new api.ClientModule for web pages. func New(processor processing.Processor) api.ClientModule { - assetsETagCache := cache.New[string, eTagCacheEntry]() - assetsETagCache.SetTTL(time.Hour, false) - assetsETagCache.Start(time.Minute) - return &Module{ - processor: processor, - assetsETagCache: assetsETagCache, + processor: processor, + eTagCache: newETagCache(), } } @@ -99,6 +102,8 @@ func (m *Module) Route(s router.Router) error { // serve custom css at /@username/custom.css s.AttachHandler(http.MethodGet, customCSSPath, m.customCSSGETHandler) + s.AttachHandler(http.MethodGet, rssFeedPath, m.rssFeedGETHandler) + // serve statuses s.AttachHandler(http.MethodGet, statusPath, m.threadGETHandler) -- cgit v1.2.3