fix: onchange bug
This commit is contained in:
parent
b510c7419f
commit
6dd1d4d83a
@ -41,7 +41,10 @@ export class ContentDiffHandler{
|
||||
}
|
||||
const dbc = await this.doc_cntr.findByPath(basepath, filename);
|
||||
//when there is no related content in db, ignore.
|
||||
if(dbc.length === 0) return;
|
||||
if (dbc.length === 0) {
|
||||
console.log("its not in waiting_list and db!!!: ", cpath);
|
||||
return;
|
||||
}
|
||||
const content_hash = dbc[0].content_hash;
|
||||
// When a path is changed, it takes into account when the
|
||||
// creation event occurs first and the deletion occurs, not
|
||||
@ -52,7 +55,7 @@ export class ContentDiffHandler{
|
||||
console.log("update path from", cpath, "to", cf.path);
|
||||
const newFilename = basename(cf.path);
|
||||
const newBasepath = dirname(cf.path);
|
||||
await this.waiting_list.deleteByHash(content_hash);
|
||||
this.waiting_list.deleteByHash(content_hash);
|
||||
await this.doc_cntr.update({
|
||||
id: dbc[0].id,
|
||||
deleted_at: null,
|
||||
@ -72,31 +75,47 @@ export class ContentDiffHandler{
|
||||
const basepath = dirname(cpath);
|
||||
const filename = basename(cpath);
|
||||
console.log("createContentFile", cpath);
|
||||
const content = createContentFile(this.content_type,pathjoin(basepath,filename));
|
||||
const content = createContentFile(this.content_type, cpath);
|
||||
const hash = await content.getHash();
|
||||
const c = this.tombstone.get(hash);
|
||||
if (c !== undefined) {
|
||||
this.doc_cntr.update({
|
||||
await this.doc_cntr.update({
|
||||
id: c.id,
|
||||
deleted_at: null,
|
||||
filename: filename,
|
||||
basepath: basepath
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (this.waiting_list.hasByHash(hash)) {
|
||||
console.log("Conflict!!!");
|
||||
console.log("Hash Conflict!!!");
|
||||
}
|
||||
this.waiting_list.set(content);
|
||||
|
||||
}
|
||||
private async OnChanged(prev_path: string, cur_path: string) {
|
||||
const prev_basepath = dirname(prev_path);
|
||||
const prev_filename = basename(prev_path);
|
||||
const cur_basepath = dirname(cur_path);
|
||||
const cur_filename = basename(cur_path);
|
||||
console.log("modify", cur_path, "from", prev_path);
|
||||
const c = this.waiting_list.getByPath(prev_path);
|
||||
if(c !== undefined){
|
||||
await this.waiting_list.delete(c);
|
||||
const content = createContentFile(this.content_type, cur_path);
|
||||
await this.waiting_list.set(content);
|
||||
return;
|
||||
}
|
||||
const doc = await this.doc_cntr.findByPath(prev_basepath, prev_filename);
|
||||
await this.doc_cntr.update({...doc[0],
|
||||
|
||||
if(doc.length === 0){
|
||||
await this.OnCreated(cur_path);
|
||||
return;
|
||||
}
|
||||
|
||||
await this.doc_cntr.update({
|
||||
...doc[0],
|
||||
basepath: cur_basepath,
|
||||
filename:cur_filename});
|
||||
filename: cur_filename
|
||||
});
|
||||
}
|
||||
}
|
@ -39,12 +39,15 @@ export class ContentList{
|
||||
async deleteByPath(p:string){
|
||||
const o = this.getByPath(p);
|
||||
if(o === undefined) return false;
|
||||
return this.delete(o);
|
||||
return await this.delete(o);
|
||||
}
|
||||
async deleteByHash(s:string){
|
||||
deleteByHash(s:string){
|
||||
const o = this.getByHash(s);
|
||||
if(o === undefined) return false;
|
||||
return this.delete(o);
|
||||
let r = true;
|
||||
r = this.cl.delete(o.path) && r;
|
||||
r = this.hl.delete(s) && r;
|
||||
return r;
|
||||
}
|
||||
clear(){
|
||||
this.cl.clear();
|
||||
|
@ -73,6 +73,7 @@ const ContentQueryHandler = (controller : DocumentAccessor) => async (ctx: Conte
|
||||
}
|
||||
const UpdateContentHandler = (controller : DocumentAccessor) => async (ctx: Context, next: Next) => {
|
||||
const num = Number.parseInt(ctx.params['num']);
|
||||
|
||||
if(ctx.request.type !== 'json'){
|
||||
return sendError(400,"update fail. invalid document type: it is not json.");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user