mirror of
https://github.com/pockethost/pockethost.git
synced 2025-03-30 15:08:30 +00:00
chore: refactor clientService
This commit is contained in:
parent
5f8351ebf7
commit
a611c86c9c
@ -1,18 +1,11 @@
|
||||
import { logger, mkSingleton } from '@pockethost/common'
|
||||
import { logger } from '@pockethost/common'
|
||||
import { Knex } from 'knex'
|
||||
import {
|
||||
Collection,
|
||||
default as PocketBase,
|
||||
default as pocketbaseEs,
|
||||
} from 'pocketbase'
|
||||
import {
|
||||
DAEMON_PB_DATA_DIR,
|
||||
DAEMON_PB_PASSWORD,
|
||||
DAEMON_PB_USERNAME,
|
||||
PUBLIC_PB_DOMAIN,
|
||||
PUBLIC_PB_PROTOCOL,
|
||||
PUBLIC_PB_SUBDOMAIN,
|
||||
} from '../constants'
|
||||
import { DAEMON_PB_DATA_DIR, PUBLIC_PB_SUBDOMAIN } from '../constants'
|
||||
import { Collection_Serialized } from '../migrate/schema'
|
||||
import { safeCatch } from '../util/promiseHelper'
|
||||
import { createBackupMixin } from './BackupMixin'
|
||||
@ -68,18 +61,3 @@ export const createPbClient = (url: string) => {
|
||||
|
||||
return api
|
||||
}
|
||||
|
||||
export const clientService = mkSingleton(async (url: string) => {
|
||||
const { dbg, error } = logger().create(`client singleton`)
|
||||
const client = createPbClient(url)
|
||||
try {
|
||||
await client.adminAuthViaEmail(DAEMON_PB_USERNAME, DAEMON_PB_PASSWORD)
|
||||
dbg(`Logged in`)
|
||||
} catch (e) {
|
||||
error(
|
||||
`***WARNING*** CANNOT AUTHENTICATE TO ${PUBLIC_PB_PROTOCOL}://${PUBLIC_PB_SUBDOMAIN}.${PUBLIC_PB_DOMAIN}/_/`
|
||||
)
|
||||
error(`***WARNING*** LOG IN MANUALLY, ADJUST .env, AND RESTART DOCKER`)
|
||||
}
|
||||
return client
|
||||
})
|
||||
|
24
packages/daemon/src/db/clientService.ts
Normal file
24
packages/daemon/src/db/clientService.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { logger, mkSingleton } from '@pockethost/common'
|
||||
import {
|
||||
DAEMON_PB_PASSWORD,
|
||||
DAEMON_PB_USERNAME,
|
||||
PUBLIC_PB_DOMAIN,
|
||||
PUBLIC_PB_PROTOCOL,
|
||||
PUBLIC_PB_SUBDOMAIN,
|
||||
} from '../constants'
|
||||
import { createPbClient } from './PbClient'
|
||||
|
||||
export const clientService = mkSingleton(async (url: string) => {
|
||||
const { dbg, error } = logger().create(`client singleton`)
|
||||
const client = createPbClient(url)
|
||||
try {
|
||||
await client.adminAuthViaEmail(DAEMON_PB_USERNAME, DAEMON_PB_PASSWORD)
|
||||
dbg(`Logged in`)
|
||||
} catch (e) {
|
||||
error(
|
||||
`***WARNING*** CANNOT AUTHENTICATE TO ${PUBLIC_PB_PROTOCOL}://${PUBLIC_PB_SUBDOMAIN}.${PUBLIC_PB_DOMAIN}/_/`
|
||||
)
|
||||
error(`***WARNING*** LOG IN MANUALLY, ADJUST .env, AND RESTART DOCKER`)
|
||||
}
|
||||
return client
|
||||
})
|
@ -1,6 +1,6 @@
|
||||
import { logger } from '@pockethost/common'
|
||||
import { DEBUG, PH_BIN_CACHE, PUBLIC_PB_SUBDOMAIN } from './constants'
|
||||
import { clientService } from './db/PbClient'
|
||||
import { clientService } from './db/clientService'
|
||||
import { backupService } from './services/BackupService'
|
||||
import { ftpService } from './services/FtpService/FtpService'
|
||||
import { instanceService } from './services/InstanceService'
|
||||
|
@ -14,7 +14,7 @@ import {
|
||||
RpcCommands,
|
||||
} from '@pockethost/common'
|
||||
import Bottleneck from 'bottleneck'
|
||||
import { clientService } from '../db/PbClient'
|
||||
import { clientService } from '../db/clientService'
|
||||
import { backupInstance } from '../util/backupInstance'
|
||||
import { rpcService } from './RpcService'
|
||||
|
||||
|
@ -9,7 +9,8 @@ import {
|
||||
SSL_CERT,
|
||||
SSL_KEY,
|
||||
} from '../../constants'
|
||||
import { clientService, createPbClient } from '../../db/PbClient'
|
||||
import { clientService } from '../../db/clientService'
|
||||
import { createPbClient } from '../../db/PbClient'
|
||||
import { PhFs } from './PhFs'
|
||||
|
||||
export type FtpConfig = {}
|
||||
|
@ -20,7 +20,7 @@ import {
|
||||
PUBLIC_APP_DOMAIN,
|
||||
PUBLIC_APP_PROTOCOL,
|
||||
} from '../constants'
|
||||
import { clientService } from '../db/PbClient'
|
||||
import { clientService } from '../db/clientService'
|
||||
import { mkInternalUrl } from '../util/internal'
|
||||
import { now } from '../util/now'
|
||||
import { safeCatch } from '../util/promiseHelper'
|
||||
|
@ -13,7 +13,7 @@ import Bottleneck from 'bottleneck'
|
||||
import { default as knexFactory } from 'knex'
|
||||
import pocketbaseEs from 'pocketbase'
|
||||
import { AsyncReturnType, JsonObject } from 'type-fest'
|
||||
import { clientService } from '../db/PbClient'
|
||||
import { clientService } from '../db/clientService'
|
||||
|
||||
export type RpcServiceApi = AsyncReturnType<typeof rpcService>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user