Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: URLプレビューの動作改善+動作設定を可能にする #13579

Merged
merged 15 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
## Unreleased

### Note
- コントロールパネル内にあるサマリープロキシの設定個所がセキュリティから全般へ変更となります。

### General
- Enhance: URLプレビューの有効化・無効化を設定できるように #13569
- Enhance: アンテナでBotによるノートを除外できるように
(Cherry-picked from https://github.com/MisskeyIO/misskey/pull/545)
- Fix: Play作成時に設定した公開範囲が機能していない問題を修正
Expand All @@ -25,6 +29,7 @@

### Server
- Enhance: エンドポイント`antennas/update`の必須項目を`antennaId`のみに
- Enhance: misskey-dev/summaly@5.1.0の取り込み(プレビュー生成処理の効率化)
- Fix: フォローリクエストを作成する際に既存のものは削除するように
(Cherry-picked from https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/440)

Expand Down
58 changes: 58 additions & 0 deletions locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4916,6 +4916,10 @@ export interface Locale extends ILocale {
* リトライ
*/
"gameRetry": string;
/**
* 使用しない場合は空欄にしてください
*/
"notUsePleaseLeaveBlank": string;
"_bubbleGame": {
/**
* 遊び方
Expand Down Expand Up @@ -9768,6 +9772,60 @@ export interface Locale extends ILocale {
*/
"header": string;
};
"_urlPreviewSetting": {
/**
* URLプレビューの設定
*/
"title": string;
/**
* URLプレビューを有効にする
*/
"enable": string;
/**
* プレビュー取得時のタイムアウト(ms)
*/
"timeout": string;
/**
* プレビュー取得の所要時間がこの値を超えた場合、プレビューは生成されません。
*/
"timeoutDescription": string;
/**
* Content-Lengthの最大値(byte)
*/
"maximumContentLength": string;
/**
* Content-Lengthがこの値を超えた場合、プレビューは生成されません。
*/
"maximumContentLengthDescription": string;
/**
* Content-Lengthが取得できた場合のみプレビューを生成
*/
"requireContentLength": string;
/**
* 相手サーバがContent-Lengthを返さない場合、プレビューは生成されません。
*/
"requireContentLengthDescription": string;
/**
* User-Agent
*/
"userAgent": string;
/**
* プレビュー取得時に使用されるUser-Agentを設定します。空欄の場合、デフォルトのUser-Agentが使用されます。
*/
"userAgentDescription": string;
/**
* プレビューを生成するプロキシのエンドポイント
*/
"summaryProxy": string;
/**
* Misskey本体ではなく、サマリープロキシを使用してプレビューを生成します。
*/
"summaryProxyDescription": string;
/**
* プロキシには下記パラメータがクエリ文字列として連携されます。プロキシ側がこれらをサポートしない場合、設定値は無視されます。
*/
"summaryProxyDescription2": string;
};
}
declare const locales: {
[lang: string]: Locale;
Expand Down
15 changes: 15 additions & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,7 @@ enableHorizontalSwipe: "スワイプしてタブを切り替える"
loading: "読み込み中"
surrender: "やめる"
gameRetry: "リトライ"
notUsePleaseLeaveBlank: "使用しない場合は空欄にしてください"

_bubbleGame:
howToPlay: "遊び方"
Expand Down Expand Up @@ -2602,3 +2603,17 @@ _offlineScreen:
title: "オフライン - サーバーに接続できません"
header: "サーバーに接続できません"

_urlPreviewSetting:
title: "URLプレビューの設定"
enable: "URLプレビューを有効にする"
timeout: "プレビュー取得時のタイムアウト(ms)"
timeoutDescription: "プレビュー取得の所要時間がこの値を超えた場合、プレビューは生成されません。"
maximumContentLength: "Content-Lengthの最大値(byte)"
maximumContentLengthDescription: "Content-Lengthがこの値を超えた場合、プレビューは生成されません。"
requireContentLength: "Content-Lengthが取得できた場合のみプレビューを生成"
requireContentLengthDescription: "相手サーバがContent-Lengthを返さない場合、プレビューは生成されません。"
userAgent: "User-Agent"
userAgentDescription: "プレビュー取得時に使用されるUser-Agentを設定します。空欄の場合、デフォルトのUser-Agentが使用されます。"
summaryProxy: "プレビューを生成するプロキシのエンドポイント"
summaryProxyDescription: "Misskey本体ではなく、サマリープロキシを使用してプレビューを生成します。"
summaryProxyDescription2: "プロキシには下記パラメータがクエリ文字列として連携されます。プロキシ側がこれらをサポートしない場合、設定値は無視されます。"
42 changes: 42 additions & 0 deletions packages/backend/migration/1710512074000-url-preview-meta.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/

export class UrlPreviewMeta1710512074000 {
name = 'UrlPreviewMeta1710512074000'

async up(queryRunner) {
await queryRunner.query(`
alter table meta
rename column "summalyProxy" to "urlPreviewSummaryProxyUrl";
alter table meta
add "urlPreviewEnabled" boolean default true not null;
alter table meta
add "urlPreviewTimeout" integer default 10000 not null;
alter table meta
add "urlPreviewMaximumContentLength" bigint default 10485760 not null;
alter table meta
add "urlPreviewRequireContentLength" boolean default false not null;
alter table meta
add "urlPreviewUserAgent" varchar(1024) default null;
`);
}

async down(queryRunner) {
await queryRunner.query(`
alter table meta
rename column "urlPreviewSummaryProxyUrl" to "summalyProxy";
alter table meta
drop column "urlPreviewEnabled";
alter table meta
drop column "urlPreviewTimeout";
alter table meta
drop column "urlPreviewMaximumContentLength";
alter table meta
drop column "urlPreviewRequireContentLength";
alter table meta
drop column "urlPreviewUserAgent";
`);
}
}
2 changes: 1 addition & 1 deletion packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"@fastify/static": "6.12.0",
"@fastify/view": "8.2.0",
"@misskey-dev/sharp-read-bmp": "1.2.0",
"@misskey-dev/summaly": "5.0.3",
"@misskey-dev/summaly": "5.1.0",
"@nestjs/common": "10.3.3",
"@nestjs/core": "10.3.3",
"@nestjs/testing": "10.3.3",
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/core/entities/MetaEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export class MetaEntityService {
policies: { ...DEFAULT_POLICIES, ...instance.policies },

mediaProxy: this.config.mediaProxy,
enableUrlPreview: instance.urlPreviewEnabled,
};

return packed;
Expand Down
38 changes: 32 additions & 6 deletions packages/backend/src/models/Meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,6 @@ export class MiMeta {
})
public enableSensitiveMediaDetectionForVideos: boolean;

@Column('varchar', {
length: 1024,
nullable: true,
})
public summalyProxy: string | null;

@Column('boolean', {
default: false,
})
Expand Down Expand Up @@ -588,4 +582,36 @@ export class MiMeta {
default: 0,
})
public notesPerOneAd: number;

@Column('boolean', {
default: true,
})
public urlPreviewEnabled: boolean;

@Column('integer', {
default: 10000,
})
public urlPreviewTimeout: number;

@Column('bigint', {
default: 1024 * 1024 * 10,
})
public urlPreviewMaximumContentLength: number;

@Column('boolean', {
default: true,
})
public urlPreviewRequireContentLength: boolean;

@Column('varchar', {
length: 1024,
nullable: true,
})
public urlPreviewSummaryProxyUrl: string | null;

@Column('varchar', {
length: 1024,
nullable: true,
})
public urlPreviewUserAgent: string | null;
}
4 changes: 4 additions & 0 deletions packages/backend/src/models/json-schema/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ export const packedMetaLiteSchema = {
type: 'string',
optional: false, nullable: false,
},
enableUrlPreview: {
type: 'boolean',
optional: false, nullable: false,
},
backgroundImageUrl: {
type: 'string',
optional: false, nullable: true,
Expand Down
34 changes: 33 additions & 1 deletion packages/backend/src/server/api/endpoints/admin/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ export const meta = {
summalyProxy: {
type: 'string',
optional: false, nullable: true,
deprecated: true,
description: '[Deprecated] Use "urlPreviewSummaryProxyUrl" instead.',
},
themeColor: {
type: 'string',
Expand All @@ -451,6 +453,30 @@ export const meta = {
type: 'string',
optional: false, nullable: false,
},
urlPreviewEnabled: {
type: 'boolean',
optional: false, nullable: false,
},
urlPreviewTimeout: {
type: 'number',
optional: false, nullable: false,
},
urlPreviewMaximumContentLength: {
type: 'number',
optional: false, nullable: false,
},
urlPreviewRequireContentLength: {
type: 'boolean',
optional: false, nullable: false,
},
urlPreviewUserAgent: {
type: 'string',
optional: false, nullable: true,
},
urlPreviewSummaryProxyUrl: {
type: 'string',
optional: false, nullable: true,
},
},
},
} as const;
Expand Down Expand Up @@ -533,7 +559,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
setSensitiveFlagAutomatically: instance.setSensitiveFlagAutomatically,
enableSensitiveMediaDetectionForVideos: instance.enableSensitiveMediaDetectionForVideos,
proxyAccountId: instance.proxyAccountId,
summalyProxy: instance.summalyProxy,
email: instance.email,
smtpSecure: instance.smtpSecure,
smtpHost: instance.smtpHost,
Expand Down Expand Up @@ -577,6 +602,13 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
perUserHomeTimelineCacheMax: instance.perUserHomeTimelineCacheMax,
perUserListTimelineCacheMax: instance.perUserListTimelineCacheMax,
notesPerOneAd: instance.notesPerOneAd,
summalyProxy: instance.urlPreviewSummaryProxyUrl,
urlPreviewEnabled: instance.urlPreviewEnabled,
urlPreviewTimeout: instance.urlPreviewTimeout,
urlPreviewMaximumContentLength: instance.urlPreviewMaximumContentLength,
urlPreviewRequireContentLength: instance.urlPreviewRequireContentLength,
urlPreviewUserAgent: instance.urlPreviewUserAgent,
urlPreviewSummaryProxyUrl: instance.urlPreviewSummaryProxyUrl,
};
});
}
Expand Down
41 changes: 36 additions & 5 deletions packages/backend/src/server/api/endpoints/admin/update-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ export const paramDef = {
type: 'string',
},
},
summalyProxy: { type: 'string', nullable: true },
deeplAuthKey: { type: 'string', nullable: true },
deeplIsPro: { type: 'boolean' },
enableEmail: { type: 'boolean' },
Expand Down Expand Up @@ -150,6 +149,16 @@ export const paramDef = {
type: 'string',
},
},
summalyProxy: {
type: 'string', nullable: true,
description: '[Deprecated] Use "urlPreviewSummaryProxyUrl" instead.',
},
urlPreviewEnabled: { type: 'boolean' },
urlPreviewTimeout: { type: 'integer' },
urlPreviewMaximumContentLength: { type: 'integer' },
urlPreviewRequireContentLength: { type: 'boolean' },
urlPreviewUserAgent: { type: 'string', nullable: true },
urlPreviewSummaryProxyUrl: { type: 'string', nullable: true },
},
required: [],
} as const;
Expand Down Expand Up @@ -353,10 +362,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
set.langs = ps.langs.filter(Boolean);
}

if (ps.summalyProxy !== undefined) {
set.summalyProxy = ps.summalyProxy;
}

if (ps.enableEmail !== undefined) {
set.enableEmail = ps.enableEmail;
}
Expand Down Expand Up @@ -581,6 +586,32 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
set.bannedEmailDomains = ps.bannedEmailDomains;
}

if (ps.urlPreviewEnabled !== undefined) {
set.urlPreviewEnabled = ps.urlPreviewEnabled;
}

if (ps.urlPreviewTimeout !== undefined) {
set.urlPreviewTimeout = ps.urlPreviewTimeout;
}

if (ps.urlPreviewMaximumContentLength !== undefined) {
set.urlPreviewMaximumContentLength = ps.urlPreviewMaximumContentLength;
}

if (ps.urlPreviewRequireContentLength !== undefined) {
set.urlPreviewRequireContentLength = ps.urlPreviewRequireContentLength;
}

if (ps.urlPreviewUserAgent !== undefined) {
const value = (ps.urlPreviewUserAgent ?? '').trim();
set.urlPreviewUserAgent = value === '' ? null : ps.urlPreviewUserAgent;
}

if (ps.summalyProxy !== undefined || ps.urlPreviewSummaryProxyUrl !== undefined) {
const value = ((ps.urlPreviewSummaryProxyUrl ?? ps.summalyProxy) ?? '').trim();
set.urlPreviewSummaryProxyUrl = value === '' ? null : value;
}

const before = await this.metaService.fetch(true);

await this.metaService.update(set);
Expand Down
Loading
Loading