allow summaly previews to redirect
This commit is contained in:
@@ -104,8 +104,7 @@ export class UrlPreviewService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const host = new URL(url).host;
|
if (this.utilityService.isBlockedHost(this.meta.blockedHosts, new URL(url).host)) {
|
||||||
if (this.utilityService.isBlockedHost(this.meta.blockedHosts, host)) {
|
|
||||||
reply.code(403);
|
reply.code(403);
|
||||||
return {
|
return {
|
||||||
error: new ApiError({
|
error: new ApiError({
|
||||||
@@ -139,6 +138,18 @@ export class UrlPreviewService {
|
|||||||
? await this.fetchSummaryFromProxy(url, this.meta, lang)
|
? await this.fetchSummaryFromProxy(url, this.meta, lang)
|
||||||
: await this.fetchSummary(url, this.meta, lang);
|
: await this.fetchSummary(url, this.meta, lang);
|
||||||
|
|
||||||
|
// Repeat check, since redirects are allowed.
|
||||||
|
if (this.utilityService.isBlockedHost(this.meta.blockedHosts, new URL(summary.url).host)) {
|
||||||
|
reply.code(403);
|
||||||
|
return {
|
||||||
|
error: new ApiError({
|
||||||
|
message: 'URL is blocked',
|
||||||
|
code: 'URL_PREVIEW_BLOCKED',
|
||||||
|
id: '50294652-857b-4b13-9700-8e5c7a8deae8',
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
this.logger.succ(`Got preview of ${url}: ${summary.title}`);
|
this.logger.succ(`Got preview of ${url}: ${summary.title}`);
|
||||||
|
|
||||||
if (!(summary.url.startsWith('http://') || summary.url.startsWith('https://'))) {
|
if (!(summary.url.startsWith('http://') || summary.url.startsWith('https://'))) {
|
||||||
@@ -189,7 +200,7 @@ export class UrlPreviewService {
|
|||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
return summaly(url, {
|
return summaly(url, {
|
||||||
followRedirects: false,
|
followRedirects: true,
|
||||||
lang: lang ?? 'ja-JP',
|
lang: lang ?? 'ja-JP',
|
||||||
agent: agent,
|
agent: agent,
|
||||||
userAgent: meta.urlPreviewUserAgent ?? undefined,
|
userAgent: meta.urlPreviewUserAgent ?? undefined,
|
||||||
@@ -202,6 +213,7 @@ export class UrlPreviewService {
|
|||||||
private fetchSummaryFromProxy(url: string, meta: MiMeta, lang?: string): Promise<LocalSummalyResult> {
|
private fetchSummaryFromProxy(url: string, meta: MiMeta, lang?: string): Promise<LocalSummalyResult> {
|
||||||
const proxy = meta.urlPreviewSummaryProxyUrl!;
|
const proxy = meta.urlPreviewSummaryProxyUrl!;
|
||||||
const queryStr = query({
|
const queryStr = query({
|
||||||
|
followRedirects: true,
|
||||||
url: url,
|
url: url,
|
||||||
lang: lang ?? 'ja-JP',
|
lang: lang ?? 'ja-JP',
|
||||||
userAgent: meta.urlPreviewUserAgent ?? undefined,
|
userAgent: meta.urlPreviewUserAgent ?? undefined,
|
||||||
|
|||||||
Reference in New Issue
Block a user