-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP WIP # Conflicts: # packages/worker/package.json # packages/worker/workers/bookmark-initializer/index.js Deps WIP Refactor PgClient types WIP
- Loading branch information
Showing
58 changed files
with
1,017 additions
and
433 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
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* @import { Queue, Worker, Processor } from 'bullmq' | ||
*/ | ||
|
||
/** | ||
* Data relating to resolve document jobs | ||
* | ||
* @typedef {{ | ||
* url: string | ||
* userId: string | ||
* archive: boolean | ||
* archiveId: string | ||
* archiveURL: string | ||
* }} ResolveArchiveData | ||
*/ | ||
|
||
export const resolveArchiveQName = 'resolveArchive' | ||
export const resolveArchiveJobName = 'resolve-archive' | ||
|
||
/** | ||
* @typedef {Queue< | ||
* ResolveArchiveData, | ||
* null, | ||
* typeof resolveArchiveJobName | ||
* >} ResolveArchiveQ | ||
*/ | ||
|
||
/** | ||
* @typedef {Worker< | ||
* ResolveArchiveData, | ||
* null, | ||
* typeof resolveArchiveJobName | ||
* >} ResolveArchiveW | ||
*/ | ||
|
||
/** | ||
* @typedef {Processor< | ||
* ResolveArchiveData, | ||
* null, | ||
* typeof resolveArchiveJobName | ||
* >} ResolveArchiveP | ||
*/ |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* Normalizes a URL object by modifying its host property if necessary. | ||
* | ||
* @param {URL} url - The URL string to be normalized. | ||
* @returns {Promise<URL>} An object containing the normalized URL string. | ||
*/ | ||
export async function normalizeURL (url) { | ||
if (url.host === 'm.youtube.com') url.host = 'www.youtube.com' | ||
return url | ||
} |
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* @import { Queue, Worker, Processor } from 'bullmq' | ||
*/ | ||
|
||
/** | ||
* User-provided metadata for a bookmark. | ||
* | ||
* @typedef {{ | ||
* title: string | ||
* tags: string[] | ||
* summary: string | ||
* }} UserProvidedMeta | ||
*/ | ||
|
||
/** | ||
* Data required to initialize a bookmark. | ||
* | ||
* @typedef {{ | ||
* userId: string | ||
* bookmarkId: string | ||
* url: string | ||
* resolveBookmark: boolean | ||
* resolveArchive: boolean | ||
* resolveEpisode: boolean | ||
* userProvidedMeta: UserProvidedMeta | ||
* }} ResolveBookmarkData | ||
*/ | ||
|
||
export const resolveBookmarkQName = 'resolveBookmark' | ||
export const resolveBookmarkJobName = 'resolve-bookmark' | ||
|
||
/** | ||
* @typedef {Queue< | ||
* ResolveBookmarkData, | ||
* null, | ||
* typeof resolveBookmarkJobName | ||
* >} ResolveBookmarkQ | ||
*/ | ||
|
||
/** | ||
* @typedef {Worker< | ||
* ResolveBookmarkData, | ||
* null, | ||
* typeof resolveBookmarkJobName | ||
* >} ResolveBookmarkW | ||
*/ | ||
|
||
/** | ||
* @typedef {Processor< | ||
* ResolveBookmarkData, | ||
* null, | ||
* typeof resolveBookmarkJobName | ||
* >} ResolveBookmarkP | ||
*/ |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* @import { JobsOptions } from 'bullmq' | ||
*/ | ||
|
||
/** @type {JobsOptions} */ | ||
export const defaultJobOptions = { | ||
removeOnComplete: { | ||
age: 3600, // keep up to 1 hour | ||
count: 1000, // keep up to 1000 jobs | ||
}, | ||
removeOnFail: { | ||
age: 24 * 3600, // keep up to 24 hours | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* @import { Queue, Worker, Processor } from 'bullmq' | ||
* @import { MediumTypes } from './yt-dlp-api-client.js' | ||
*/ | ||
|
||
/** | ||
* Data required to resolve an episode. | ||
* | ||
* @typedef {{ | ||
* userId: string | ||
* bookmarkTitle: string | ||
* episodeId: string | ||
* url: string | ||
* medium: MediumTypes | ||
* }} ResolveEpisodeData | ||
*/ | ||
|
||
export const resolveEpisodeQName = 'resolveEpisode' | ||
export const resolveEpisodeJobName = 'resolve-episode' | ||
|
||
/** | ||
* @typedef {Queue< | ||
* ResolveEpisodeData, | ||
* null, | ||
* typeof resolveEpisodeJobName | ||
* >} ResolveEpisodeQ | ||
*/ | ||
|
||
/** | ||
* @typedef {Worker< | ||
* ResolveEpisodeData, | ||
* null, | ||
* typeof resolveEpisodeJobName | ||
* >} ResolveEpisodeW | ||
*/ | ||
|
||
/** | ||
* @typedef {Processor< | ||
* ResolveEpisodeData, | ||
* null, | ||
* typeof resolveEpisodeJobName | ||
* >} ResolveEpisodeP | ||
*/ |
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,15 +1,15 @@ | ||
/** | ||
* @param {object} metadata | ||
* @param {string} [metadata.ext] | ||
* @param {string} [metadata._type] | ||
* @param {object} media | ||
* @param {string} [media.ext] | ||
* @param {string} [media._type] | ||
* @return {'audio' | 'video' | string | null | undefined } | ||
*/ | ||
export function resolveType (metadata) { | ||
export function resolveType (media) { | ||
return ( | ||
['mp3', 'm4a'].includes(metadata.ext ?? '') | ||
['mp3', 'm4a'].includes(media.ext ?? '') | ||
? 'audio' | ||
: ['mp4', 'mov', 'm3u8'].includes(metadata.ext ?? '') | ||
: ['mp4', 'mov', 'm3u8'].includes(media.ext ?? '') | ||
? 'video' | ||
: metadata._type | ||
: media._type | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { PoolClient } from 'pg' | ||
import { PostgresDb } from '@fastify/postgres' | ||
|
||
export type PgClient = PoolClient | PostgresDb |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* @param {Url} url A URL object to check | ||
* @return {[type]} [description] | ||
*/ | ||
export async function ssrfCheck (url) { | ||
try { | ||
// Validate protocol | ||
if (url.protocol !== 'https:' && url.protocol !== 'http:') { | ||
return { | ||
ssrf: false | ||
} | ||
} | ||
|
||
// Block cloud metadata endpoints | ||
const blockedHostnames = ['169.254.169.254', 'metadata.google.internal'] | ||
if (blockedHostnames.includes(url.hostname)) { | ||
return false // Block specific metadata endpoints | ||
} | ||
|
||
// Resolve hostname to IP addresses | ||
const addresses = await dns.lookup(url.hostname, { all: true }) | ||
|
||
// Validate each resolved IP | ||
for (const { address } of addresses) { | ||
if (isBlockedIP(address)) { | ||
return false // Blocked IP detected | ||
} | ||
} | ||
|
||
// Additional DNS rebinding check | ||
await dnsRebindingCheck(url.hostname) | ||
|
||
return true // Passed all checks, URL is safe | ||
} catch (err) { | ||
console.error('Error validating URL:', err.message) | ||
return false // Fail closed on error | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
alter table bookmarks | ||
add column original_url text; | ||
|
||
comment on column bookmarks.original_url is 'The original, unnormalized URL of the bookmark.'; |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
alter table bookmarks | ||
drop column if exists original_url; |
Oops, something went wrong.