Skip to content

Commit 4c7d6b0

Browse files
committed
refactor(storage): rename aws storage to s3, update env vars and docs for S3-compatible storage support (CloudFlare R2, DigitalOcean Spaces, etc.)
1 parent 3464f0b commit 4c7d6b0

File tree

3 files changed

+47
-16
lines changed

3 files changed

+47
-16
lines changed

.env.example

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ LIVEKIT_API_SECRET=
6262

6363
# - SQLite (default - no configuration needed)
6464
# - PostgreSQL (DB_TYPE=pg with DB_URL)
65-
#
65+
#
6666
# If DB_TYPE and DB_URL are not provided or empty,
6767
# the application will automatically use SQLite in the world folder.
6868

@@ -72,3 +72,29 @@ DB_TYPE=
7272
# Database connection URL - leave empty for SQLite
7373
# For PostgreSQL, use format: postgres://username:password@host:port/database?schema=public
7474
DB_URL=
75+
76+
# ==============================================
77+
# STORAGE CONFIGURATION
78+
# ==============================================
79+
# Configure your file storage system here.
80+
#
81+
# Supported storage types:
82+
# - Local file system (default - no configuration needed)
83+
# - S3-compatible storage (CloudFlare R2, AWS S3, DigitalOcean Spaces, etc.)
84+
#
85+
# If STORAGE_TYPE is set to 's3', S3-compatible storage will be used.
86+
# If STORAGE_TYPE is empty or not set, local file storage will be used.
87+
#
88+
# S3 credentials can be provided via environment variables below,
89+
# or through AWS CLI configuration, IAM roles, or instance profiles.
90+
91+
# S3 storage configuration (only required when using S3)
92+
# To use S3-compatible storage, set STORAGE_TYPE and other S3 variables below
93+
STORAGE_TYPE=
94+
S3_BUCKET_NAME=bucket-name
95+
S3_ACCESS_KEY_ID=access-key-id
96+
S3_SECRET_ACCESS_KEY=secret-key-id
97+
S3_REGION=eu-west-1
98+
S3_ASSETS_PREFIX=
99+
S3_COLLECTIONS_PREFIX=
100+
S3_STORAGE_PREFIX=

src/server/storage/AwsS3Storage.js renamed to src/server/storage/S3Storage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import fs from 'fs-extra'
44
import { getSignedUrl } from '@aws-sdk/s3-request-presigner'
55
import { S3Client, PutObjectCommand, GetObjectCommand, HeadObjectCommand, ListObjectsV2Command, DeleteObjectCommand } from '@aws-sdk/client-s3'
66

7-
export class AwsS3Storage {
7+
export class S3Storage {
88
constructor(config) {
99
this.bucketName = config.bucketName
1010
this.region = config.region || 'us-east-1'

src/server/storage/StorageManager.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
import path from 'path'
22
import { throttle } from 'lodash-es'
33

4-
import { AwsS3Storage } from './AwsS3Storage.js'
4+
import { S3Storage } from './S3Storage.js'
55
import { FileStorage } from './FileStorage.js'
66

77
export class StorageManager {
8+
static STORAGE_TYPE = {
9+
LOCAL: 'local',
10+
S3: 's3',
11+
}
12+
813
constructor() {
914
this.storage = null
1015
this.isS3 = false
1116
this.storageData = {}
1217
this.storageLoaded = false
13-
18+
1419
// Throttle saves to avoid too many writes
1520
this.saveStorageData = throttle(() => this.persistStorageData(), 1000, { leading: true, trailing: true })
1621
}
@@ -30,26 +35,26 @@ export class StorageManager {
3035
storagePrefix: process.env.S3_STORAGE_PREFIX || 'storage/',
3136
cloudfrontUrl: process.env.CLOUDFRONT_URL,
3237
}
33-
34-
if (process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY) {
38+
39+
if (process.env.S3_ACCESS_KEY_ID && process.env.S3_SECRET_ACCESS_KEY) {
3540
s3Config.credentials = {
36-
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
37-
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
41+
accessKeyId: process.env.S3_ACCESS_KEY_ID,
42+
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
3843
}
3944
}
40-
41-
this.storage = new AwsS3Storage(s3Config)
42-
45+
46+
this.storage = new S3Storage(s3Config)
47+
4348
console.log('Initializing S3 storage...')
4449
await this.storage.initialize()
45-
50+
4651
} else {
4752
// Initialize local file storage
4853
this.isS3 = false
4954
this.storage = new FileStorage({
5055
assetsUrl: '/assets/',
5156
})
52-
57+
5358
console.log('Initializing local file storage...')
5459
await this.storage.initialize()
5560
}
@@ -96,7 +101,7 @@ export class StorageManager {
96101
console.warn('Storage not yet loaded, cannot set value')
97102
return
98103
}
99-
104+
100105
try {
101106
// Ensure value is serializable
102107
value = JSON.parse(JSON.stringify(value))
@@ -115,7 +120,7 @@ export class StorageManager {
115120
console.warn('Storage not yet loaded, cannot persist')
116121
return
117122
}
118-
123+
119124
try {
120125
await this.storage.saveStorageData(this.storageData)
121126
// console.log('Storage data persisted successfully')
@@ -180,7 +185,7 @@ export class StorageManager {
180185
if (this.isS3) {
181186
// If CloudFront URL is configured, use it with assets prefix
182187
if (process.env.CLOUDFRONT_URL) {
183-
const baseUrl = process.env.CLOUDFRONT_URL.endsWith('/')
188+
const baseUrl = process.env.CLOUDFRONT_URL.endsWith('/')
184189
? process.env.CLOUDFRONT_URL.slice(0, -1) // Remove trailing slash
185190
: process.env.CLOUDFRONT_URL
186191
const assetsPrefix = (process.env.S3_ASSETS_PREFIX || 'assets/').replace(/\/$/, '') // Remove trailing slash

0 commit comments

Comments
 (0)