This commit is contained in:
xing 2022-10-07 22:54:53 +08:00
parent 7c4f4f10fc
commit fd3d8bc32e

View File

@ -52,7 +52,14 @@ func Feed(c *gin.Context) {
if !isCacheExpired(c, feedCache.SetTime()) { if !isCacheExpired(c, feedCache.SetTime()) {
c.Status(http.StatusNotModified) c.Status(http.StatusNotModified)
} else { } else {
setFeed(feedCache, c) r, err := feedCache.GetCache(c, time.Second, c)
if err != nil {
c.Status(http.StatusInternalServerError)
c.Abort()
c.Error(err)
return
}
setFeed(r[0], c, feedCache.SetTime())
} }
} }
@ -102,20 +109,13 @@ func feed(arg ...any) (xml []string, err error) {
return return
} }
func setFeed(sliceCache *cache.SliceCache[string], c *gin.Context) { func setFeed(s string, c *gin.Context, t time.Time) {
s, err := sliceCache.GetCache(c, time.Second, c) lastTimeGMT := t.Format(tmp)
if err != nil {
c.Status(http.StatusInternalServerError)
c.Abort()
c.Error(err)
return
}
lastTimeGMT := sliceCache.SetTime().Format(tmp)
eTag := helper.StringMd5(lastTimeGMT) eTag := helper.StringMd5(lastTimeGMT)
c.Header("Content-Type", "application/rss+xml; charset=UTF-8") c.Header("Content-Type", "application/rss+xml; charset=UTF-8")
c.Header("Last-Modified", lastTimeGMT) c.Header("Last-Modified", lastTimeGMT)
c.Header("ETag", eTag) c.Header("ETag", eTag)
c.String(http.StatusOK, s[0]) c.String(http.StatusOK, s)
} }
func PostFeed(c *gin.Context) { func PostFeed(c *gin.Context) {
@ -130,12 +130,7 @@ func PostFeed(c *gin.Context) {
c.Error(err) c.Error(err)
return return
} }
lastTimeGMT := postFeedCache.GetSetTime(id).Format(tmp) setFeed(s, c, postFeedCache.GetSetTime(id))
eTag := helper.StringMd5(lastTimeGMT)
c.Header("Content-Type", "application/rss+xml; charset=UTF-8")
c.Header("Last-Modified", lastTimeGMT)
c.Header("ETag", eTag)
c.String(http.StatusOK, s)
} }
} }