Skip to content

Commit

Permalink
remoteProxyエンドポイント設定を追加 (yojo-art#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
kozakura913 authored Jun 20, 2024
1 parent 25de0c6 commit d6a13b2
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .config/docker_example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ proxyBypassHosts:
# Media Proxy
#mediaProxy: https://example.com/proxy

# Proxy remote files endpoint
# remoteProxy: https://example.com/files/
# remoteProxy: /files/

# Proxy remote files (default: true)
proxyRemoteFiles: true

Expand Down
4 changes: 4 additions & 0 deletions .config/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ proxyBypassHosts:
# * Perform image compression (on a different server resource than the main process)
#mediaProxy: https://example.com/proxy

# Proxy remote files endpoint
# remoteProxy: https://example.com/files/
# remoteProxy: /files/

# Proxy remote files (default: true)
# Proxy remote files by this instance or mediaProxy to prevent remote files from running in remote domains.
proxyRemoteFiles: true
Expand Down
31 changes: 31 additions & 0 deletions CHANGELOG_yojo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!--
## engawa-x.x.x (unreleased)
### Release Date
### General
-
### Client
-
### Server
-
### Misc
-->
## 0.1.0 (unreleased)

### Release Date
2024-03-09

### General
- メディアプロキシurlと拡大画像urlを分割

### Server
- remoteProxyエンドポイント設定を追加

### Others
- engawaをマージ
- cherrypickからフォーク
8 changes: 8 additions & 0 deletions packages/backend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ type Source = {
apFileBaseUrl?: string;

mediaProxy?: string;
remoteProxy?: string;
proxyRemoteFiles?: boolean;
videoThumbnailGenerator?: string;

Expand Down Expand Up @@ -197,6 +198,7 @@ export type Config = {
clientEntry: string;
clientManifestExists: boolean;
mediaProxy: string;
remoteProxy?: string;
externalMediaProxyEnabled: boolean;
videoThumbnailGenerator: string | null;
redis: RedisOptions & RedisOptionsSource;
Expand Down Expand Up @@ -246,6 +248,11 @@ export function loadConfig(): Config {
config.mediaProxy.endsWith('/') ? config.mediaProxy.substring(0, config.mediaProxy.length - 1) : config.mediaProxy
: null;
const internalMediaProxy = `${scheme}://${host}/proxy`;

const remoteProxy = config.remoteProxy ?
config.remoteProxy.endsWith('/') ? config.remoteProxy.substring(0, config.remoteProxy.length - 1) : config.remoteProxy
: null;

const redis = convertRedisOptions(config.redis, host);

return {
Expand Down Expand Up @@ -297,6 +304,7 @@ export function loadConfig(): Config {
apFileBaseUrl: config.apFileBaseUrl,
mediaProxy: externalMediaProxy ?? internalMediaProxy,
externalMediaProxyEnabled: externalMediaProxy !== null && externalMediaProxy !== internalMediaProxy,
remoteProxy,
videoThumbnailGenerator: config.videoThumbnailGenerator ?
config.videoThumbnailGenerator.endsWith('/') ? config.videoThumbnailGenerator.substring(0, config.videoThumbnailGenerator.length - 1) : config.videoThumbnailGenerator
: null,
Expand Down
12 changes: 12 additions & 0 deletions packages/backend/src/core/entities/DriveFileEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ export class DriveFileEntityService {

@bindThis
public getPublicUrl(file: MiDriveFile, mode?: 'avatar', ap?: boolean): string { // static = thumbnail
// PublicUrlにはexternalMediaProxyEnabledでもremoteProxyを使う
// https://github.com/yojo-art/cherrypick/issues/84
if (file.uri != null && file.userHost != null && mode !== 'avatar' && this.config.remoteProxy != null) {
//下のローカルプロキシからコピペで持ってきた
const key = file.webpublicAccessKey;
if (key && !key.match('/')) { // 古いものはここにオブジェクトストレージキーが入ってるので除外
if (this.config.remoteProxy.startsWith('/')) {
return `${this.config.url}${this.config.remoteProxy}/${key}`;
}
return `${this.config.remoteProxy}/${key}`;
}
}
// リモートかつメディアプロキシ
if (file.uri != null && file.userHost != null && this.config.externalMediaProxyEnabled) {
return this.getProxiedUrl(file.uri, mode);
Expand Down

0 comments on commit d6a13b2

Please sign in to comment.