2022-06-03 10:54:30 +02:00
|
|
|
import express from 'express'
|
2022-12-20 15:18:43 +01:00
|
|
|
import { ResultList } from '@peertube/peertube-types'
|
2020-02-13 11:49:03 +01:00
|
|
|
|
|
|
|
function badRequest (req: express.Request, res: express.Response) {
|
|
|
|
return res.type('json').status(400).end()
|
|
|
|
}
|
|
|
|
|
2021-06-25 10:04:50 +02:00
|
|
|
interface FormattableToJSON <T> {
|
|
|
|
toFormattedJSON: () => T
|
2020-02-13 11:49:03 +01:00
|
|
|
}
|
|
|
|
|
2021-06-25 10:04:50 +02:00
|
|
|
function getFormattedObjects<U, T extends FormattableToJSON<U>> (objects: T[], objectsTotal: number) {
|
2020-02-13 11:49:03 +01:00
|
|
|
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
|
|
|
}
|