mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
regex guard around opengraph routes
This commit is contained in:
parent
f48d8e0a66
commit
2283f64204
2 changed files with 8 additions and 4 deletions
|
|
@ -250,6 +250,10 @@ class Conf {
|
||||||
static get cronEnabled(): boolean {
|
static get cronEnabled(): boolean {
|
||||||
return optionalBooleanSchema.parse(Deno.env.get('CRON_ENABLED')) ?? true;
|
return optionalBooleanSchema.parse(Deno.env.get('CRON_ENABLED')) ?? true;
|
||||||
}
|
}
|
||||||
|
static get opengraphRouteRegex(): string {
|
||||||
|
return Deno.env.get('OPENGRAPH_ROUTE_REGEX') ||
|
||||||
|
'googlebot|bingbot|yandex|baiduspider|twitterbot|facebookexternalhit|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterestbot|slackbot|vkShare|W3C_Validator|whatsapp|mastodon|pleroma|Discordbot|AhrefsBot|SEMrushBot|MJ12bot|SeekportBot|Synapse|Matrix';
|
||||||
|
}
|
||||||
/** Path to the custom policy module. Must be an absolute path, https:, npm:, or jsr: URI. */
|
/** Path to the custom policy module. Must be an absolute path, https:, npm:, or jsr: URI. */
|
||||||
static get policy(): string {
|
static get policy(): string {
|
||||||
return Deno.env.get('DITTO_POLICY') || new URL('../data/policy.ts', import.meta.url).pathname;
|
return Deno.env.get('DITTO_POLICY') || new URL('../data/policy.ts', import.meta.url).pathname;
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,6 @@ const console = new Stickynotes('ditto:frontend');
|
||||||
/** Placeholder to find & replace with metadata. */
|
/** Placeholder to find & replace with metadata. */
|
||||||
const META_PLACEHOLDER = '<!--server-generated-meta-->' as const;
|
const META_PLACEHOLDER = '<!--server-generated-meta-->' as const;
|
||||||
|
|
||||||
/*
|
|
||||||
* TODO: implement caching for posts (LRUCache)
|
|
||||||
*/
|
|
||||||
|
|
||||||
async function buildTemplateOpts(params: PathParams, url: string): Promise<OpenGraphTemplateOpts> {
|
async function buildTemplateOpts(params: PathParams, url: string): Promise<OpenGraphTemplateOpts> {
|
||||||
const store = await Storages.db();
|
const store = await Storages.db();
|
||||||
const meta = await getInstanceMetadata(store);
|
const meta = await getInstanceMetadata(store);
|
||||||
|
|
@ -70,6 +66,10 @@ async function buildTemplateOpts(params: PathParams, url: string): Promise<OpenG
|
||||||
export const frontendController: AppMiddleware = async (c, next) => {
|
export const frontendController: AppMiddleware = async (c, next) => {
|
||||||
try {
|
try {
|
||||||
const content = await Deno.readTextFile(new URL('../../public/index.html', import.meta.url));
|
const content = await Deno.readTextFile(new URL('../../public/index.html', import.meta.url));
|
||||||
|
const shouldInject = new RegExp(Conf.opengraphRouteRegex, 'i');
|
||||||
|
if (!shouldInject) {
|
||||||
|
return c.html(content);
|
||||||
|
}
|
||||||
if (content.includes(META_PLACEHOLDER)) {
|
if (content.includes(META_PLACEHOLDER)) {
|
||||||
const params = getPathParams(c.req.path);
|
const params = getPathParams(c.req.path);
|
||||||
if (params) {
|
if (params) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue