1
0
mirror of https://github.com/seejohnrun/haste-server.git synced 2026-02-10 16:01:32 +00:00

convert optional fiels to required fields

This commit is contained in:
Yusuf Yilmaz
2022-06-02 10:57:42 +02:00
parent fa9d3f98e9
commit 9c2f1d24ba
6 changed files with 172 additions and 23 deletions
+8 -8
View File
@@ -12,11 +12,11 @@ class DocumentHandler {
maxLength?: number
public store?: Store
public store: Store
keyGenerator: KeyGenerator
config?: Config
config: Config
constructor(options: Document) {
this.keyLength = options.keyLength || constants.DEFAULT_KEY_LENGTH
@@ -28,9 +28,9 @@ class DocumentHandler {
public handleGet(request: Request, response: Response) {
const key = request.params.id.split('.')[0]
const skipExpire = !!this.config?.documents[key]
const skipExpire = !!this.config.documents[key]
this.store?.get(
this.store.get(
key,
ret => {
if (ret) {
@@ -74,7 +74,7 @@ class DocumentHandler {
}
// And then save if we should
this.chooseKey(key => {
this.store?.set(key, buffer, res => {
this.store.set(key, buffer, res => {
if (res) {
winston.verbose('added document', { key })
response.writeHead(200, { 'content-type': 'application/json' })
@@ -123,9 +123,9 @@ class DocumentHandler {
public handleRawGet(request: Request, response: Response) {
const key = request.params.id.split('.')[0]
const skipExpire = !!this.config?.documents[key]
const skipExpire = !!this.config.documents[key]
this.store?.get(
this.store.get(
key,
ret => {
if (ret) {
@@ -157,7 +157,7 @@ class DocumentHandler {
if (!key) return
this.store?.get(
this.store.get(
key,
(ret: string | boolean) => {
if (ret) {
+6 -6
View File
@@ -64,7 +64,7 @@ Object.keys(config.documents).forEach(name => {
winston.info('loading static document', { name, path: documentPath })
if (data) {
documentHandler?.store?.set(
documentHandler.store?.set(
name,
data,
cb => {
@@ -90,25 +90,25 @@ if (config.rateLimits) {
// get raw documents - support getting with extension
app.get('/raw/:id', async (request, response) =>
documentHandler?.handleRawGet(request, response),
documentHandler.handleRawGet(request, response),
)
app.head('/raw/:id', (request, response) =>
documentHandler?.handleRawGet(request, response),
documentHandler.handleRawGet(request, response),
)
// // add documents
app.post('/documents', (request, response) =>
documentHandler?.handlePost(request, response),
documentHandler.handlePost(request, response),
)
// get documents
app.get('/documents/:id', (request, response) =>
documentHandler?.handleGet(request, response),
documentHandler.handleGet(request, response),
)
app.head('/documents/:id', (request, response) =>
documentHandler?.handleGet(request, response),
documentHandler.handleGet(request, response),
)
// Otherwise, try to match static files
+3 -3
View File
@@ -3,11 +3,11 @@ import type { KeyGenerator } from './key-generator'
import type { Store } from './store'
export type Document = {
store?: Store
config?: Config
store: Store
config: Config
keyGenerator: KeyGenerator
maxLength?: number
keyLength?: number
keyGenerator: KeyGenerator
}
export interface Documents {