From 5bda122da983db96a79952bf6589d7baedab7b87 Mon Sep 17 00:00:00 2001 From: monoid Date: Fri, 1 Jan 2021 03:25:21 +0900 Subject: [PATCH] move render --- src/{ => route}/render.ts | 4 ++-- src/server.ts | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) rename src/{ => route}/render.ts (97%) diff --git a/src/render.ts b/src/route/render.ts similarity index 97% rename from src/render.ts rename to src/route/render.ts index 3a076b3..09f7bd3 100644 --- a/src/render.ts +++ b/src/route/render.ts @@ -1,6 +1,6 @@ import {Context} from 'koa'; import {promises, createReadStream} from "fs"; -import {createReadStreamFromZip, entriesByNaturalOrder, readZip} from "./util/ziputil"; +import {createReadStreamFromZip, entriesByNaturalOrder, readZip} from "../util/ziputil"; function since_last_modified(ctx: Context, last_modified: Date): boolean{ const con = ctx.get("If-Modified-Since"); @@ -28,7 +28,7 @@ export async function renderZipImage(ctx: Context,path : string, page:number){ read_stream.on('close',()=>zip.close()); ctx.body = read_stream; ctx.response.length = entry.size; - console.log(`${entry.name}'s ${page}:${entry.size}`); + //console.log(`${entry.name}'s ${page}:${entry.size}`); ctx.response.type = entry.name.split(".").pop() as string; ctx.status = 200; ctx.set('Date', new Date().toUTCString()); diff --git a/src/server.ts b/src/server.ts index 11091fa..1dc1ee4 100644 --- a/src/server.ts +++ b/src/server.ts @@ -4,7 +4,7 @@ import Router from 'koa-router'; import {get_setting} from './setting'; import {connectDB} from './database'; import {Watcher} from './diff' -import {renderImage, renderVideo, renderZipImage} from './render'; +import {renderImage, renderVideo, renderZipImage} from './route/render'; import { createReadStream, readFileSync } from 'fs'; import getContentRouter from './route/contents'; import { createKnexContentsAccessor } from './db/contents'; @@ -54,6 +54,14 @@ async function main(){ }); router.get('/image/:number',async (ctx,next)=>{ let page = ctx.params.number; + console.log("page type : "+typeof page) + await renderZipImage(ctx,"testdata/test_zip.zip",page); + ctx.set("cache-control","max-age=3600"); + await next(); + }); + router.get('/aaaa/:number(\\d+)',async (ctx,next)=>{ + let page = ctx.params.number; + console.log("matched"); await renderZipImage(ctx,"testdata/test_zip.zip",page); ctx.set("cache-control","max-age=3600"); await next();