feat(backend): Override the file URL rendering in AP
This commit is contained in:
parent
13e7b49f09
commit
ccb1883e3e
@ -178,6 +178,9 @@ id: 'aidx'
|
|||||||
# IP address family used for outgoing request (ipv4, ipv6 or dual)
|
# IP address family used for outgoing request (ipv4, ipv6 or dual)
|
||||||
#outgoingAddressFamily: ipv4
|
#outgoingAddressFamily: ipv4
|
||||||
|
|
||||||
|
# Override the file URL rendering in ActivityPub (Object Storage file only)
|
||||||
|
#apFileBaseUrl: https://example.com/
|
||||||
|
|
||||||
# Proxy for HTTP/HTTPS
|
# Proxy for HTTP/HTTPS
|
||||||
#proxy: http://127.0.0.1:3128
|
#proxy: http://127.0.0.1:3128
|
||||||
|
|
||||||
|
@ -251,6 +251,9 @@ id: 'aidx'
|
|||||||
# IP address family used for outgoing request (ipv4, ipv6 or dual)
|
# IP address family used for outgoing request (ipv4, ipv6 or dual)
|
||||||
#outgoingAddressFamily: ipv4
|
#outgoingAddressFamily: ipv4
|
||||||
|
|
||||||
|
# Override the file URL rendering in ActivityPub (Object Storage file only)
|
||||||
|
#apFileBaseUrl: https://example.com/
|
||||||
|
|
||||||
# Proxy for HTTP/HTTPS
|
# Proxy for HTTP/HTTPS
|
||||||
#proxy: http://127.0.0.1:3128
|
#proxy: http://127.0.0.1:3128
|
||||||
|
|
||||||
|
@ -171,6 +171,9 @@ id: 'aidx'
|
|||||||
# IP address family used for outgoing request (ipv4, ipv6 or dual)
|
# IP address family used for outgoing request (ipv4, ipv6 or dual)
|
||||||
#outgoingAddressFamily: ipv4
|
#outgoingAddressFamily: ipv4
|
||||||
|
|
||||||
|
# Override the file URL rendering in ActivityPub (Object Storage file only)
|
||||||
|
#apFileBaseUrl: https://example.com/
|
||||||
|
|
||||||
# Proxy for HTTP/HTTPS
|
# Proxy for HTTP/HTTPS
|
||||||
#proxy: http://127.0.0.1:3128
|
#proxy: http://127.0.0.1:3128
|
||||||
|
|
||||||
|
@ -192,6 +192,9 @@ id: "aidx"
|
|||||||
# IP address family used for outgoing request (ipv4, ipv6 or dual)
|
# IP address family used for outgoing request (ipv4, ipv6 or dual)
|
||||||
#outgoingAddressFamily: ipv4
|
#outgoingAddressFamily: ipv4
|
||||||
|
|
||||||
|
# Override the file URL rendering in ActivityPub (Object Storage file only)
|
||||||
|
#apFileBaseUrl: https://example.com/
|
||||||
|
|
||||||
# Proxy for HTTP/HTTPS
|
# Proxy for HTTP/HTTPS
|
||||||
#proxy: http://127.0.0.1:3128
|
#proxy: http://127.0.0.1:3128
|
||||||
|
|
||||||
|
@ -62,6 +62,8 @@ type Source = {
|
|||||||
|
|
||||||
publishTarballInsteadOfProvideRepositoryUrl?: boolean;
|
publishTarballInsteadOfProvideRepositoryUrl?: boolean;
|
||||||
|
|
||||||
|
apFileBaseUrl?: string;
|
||||||
|
|
||||||
proxy?: string;
|
proxy?: string;
|
||||||
proxySmtp?: string;
|
proxySmtp?: string;
|
||||||
proxyBypassHosts?: string[];
|
proxyBypassHosts?: string[];
|
||||||
@ -129,6 +131,7 @@ export type Config = {
|
|||||||
index: string;
|
index: string;
|
||||||
scope?: 'local' | 'global' | string[];
|
scope?: 'local' | 'global' | string[];
|
||||||
} | undefined;
|
} | undefined;
|
||||||
|
apFileBaseUrl: string | undefined;
|
||||||
proxy: string | undefined;
|
proxy: string | undefined;
|
||||||
proxySmtp: string | undefined;
|
proxySmtp: string | undefined;
|
||||||
proxyBypassHosts: string[] | undefined;
|
proxyBypassHosts: string[] | undefined;
|
||||||
@ -246,6 +249,7 @@ export function loadConfig(): Config {
|
|||||||
sentryForBackend: config.sentryForBackend,
|
sentryForBackend: config.sentryForBackend,
|
||||||
sentryForFrontend: config.sentryForFrontend,
|
sentryForFrontend: config.sentryForFrontend,
|
||||||
id: config.id,
|
id: config.id,
|
||||||
|
apFileBaseUrl: config.apFileBaseUrl,
|
||||||
proxy: config.proxy,
|
proxy: config.proxy,
|
||||||
proxySmtp: config.proxySmtp,
|
proxySmtp: config.proxySmtp,
|
||||||
proxyBypassHosts: config.proxyBypassHosts,
|
proxyBypassHosts: config.proxyBypassHosts,
|
||||||
|
@ -164,7 +164,7 @@ export class ApRendererService {
|
|||||||
return {
|
return {
|
||||||
type: 'Document',
|
type: 'Document',
|
||||||
mediaType: file.webpublicType ?? file.type,
|
mediaType: file.webpublicType ?? file.type,
|
||||||
url: this.driveFileEntityService.getPublicUrl(file),
|
url: this.driveFileEntityService.getPublicUrl(file, undefined, true),
|
||||||
name: file.comment,
|
name: file.comment,
|
||||||
sensitive: file.isSensitive,
|
sensitive: file.isSensitive,
|
||||||
};
|
};
|
||||||
@ -244,7 +244,7 @@ export class ApRendererService {
|
|||||||
public renderImage(file: MiDriveFile): IApImage {
|
public renderImage(file: MiDriveFile): IApImage {
|
||||||
return {
|
return {
|
||||||
type: 'Image',
|
type: 'Image',
|
||||||
url: this.driveFileEntityService.getPublicUrl(file),
|
url: this.driveFileEntityService.getPublicUrl(file, undefined, true),
|
||||||
sensitive: file.isSensitive,
|
sensitive: file.isSensitive,
|
||||||
name: file.comment,
|
name: file.comment,
|
||||||
};
|
};
|
||||||
|
@ -256,12 +256,12 @@ export class ApPersonService implements OnModuleInit {
|
|||||||
return {
|
return {
|
||||||
...( avatar ? {
|
...( avatar ? {
|
||||||
avatarId: avatar.id,
|
avatarId: avatar.id,
|
||||||
avatarUrl: avatar.url ? this.driveFileEntityService.getPublicUrl(avatar, 'avatar') : null,
|
avatarUrl: avatar.url ? this.driveFileEntityService.getPublicUrl(avatar, 'avatar', true) : null,
|
||||||
avatarBlurhash: avatar.blurhash,
|
avatarBlurhash: avatar.blurhash,
|
||||||
} : {}),
|
} : {}),
|
||||||
...( banner ? {
|
...( banner ? {
|
||||||
bannerId: banner.id,
|
bannerId: banner.id,
|
||||||
bannerUrl: banner.url ? this.driveFileEntityService.getPublicUrl(banner) : null,
|
bannerUrl: banner.url ? this.driveFileEntityService.getPublicUrl(banner, undefined, true) : null,
|
||||||
bannerBlurhash: banner.blurhash,
|
bannerBlurhash: banner.blurhash,
|
||||||
} : {}),
|
} : {}),
|
||||||
};
|
};
|
||||||
|
@ -108,7 +108,7 @@ export class DriveFileEntityService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
public getPublicUrl(file: MiDriveFile, mode?: 'avatar'): string { // static = thumbnail
|
public getPublicUrl(file: MiDriveFile, mode?: 'avatar', ap?: boolean): string { // static = thumbnail
|
||||||
// リモートかつメディアプロキシ
|
// リモートかつメディアプロキシ
|
||||||
if (file.uri != null && file.userHost != null && this.config.externalMediaProxyEnabled) {
|
if (file.uri != null && file.userHost != null && this.config.externalMediaProxyEnabled) {
|
||||||
return this.getProxiedUrl(file.uri, mode);
|
return this.getProxiedUrl(file.uri, mode);
|
||||||
@ -130,6 +130,16 @@ export class DriveFileEntityService {
|
|||||||
if (mode === 'avatar') {
|
if (mode === 'avatar') {
|
||||||
return this.getProxiedUrl(url, 'avatar');
|
return this.getProxiedUrl(url, 'avatar');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ap && this.config.apFileBaseUrl) {
|
||||||
|
const baseUrl = this.config.apFileBaseUrl;
|
||||||
|
const isValidBaseUrl = /^https?:\/\/[\w.-]+\.[a-zA-Z]{2,}(\/.*)?$/i.test(baseUrl);
|
||||||
|
if (isValidBaseUrl) {
|
||||||
|
const trimmedBaseUrl = baseUrl.replace(/\/$/, '');
|
||||||
|
return url.replace(/^https?:\/\/[\w.-]+\.[a-zA-Z]{2,}/, trimmedBaseUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user