Skip to content

feat(REST API): Get cached time of Response #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions rest/getCachedAt.ts
Original file line number Diff line number Diff line change
@@ -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);
};
1 change: 1 addition & 0 deletions rest/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ export * from "./error.ts";
export * from "./getCodeBlocks.ts";
export * from "./getCodeBlock.ts";
export * from "./uploadToGCS.ts";
export * from "./getCachedAt.ts";
Loading