mirror of
https://github.com/seejohnrun/haste-server.git
synced 2026-01-27 21:37:12 +00:00
fix types and build
This commit is contained in:
@@ -2,10 +2,10 @@ import { Request, Response } from 'express'
|
||||
import * as winston from 'winston'
|
||||
import Busboy from 'busboy'
|
||||
import type { Config } from 'src/types/config'
|
||||
import type { Store } from 'src/types/callback'
|
||||
import type { Document } from 'src/types/document'
|
||||
import constants from 'src/constants'
|
||||
import KeyGenerator from 'src/lib/key-generators'
|
||||
import { Store } from '../document-stores'
|
||||
|
||||
class DocumentHandler {
|
||||
keyLength: number
|
||||
|
||||
@@ -1,51 +1,12 @@
|
||||
import type {
|
||||
AmazonStoreConfig,
|
||||
BaseStoreConfig,
|
||||
Config,
|
||||
GoogleStoreConfig,
|
||||
MemcachedStoreConfig,
|
||||
MongoStoreConfig,
|
||||
PostgresStoreConfig,
|
||||
RedisStoreConfig,
|
||||
RethinkDbStoreConfig
|
||||
} from 'src/types/config'
|
||||
import type { Store } from 'src/types/callback'
|
||||
import { StoreNames } from 'src/types/store-names'
|
||||
import type { Config } from 'src/types/config'
|
||||
import { Store } from '.'
|
||||
|
||||
const build = async (config: Config): Promise<Store> => {
|
||||
const DocumentStore = (await import(`../document-stores/${config.storeName}`))
|
||||
.default
|
||||
const DocumentStore = (
|
||||
await import(`../document-stores/${config.storage.type}`)
|
||||
).default
|
||||
|
||||
let store: BaseStoreConfig
|
||||
|
||||
switch (config.storeName) {
|
||||
case StoreNames.amazons3:
|
||||
store = config.storage as AmazonStoreConfig
|
||||
break
|
||||
case StoreNames.googledatastore:
|
||||
store = config.storage as GoogleStoreConfig
|
||||
break
|
||||
case StoreNames.memcached:
|
||||
store = config.storage as MemcachedStoreConfig
|
||||
break
|
||||
case StoreNames.mongo:
|
||||
store = config.storage as MongoStoreConfig
|
||||
break
|
||||
case StoreNames.postgres:
|
||||
store = config.storage as PostgresStoreConfig
|
||||
break
|
||||
case StoreNames.redis:
|
||||
store = config.storage as RedisStoreConfig
|
||||
break
|
||||
case StoreNames.rethinkdb:
|
||||
store = config.storage as RethinkDbStoreConfig
|
||||
break
|
||||
case StoreNames.file:
|
||||
default:
|
||||
store = config.storage as BaseStoreConfig
|
||||
break
|
||||
}
|
||||
return new DocumentStore(store)
|
||||
return new DocumentStore(config.storage)
|
||||
}
|
||||
|
||||
export default build
|
||||
|
||||
@@ -17,8 +17,8 @@ const getConfig = (): Config => {
|
||||
config.storage = {}
|
||||
}
|
||||
|
||||
if (!config.storeName) {
|
||||
config.storeName = 'file'
|
||||
if (!config.storage.type) {
|
||||
config.storage.type = 'file'
|
||||
}
|
||||
|
||||
return config
|
||||
|
||||
@@ -4,4 +4,4 @@ export const getStaticDirectory = (baseDirectory: string) =>
|
||||
path.join(baseDirectory, '..', 'static')
|
||||
|
||||
export const getStaticItemDirectory = (baseDirectory: string, item: string) =>
|
||||
path.join(getStaticDirectory(baseDirectory), item)
|
||||
path.join(baseDirectory, '..', 'static', item)
|
||||
|
||||
@@ -12,36 +12,40 @@ export interface Config {
|
||||
logging: Logging[]
|
||||
keyGenerator: KeyGeneratorConfig
|
||||
rateLimits: RateLimits
|
||||
storage: unknown
|
||||
storage: StoreConfig
|
||||
documents: Record<string, string>
|
||||
storeName: StoreNames
|
||||
}
|
||||
|
||||
export type BaseStoreConfig = {
|
||||
type: string
|
||||
type: StoreNames
|
||||
expire?: number
|
||||
}
|
||||
|
||||
export interface MongoStoreConfig extends BaseStoreConfig {
|
||||
connectionUrl: string
|
||||
type: StoreNames.mongo
|
||||
}
|
||||
|
||||
export interface MemcachedStoreConfig extends BaseStoreConfig {
|
||||
host: string
|
||||
port: number
|
||||
type: StoreNames.memcached
|
||||
}
|
||||
|
||||
export interface FileStoreConfig extends BaseStoreConfig {
|
||||
path: string
|
||||
type: StoreNames.file
|
||||
}
|
||||
|
||||
export interface AmazonStoreConfig extends BaseStoreConfig {
|
||||
bucket: string
|
||||
region: string
|
||||
type: StoreNames.amazons3
|
||||
}
|
||||
|
||||
export interface PostgresStoreConfig extends BaseStoreConfig {
|
||||
connectionUrl: string
|
||||
type: StoreNames.postgres
|
||||
}
|
||||
|
||||
export interface RethinkDbStoreConfig extends BaseStoreConfig {
|
||||
@@ -50,6 +54,7 @@ export interface RethinkDbStoreConfig extends BaseStoreConfig {
|
||||
db: string
|
||||
user: string
|
||||
password: string
|
||||
type: StoreNames.rethinkdb
|
||||
}
|
||||
|
||||
export interface RedisStoreConfig extends BaseStoreConfig {
|
||||
@@ -60,9 +65,22 @@ export interface RedisStoreConfig extends BaseStoreConfig {
|
||||
password?: string
|
||||
host?: string
|
||||
port?: string
|
||||
type: StoreNames.redis
|
||||
}
|
||||
|
||||
export type GoogleStoreConfig = BaseStoreConfig
|
||||
export interface GoogleStoreConfig extends BaseStoreConfig {
|
||||
type: StoreNames.googledatastore
|
||||
}
|
||||
|
||||
export type StoreConfig =
|
||||
| MongoStoreConfig
|
||||
| MemcachedStoreConfig
|
||||
| FileStoreConfig
|
||||
| AmazonStoreConfig
|
||||
| PostgresStoreConfig
|
||||
| RethinkDbStoreConfig
|
||||
| RedisStoreConfig
|
||||
| GoogleStoreConfig
|
||||
|
||||
export interface KeyGeneratorConfig {
|
||||
type: string
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Store } from 'src/lib/document-stores'
|
||||
import KeyGenerator from 'src/lib/key-generators'
|
||||
import type { Config } from './config'
|
||||
import type { Store } from './callback'
|
||||
|
||||
export type Document = {
|
||||
store: Store
|
||||
|
||||
Reference in New Issue
Block a user