mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-14 08:36:22 +08:00
feat!: affine cloud support (#3813)
Co-authored-by: Hongtao Lye <codert.sn@gmail.com> Co-authored-by: liuyi <forehalo@gmail.com> Co-authored-by: LongYinan <lynweklm@gmail.com> Co-authored-by: X1a0t <405028157@qq.com> Co-authored-by: JimmFly <yangjinfei001@gmail.com> Co-authored-by: Peng Xiao <pengxiao@outlook.com> Co-authored-by: xiaodong zuo <53252747+zuoxiaodong0815@users.noreply.github.com> Co-authored-by: DarkSky <25152247+darkskygit@users.noreply.github.com> Co-authored-by: Qi <474021214@qq.com> Co-authored-by: danielchim <kahungchim@gmail.com>
This commit is contained in:
@@ -1,28 +1,25 @@
|
||||
import { createRequire } from 'node:module';
|
||||
|
||||
import type { Storage } from '@affine/storage';
|
||||
import { type DynamicModule, type FactoryProvider } from '@nestjs/common';
|
||||
|
||||
import { Config } from '../config';
|
||||
|
||||
export const StorageProvide = Symbol('Storage');
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
let storageModule: typeof import('@affine/storage');
|
||||
try {
|
||||
storageModule = await import('@affine/storage');
|
||||
} catch {
|
||||
const require = createRequire(import.meta.url);
|
||||
storageModule = require('../../storage.node');
|
||||
}
|
||||
|
||||
export class StorageModule {
|
||||
static forRoot(): DynamicModule {
|
||||
const storageProvider: FactoryProvider = {
|
||||
provide: StorageProvide,
|
||||
useFactory: async (config: Config) => {
|
||||
let StorageFactory: typeof Storage;
|
||||
try {
|
||||
// dev mode
|
||||
StorageFactory = (await import('@affine/storage')).Storage;
|
||||
} catch {
|
||||
// In docker
|
||||
StorageFactory = require('../../storage.node').Storage;
|
||||
}
|
||||
return StorageFactory.connect(config.db.url);
|
||||
return storageModule.Storage.connect(config.db.url);
|
||||
},
|
||||
inject: [Config],
|
||||
};
|
||||
@@ -35,3 +32,5 @@ export class StorageModule {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export const mergeUpdatesInApplyWay = storageModule.mergeUpdatesInApplyWay;
|
||||
|
||||
Reference in New Issue
Block a user