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)
|
||||
#outgoingAddressFamily: ipv4
|
||||
|
||||
# Override the file URL rendering in ActivityPub (Object Storage file only)
|
||||
#apFileBaseUrl: https://example.com/
|
||||
|
||||
# Proxy for HTTP/HTTPS
|
||||
#proxy: http://127.0.0.1:3128
|
||||
|
||||
|
@ -251,6 +251,9 @@ id: 'aidx'
|
||||
# IP address family used for outgoing request (ipv4, ipv6 or dual)
|
||||
#outgoingAddressFamily: ipv4
|
||||
|
||||
# Override the file URL rendering in ActivityPub (Object Storage file only)
|
||||
#apFileBaseUrl: https://example.com/
|
||||
|
||||
# Proxy for HTTP/HTTPS
|
||||
#proxy: http://127.0.0.1:3128
|
||||
|
||||
|
@ -171,6 +171,9 @@ id: 'aidx'
|
||||
# IP address family used for outgoing request (ipv4, ipv6 or dual)
|
||||
#outgoingAddressFamily: ipv4
|
||||
|
||||
# Override the file URL rendering in ActivityPub (Object Storage file only)
|
||||
#apFileBaseUrl: https://example.com/
|
||||
|
||||
# Proxy for HTTP/HTTPS
|
||||
#proxy: http://127.0.0.1:3128
|
||||
|
||||
|
@ -192,6 +192,9 @@ id: "aidx"
|
||||
# IP address family used for outgoing request (ipv4, ipv6 or dual)
|
||||
#outgoingAddressFamily: ipv4
|
||||
|
||||
# Override the file URL rendering in ActivityPub (Object Storage file only)
|
||||
#apFileBaseUrl: https://example.com/
|
||||
|
||||
# Proxy for HTTP/HTTPS
|
||||
#proxy: http://127.0.0.1:3128
|
||||
|
||||
|
@ -62,6 +62,8 @@ type Source = {
|
||||
|
||||
publishTarballInsteadOfProvideRepositoryUrl?: boolean;
|
||||
|
||||
apFileBaseUrl?: string;
|
||||
|
||||
proxy?: string;
|
||||
proxySmtp?: string;
|
||||
proxyBypassHosts?: string[];
|
||||
@ -129,6 +131,7 @@ export type Config = {
|
||||
index: string;
|
||||
scope?: 'local' | 'global' | string[];
|
||||
} | undefined;
|
||||
apFileBaseUrl: string | undefined;
|
||||
proxy: string | undefined;
|
||||
proxySmtp: string | undefined;
|
||||
proxyBypassHosts: string[] | undefined;
|
||||
@ -246,6 +249,7 @@ export function loadConfig(): Config {
|
||||
sentryForBackend: config.sentryForBackend,
|
||||
sentryForFrontend: config.sentryForFrontend,
|
||||
id: config.id,
|
||||
apFileBaseUrl: config.apFileBaseUrl,
|
||||
proxy: config.proxy,
|
||||
proxySmtp: config.proxySmtp,
|
||||
proxyBypassHosts: config.proxyBypassHosts,
|
||||
|
@ -164,7 +164,7 @@ export class ApRendererService {
|
||||
return {
|
||||
type: 'Document',
|
||||
mediaType: file.webpublicType ?? file.type,
|
||||
url: this.driveFileEntityService.getPublicUrl(file),
|
||||
url: this.driveFileEntityService.getPublicUrl(file, undefined, true),
|
||||
name: file.comment,
|
||||
sensitive: file.isSensitive,
|
||||
};
|
||||
@ -244,7 +244,7 @@ export class ApRendererService {
|
||||
public renderImage(file: MiDriveFile): IApImage {
|
||||
return {
|
||||
type: 'Image',
|
||||
url: this.driveFileEntityService.getPublicUrl(file),
|
||||
url: this.driveFileEntityService.getPublicUrl(file, undefined, true),
|
||||
sensitive: file.isSensitive,
|
||||
name: file.comment,
|
||||
};
|
||||
|
@ -256,12 +256,12 @@ export class ApPersonService implements OnModuleInit {
|
||||
return {
|
||||
...( avatar ? {
|
||||
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,
|
||||
} : {}),
|
||||
...( banner ? {
|
||||
bannerId: banner.id,
|
||||
bannerUrl: banner.url ? this.driveFileEntityService.getPublicUrl(banner) : null,
|
||||
bannerUrl: banner.url ? this.driveFileEntityService.getPublicUrl(banner, undefined, true) : null,
|
||||
bannerBlurhash: banner.blurhash,
|
||||
} : {}),
|
||||
};
|
||||
|
@ -108,7 +108,7 @@ export class DriveFileEntityService {
|
||||
}
|
||||
|
||||
@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) {
|
||||
return this.getProxiedUrl(file.uri, mode);
|
||||
@ -130,6 +130,16 @@ export class DriveFileEntityService {
|
||||
if (mode === '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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user