v3: added opengraph support to the app, wrote README instructions incl. a Docker image
This commit is contained in:
@@ -2,6 +2,7 @@ import type { RichContent } from "../model/interfaces.ts";
|
||||
import { youtubeProvider } from "./providers/youtube.ts";
|
||||
import { bandcampProvider } from "./providers/bandcamp.ts";
|
||||
import { soundcloudProvider } from "./providers/soundcloud.ts";
|
||||
import { selfProvider } from "./providers/self.ts";
|
||||
import { genericProvider } from "./providers/generic.ts";
|
||||
|
||||
export interface RichContentProvider {
|
||||
@@ -12,12 +13,14 @@ export interface RichContentProvider {
|
||||
|
||||
/**
|
||||
* Register providers in priority order. The first match wins.
|
||||
* `selfProvider` resolves gerbeur URLs directly from the DB (no HTTP round-trip).
|
||||
* `genericProvider` must stay last — it always matches.
|
||||
*/
|
||||
const providers: RichContentProvider[] = [
|
||||
youtubeProvider,
|
||||
bandcampProvider,
|
||||
soundcloudProvider,
|
||||
selfProvider,
|
||||
genericProvider,
|
||||
];
|
||||
|
||||
@@ -86,11 +89,17 @@ function isPrivateHost(hostname: string): boolean {
|
||||
return /^(127\.|10\.|172\.(1[6-9]|2\d|3[01])\.|192\.168\.)/.test(hostname);
|
||||
}
|
||||
|
||||
const SELF_PATH_RE = /^\/(dumps|users|playlists)\/[^/]+$/;
|
||||
|
||||
export function isValidHttpUrl(raw: string): boolean {
|
||||
try {
|
||||
const u = new URL(raw);
|
||||
if (u.protocol !== "http:" && u.protocol !== "https:") return false;
|
||||
if (isPrivateHost(u.hostname)) return false;
|
||||
// Allow private hosts for self-referential gerbeur URLs — they are
|
||||
// resolved directly from the DB by selfProvider, no outbound HTTP needed.
|
||||
if (isPrivateHost(u.hostname) && !SELF_PATH_RE.test(u.pathname)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user