From 0bd0d3e11b0adc6d104e564f8bb224c82c1ab65d Mon Sep 17 00:00:00 2001 From: monoid Date: Sun, 3 Jan 2021 01:35:45 +0900 Subject: [PATCH] move since_last_modified function --- src/content/util.ts | 10 ---------- src/route/manga.ts | 2 +- src/route/util.ts | 13 ++++++++++++- 3 files changed, 13 insertions(+), 12 deletions(-) delete mode 100644 src/content/util.ts diff --git a/src/content/util.ts b/src/content/util.ts deleted file mode 100644 index c2a444e..0000000 --- a/src/content/util.ts +++ /dev/null @@ -1,10 +0,0 @@ -import {Context} from 'koa'; - -export function since_last_modified(ctx: Context, last_modified: Date): boolean{ - const con = ctx.get("If-Modified-Since"); - if(con === "") return false; - const mdate = new Date(con); - if(last_modified > mdate) return false; - ctx.status = 304; - return true; -} diff --git a/src/route/manga.ts b/src/route/manga.ts index d342452..44ef2b7 100644 --- a/src/route/manga.ts +++ b/src/route/manga.ts @@ -2,7 +2,7 @@ import {Context, DefaultContext, DefaultState, Next} from 'koa'; import StreamZip, { ZipEntry } from 'node-stream-zip'; import {orderBy} from 'natural-orderby'; -import {since_last_modified} from '../content/util'; +import {since_last_modified} from './util'; import {ContentContext} from './context'; import Router from 'koa-router'; diff --git a/src/route/util.ts b/src/route/util.ts index 0116694..9e4892e 100644 --- a/src/route/util.ts +++ b/src/route/util.ts @@ -1,4 +1,6 @@ +import {Context} from 'koa'; + export function ParseQueryNumber(s: string|undefined): number| undefined{ if(s === undefined) return undefined; @@ -19,4 +21,13 @@ export function ParseQueryBoolean(s: string|undefined): [boolean,boolean|undefin else return [false,undefined] return [true,value] -} \ No newline at end of file +} + +export function since_last_modified(ctx: Context, last_modified: Date): boolean{ + const con = ctx.get("If-Modified-Since"); + if(con === "") return false; + const mdate = new Date(con); + if(last_modified > mdate) return false; + ctx.status = 304; + return true; +}