mirror of
https://github.com/kokonect-link/cherrypick
synced 2025-01-19 00:03:19 +09:00
Merge pull request #371
* feat(backend): Override the file URL rendering in AP
This commit is contained in:
parent
176af77635
commit
1959194cd6
@ -56,17 +56,17 @@ dbReplications: false
|
||||
# You can configure any number of replicas here
|
||||
#dbSlaves:
|
||||
# -
|
||||
# host:
|
||||
# port:
|
||||
# db:
|
||||
# user:
|
||||
# pass:
|
||||
# host:
|
||||
# port:
|
||||
# db:
|
||||
# user:
|
||||
# pass:
|
||||
# -
|
||||
# host:
|
||||
# port:
|
||||
# db:
|
||||
# user:
|
||||
# pass:
|
||||
# host:
|
||||
# port:
|
||||
# db:
|
||||
# user:
|
||||
# pass:
|
||||
|
||||
# ┌─────────────────────┐
|
||||
#───┘ Redis configuration └─────────────────────────────────────
|
||||
@ -154,6 +154,9 @@ id: 'aidx'
|
||||
# saKeyPath: /path/to/service-account-key.json
|
||||
# logName: cherrypick
|
||||
|
||||
# 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
|
||||
|
||||
|
@ -172,6 +172,9 @@ id: 'aidx'
|
||||
# saKeyPath: /path/to/service-account-key.json
|
||||
# logName: cherrypick
|
||||
|
||||
# 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
|
||||
|
||||
|
@ -56,17 +56,17 @@ dbReplications: false
|
||||
# You can configure any number of replicas here
|
||||
#dbSlaves:
|
||||
# -
|
||||
# host:
|
||||
# port:
|
||||
# db:
|
||||
# user:
|
||||
# pass:
|
||||
# host:
|
||||
# port:
|
||||
# db:
|
||||
# user:
|
||||
# pass:
|
||||
# -
|
||||
# host:
|
||||
# port:
|
||||
# db:
|
||||
# user:
|
||||
# pass:
|
||||
# host:
|
||||
# port:
|
||||
# db:
|
||||
# user:
|
||||
# pass:
|
||||
|
||||
# ┌─────────────────────┐
|
||||
#───┘ Redis configuration └─────────────────────────────────────
|
||||
@ -154,6 +154,9 @@ id: 'aidx'
|
||||
# saKeyPath: /path/to/service-account-key.json
|
||||
# logName: cherrypick
|
||||
|
||||
# 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
|
||||
|
||||
|
@ -77,17 +77,17 @@ dbReplications: false
|
||||
# You can configure any number of replicas here
|
||||
#dbSlaves:
|
||||
# -
|
||||
# host:
|
||||
# port:
|
||||
# db:
|
||||
# user:
|
||||
# pass:
|
||||
# host:
|
||||
# port:
|
||||
# db:
|
||||
# user:
|
||||
# pass:
|
||||
# -
|
||||
# host:
|
||||
# port:
|
||||
# db:
|
||||
# user:
|
||||
# pass:
|
||||
# host:
|
||||
# port:
|
||||
# db:
|
||||
# user:
|
||||
# pass:
|
||||
|
||||
# ┌─────────────────────┐
|
||||
#───┘ Redis configuration └─────────────────────────────────────
|
||||
@ -174,6 +174,9 @@ id: "aidx"
|
||||
# saKeyPath: /path/to/service-account-key.json
|
||||
# logName: cherrypick
|
||||
|
||||
# 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
|
||||
|
||||
|
@ -86,6 +86,8 @@ type Source = {
|
||||
logName?: string;
|
||||
}
|
||||
|
||||
apFileBaseUrl?: string;
|
||||
|
||||
mediaProxy?: string;
|
||||
proxyRemoteFiles?: boolean;
|
||||
videoThumbnailGenerator?: string;
|
||||
@ -145,6 +147,7 @@ export type Config = {
|
||||
relashionshipJobPerSec: number | undefined;
|
||||
deliverJobMaxAttempts: number | undefined;
|
||||
inboxJobMaxAttempts: number | undefined;
|
||||
apFileBaseUrl: string | undefined;
|
||||
proxyRemoteFiles: boolean | undefined;
|
||||
signToActivityPubGet: boolean | undefined;
|
||||
|
||||
@ -250,6 +253,7 @@ export function loadConfig(): Config {
|
||||
inboxJobMaxAttempts: config.inboxJobMaxAttempts,
|
||||
proxyRemoteFiles: config.proxyRemoteFiles,
|
||||
signToActivityPubGet: config.signToActivityPubGet,
|
||||
apFileBaseUrl: config.apFileBaseUrl,
|
||||
mediaProxy: externalMediaProxy ?? internalMediaProxy,
|
||||
externalMediaProxyEnabled: externalMediaProxy !== null && externalMediaProxy !== internalMediaProxy,
|
||||
videoThumbnailGenerator: config.videoThumbnailGenerator ?
|
||||
|
@ -166,7 +166,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,
|
||||
};
|
||||
}
|
||||
@ -245,7 +245,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,
|
||||
};
|
||||
|
@ -250,8 +250,8 @@ export class ApPersonService implements OnModuleInit {
|
||||
return {
|
||||
avatarId: avatar?.id ?? null,
|
||||
bannerId: banner?.id ?? null,
|
||||
avatarUrl: avatar ? this.driveFileEntityService.getPublicUrl(avatar, 'avatar') : null,
|
||||
bannerUrl: banner ? this.driveFileEntityService.getPublicUrl(banner) : null,
|
||||
avatarUrl: avatar ? this.driveFileEntityService.getPublicUrl(avatar, 'avatar', true) : null,
|
||||
bannerUrl: banner ? this.driveFileEntityService.getPublicUrl(banner, undefined, true) : null,
|
||||
avatarBlurhash: avatar?.blurhash ?? null,
|
||||
bannerBlurhash: banner?.blurhash ?? null,
|
||||
};
|
||||
|
@ -107,7 +107,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);
|
||||
@ -129,6 +129,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