Skip to content

Commit 8acb76e

Browse files
committed
Merge branch 'feat/full-storage-and-db-support' of github.com:numengames/numinia-hyperfy2 into feat/full-storage-and-db-support
# Conflicts: # .env.example # scripts/clean-world.mjs # src/server/storage/StorageManager.js
2 parents aa2bbeb + a3d71aa commit 8acb76e

File tree

3 files changed

+16
-29
lines changed

3 files changed

+16
-29
lines changed

.env.example

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,36 +30,17 @@ PUBLIC_API_URL=http://localhost:3000/api
3030
# The public url used by clients to fetch assets
3131
PUBLIC_ASSETS_URL=http://localhost:3000/assets
3232

33+
# LiveKit (voice chat)
34+
LIVEKIT_WS_URL=
35+
LIVEKIT_API_KEY=
36+
LIVEKIT_API_SECRET=
37+
3338
# ==============================================
3439
# DATABASE CONFIGURATION
3540
# ==============================================
3641
# Configure your database connection here.
3742
#
3843
# Supported databases:
39-
# - PostgreSQL (DB_TYPE=pg)
40-
# - MySQL (DB_TYPE=mysql2)
41-
# - SQLite (fallback - no configuration needed)
42-
#
43-
# If database environment variables are not provided,
44-
# the application will automatically fall back to SQLite.
45-
46-
# Database type - specify the database engine to use
47-
# Options: 'pg' (PostgreSQL), 'mysql2' (MySQL)
48-
DB_TYPE=pg
49-
50-
# Database connection details
51-
DB_HOST=localhost
52-
DB_PORT=5432
53-
DB_USER=your_username
54-
DB_PASSWORD=your_password
55-
DB_NAME=your_database_name
56-
DB_SCHEMA=your_database_schema
57-
58-
# LiveKit (voice chat)
59-
LIVEKIT_WS_URL=
60-
LIVEKIT_API_KEY=
61-
LIVEKIT_API_SECRET=
62-
6344
# - SQLite (default - no configuration needed)
6445
# - PostgreSQL (DB_TYPE=pg with DB_URL)
6546
#

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"yoga-layout": "^3.2.1"
7171
},
7272
"optionalDependencies": {
73+
"pg": "^8.16.0",
7374
"@aws-sdk/client-s3": "^3.685.0",
7475
"@aws-sdk/s3-request-presigner": "^3.685.0",
7576
"pg": "^8.16.0"

src/server/storage/StorageManager.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export class StorageManager {
1515
this.isS3 = false
1616
this.storageData = {}
1717
this.storageLoaded = false
18-
1918
// Throttle saves to avoid too many writes
2019
this.saveStorageData = throttle(() => this.persistStorageData(), 1000, { leading: true, trailing: true })
2120
}
@@ -24,7 +23,14 @@ export class StorageManager {
2423
* Initialize storage based on environment configuration
2524
*/
2625
async initialize() {
27-
if (process.env.S3_BUCKET_NAME) {
26+
const storageType = process.env.STORAGE_TYPE || StorageManager.STORAGE_TYPE.LOCAL;
27+
28+
if (storageType === StorageManager.STORAGE_TYPE.S3) {
29+
// Validate required S3 configuration
30+
if (!process.env.S3_BUCKET_NAME) {
31+
throw new Error('S3_BUCKET_NAME is required when STORAGE_TYPE=s3')
32+
}
33+
2834
// Initialize S3 storage
2935
this.isS3 = true
3036
const s3Config = {
@@ -35,7 +41,6 @@ export class StorageManager {
3541
storagePrefix: process.env.S3_STORAGE_PREFIX || 'storage/',
3642
cloudfrontUrl: process.env.CLOUDFRONT_URL,
3743
}
38-
3944
if (process.env.S3_ACCESS_KEY_ID && process.env.S3_SECRET_ACCESS_KEY) {
4045
s3Config.credentials = {
4146
accessKeyId: process.env.S3_ACCESS_KEY_ID,
@@ -57,6 +62,8 @@ export class StorageManager {
5762

5863
console.log('Initializing local file storage...')
5964
await this.storage.initialize()
65+
} else {
66+
throw new Error(`Unsupported storage type: ${storageType}. Supported types: 'local', 's3'`)
6067
}
6168

6269
// Initialize storage data
@@ -101,7 +108,6 @@ export class StorageManager {
101108
console.warn('Storage not yet loaded, cannot set value')
102109
return
103110
}
104-
105111
try {
106112
// Ensure value is serializable
107113
value = JSON.parse(JSON.stringify(value))
@@ -120,7 +126,6 @@ export class StorageManager {
120126
console.warn('Storage not yet loaded, cannot persist')
121127
return
122128
}
123-
124129
try {
125130
await this.storage.saveStorageData(this.storageData)
126131
// console.log('Storage data persisted successfully')

0 commit comments

Comments
 (0)