mirror of
https://github.com/pockethost/pockethost.git
synced 2025-07-09 22:32:31 +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 { Knex } from 'knex'
|
||||||
import {
|
import {
|
||||||
Collection,
|
Collection,
|
||||||
default as PocketBase,
|
default as PocketBase,
|
||||||
default as pocketbaseEs,
|
default as pocketbaseEs,
|
||||||
} from 'pocketbase'
|
} from 'pocketbase'
|
||||||
import {
|
import { DAEMON_PB_DATA_DIR, PUBLIC_PB_SUBDOMAIN } from '../constants'
|
||||||
DAEMON_PB_DATA_DIR,
|
|
||||||
DAEMON_PB_PASSWORD,
|
|
||||||
DAEMON_PB_USERNAME,
|
|
||||||
PUBLIC_PB_DOMAIN,
|
|
||||||
PUBLIC_PB_PROTOCOL,
|
|
||||||
PUBLIC_PB_SUBDOMAIN,
|
|
||||||
} from '../constants'
|
|
||||||
import { Collection_Serialized } from '../migrate/schema'
|
import { Collection_Serialized } from '../migrate/schema'
|
||||||
import { safeCatch } from '../util/promiseHelper'
|
import { safeCatch } from '../util/promiseHelper'
|
||||||
import { createBackupMixin } from './BackupMixin'
|
import { createBackupMixin } from './BackupMixin'
|
||||||
@ -68,18 +61,3 @@ export const createPbClient = (url: string) => {
|
|||||||
|
|
||||||
return api
|
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 { logger } from '@pockethost/common'
|
||||||
import { DEBUG, PH_BIN_CACHE, PUBLIC_PB_SUBDOMAIN } from './constants'
|
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 { backupService } from './services/BackupService'
|
||||||
import { ftpService } from './services/FtpService/FtpService'
|
import { ftpService } from './services/FtpService/FtpService'
|
||||||
import { instanceService } from './services/InstanceService'
|
import { instanceService } from './services/InstanceService'
|
||||||
|
@ -14,7 +14,7 @@ import {
|
|||||||
RpcCommands,
|
RpcCommands,
|
||||||
} from '@pockethost/common'
|
} from '@pockethost/common'
|
||||||
import Bottleneck from 'bottleneck'
|
import Bottleneck from 'bottleneck'
|
||||||
import { clientService } from '../db/PbClient'
|
import { clientService } from '../db/clientService'
|
||||||
import { backupInstance } from '../util/backupInstance'
|
import { backupInstance } from '../util/backupInstance'
|
||||||
import { rpcService } from './RpcService'
|
import { rpcService } from './RpcService'
|
||||||
|
|
||||||
|
@ -9,7 +9,8 @@ import {
|
|||||||
SSL_CERT,
|
SSL_CERT,
|
||||||
SSL_KEY,
|
SSL_KEY,
|
||||||
} from '../../constants'
|
} from '../../constants'
|
||||||
import { clientService, createPbClient } from '../../db/PbClient'
|
import { clientService } from '../../db/clientService'
|
||||||
|
import { createPbClient } from '../../db/PbClient'
|
||||||
import { PhFs } from './PhFs'
|
import { PhFs } from './PhFs'
|
||||||
|
|
||||||
export type FtpConfig = {}
|
export type FtpConfig = {}
|
||||||
|
@ -20,7 +20,7 @@ import {
|
|||||||
PUBLIC_APP_DOMAIN,
|
PUBLIC_APP_DOMAIN,
|
||||||
PUBLIC_APP_PROTOCOL,
|
PUBLIC_APP_PROTOCOL,
|
||||||
} from '../constants'
|
} from '../constants'
|
||||||
import { clientService } from '../db/PbClient'
|
import { clientService } from '../db/clientService'
|
||||||
import { mkInternalUrl } from '../util/internal'
|
import { mkInternalUrl } from '../util/internal'
|
||||||
import { now } from '../util/now'
|
import { now } from '../util/now'
|
||||||
import { safeCatch } from '../util/promiseHelper'
|
import { safeCatch } from '../util/promiseHelper'
|
||||||
|
@ -13,7 +13,7 @@ import Bottleneck from 'bottleneck'
|
|||||||
import { default as knexFactory } from 'knex'
|
import { default as knexFactory } from 'knex'
|
||||||
import pocketbaseEs from 'pocketbase'
|
import pocketbaseEs from 'pocketbase'
|
||||||
import { AsyncReturnType, JsonObject } from 'type-fest'
|
import { AsyncReturnType, JsonObject } from 'type-fest'
|
||||||
import { clientService } from '../db/PbClient'
|
import { clientService } from '../db/clientService'
|
||||||
|
|
||||||
export type RpcServiceApi = AsyncReturnType<typeof rpcService>
|
export type RpcServiceApi = AsyncReturnType<typeof rpcService>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user