Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@ S3_ACCESS_KEY_ID=
S3_SECRET_ACCESS_KEY=
S3_ENDPOINT=
S3_BUCKET=
S3_REGION=us-east-1
# For self hosted s3 compatiable service, like minio
S3_PROTOCOL=https
S3_TYPE=virtual-hosted

SEARXNG_URL=
SEARXNG_URL=
8 changes: 5 additions & 3 deletions docker-compose.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ services:
S3_ACCESS_KEY_ID: update-this
S3_SECRET_ACCESS_KEY: update-this
S3_ENDPOINT: update-this
S3_REGION: update-this
S3_BUCKET: update-this
S3_REGION: update-this
S3_PROTOCOL: https
S3_TYPE: virtual-hosted
SEARXNG_URL: update-this

depends_on:
Expand All @@ -49,7 +51,7 @@ services:
environment:
SERVER_URL: http://server:3000
ZERO_CACHE_URL: http://zero-cache:4848

zero-cache:
image: rocicorp/zero:0.26.1
environment:
Expand Down Expand Up @@ -84,4 +86,4 @@ configs:
CREATE DATABASE zero;

\c app;
CREATE EXTENSION IF NOT EXISTS zhparser;
CREATE EXTENSION IF NOT EXISTS zhparser;
3 changes: 3 additions & 0 deletions src-server/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export const DATABASE_URL = process.env.DATABASE_URL!
export const OPENAI_BASE_URL = process.env.OPENAI_BASE_URL
export const OPENAI_API_KEY = process.env.OPENAI_API_KEY
export const S3_ENDPOINT = process.env.S3_ENDPOINT!
export const S3_PROTOCOL = process.env.S3_PROTOCOL || 'https'
export const S3_REGION = process.env.S3_REGION || 'us-east-1'
export const S3_TYPE = process.env.S3_TYPE || 'virtual-hosted'
export const S3_BUCKET = process.env.S3_BUCKET!
export const S3_ACCESS_KEY_ID = process.env.S3_ACCESS_KEY_ID!
export const S3_SECRET_ACCESS_KEY = process.env.S3_SECRET_ACCESS_KEY!
Expand Down
8 changes: 6 additions & 2 deletions src-server/utils/s3.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { AwsClient } from 'aws4fetch'
import { S3_ENDPOINT, S3_BUCKET, S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY } from './config'
import { S3_ENDPOINT, S3_PROTOCOL, S3_REGION, S3_TYPE, S3_BUCKET, S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY } from './config'

const aws = new AwsClient({
accessKeyId: S3_ACCESS_KEY_ID,
secretAccessKey: S3_SECRET_ACCESS_KEY,
service: 's3',
region: S3_REGION,
})

function objectUrl(key: string) {
return `https://${S3_BUCKET}.${S3_ENDPOINT}/${key}`
return S3_TYPE === 'path'
? `${S3_PROTOCOL}://${S3_ENDPOINT}/${S3_BUCKET}/${key}`
: `${S3_PROTOCOL}://${S3_BUCKET}.${S3_ENDPOINT}/${key}`
}

export async function presignedGetObject(key: string, { expires, contentDisposition }: {
Expand Down