Skip to content
This repository has been archived by the owner on Aug 15, 2023. It is now read-only.

Commit

Permalink
fix(yttrex): codec configuration for metadata logger ui
Browse files Browse the repository at this point in the history
  • Loading branch information
ascariandrea committed Sep 21, 2022
1 parent bcefe52 commit 86af530
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 17 deletions.
36 changes: 34 additions & 2 deletions platforms/yttrex/extension/src/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

import { boot } from '@shared/extension/app';
import { bo } from '@shared/extension/utils/browser.utils';
import { youtubeDomainRegExp } from '@yttrex/shared/parsers/selectors';
import { getParser } from '@yttrex/shared/parsers/parser/html';
import { youtubeDomainRegExp } from '@yttrex/shared/parsers/selectors';
import * as E from 'fp-ts/lib/Either';
import * as hubHandlers from '../handlers/events';
import ytHub from '../handlers/hub';
import { ContributionEvent, NEW_VIDEO_EVENT } from '../models/HubEvent';
import { onLocationChange, watchedPaths, ytLogger, ytTrexActions } from './app';

bo.runtime.sendMessage({ type: 'chromeConfig' }, (config) => {
Expand Down Expand Up @@ -38,7 +40,37 @@ bo.runtime.sendMessage({ type: 'chromeConfig' }, (config) => {
},
onAuthenticated: ytTrexActions,
ui: {
getParser,
metadataLogger: {
getParser: (db) => {
return getParser(
db,
{ contribution: 'contributions', metadata: 'metadata' },
(contribution) => ({
...contribution,
jsdom: new DOMParser().parseFromString(
contribution.html.html,
'text/html'
),
})
);
},
mapEvent: (e: any) => {
if (e.type === NEW_VIDEO_EVENT.value) {
return {
...e,
};
}
return e;
},
decode: (e: any) => {
// return E.right(null) for events that don't need parsing
if (['APIEvent', 'SyncResponse', 'WindowUnload'].includes(e.type)) {
return E.right(null);
}

return ContributionEvent.decode(e);
},
},
},
});
} catch (e) {
Expand Down
79 changes: 64 additions & 15 deletions platforms/yttrex/extension/src/models/HubEvent.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,68 @@
import { HubEvent, HubEventBase } from '@shared/extension/models/HubEvent';
import { HubEvent } from '@shared/extension/models/HubEvent';
import * as t from 'io-ts';

export interface NewVideoEvent extends HubEventBase {
type: 'NewVideo';
payload: {
type: number | undefined;
element: string;
size: number;
href: string;
randomUUID: string;
};
}
export const NEW_VIDEO_EVENT = t.literal('NewVideo');
export type NEW_VIDEO_EVENT = t.TypeOf<typeof NEW_VIDEO_EVENT>;
export const NewVideoEvent = t.type(
{
type: NEW_VIDEO_EVENT,
payload: t.type(
{
type: t.string,
element: t.string,
size: t.number,
href: t.string,
html: t.string,
randomUUID: t.string,
feedCounter: t.number,
videoCounter: t.number,
rect: t.type(
{
height: t.number,
width: t.number,
x: t.number,
y: t.number,
bottom: t.union([t.number, t.undefined]),
left: t.union([t.number, t.undefined]),
right: t.union([t.number, t.undefined]),
top: t.union([t.number, t.undefined]),
},
'DOMRect'
),
},
'NewVideoPayload'
),
},
'NewVideoEvent'
);
export type NewVideoEvent = t.TypeOf<typeof NewVideoEvent>;

export interface NewLeafEvent extends HubEventBase {
type: 'leaf';
payload: {};
}
export const LEAF_EVENT = t.literal('leaf');
export type LEAF_EVENT = t.TypeOf<typeof LEAF_EVENT>;
export const NewLeafEvent = t.type(
{
type: LEAF_EVENT,
payload: t.type(
{
type: t.string,
element: t.string,
size: t.number,
href: t.string,
html: t.string,
randomUUID: t.string,
feedCounter: t.number,
videoCounter: t.number,
},
'NewVideoPayload'
),
},
'NewLeafEvent'
);
export type NewLeafEvent = t.TypeOf<typeof NewLeafEvent>;

export const ContributionEvent = t.union(
[NewVideoEvent, NewLeafEvent],
'ContributionEvent'
);

export type YTHubEvent = HubEvent | NewVideoEvent | NewLeafEvent;

0 comments on commit 86af530

Please sign in to comment.