URLプレビューのサムネイルを隠す機能を追加 (MisskeyIO#214)
This commit is contained in:
parent
f229e26312
commit
ec5e1df9f5
11 changed files with 76 additions and 1 deletions
|
@ -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');
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue