-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
d2b2bf5
commit 879c6cd
Showing
20 changed files
with
363 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 17 additions & 14 deletions
31
apps/server/src/modules/meta-tag-extractor/service/url-handler/abstract-url-handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,38 @@ | ||
import { basename } from 'node:path'; | ||
import { MetaData } from '../../types'; | ||
import { MetaData, MetaDataEntityType } from '../../types'; | ||
|
||
export abstract class AbstractUrlHandler { | ||
protected abstract patterns: RegExp[]; | ||
|
||
protected extractId(url: URL): string | undefined { | ||
const results: RegExpMatchArray = this.patterns | ||
.map((pattern: RegExp) => pattern.exec(url.toString())) | ||
.filter((result) => result !== null) | ||
.find((result) => (result?.length ?? 0) >= 2) as RegExpMatchArray; | ||
const results: RegExpExecArray | undefined = this.patterns | ||
.map((pattern: RegExp) => pattern.exec(url.pathname)) | ||
.filter((result: RegExpExecArray | null): result is RegExpExecArray => result !== null) | ||
.find((result: RegExpExecArray) => result.length >= 2); | ||
|
||
if (results && results[1]) { | ||
return results[1]; | ||
} | ||
|
||
return undefined; | ||
} | ||
|
||
doesUrlMatch(url: URL): boolean { | ||
const doesMatch = this.patterns.some((pattern) => pattern.test(url.toString())); | ||
public doesUrlMatch(url: URL): boolean { | ||
const doesMatch = this.patterns.some((pattern) => pattern.test(url.pathname)); | ||
|
||
return doesMatch; | ||
} | ||
|
||
getDefaultMetaData(url: URL, partial: Partial<MetaData> = {}): MetaData { | ||
const urlObject = new URL(url); | ||
const title = basename(urlObject.pathname); | ||
public getDefaultMetaData(url: URL, partial: Partial<MetaData> = {}): MetaData { | ||
const urlObject: URL = new URL(url); | ||
const title: string = basename(urlObject.pathname); | ||
|
||
return { | ||
title, | ||
description: '', | ||
url: url.toString(), | ||
type: 'unknown', | ||
...partial, | ||
title: partial.title ?? title, | ||
description: partial.description ?? '', | ||
url: partial.url ?? url.toString(), | ||
type: partial.type ?? MetaDataEntityType.UNKNOWN, | ||
}; | ||
} | ||
} |
Oops, something went wrong.