2020-04-12 14:37:04 -04:00
|
|
|
import { Sequelize } from 'sequelize-typescript'
|
2020-04-11 04:22:06 -04:00
|
|
|
|
2020-04-12 14:37:04 -04:00
|
|
|
export function isSQLite (sequelize: Sequelize): boolean {
|
|
|
|
return sequelize.options.dialect === 'sqlite'
|
|
|
|
}
|
2020-04-11 04:22:06 -04:00
|
|
|
|
2020-04-12 14:37:04 -04:00
|
|
|
export function getImageMimeType (imagePath: string): string | undefined {
|
|
|
|
const fileExtension = /[^.]+$/.exec(imagePath)
|
|
|
|
switch (fileExtension?.[0]) {
|
|
|
|
case 'bmp':
|
|
|
|
return 'image/bmp'
|
|
|
|
case 'gif':
|
|
|
|
return 'image/gif'
|
|
|
|
case 'jpg':
|
|
|
|
case 'jpeg':
|
|
|
|
return 'image/jpeg'
|
|
|
|
case 'png':
|
|
|
|
return 'image/png'
|
|
|
|
case 'tiff':
|
|
|
|
return 'image/tiff'
|
|
|
|
case 'svg':
|
|
|
|
return 'image/svg+xml'
|
|
|
|
default:
|
|
|
|
return undefined
|
2020-04-11 05:22:55 -04:00
|
|
|
}
|
2020-04-12 14:37:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// [Postgres] Handling NULL bytes
|
|
|
|
// https://github.com/sequelize/sequelize/issues/6485
|
|
|
|
export function stripNullByte (value: string): string {
|
|
|
|
value = '' + value
|
|
|
|
// eslint-disable-next-line no-control-regex
|
|
|
|
return value ? value.replace(/\u0000/g, '') : value
|
|
|
|
}
|
2020-04-11 05:22:55 -04:00
|
|
|
|
2020-04-12 14:37:04 -04:00
|
|
|
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
|
2020-04-11 05:22:55 -04:00
|
|
|
} else {
|
2020-04-12 14:37:04 -04:00
|
|
|
return data
|
2020-04-11 05:22:55 -04:00
|
|
|
}
|
|
|
|
}
|
2020-04-11 04:22:06 -04:00
|
|
|
}
|