From a04a88d2cd6318d9afdff68bcb09fa697bd2bf85 Mon Sep 17 00:00:00 2001 From: tuzi3040 <28290621+tuzi3040@users.noreply.github.com> Date: Tue, 4 Jun 2019 11:02:56 +0800 Subject: [PATCH] fix: value of rss TTL tag (#2297) * fix value of rss TTL tag * fix test algorithm for rss ttl tag --- lib/middleware/template.js | 4 +++- test/router.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/middleware/template.js b/lib/middleware/template.js index c18ec8ceff..0653f2aecf 100644 --- a/lib/middleware/template.js +++ b/lib/middleware/template.js @@ -51,10 +51,12 @@ module.exports = async (ctx, next) => { }); } + const routeTtl = (config.cache.routeExpire / 60) | 0; + const data = { lastBuildDate: new Date().toUTCString(), updated: new Date().toISOString(), - ttl: config.cache.routeExpire, + ttl: routeTtl, ...ctx.state.data, }; if (template) { diff --git a/test/router.js b/test/router.js index 1ab4013c1f..23a13e9171 100644 --- a/test/router.js +++ b/test/router.js @@ -21,7 +21,7 @@ async function checkRSS(response) { expect(parsed.description).toEqual(expect.any(String)); expect(parsed.link).toEqual(expect.any(String)); expect(parsed.lastBuildDate).toEqual(expect.any(String)); - expect(parsed.ttl).toEqual(config.cache.routeExpire + ''); + expect(parsed.ttl).toEqual(((config.cache.routeExpire / 60) | 0) + ''); expect(parsed.items).toEqual(expect.any(Array)); checkDate(parsed.lastBuildDate);