mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-01-08 21:50:48 +00:00
Simplify processData
Signed-off-by: David Mehren <dmehren1@gmail.com>
This commit is contained in:
parent
d3aa040626
commit
ea9cd56a20
1 changed files with 10 additions and 19 deletions
29
lib/utils.ts
29
lib/utils.ts
|
@ -1,8 +1,8 @@
|
|||
import { logger } from './logger'
|
||||
import { realtime } from './realtime'
|
||||
import { config } from './config'
|
||||
import fs from 'fs'
|
||||
import { config } from './config'
|
||||
import { logger } from './logger'
|
||||
import { Revision } from './models'
|
||||
import { realtime } from './realtime'
|
||||
|
||||
export function getImageMimeType (imagePath: string): string | undefined {
|
||||
const fileExtension = /[^.]+$/.exec(imagePath)
|
||||
|
@ -33,21 +33,11 @@ export function stripNullByte (value: string): string {
|
|||
return value ? value.replace(/\u0000/g, '') : value
|
||||
}
|
||||
|
||||
export function processData (data, _default, process?) {
|
||||
if (data === undefined) return data
|
||||
else if (process) {
|
||||
if (data === null) {
|
||||
return _default
|
||||
} else {
|
||||
return process(data)
|
||||
}
|
||||
} else {
|
||||
if (data === null) {
|
||||
return _default
|
||||
} else {
|
||||
return data
|
||||
}
|
||||
}
|
||||
export function processData<T> (data: T, _default: T, process?: (T) => T): T | undefined {
|
||||
if (data === undefined) return undefined
|
||||
else if (data === null) return _default
|
||||
else if (process) return process(data)
|
||||
else return data
|
||||
}
|
||||
|
||||
export function handleTermSignals (io): void {
|
||||
|
@ -65,7 +55,8 @@ export function handleTermSignals (io): void {
|
|||
if (config.path) {
|
||||
// ToDo: add a proper error handler
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
fs.unlink(config.path, (_) => {})
|
||||
fs.unlink(config.path, (_) => {
|
||||
})
|
||||
}
|
||||
const checkCleanTimer = setInterval(function () {
|
||||
if (realtime.isReady()) {
|
||||
|
|
Loading…
Reference in a new issue