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

Commit bd8adaa

Browse files
committed
fix(yttrex): codec configuration for metadata logger ui
1 parent 47a4483 commit bd8adaa

File tree

2 files changed

+98
-17
lines changed

2 files changed

+98
-17
lines changed

platforms/yttrex/extension/src/app/index.ts

+34-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33

44
import { boot } from '@shared/extension/app';
55
import { bo } from '@shared/extension/utils/browser.utils';
6-
import { youtubeDomainRegExp } from '@yttrex/shared/parsers/selectors';
76
import { getParser } from '@yttrex/shared/parsers/parser/html';
7+
import { youtubeDomainRegExp } from '@yttrex/shared/parsers/selectors';
8+
import * as E from 'fp-ts/lib/Either';
89
import * as hubHandlers from '../handlers/events';
910
import ytHub from '../handlers/hub';
11+
import { ContributionEvent, NEW_VIDEO_EVENT } from '../models/HubEvent';
1012
import { onLocationChange, watchedPaths, ytLogger, ytTrexActions } from './app';
1113

1214
bo.runtime.sendMessage({ type: 'chromeConfig' }, (config) => {
@@ -38,7 +40,37 @@ bo.runtime.sendMessage({ type: 'chromeConfig' }, (config) => {
3840
},
3941
onAuthenticated: ytTrexActions,
4042
ui: {
41-
getParser,
43+
metadataLogger: {
44+
getParser: (db) => {
45+
return getParser(
46+
db,
47+
{ contribution: 'contributions', metadata: 'metadata' },
48+
(contribution) => ({
49+
...contribution,
50+
jsdom: new DOMParser().parseFromString(
51+
contribution.html.html,
52+
'text/html'
53+
),
54+
})
55+
);
56+
},
57+
mapEvent: (e: any) => {
58+
if (e.type === NEW_VIDEO_EVENT.value) {
59+
return {
60+
...e,
61+
};
62+
}
63+
return e;
64+
},
65+
decode: (e: any) => {
66+
// return E.right(null) for events that don't need parsing
67+
if (['APIEvent', 'SyncResponse', 'WindowUnload'].includes(e.type)) {
68+
return E.right(null);
69+
}
70+
71+
return ContributionEvent.decode(e);
72+
},
73+
},
4274
},
4375
});
4476
} catch (e) {
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,68 @@
1-
import { HubEvent, HubEventBase } from '@shared/extension/models/HubEvent';
1+
import { HubEvent } from '@shared/extension/models/HubEvent';
2+
import * as t from 'io-ts';
23

3-
export interface NewVideoEvent extends HubEventBase {
4-
type: 'NewVideo';
5-
payload: {
6-
type: number | undefined;
7-
element: string;
8-
size: number;
9-
href: string;
10-
randomUUID: string;
11-
};
12-
}
4+
export const NEW_VIDEO_EVENT = t.literal('NewVideo');
5+
export type NEW_VIDEO_EVENT = t.TypeOf<typeof NEW_VIDEO_EVENT>;
6+
export const NewVideoEvent = t.type(
7+
{
8+
type: NEW_VIDEO_EVENT,
9+
payload: t.type(
10+
{
11+
type: t.string,
12+
element: t.string,
13+
size: t.number,
14+
href: t.string,
15+
html: t.string,
16+
randomUUID: t.string,
17+
feedCounter: t.number,
18+
videoCounter: t.number,
19+
rect: t.type(
20+
{
21+
height: t.number,
22+
width: t.number,
23+
x: t.number,
24+
y: t.number,
25+
bottom: t.union([t.number, t.undefined]),
26+
left: t.union([t.number, t.undefined]),
27+
right: t.union([t.number, t.undefined]),
28+
top: t.union([t.number, t.undefined]),
29+
},
30+
'DOMRect'
31+
),
32+
},
33+
'NewVideoPayload'
34+
),
35+
},
36+
'NewVideoEvent'
37+
);
38+
export type NewVideoEvent = t.TypeOf<typeof NewVideoEvent>;
1339

14-
export interface NewLeafEvent extends HubEventBase {
15-
type: 'leaf';
16-
payload: {};
17-
}
40+
export const LEAF_EVENT = t.literal('leaf');
41+
export type LEAF_EVENT = t.TypeOf<typeof LEAF_EVENT>;
42+
export const NewLeafEvent = t.type(
43+
{
44+
type: LEAF_EVENT,
45+
payload: t.type(
46+
{
47+
type: t.string,
48+
element: t.string,
49+
size: t.number,
50+
href: t.string,
51+
html: t.string,
52+
randomUUID: t.string,
53+
feedCounter: t.number,
54+
videoCounter: t.number,
55+
},
56+
'NewVideoPayload'
57+
),
58+
},
59+
'NewLeafEvent'
60+
);
61+
export type NewLeafEvent = t.TypeOf<typeof NewLeafEvent>;
62+
63+
export const ContributionEvent = t.union(
64+
[NewVideoEvent, NewLeafEvent],
65+
'ContributionEvent'
66+
);
1867

1968
export type YTHubEvent = HubEvent | NewVideoEvent | NewLeafEvent;

0 commit comments

Comments
 (0)