URLプレビューのサムネイルを隠す機能を追加 (MisskeyIO#214)

This commit is contained in:
CyberRex 2023-11-07 02:31:26 +09:00 committed by GitHub
parent f229e26312
commit ec5e1df9f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 76 additions and 1 deletions

View file

@ -5,6 +5,7 @@
import { Inject, Injectable } from '@nestjs/common';
import { summaly } from 'summaly';
import RE2 from 're2';
import { DI } from '@/di-symbols.js';
import type { Config } from '@/config.js';
import { MetaService } from '@/core/MetaService.js';
@ -94,6 +95,23 @@ export class UrlPreviewService {
summary.icon = this.wrap(summary.icon);
summary.thumbnail = this.wrap(summary.thumbnail);
const includeDenyList = meta.urlPreviewDenyList.some(filter => {
// represents RegExp
const regexp = /^\/(.+)\/(.*)$/.exec(filter);
// This should never happen due to input sanitisation.
if (!regexp) {
const words = filter.split(' ');
return words.every(keyword => summary.url.includes(keyword));
}
try {
return new RE2(regexp[1], regexp[2]).test(summary.url);
} catch (err) {
// This should never happen due to input sanitisation.
return false;
}
});
if (includeDenyList) summary.sensitive = true;
// Cache 7days
reply.header('Cache-Control', 'max-age=604800, immutable');