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