Skip to content

Commit

Permalink
add sermcs
Browse files Browse the repository at this point in the history
  • Loading branch information
caipira113 committed Apr 23, 2024
1 parent 3a7ffe2 commit 1b4a68e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/backend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ type Source = {
apFileBaseUrl?: string;

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

Expand Down Expand Up @@ -177,6 +178,7 @@ export type Config = {
clientEntry: string;
clientManifestExists: boolean;
mediaProxy: string;
sermcsUrl: string | null;
externalMediaProxyEnabled: boolean;
videoThumbnailGenerator: string | null;
redis: RedisOptions & RedisOptionsSource;
Expand Down Expand Up @@ -222,6 +224,9 @@ export function loadConfig(): Config {
const scheme = url.protocol.replace(/:$/, '');
const wsScheme = scheme.replace('http', 'ws');

const sermcsUrl = config.sermcsUrl ?
config.sermcsUrl.endsWith('/') ? config.sermcsUrl.substring(0, config.sermcsUrl.length - 1) : config.sermcsUrl
: null;
const externalMediaProxy = config.mediaProxy ?
config.mediaProxy.endsWith('/') ? config.mediaProxy.substring(0, config.mediaProxy.length - 1) : config.mediaProxy
: null;
Expand Down Expand Up @@ -274,6 +279,7 @@ export function loadConfig(): Config {
signToActivityPubGet: config.signToActivityPubGet,
apFileBaseUrl: config.apFileBaseUrl,
mediaProxy: externalMediaProxy ?? internalMediaProxy,
sermcsUrl: sermcsUrl,
externalMediaProxyEnabled: externalMediaProxy !== null && externalMediaProxy !== internalMediaProxy,
videoThumbnailGenerator: config.videoThumbnailGenerator ?
config.videoThumbnailGenerator.endsWith('/') ? config.videoThumbnailGenerator.substring(0, config.videoThumbnailGenerator.length - 1) : config.videoThumbnailGenerator
Expand Down
19 changes: 19 additions & 0 deletions packages/backend/src/core/entities/DriveFileEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ export class DriveFileEntityService {
return this.getProxiedUrl(file.uri, 'static');
}

if (file.uri != null && file.isLink && this.config.proxyRemoteFiles && this.config.sermcsUrl) {
const key = file.thumbnailAccessKey;

if (key && !key.match('/')) { // 古いものはここにオブジェクトストレージキーが入ってるので除外
const url = `${this.config.sermcsUrl}/${key}`;
return url;
}
}

if (file.uri != null && file.isLink && this.config.proxyRemoteFiles) {
// リモートかつ期限切れはローカルプロキシを試みる
// 従来は/files/${thumbnailAccessKey}にアクセスしていたが、
Expand All @@ -116,6 +125,16 @@ export class DriveFileEntityService {
}

// リモートかつ期限切れはローカルプロキシを試みる
if (file.uri != null && file.isLink && this.config.proxyRemoteFiles && this.config.sermcsUrl) {
const key = file.webpublicAccessKey;

if (key && !key.match('/')) { // 古いものはここにオブジェクトストレージキーが入ってるので除外
const url = `${this.config.sermcsUrl}/${key}`;
if (mode === 'avatar') return this.getProxiedUrl(file.uri, 'avatar');
return url;
}
}

if (file.uri != null && file.isLink && this.config.proxyRemoteFiles) {
const key = file.webpublicAccessKey;

Expand Down

0 comments on commit 1b4a68e

Please sign in to comment.