fix: sync incoming segment

This commit is contained in:
Michal Szczepanski 2023-09-25 09:10:04 +02:00
parent be5ab59687
commit 36f0a47558
2 changed files with 14 additions and 14 deletions

@ -35,7 +35,6 @@ export class PageSegmentAddRefCommand implements ICommand<Promise<boolean>> {
const key = `${ObjectStoreKeys.CONTENT_HASH_COUNT}:${this.hash}`;
let count = (await BrowserStorage.get<number | undefined>(key)) || 0;
count++;
fnConsoleLog('PageSegmentAddRefCommand->incrementCount', count);
await BrowserStorage.set(key, count);
}
}

@ -106,23 +106,23 @@ export class SyncSnapshotIncomingCommand implements ICommand<Promise<boolean>> {
private getSnapshot = async (hashList: SegmentHashListResponse): Promise<PageSnapshotDto | undefined> => {
let data: PageSnapshotDataDto | undefined;
let info: PageSnapshotInfoDto | undefined;
const segment: string | undefined = undefined;
let segment: string | undefined = undefined;
for (const child of hashList.children) {
const segment = await new ApiSegmentGetCommand(child.hash).execute();
if (!segment) continue;
const segmentData = await new ApiSegmentGetCommand(child.hash).execute();
if (!segmentData) continue;
switch (child.type.toString()) {
case SyncHashType.Img: {
const src = await UrlFactory.toDataUri(segment);
const has = new PageSegmentAddRefCommand(child.hash);
const src = await UrlFactory.toDataUri(segmentData);
const has = await new PageSegmentAddRefCommand(child.hash).execute();
if (has) break;
const content: SegmentImg = { src };
await new PageSegmentAddCommand({ type: SegmentType.IMG, hash: child.hash, content }).execute();
break;
}
case SyncHashType.Css: {
const has = new PageSegmentAddRefCommand(child.hash);
const has = await new PageSegmentAddRefCommand(child.hash).execute();
if (has) break;
const content = await this.getString(segment);
const content = await this.getString(segmentData);
await new PageSegmentAddCommand({
type: SegmentType.CSS,
hash: child.hash,
@ -131,9 +131,9 @@ export class SyncSnapshotIncomingCommand implements ICommand<Promise<boolean>> {
break;
}
case SyncHashType.IFrame: {
const has = new PageSegmentAddRefCommand(child.hash);
const has = await new PageSegmentAddRefCommand(child.hash).execute();
if (has) break;
const content = await this.getString(segment);
const content = await this.getString(segmentData);
await new PageSegmentAddCommand({
type: SegmentType.IFRAME,
hash: child.hash,
@ -142,19 +142,20 @@ export class SyncSnapshotIncomingCommand implements ICommand<Promise<boolean>> {
break;
}
case SyncHashType.PageSnapshotDataDto: {
const content = await this.getString(segment);
const content = await this.getString(segmentData);
data = JSON.parse(content);
break;
}
case SyncHashType.PageSnapshotInfoDto: {
const content = await this.getString(segment);
const content = await this.getString(segmentData);
info = JSON.parse(content);
break;
}
case SyncHashType.PageSnapshotFirstHash: {
const content = await this.getString(segment);
segment = child.hash;
const content = await this.getString(segmentData);
const html: SegmentHtml = JSON.parse(content);
fnConsoleLog('SyncSnapshotIncomingCommand->getSnapshot->PageSnapshotFirstHash', html.hash, child.hash);
fnConsoleLog('SyncSnapshotIncomingCommand->getSnapshot->PageSnapshotFirstHash', html, child.hash);
await new PageSegmentAddCommand({
type: SegmentType.SNAPSHOT,
content: html,