diff --git a/src/services/file/index.ts b/src/services/file/index.ts index 982ffc83a636..72bb54f91872 100644 --- a/src/services/file/index.ts +++ b/src/services/file/index.ts @@ -1,6 +1,5 @@ -import { isServerMode } from '@/const/version'; - import { ClientService } from './client'; import { ServerService } from './server'; -export const fileService = isServerMode ? new ServerService() : new ClientService(); +export const fileService = + process.env.NEXT_PUBLIC_SERVICE_MODE === 'server' ? new ServerService() : new ClientService(); diff --git a/src/services/import/index.ts b/src/services/import/index.ts index 2400e7b8c8e3..4f2ab75bfea8 100644 --- a/src/services/import/index.ts +++ b/src/services/import/index.ts @@ -1,6 +1,5 @@ -import { isServerMode } from '@/const/version'; - import { ClientService } from './client'; import { ServerService } from './server'; -export const importService = isServerMode ? new ServerService() : new ClientService(); +export const importService = + process.env.NEXT_PUBLIC_SERVICE_MODE === 'server' ? new ServerService() : new ClientService(); diff --git a/src/services/message/index.ts b/src/services/message/index.ts index 440fae00a09c..930eaf6034ed 100644 --- a/src/services/message/index.ts +++ b/src/services/message/index.ts @@ -1,6 +1,5 @@ -import { isServerMode } from '@/const/version'; - import { ClientService } from './client'; import { ServerService } from './server'; -export const messageService = isServerMode ? new ServerService() : new ClientService(); +export const messageService = + process.env.NEXT_PUBLIC_SERVICE_MODE === 'server' ? new ServerService() : new ClientService(); diff --git a/src/services/plugin/index.ts b/src/services/plugin/index.ts index 35561e18167d..77b3ab38869b 100644 --- a/src/services/plugin/index.ts +++ b/src/services/plugin/index.ts @@ -1,6 +1,5 @@ -import { isServerMode } from '@/const/version'; - import { ClientService } from './client'; import { ServerService } from './server'; -export const pluginService = isServerMode ? new ServerService() : new ClientService(); +export const pluginService = + process.env.NEXT_PUBLIC_SERVICE_MODE === 'server' ? new ServerService() : new ClientService(); diff --git a/src/services/session/index.ts b/src/services/session/index.ts index 3e3d5eb600cd..0d55e3cc45e5 100644 --- a/src/services/session/index.ts +++ b/src/services/session/index.ts @@ -1,6 +1,5 @@ -import { isServerMode } from '@/const/version'; - import { ClientService } from './client'; import { ServerService } from './server'; -export const sessionService = isServerMode ? new ServerService() : new ClientService(); +export const sessionService = + process.env.NEXT_PUBLIC_SERVICE_MODE === 'server' ? new ServerService() : new ClientService(); diff --git a/src/services/topic/index.ts b/src/services/topic/index.ts index 60ba0c3a7698..360656149ea5 100644 --- a/src/services/topic/index.ts +++ b/src/services/topic/index.ts @@ -1,6 +1,6 @@ -import { isServerMode } from '@/const/version'; import { ClientService } from './client'; import { ServerService } from './server'; -export const topicService = isServerMode ? new ServerService() : new ClientService(); +export const topicService = + process.env.NEXT_PUBLIC_SERVICE_MODE === 'server' ? new ServerService() : new ClientService(); diff --git a/src/services/upload.ts b/src/services/upload.ts index 9623764ff1b9..311b329150e3 100644 --- a/src/services/upload.ts +++ b/src/services/upload.ts @@ -1,5 +1,4 @@ import { fileEnv } from '@/config/file'; -import { FileModel } from '@/database/client/models/file'; import { edgeClient } from '@/libs/trpc/client'; import { API_ENDPOINTS } from '@/services/_url'; import { FileMetadata, UploadFileParams } from '@/types/files'; @@ -68,6 +67,7 @@ class UploadService { }; uploadToClientDB = async (params: UploadFileParams, file: File) => { + const { FileModel } = await import('@/database/client/models/file'); const fileArrayBuffer = await file.arrayBuffer(); // save to local storage diff --git a/src/services/user/index.ts b/src/services/user/index.ts index 3ad969dad170..e472bdaef2c0 100644 --- a/src/services/user/index.ts +++ b/src/services/user/index.ts @@ -1,6 +1,5 @@ -import { isServerMode } from '@/const/version'; - import { ClientService } from './client'; import { ServerService } from './server'; -export const userService = isServerMode ? new ServerService() : new ClientService(); +export const userService = + process.env.NEXT_PUBLIC_SERVICE_MODE === 'server' ? new ServerService() : new ClientService(); diff --git a/src/store/user/slices/common/action.ts b/src/store/user/slices/common/action.ts index 00024cfc1fef..5f523d8d7dde 100644 --- a/src/store/user/slices/common/action.ts +++ b/src/store/user/slices/common/action.ts @@ -5,7 +5,6 @@ import type { StateCreator } from 'zustand/vanilla'; import { DEFAULT_PREFERENCE } from '@/const/user'; import { useOnlyFetchOnceSWR } from '@/libs/swr'; import { userService } from '@/services/user'; -import { ClientService } from '@/services/user/client'; import type { UserStore } from '@/store/user'; import type { GlobalServerConfig } from '@/types/serverConfig'; import { UserInitializationState } from '@/types/user'; @@ -47,6 +46,8 @@ export const createCommonSlice: StateCreator< await mutate(GET_USER_STATE_KEY); }, updateAvatar: async (avatar) => { + const { ClientService } = await import('@/services/user/client'); + const clientService = new ClientService(); await clientService.updateAvatar(avatar); diff --git a/src/store/user/slices/sync/action.ts b/src/store/user/slices/sync/action.ts index 3dac5c52fcaa..4860f5ec5d3a 100644 --- a/src/store/user/slices/sync/action.ts +++ b/src/store/user/slices/sync/action.ts @@ -1,7 +1,6 @@ import useSWR, { SWRResponse } from 'swr'; import type { StateCreator } from 'zustand/vanilla'; -import { syncService } from '@/services/sync'; import type { UserStore } from '@/store/user'; import { OnSyncEvent, PeerSyncStatus } from '@/types/sync'; import { browserInfo } from '@/utils/platform'; @@ -53,6 +52,8 @@ export const createSyncSlice: StateCreator< const defaultUserName = `My ${browserInfo.browser} (${browserInfo.os})`; set({ syncStatus: PeerSyncStatus.Connecting }); + const { syncService } = await import('@/services/sync'); + return syncService.enabledSync({ channel: { name: sync.channelName, @@ -83,7 +84,10 @@ export const createSyncSlice: StateCreator< if (!userId) return false; // if user don't enable sync, stop sync - if (!userEnableSync) return syncService.disableSync(); + if (!userEnableSync) { + const { syncService } = await import('@/services/sync'); + return syncService.disableSync(); + } return get().triggerEnableSync(userId, onEvent); },