diff --git a/src/content/mod.ts b/src/content/mod.ts index db96484..6bebf16 100644 --- a/src/content/mod.ts +++ b/src/content/mod.ts @@ -1 +1,3 @@ +import './manga'; +import './video'; export {ContentReferrer,createContentReferrer} from './referrer'; \ No newline at end of file diff --git a/src/content/referrer.ts b/src/content/referrer.ts index fada096..32e8146 100644 --- a/src/content/referrer.ts +++ b/src/content/referrer.ts @@ -37,8 +37,14 @@ export const createDefaultClass = (type:string):ContentReferrerConstructor=>{ } let ContstructorTable:{[k:string]:ContentReferrerConstructor} = {}; export function registerContentReferrer(s: ContentReferrerConstructor){ + console.log(`registered content type: ${s.content_type}`) ContstructorTable[s.content_type] = s; } export function createContentReferrer(type:string,path:string,desc?:object){ - return new ContstructorTable[type](path,desc); + const constructorMethod = ContstructorTable[type]; + if(constructorMethod === undefined){ + console.log(type); + throw new Error("undefined"); + } + return new constructorMethod(path,desc); } \ No newline at end of file diff --git a/src/model/contents.ts b/src/model/contents.ts index b3d32eb..823489e 100644 --- a/src/model/contents.ts +++ b/src/model/contents.ts @@ -7,7 +7,7 @@ export interface ContentContent{ content_type : string, basepath : string, filename : string, - thumbnail? : string, + hash? : string, additional : object, tags : string[],//eager loading } @@ -17,6 +17,7 @@ export const MetaContentContent = { content_type : "string", basepath : "string", filename : "string", + hash : "string", additional : "object", tags : "string[]", } diff --git a/src/route/all.ts b/src/route/all.ts index dc22c53..1237c03 100644 --- a/src/route/all.ts +++ b/src/route/all.ts @@ -15,6 +15,7 @@ const all_middleware = (cont: string|undefined, restarg: string|undefined)=>asyn return; } if(ctx.state.content.type != cont){ + console.error("not matched") ctx.status = 404; return; } @@ -26,7 +27,6 @@ const all_middleware = (cont: string|undefined, restarg: string|undefined)=>asyn const rest = "/"+(restarg as string|undefined || ""); const result = router.match(rest,"GET"); - console.log(`s : ${result.pathAndMethod}`); if(!result.route){ return await next(); } @@ -46,11 +46,9 @@ export class AllContentRouter extends Router{ constructor(){ super(); this.get('/:content_type',async (ctx,next)=>{ - console.log("no x"); return await (all_middleware(ctx.params["content_type"],undefined))(ctx,next); }); this.get('/:content_type/:rest(.*)', async (ctx,next) => { - console.log("yes x"); const cont = ctx.params["content_type"] as string; return await (all_middleware(cont,ctx.params["rest"]))(ctx,next); }); diff --git a/src/route/contents.ts b/src/route/contents.ts index c7c892c..b995cce 100644 --- a/src/route/contents.ts +++ b/src/route/contents.ts @@ -4,7 +4,7 @@ import {Content, ContentAccessor, isContentContent} from './../model/contents'; import {QueryListOption} from './../model/contents'; import {ParseQueryNumber, ParseQueryArray, ParseQueryBoolean} from './util' import {sendError} from './error_handler'; -import { createContentReferrer } from '../content/referrer'; +import { createContentReferrer } from '../content/mod'; import { join } from 'path'; import {AllContentRouter} from './all'; diff --git a/src/route/context.ts b/src/route/context.ts index f810743..9ca6268 100644 --- a/src/route/context.ts +++ b/src/route/context.ts @@ -1,4 +1,4 @@ -import {ContentReferrer} from '../content/referrer'; +import {ContentReferrer} from '../content/mod'; export interface ContentContext{ content:ContentReferrer diff --git a/src/route/manga.ts b/src/route/manga.ts index 44ef2b7..610baf2 100644 --- a/src/route/manga.ts +++ b/src/route/manga.ts @@ -78,6 +78,9 @@ export class MangaRouter extends Router{ const page = Number.parseInt(ctx.params['page']); await renderZipImage(ctx,ctx.state.content.path,page); }); + this.get("/thumbnail", async (ctx,next)=>{ + await renderZipImage(ctx,ctx.state.content.path,0); + }); } } diff --git a/src/route/video.ts b/src/route/video.ts index 8638085..c859384 100644 --- a/src/route/video.ts +++ b/src/route/video.ts @@ -59,6 +59,9 @@ export class VideoRouter extends Router{ this.get("/", async (ctx,next)=>{ await renderVideo(ctx,ctx.state.content.path); }); + this.get("/thumbnail", async (ctx,next)=>{ + await renderVideo(ctx,ctx.state.content.path); + }) } } diff --git a/src/server.ts b/src/server.ts index bc40b31..ec6b48a 100644 --- a/src/server.ts +++ b/src/server.ts @@ -1,5 +1,5 @@ -import Koa, { DefaultState } from 'koa'; -import Router, { IParamMiddleware, IRouterParamContext } from 'koa-router'; +import Koa from 'koa'; +import Router from 'koa-router'; import {get_setting} from './setting'; import {connectDB} from './database'; @@ -10,11 +10,6 @@ import getContentRouter from './route/contents'; import { createKnexContentsAccessor } from './db/contents'; import bodyparser from 'koa-bodyparser'; import {error_handler} from './route/error_handler'; -import {MangaReferrer} from './content/manga'; -import {VideoReferrer} from './content/video'; - -import { ContentContext } from './route/context'; -import { AllContentRouter } from './route/all'; //let Koa = require("koa"); async function main(){ @@ -39,6 +34,7 @@ async function main(){ }); router.get('/dist/js/bundle.js',async (ctx,next)=>{ ctx.type = "js"; + //ctx.set("",""); ctx.body = createReadStream("dist/js/bundle.js"); }); router.get('/get' @@ -51,17 +47,7 @@ async function main(){ let content_router = getContentRouter(createKnexContentsAccessor(db)); router.use('/content',content_router.routes()); router.use('/content',content_router.allowedMethods()); - let ctnrouter = new AllContentRouter(); - router.all('/image/(.*)', async (ctx,next)=>{ - ctx.state['content'] = new MangaReferrer("testdata/test_zip.zip"); - await next(); - }); - router.use('/image',ctnrouter.routes()); - router.all('/ss/(.*)', async (ctx,next)=>{ - ctx.state['content'] = new VideoReferrer("testdata/video_test.mp4"); - await next(); - }); - router.use('/ss',ctnrouter.routes()); + let mm_count=0; app.use(async (ctx,next)=>{ console.log(`==========================${mm_count++}`);