clean
This commit is contained in:
parent
45387936be
commit
fed498d22b
@ -1 +1,3 @@
|
|||||||
|
import './manga';
|
||||||
|
import './video';
|
||||||
export {ContentReferrer,createContentReferrer} from './referrer';
|
export {ContentReferrer,createContentReferrer} from './referrer';
|
@ -37,8 +37,14 @@ export const createDefaultClass = (type:string):ContentReferrerConstructor=>{
|
|||||||
}
|
}
|
||||||
let ContstructorTable:{[k:string]:ContentReferrerConstructor} = {};
|
let ContstructorTable:{[k:string]:ContentReferrerConstructor} = {};
|
||||||
export function registerContentReferrer(s: ContentReferrerConstructor){
|
export function registerContentReferrer(s: ContentReferrerConstructor){
|
||||||
|
console.log(`registered content type: ${s.content_type}`)
|
||||||
ContstructorTable[s.content_type] = s;
|
ContstructorTable[s.content_type] = s;
|
||||||
}
|
}
|
||||||
export function createContentReferrer(type:string,path:string,desc?:object){
|
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,
|
content_type : string,
|
||||||
basepath : string,
|
basepath : string,
|
||||||
filename : string,
|
filename : string,
|
||||||
thumbnail? : string,
|
hash? : string,
|
||||||
additional : object,
|
additional : object,
|
||||||
tags : string[],//eager loading
|
tags : string[],//eager loading
|
||||||
}
|
}
|
||||||
@ -17,6 +17,7 @@ export const MetaContentContent = {
|
|||||||
content_type : "string",
|
content_type : "string",
|
||||||
basepath : "string",
|
basepath : "string",
|
||||||
filename : "string",
|
filename : "string",
|
||||||
|
hash : "string",
|
||||||
additional : "object",
|
additional : "object",
|
||||||
tags : "string[]",
|
tags : "string[]",
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ const all_middleware = (cont: string|undefined, restarg: string|undefined)=>asyn
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(ctx.state.content.type != cont){
|
if(ctx.state.content.type != cont){
|
||||||
|
console.error("not matched")
|
||||||
ctx.status = 404;
|
ctx.status = 404;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -26,7 +27,6 @@ const all_middleware = (cont: string|undefined, restarg: string|undefined)=>asyn
|
|||||||
const rest = "/"+(restarg as string|undefined || "");
|
const rest = "/"+(restarg as string|undefined || "");
|
||||||
|
|
||||||
const result = router.match(rest,"GET");
|
const result = router.match(rest,"GET");
|
||||||
console.log(`s : ${result.pathAndMethod}`);
|
|
||||||
if(!result.route){
|
if(!result.route){
|
||||||
return await next();
|
return await next();
|
||||||
}
|
}
|
||||||
@ -46,11 +46,9 @@ export class AllContentRouter extends Router<ContentContext>{
|
|||||||
constructor(){
|
constructor(){
|
||||||
super();
|
super();
|
||||||
this.get('/:content_type',async (ctx,next)=>{
|
this.get('/:content_type',async (ctx,next)=>{
|
||||||
console.log("no x");
|
|
||||||
return await (all_middleware(ctx.params["content_type"],undefined))(ctx,next);
|
return await (all_middleware(ctx.params["content_type"],undefined))(ctx,next);
|
||||||
});
|
});
|
||||||
this.get('/:content_type/:rest(.*)', async (ctx,next) => {
|
this.get('/:content_type/:rest(.*)', async (ctx,next) => {
|
||||||
console.log("yes x");
|
|
||||||
const cont = ctx.params["content_type"] as string;
|
const cont = ctx.params["content_type"] as string;
|
||||||
return await (all_middleware(cont,ctx.params["rest"]))(ctx,next);
|
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 {QueryListOption} from './../model/contents';
|
||||||
import {ParseQueryNumber, ParseQueryArray, ParseQueryBoolean} from './util'
|
import {ParseQueryNumber, ParseQueryArray, ParseQueryBoolean} from './util'
|
||||||
import {sendError} from './error_handler';
|
import {sendError} from './error_handler';
|
||||||
import { createContentReferrer } from '../content/referrer';
|
import { createContentReferrer } from '../content/mod';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import {AllContentRouter} from './all';
|
import {AllContentRouter} from './all';
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import {ContentReferrer} from '../content/referrer';
|
import {ContentReferrer} from '../content/mod';
|
||||||
|
|
||||||
export interface ContentContext{
|
export interface ContentContext{
|
||||||
content:ContentReferrer
|
content:ContentReferrer
|
||||||
|
@ -78,6 +78,9 @@ export class MangaRouter extends Router<ContentContext>{
|
|||||||
const page = Number.parseInt(ctx.params['page']);
|
const page = Number.parseInt(ctx.params['page']);
|
||||||
await renderZipImage(ctx,ctx.state.content.path,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)=>{
|
this.get("/", async (ctx,next)=>{
|
||||||
await renderVideo(ctx,ctx.state.content.path);
|
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 Koa from 'koa';
|
||||||
import Router, { IParamMiddleware, IRouterParamContext } from 'koa-router';
|
import Router from 'koa-router';
|
||||||
|
|
||||||
import {get_setting} from './setting';
|
import {get_setting} from './setting';
|
||||||
import {connectDB} from './database';
|
import {connectDB} from './database';
|
||||||
@ -10,11 +10,6 @@ import getContentRouter from './route/contents';
|
|||||||
import { createKnexContentsAccessor } from './db/contents';
|
import { createKnexContentsAccessor } from './db/contents';
|
||||||
import bodyparser from 'koa-bodyparser';
|
import bodyparser from 'koa-bodyparser';
|
||||||
import {error_handler} from './route/error_handler';
|
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");
|
//let Koa = require("koa");
|
||||||
async function main(){
|
async function main(){
|
||||||
@ -39,6 +34,7 @@ async function main(){
|
|||||||
});
|
});
|
||||||
router.get('/dist/js/bundle.js',async (ctx,next)=>{
|
router.get('/dist/js/bundle.js',async (ctx,next)=>{
|
||||||
ctx.type = "js";
|
ctx.type = "js";
|
||||||
|
//ctx.set("","");
|
||||||
ctx.body = createReadStream("dist/js/bundle.js");
|
ctx.body = createReadStream("dist/js/bundle.js");
|
||||||
});
|
});
|
||||||
router.get('/get'
|
router.get('/get'
|
||||||
@ -51,17 +47,7 @@ async function main(){
|
|||||||
let content_router = getContentRouter(createKnexContentsAccessor(db));
|
let content_router = getContentRouter(createKnexContentsAccessor(db));
|
||||||
router.use('/content',content_router.routes());
|
router.use('/content',content_router.routes());
|
||||||
router.use('/content',content_router.allowedMethods());
|
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;
|
let mm_count=0;
|
||||||
app.use(async (ctx,next)=>{
|
app.use(async (ctx,next)=>{
|
||||||
console.log(`==========================${mm_count++}`);
|
console.log(`==========================${mm_count++}`);
|
||||||
|
Loading…
Reference in New Issue
Block a user