URLプレビューのサムネイルを隠す機能を追加 (MisskeyIO#214)
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
export class UrlPreviewDenyList1699284486293 {
|
||||
name = 'UrlPreviewDenyList1699284486293'
|
||||
|
||||
async up(queryRunner) {
|
||||
await queryRunner.query(`ALTER TABLE "meta" ADD "urlPreviewDenyList" character varying(3072) array NOT NULL DEFAULT '{}'`);
|
||||
}
|
||||
|
||||
async down(queryRunner) {
|
||||
await queryRunner.query(`ALTER TABLE "meta" DROP COLUMN "urlPreviewDenyList"`);
|
||||
}
|
||||
}
|
@@ -468,4 +468,9 @@ export class MiMeta {
|
||||
default: 300,
|
||||
})
|
||||
public perUserListTimelineCacheMax: number;
|
||||
|
||||
@Column('varchar', {
|
||||
length: 3072, array: true, default: '{}',
|
||||
})
|
||||
public urlPreviewDenyList: string[];
|
||||
}
|
||||
|
@@ -298,6 +298,14 @@ export const meta = {
|
||||
type: 'number',
|
||||
optional: false, nullable: false,
|
||||
},
|
||||
urlPreviewDenyList: {
|
||||
type: 'array',
|
||||
optional: true, nullable: false,
|
||||
items: {
|
||||
type: 'string',
|
||||
optional: false, nullable: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} as const;
|
||||
@@ -404,6 +412,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||
perRemoteUserUserTimelineCacheMax: instance.perRemoteUserUserTimelineCacheMax,
|
||||
perUserHomeTimelineCacheMax: instance.perUserHomeTimelineCacheMax,
|
||||
perUserListTimelineCacheMax: instance.perUserListTimelineCacheMax,
|
||||
urlPreviewDenyList: instance.urlPreviewDenyList,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
@@ -110,6 +110,9 @@ export const paramDef = {
|
||||
perRemoteUserUserTimelineCacheMax: { type: 'integer' },
|
||||
perUserHomeTimelineCacheMax: { type: 'integer' },
|
||||
perUserListTimelineCacheMax: { type: 'integer' },
|
||||
urlPreviewDenyList: { type: 'array', nullable: true, items: {
|
||||
type: 'string',
|
||||
} },
|
||||
},
|
||||
required: [],
|
||||
} as const;
|
||||
@@ -147,6 +150,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||
set.sensitiveWords = ps.sensitiveWords.filter(Boolean);
|
||||
}
|
||||
|
||||
if (Array.isArray(ps.urlPreviewDenyList)) {
|
||||
set.urlPreviewDenyList = ps.urlPreviewDenyList.filter(Boolean);
|
||||
}
|
||||
|
||||
if (ps.themeColor !== undefined) {
|
||||
set.themeColor = ps.themeColor;
|
||||
}
|
||||
|
@@ -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');
|
||||
|
||||
|
Reference in New Issue
Block a user