support optional B2 service

This commit is contained in:
SrGooglo 2024-04-18 16:58:24 +00:00
parent 7619c1f4d9
commit 0500118b68
2 changed files with 16 additions and 5 deletions

View File

@ -25,16 +25,23 @@ class API extends Server {
cache: new CacheService(),
redis: RedisClient(),
storage: StorageClient(),
b2Storage: new B2({
applicationKeyId: process.env.B2_KEY_ID,
applicationKey: process.env.B2_APP_KEY,
}),
b2Storage: null,
limits: {},
}
async onInitialize() {
global.storage = this.contexts.storage
if (process.env.B2_KEY_ID && process.env.B2_APP_KEY) {
this.contexts.b2Storage = new B2({
applicationKeyId: process.env.B2_KEY_ID,
applicationKey: process.env.B2_APP_KEY,
})
global.b2Storage = this.contexts.b2Storage
} else {
console.warn("B2 storage not configured on environment, skipping...")
}
await this.contexts.db.initialize()
await this.contexts.redis.initialize()

View File

@ -106,6 +106,10 @@ export default async ({
switch (service) {
case "b2":
if (!global.b2Storage) {
throw new OperationError(500, "B2 storage not configured on environment, unsupported service. Please use `standard` service.")
}
result = await b2Upload({
remotePath,
source,