mirror of
https://github.com/pockethost/pockethost.git
synced 2025-03-30 15:08:30 +00:00
chore(pockethost): move util to public-api
This commit is contained in:
parent
d2a404e0e0
commit
a6427ac469
@ -3,17 +3,15 @@ import {
|
||||
MOTHERSHIP_ADMIN_USERNAME,
|
||||
MOTHERSHIP_INTERNAL_URL,
|
||||
} from '$constants'
|
||||
import { LoggerService } from '$public'
|
||||
import { LoggerService, discordAlert, tryFetch } from '$public'
|
||||
import {
|
||||
MothershipAdminClientService,
|
||||
PocketbaseService,
|
||||
PortService,
|
||||
SqliteService,
|
||||
instanceService,
|
||||
proxyService,
|
||||
realtimeLog,
|
||||
} from '$services'
|
||||
import { discordAlert, tryFetch } from '$util'
|
||||
import { ErrorRequestHandler } from 'express'
|
||||
|
||||
export async function daemon() {
|
||||
@ -38,7 +36,6 @@ export async function daemon() {
|
||||
await proxyService({
|
||||
coreInternalUrl: MOTHERSHIP_INTERNAL_URL(),
|
||||
})
|
||||
await SqliteService({})
|
||||
await realtimeLog({})
|
||||
await instanceService({
|
||||
instanceApiCheckIntervalMs: 50,
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { DATA_ROOT } from '$constants'
|
||||
import { InstanceFields, Logger, PocketBase, newId } from '$public'
|
||||
import { assert } from '$util'
|
||||
import { InstanceFields, Logger, PocketBase, assert, newId } from '$public'
|
||||
import { compact, map } from '@s-libs/micro-dash'
|
||||
import {
|
||||
Mode,
|
@ -1,14 +1,17 @@
|
||||
import {
|
||||
LoggerService,
|
||||
MOTHERSHIP_INTERNAL_URL,
|
||||
PH_FTP_PASV_IP,
|
||||
PH_FTP_PASV_PORT_MAX,
|
||||
PH_FTP_PASV_PORT_MIN,
|
||||
PH_FTP_PORT,
|
||||
PocketBase,
|
||||
SSL_CERT,
|
||||
SSL_KEY,
|
||||
} from '$constants'
|
||||
import { LoggerService, PocketBase, mergeConfig, mkSingleton } from '$public'
|
||||
import { exitHook } from '$util'
|
||||
asyncExitHook,
|
||||
mergeConfig,
|
||||
mkSingleton,
|
||||
} from '$public'
|
||||
import { keys, values } from '@s-libs/micro-dash'
|
||||
import { readFileSync } from 'fs'
|
||||
import { FtpSrv } from 'ftp-srv'
|
||||
@ -105,7 +108,7 @@ export const ftpService = mkSingleton((config: Partial<FtpConfig> = {}) => {
|
||||
dbg('Ftp server started...')
|
||||
})
|
||||
|
||||
exitHook(() => {
|
||||
asyncExitHook(async () => {
|
||||
dbg(`Closing FTP server`)
|
||||
ftpServer.close()
|
||||
})
|
@ -1,7 +1,5 @@
|
||||
import { MOTHERSHIP_INTERNAL_URL } from '$constants'
|
||||
import { LoggerService } from '$public'
|
||||
import { ftpService } from '$services'
|
||||
import { tryFetch } from '$util'
|
||||
import { LoggerService, MOTHERSHIP_INTERNAL_URL, tryFetch } from '$public'
|
||||
import { ftpService } from '../FtpService'
|
||||
|
||||
export async function ftp() {
|
||||
const logger = LoggerService().create(`EdgeFtpCommand`)
|
||||
|
@ -9,8 +9,7 @@ import {
|
||||
SSL_CERT,
|
||||
SSL_KEY,
|
||||
} from '$constants'
|
||||
import { LoggerService } from '$public'
|
||||
import { discordAlert } from '$util'
|
||||
import { LoggerService, discordAlert } from '$public'
|
||||
import { forEach } from '@s-libs/micro-dash'
|
||||
import cors from 'cors'
|
||||
import express, { ErrorRequestHandler } from 'express'
|
||||
|
@ -3,8 +3,7 @@ import {
|
||||
DISCORD_HEALTH_CHANNEL_URL,
|
||||
MOTHERSHIP_PORT,
|
||||
} from '$constants'
|
||||
import { LoggerService, stringify } from '$public'
|
||||
import { discordAlert } from '$util'
|
||||
import { LoggerService, discordAlert, stringify } from '$public'
|
||||
import Bottleneck from 'bottleneck'
|
||||
import { execSync } from 'child_process'
|
||||
import fetch from 'node-fetch'
|
||||
|
@ -7,10 +7,10 @@ import {
|
||||
TEST_EMAIL,
|
||||
} from '$constants'
|
||||
import { LoggerService, PocketBase, UserFields } from '$public'
|
||||
import { SqliteService } from '$services'
|
||||
import { map } from '@s-libs/micro-dash'
|
||||
import Bottleneck from 'bottleneck'
|
||||
import { InvalidArgumentError, program } from 'commander'
|
||||
import { SqliteService } from './SqliteService'
|
||||
|
||||
const TBL_SENT_MESSAGES = `sent_messages`
|
||||
|
||||
|
@ -2,18 +2,16 @@ import {
|
||||
InstanceFields,
|
||||
InstanceId,
|
||||
IoCManager,
|
||||
UserFields,
|
||||
mkSingleton,
|
||||
} from '$public'
|
||||
import {
|
||||
HandlerFactory,
|
||||
SettingsHandlerFactory,
|
||||
SettingsService,
|
||||
UserFields,
|
||||
mkBoolean,
|
||||
mkCsvString,
|
||||
mkNumber,
|
||||
mkPath,
|
||||
mkSingleton,
|
||||
mkString,
|
||||
} from '$util'
|
||||
} from '$public'
|
||||
import { forEach } from '@s-libs/micro-dash'
|
||||
import devcert from 'devcert'
|
||||
import envPaths from 'env-paths'
|
||||
@ -134,7 +132,7 @@ export const SETTINGS = {
|
||||
|
||||
export type Settings = ReturnType<typeof DefaultSettingsService>
|
||||
export type SettingsDefinition = {
|
||||
[_ in keyof Settings]: HandlerFactory<Settings[_]>
|
||||
[_ in keyof Settings]: SettingsHandlerFactory<Settings[_]>
|
||||
}
|
||||
|
||||
export const DefaultSettingsService = mkSingleton(
|
||||
|
@ -6,7 +6,7 @@ import { mergeConfig } from './mergeConfig'
|
||||
import { mkSingleton } from './mkSingleton'
|
||||
import { PocketHostAction, action } from './plugin'
|
||||
|
||||
export type Config = {
|
||||
export type LoggerConfig = {
|
||||
level: LogLevelName
|
||||
pfx: string[]
|
||||
}
|
||||
@ -55,8 +55,8 @@ export const LogLevels = {
|
||||
[LogLevelName.Abort]: 6,
|
||||
} as const
|
||||
|
||||
export const createLogger = (config: Partial<Config>) => {
|
||||
const _config = mergeConfig<Config>(
|
||||
export const createLogger = (config: Partial<LoggerConfig>) => {
|
||||
const _config = mergeConfig<LoggerConfig>(
|
||||
{
|
||||
level: LogLevelName.Debug,
|
||||
pfx: [''],
|
||||
@ -125,7 +125,7 @@ export const createLogger = (config: Partial<Config>) => {
|
||||
throw new Error(`Fatal error: ${stringify(args)}`)
|
||||
}
|
||||
|
||||
const create = (s: string, configOverride?: Partial<Config>) =>
|
||||
const create = (s: string, configOverride?: Partial<LoggerConfig>) =>
|
||||
createLogger({
|
||||
..._config,
|
||||
...configOverride,
|
||||
@ -161,6 +161,6 @@ export const createLogger = (config: Partial<Config>) => {
|
||||
return api
|
||||
}
|
||||
|
||||
export const LoggerService = mkSingleton((config: Partial<Config> = {}) =>
|
||||
export const LoggerService = mkSingleton((config: Partial<LoggerConfig> = {}) =>
|
||||
createLogger(config),
|
||||
)
|
||||
|
@ -2,27 +2,29 @@ import { mkSingleton } from '$public'
|
||||
import { boolean as castToBoolean } from 'boolean'
|
||||
import { existsSync, mkdirSync } from 'fs'
|
||||
|
||||
export type Caster<TValue, TConfig = {}> = {
|
||||
export type SettingsCaster<TValue, TConfig = {}> = {
|
||||
stringToType: (value: string, config?: Partial<TConfig>) => TValue
|
||||
typeToString: (value: TValue, config?: Partial<TConfig>) => string
|
||||
}
|
||||
|
||||
export type Handler<TValue> = {
|
||||
export type SettingsHandler<TValue> = {
|
||||
get: () => TValue
|
||||
set: (value: TValue) => void
|
||||
}
|
||||
|
||||
export type HandlerFactory<TValue> = (key: string) => Handler<TValue>
|
||||
export type SettingsHandlerFactory<TValue> = (
|
||||
key: string,
|
||||
) => SettingsHandler<TValue>
|
||||
|
||||
export type Maker<TValue, TConfig = {}> = (
|
||||
export type SettingsMaker<TValue, TConfig = {}> = (
|
||||
_default?: TValue,
|
||||
config?: Partial<TConfig>,
|
||||
) => HandlerFactory<TValue>
|
||||
) => SettingsHandlerFactory<TValue>
|
||||
|
||||
const mkMaker =
|
||||
<TValue, TConfig = {}>(
|
||||
caster: Caster<TValue, TConfig>,
|
||||
): Maker<TValue, TConfig> =>
|
||||
caster: SettingsCaster<TValue, TConfig>,
|
||||
): SettingsMaker<TValue, TConfig> =>
|
||||
(_default, config) =>
|
||||
(name: string) => {
|
||||
return {
|
||||
@ -98,7 +100,7 @@ export const mkCsvString = mkMaker<string[]>({
|
||||
})
|
||||
|
||||
type Config<T> = {
|
||||
[K in keyof T]: HandlerFactory<T[K]>
|
||||
[K in keyof T]: SettingsHandlerFactory<T[K]>
|
||||
}
|
||||
|
||||
export const SettingsService = <T extends Object>(config: Config<T>) => {
|
@ -1,15 +1,27 @@
|
||||
export * from '$constants'
|
||||
export * from './CleanupManager'
|
||||
export * from './Logger'
|
||||
export * from './PromiseAllocator'
|
||||
export * from './Settings'
|
||||
export * from './SyslogLogger'
|
||||
export * from './TimerManager'
|
||||
export * from './assert'
|
||||
export * from './asyncExecutionGuard'
|
||||
export * from './discordAlert'
|
||||
export * from './env'
|
||||
export * from './events'
|
||||
export * from './exit'
|
||||
export * from './internal'
|
||||
export * from './ioc'
|
||||
export * from './mergeConfig'
|
||||
export * from './mkSingleton'
|
||||
export * from './newId'
|
||||
export * from './now'
|
||||
export * from './plugin'
|
||||
export * from './pocketbase'
|
||||
export * from './pocketbase-client-helpers'
|
||||
export * from './process'
|
||||
export * from './schema'
|
||||
export * from './smartFetch'
|
||||
export * from './stringify'
|
||||
export * from './tryFetch'
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { mkInstanceDataPath } from '$constants'
|
||||
import {
|
||||
LoggerService,
|
||||
asyncExitHook,
|
||||
createCleanupManager,
|
||||
mergeConfig,
|
||||
stringify,
|
||||
} from '$public'
|
||||
import { asyncExitHook } from '$util'
|
||||
import * as fs from 'fs'
|
||||
import { Tail } from 'tail'
|
||||
import * as winston from 'winston'
|
||||
|
@ -19,9 +19,12 @@ import {
|
||||
InstanceStatus,
|
||||
LoggerService,
|
||||
SingletonBaseConfig,
|
||||
asyncExitHook,
|
||||
createCleanupManager,
|
||||
createTimerManager,
|
||||
mkInternalUrl,
|
||||
mkSingleton,
|
||||
now,
|
||||
stringify,
|
||||
} from '$public'
|
||||
import {
|
||||
@ -32,7 +35,6 @@ import {
|
||||
SpawnConfig,
|
||||
proxyService,
|
||||
} from '$services'
|
||||
import { asyncExitHook, mkInternalUrl, now } from '$util'
|
||||
import { flatten, map, values } from '@s-libs/micro-dash'
|
||||
import Bottleneck from 'bottleneck'
|
||||
import { globSync } from 'glob'
|
||||
|
@ -8,11 +8,14 @@ import {
|
||||
import {
|
||||
LoggerService,
|
||||
SingletonBaseConfig,
|
||||
SyslogLogger,
|
||||
asyncExitHook,
|
||||
createCleanupManager,
|
||||
mkInternalUrl,
|
||||
mkSingleton,
|
||||
tryFetch,
|
||||
} from '$public'
|
||||
import { PortService } from '$services'
|
||||
import { SyslogLogger, asyncExitHook, mkInternalUrl, tryFetch } from '$util'
|
||||
import { map } from '@s-libs/micro-dash'
|
||||
import Docker, { Container, ContainerCreateOptions } from 'dockerode'
|
||||
import { existsSync } from 'fs'
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { INITIAL_PORT_POOL_SIZE } from '$constants'
|
||||
import { mergeConfig, mkSingleton } from '$public'
|
||||
import { PromiseAllocator } from '$util'
|
||||
import { PromiseAllocator, mergeConfig, mkSingleton } from '$public'
|
||||
import getPort from 'get-port'
|
||||
|
||||
export type Config = { maxPorts: number }
|
||||
|
@ -3,9 +3,9 @@ import {
|
||||
Logger,
|
||||
LoggerService,
|
||||
SingletonBaseConfig,
|
||||
asyncExitHook,
|
||||
mkSingleton,
|
||||
} from '$public'
|
||||
import { asyncExitHook } from '$util'
|
||||
import cors from 'cors'
|
||||
import express, { Request, Response } from 'express'
|
||||
import 'express-async-errors'
|
||||
|
@ -1,4 +1,3 @@
|
||||
export * from './FtpService'
|
||||
export * from './InstanceLoggerService'
|
||||
export * from './InstanceService'
|
||||
export * from './MothershipAdminClientService'
|
||||
@ -6,4 +5,3 @@ export * from './PocketBaseService'
|
||||
export * from './PortService'
|
||||
export * from './ProxyService'
|
||||
export * from './RealtimeLog'
|
||||
export * from './SqliteService'
|
||||
|
@ -1,2 +0,0 @@
|
||||
import { assert } from '$public'
|
||||
export { assert }
|
@ -1,12 +0,0 @@
|
||||
export * from './PromiseAllocator'
|
||||
export * from './Settings'
|
||||
export * from './SyslogLogger'
|
||||
export * from './assert'
|
||||
export * from './discordAlert'
|
||||
export * from './env'
|
||||
export * from './exit'
|
||||
export * from './internal'
|
||||
export * from './now'
|
||||
export * from './process'
|
||||
export * from './smartFetch'
|
||||
export * from './tryFetch'
|
@ -18,7 +18,6 @@
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"$public": ["./src/public-api"],
|
||||
"$util": ["./src/util"],
|
||||
"$services": ["./src/services"],
|
||||
"$constants": ["./src/constants"],
|
||||
"$src/*": ["./src/*"]
|
||||
|
Loading…
x
Reference in New Issue
Block a user