clean
This commit is contained in:
parent
45387936be
commit
fed498d22b
@ -1 +1,3 @@
|
||||
import './manga';
|
||||
import './video';
|
||||
export {ContentReferrer,createContentReferrer} from './referrer';
|
@ -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);
|
||||
}
|
@ -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[]",
|
||||
}
|
||||
|
@ -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<ContentContext>{
|
||||
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);
|
||||
});
|
||||
|
@ -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';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import {ContentReferrer} from '../content/referrer';
|
||||
import {ContentReferrer} from '../content/mod';
|
||||
|
||||
export interface ContentContext{
|
||||
content:ContentReferrer
|
||||
|
@ -78,6 +78,9 @@ export class MangaRouter extends Router<ContentContext>{
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,6 +59,9 @@ export class VideoRouter extends Router<ContentContext>{
|
||||
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);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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++}`);
|
||||
|
Loading…
Reference in New Issue
Block a user