Skip to content

Commit

Permalink
Merge pull request #2549 from traPtitech/ogp-no-cache
Browse files Browse the repository at this point in the history
OGP をネットワーク上でキャッシュしないように
  • Loading branch information
cp-20 authored Dec 10, 2024
2 parents 9afb7d8 + 79e3a7d commit 5927f3b
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions router/v3/ogp.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package v3

import (
"fmt"
"net/http"
"net/url"
"time"

"github.com/labstack/echo/v4"

Expand All @@ -22,16 +20,12 @@ func (h *Handlers) GetOgp(c echo.Context) error {
return herror.BadRequest("invalid url")
}

res, expiresAt, err := h.OGP.GetMeta(u)
// キャッシュの削除に対応するために Cache-Control でのキャッシュはしない
res, _, err := h.OGP.GetMeta(u)
if err != nil {
return herror.InternalServerError(err)
}

expiresIn := time.Until(expiresAt)
if expiresIn > 0 {
c.Response().Header().Set(consts.HeaderCacheControl, fmt.Sprintf("public, max-age=%d", expiresIn/time.Second))
}

if res == nil {
return c.JSON(http.StatusOK, model.Ogp{
Type: "empty",
Expand Down

0 comments on commit 5927f3b

Please sign in to comment.