diff --git a/rest/getCachedAt.ts b/rest/getCachedAt.ts new file mode 100644 index 0000000..0dd5dbf --- /dev/null +++ b/rest/getCachedAt.ts @@ -0,0 +1,12 @@ +/** ServiceWorkerにcacheされた日時を得る + * + * cacheされたResponseでなければ`undefined`を返す + * + * @param res Response to check the chached date + * @return cached date (as UNIX timestamp) or `undefined` + */ +export const getCachedAt = (res: Response): number | undefined => { + const cachedAt = res.headers.get("x-serviceworker-cached"); + if (!cachedAt) return; + return parseInt(cachedAt); +}; diff --git a/rest/mod.ts b/rest/mod.ts index 610f070..916fa9a 100644 --- a/rest/mod.ts +++ b/rest/mod.ts @@ -16,3 +16,4 @@ export * from "./error.ts"; export * from "./getCodeBlocks.ts"; export * from "./getCodeBlock.ts"; export * from "./uploadToGCS.ts"; +export * from "./getCachedAt.ts";