sepia-search-motore-di-rice.../server/helpers/utils.ts

36 lines
817 B
TypeScript
Raw Normal View History

2020-02-13 11:49:03 +01:00
import * as express from 'express'
import { ResultList } from '../../PeerTube/shared/models/result-list.model'
function badRequest (req: express.Request, res: express.Response) {
return res.type('json').status(400).end()
}
interface FormattableToJSON {
toFormattedJSON ()
}
function getFormattedObjects<U, T extends FormattableToJSON> (objects: T[], objectsTotal: number) {
const formattedObjects: U[] = []
objects.forEach(object => {
formattedObjects.push(object.toFormattedJSON())
})
return {
total: objectsTotal,
data: formattedObjects
} as ResultList<U>
}
2020-05-29 16:16:55 +02:00
function buildUrl (host: string, path: string) {
return 'https://' + host + path
}
2020-02-13 11:49:03 +01:00
// ---------------------------------------------------------------------------
export {
badRequest,
2020-05-29 16:16:55 +02:00
getFormattedObjects,
buildUrl
2020-02-13 11:49:03 +01:00
}