change hash

This commit is contained in:
monoid 2021-01-11 20:48:33 +09:00
parent 60b61a8004
commit 4f69543d78

View File

@ -2,6 +2,7 @@ import {Context, DefaultState, DefaultContext, Middleware, Next} from 'koa';
import Router from 'koa-router'; import Router from 'koa-router';
import {createHash} from 'crypto'; import {createHash} from 'crypto';
import {promises} from 'fs' import {promises} from 'fs'
import {extname} from 'path';
/** /**
* content file or directory referrer * content file or directory referrer
*/ */
@ -26,6 +27,7 @@ export const createDefaultClass = (type:string):ContentReferrerConstructor=>{
async getHash():Promise<string>{ async getHash():Promise<string>{
const stat = await promises.stat(this.path); const stat = await promises.stat(this.path);
const hash = createHash("sha512"); const hash = createHash("sha512");
hash.update(extname(this.type));
hash.update(stat.mode.toString()); hash.update(stat.mode.toString());
//if(this.desc !== undefined) //if(this.desc !== undefined)
// hash.update(JSON.stringify(this.desc)); // hash.update(JSON.stringify(this.desc));
@ -47,4 +49,8 @@ export function createContentReferrer(type:string,path:string,desc?:object){
throw new Error("undefined"); throw new Error("undefined");
} }
return new constructorMethod(path,desc); return new constructorMethod(path,desc);
}
export function getContentRefererConstructor(type:string): ContentReferrerConstructor|undefined{
const ret = ContstructorTable[type];
return ret;
} }