Skip to content

Commit

Permalink
Fix version preview
Browse files Browse the repository at this point in the history
  • Loading branch information
Ndpnt committed Feb 18, 2025
1 parent 73537bb commit c6dcb64
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions src/modules/Common/services/open-terms-archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,38 @@ export type OTASelector = string | OTARangeSelector;
export interface OTAJson {
name: string;
terms: {
[key: string]: OTAPageDeclaration;
[key: string]: OTATermsDeclaration;
};
}
interface OTASnapshot {
content: string;
mimeType: string;
declaration: OTATermsDeclaration;
}

export interface OTAPageDeclaration {
export interface OTATermsDeclaration {
fetch: string;
select?: string | OTASelector[];
remove?: string | OTASelector[];
executeClientScripts?: boolean;
extract?: string[];
combine?: OTAPageDeclaration[];
combine?: OTATermsDeclaration[];
}

type OTAVersion = string;

export interface Snapshot {
content: string;
mimeType: string;
pageDeclaration: OTAPageDeclaration;
}

export const getSnapshot = async (
pageDeclaration: OTAPageDeclaration,
declaration: OTATermsDeclaration,
config: any
): Promise<Snapshot> => {
): Promise<OTASnapshot> => {
await launchHeadlessBrowser();
const { content, mimeType }: OTASnapshot = await fetch({
url: pageDeclaration.fetch,
executeClientScripts: pageDeclaration.executeClientScripts,
url: declaration.fetch,
executeClientScripts: declaration.executeClientScripts,
cssSelectors: [
...SourceDocument.extractCssSelectorsFromProperty(pageDeclaration.select),
...SourceDocument.extractCssSelectorsFromProperty(pageDeclaration.remove),
...SourceDocument.extractCssSelectorsFromProperty(declaration.select),
...SourceDocument.extractCssSelectorsFromProperty(declaration.remove),
].filter(Boolean),
config: { ...{ navigationTimeout: 30000, language: 'en', waitForElementsTimeout: 10000 }, ...config },
});
Expand All @@ -58,19 +54,17 @@ export const getSnapshot = async (
return {
content,
mimeType,
pageDeclaration,
declaration
};
};

export const getVersionFromSnapshot = async ({ content, mimeType, pageDeclaration }: Snapshot) => {
export const getVersionFromSnapshot = async ({ content, mimeType, declaration }: OTASnapshot) => {
const version: OTAVersion = await extract({
content,
mimeType,
pageDeclaration: {
location: pageDeclaration.fetch,
contentSelectors: pageDeclaration.select,
noiseSelectors: pageDeclaration.remove,
},
location: declaration.fetch,
contentSelectors: declaration.select,
noiseSelectors: declaration.remove,
});

return {
Expand All @@ -80,8 +74,8 @@ export const getVersionFromSnapshot = async ({ content, mimeType, pageDeclaratio
};
};

export const getVersion = async (pageDeclaration: OTAPageDeclaration, config: any) => {
const snapshot = await getSnapshot(pageDeclaration, config);
export const getVersion = async (declaration: OTATermsDeclaration, config: any) => {
const snapshot = await getSnapshot(declaration, config);

return getVersionFromSnapshot(snapshot);
};
Expand All @@ -91,7 +85,7 @@ export const getVersion = async (pageDeclaration: OTAPageDeclaration, config: an
// different each time a new selector is added.
// This is the same if language changes
export const generateFolderName = (
{ fetch, select, executeClientScripts }: OTAPageDeclaration,
{ fetch, select, executeClientScripts }: OTATermsDeclaration,
additionalParameter?: string
) => {
const MAX_FOLDER_CHARACTERS = 256;
Expand Down

0 comments on commit c6dcb64

Please sign in to comment.