move render
This commit is contained in:
parent
c8c0f3e209
commit
5bda122da9
@ -1,6 +1,6 @@
|
|||||||
import {Context} from 'koa';
|
import {Context} from 'koa';
|
||||||
import {promises, createReadStream} from "fs";
|
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{
|
function since_last_modified(ctx: Context, last_modified: Date): boolean{
|
||||||
const con = ctx.get("If-Modified-Since");
|
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());
|
read_stream.on('close',()=>zip.close());
|
||||||
ctx.body = read_stream;
|
ctx.body = read_stream;
|
||||||
ctx.response.length = entry.size;
|
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.response.type = entry.name.split(".").pop() as string;
|
||||||
ctx.status = 200;
|
ctx.status = 200;
|
||||||
ctx.set('Date', new Date().toUTCString());
|
ctx.set('Date', new Date().toUTCString());
|
@ -4,7 +4,7 @@ import Router from 'koa-router';
|
|||||||
import {get_setting} from './setting';
|
import {get_setting} from './setting';
|
||||||
import {connectDB} from './database';
|
import {connectDB} from './database';
|
||||||
import {Watcher} from './diff'
|
import {Watcher} from './diff'
|
||||||
import {renderImage, renderVideo, renderZipImage} from './render';
|
import {renderImage, renderVideo, renderZipImage} from './route/render';
|
||||||
import { createReadStream, readFileSync } from 'fs';
|
import { createReadStream, readFileSync } from 'fs';
|
||||||
import getContentRouter from './route/contents';
|
import getContentRouter from './route/contents';
|
||||||
import { createKnexContentsAccessor } from './db/contents';
|
import { createKnexContentsAccessor } from './db/contents';
|
||||||
@ -54,6 +54,14 @@ async function main(){
|
|||||||
});
|
});
|
||||||
router.get('/image/:number',async (ctx,next)=>{
|
router.get('/image/:number',async (ctx,next)=>{
|
||||||
let page = ctx.params.number;
|
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);
|
await renderZipImage(ctx,"testdata/test_zip.zip",page);
|
||||||
ctx.set("cache-control","max-age=3600");
|
ctx.set("cache-control","max-age=3600");
|
||||||
await next();
|
await next();
|
||||||
|
Loading…
Reference in New Issue
Block a user