move since_last_modified function

This commit is contained in:
monoid 2021-01-03 01:35:45 +09:00
parent eaafdbe577
commit 0bd0d3e11b
3 changed files with 13 additions and 12 deletions

View File

@ -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;
}

View File

@ -2,7 +2,7 @@
import {Context, DefaultContext, DefaultState, Next} from 'koa'; import {Context, DefaultContext, DefaultState, Next} from 'koa';
import StreamZip, { ZipEntry } from 'node-stream-zip'; import StreamZip, { ZipEntry } from 'node-stream-zip';
import {orderBy} from 'natural-orderby'; import {orderBy} from 'natural-orderby';
import {since_last_modified} from '../content/util'; import {since_last_modified} from './util';
import {ContentContext} from './context'; import {ContentContext} from './context';
import Router from 'koa-router'; import Router from 'koa-router';

View File

@ -1,4 +1,6 @@
import {Context} from 'koa';
export function ParseQueryNumber(s: string|undefined): number| undefined{ export function ParseQueryNumber(s: string|undefined): number| undefined{
if(s === undefined) return undefined; if(s === undefined) return undefined;
@ -19,4 +21,13 @@ export function ParseQueryBoolean(s: string|undefined): [boolean,boolean|undefin
else else
return [false,undefined] return [false,undefined]
return [true,value] return [true,value]
} }
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;
}