Skip to content

Commit 5012d34

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 e0c6dd6 commit 5012d34

File tree

3 files changed

+44
-13
lines changed

3 files changed

+44
-13
lines changed

.env.example

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ LIVEKIT_API_SECRET=
4343
# Supported databases:
4444
# - SQLite (default - no configuration needed)
4545
# - PostgreSQL (DB_TYPE=pg with DB_URL)
46-
#
46+
#
4747
# If DB_TYPE and DB_URL are not provided or empty,
4848
# the application will automatically use SQLite in the world folder.
4949

@@ -52,4 +52,30 @@ DB_TYPE=
5252

5353
# Database connection URL - leave empty for SQLite
5454
# For PostgreSQL, use format: postgres://username:password@host:port/database?schema=public
55-
DB_URL=
55+
DB_URL=
56+
57+
# ==============================================
58+
# STORAGE CONFIGURATION
59+
# ==============================================
60+
# Configure your file storage system here.
61+
#
62+
# Supported storage types:
63+
# - Local file system (default - no configuration needed)
64+
# - S3-compatible storage (CloudFlare R2, AWS S3, DigitalOcean Spaces, etc.)
65+
#
66+
# If STORAGE_TYPE is set to 's3', S3-compatible storage will be used.
67+
# If STORAGE_TYPE is empty or not set, local file storage will be used.
68+
#
69+
# S3 credentials can be provided via environment variables below,
70+
# or through AWS CLI configuration, IAM roles, or instance profiles.
71+
72+
# S3 storage configuration (only required when using S3)
73+
# To use S3-compatible storage, set STORAGE_TYPE and other S3 variables below
74+
STORAGE_TYPE=
75+
S3_BUCKET_NAME=bucket-name
76+
S3_ACCESS_KEY_ID=access-key-id
77+
S3_SECRET_ACCESS_KEY=secret-key-id
78+
S3_REGION=eu-west-1
79+
S3_ASSETS_PREFIX=
80+
S3_COLLECTIONS_PREFIX=
81+
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: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
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
@@ -19,12 +24,12 @@ export class StorageManager {
1924
* Initialize storage based on environment configuration
2025
*/
2126
async initialize() {
22-
const storageType = process.env.STORAGE_TYPE || 'local'
27+
const storageType = process.env.STORAGE_TYPE || StorageManager.STORAGE_TYPE.LOCAL;
2328

24-
if (storageType === 'aws') {
29+
if (storageType === StorageManager.STORAGE_TYPE.S3) {
2530
// Validate required S3 configuration
2631
if (!process.env.S3_BUCKET_NAME) {
27-
throw new Error('S3_BUCKET_NAME is required when STORAGE_TYPE=aws')
32+
throw new Error('S3_BUCKET_NAME is required when STORAGE_TYPE=s3')
2833
}
2934

3035
// Initialize S3 storage
@@ -38,16 +43,16 @@ export class StorageManager {
3843
cloudfrontUrl: process.env.CLOUDFRONT_URL,
3944
}
4045

41-
if (process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY) {
46+
if (process.env.S3_ACCESS_KEY_ID && process.env.S3_SECRET_ACCESS_KEY) {
4247
s3Config.credentials = {
43-
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
44-
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
48+
accessKeyId: process.env.S3_ACCESS_KEY_ID,
49+
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
4550
}
4651
}
4752

48-
this.storage = new AwsS3Storage(s3Config)
53+
this.storage = new S3Storage(s3Config)
4954

50-
console.log('Initializing AWS S3 storage...')
55+
console.log('Initializing S3 storage...')
5156
await this.storage.initialize()
5257

5358
} else if (storageType === 'local') {
@@ -60,7 +65,7 @@ export class StorageManager {
6065
console.log('Initializing local file storage...')
6166
await this.storage.initialize()
6267
} else {
63-
throw new Error(`Unsupported storage type: ${storageType}. Supported types: 'local', 'aws'`)
68+
throw new Error(`Unsupported storage type: ${storageType}. Supported types: 'local', 's3'`)
6469
}
6570

6671
// Initialize storage data

0 commit comments

Comments
 (0)