2021-03-11 10:54:52 -05:00
|
|
|
import * as express from 'express'
|
2021-04-15 07:52:27 -04:00
|
|
|
import { randomInt } from '@shared/core-utils'
|
2021-03-11 10:54:52 -05:00
|
|
|
|
|
|
|
export class MockJoinPeerTubeVersions {
|
|
|
|
private latestVersion: string
|
|
|
|
|
|
|
|
initialize () {
|
2021-04-15 07:52:27 -04:00
|
|
|
return new Promise<number>(res => {
|
2021-03-11 10:54:52 -05:00
|
|
|
const app = express()
|
|
|
|
|
|
|
|
app.use('/', (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
|
|
if (process.env.DEBUG) console.log('Receiving request on mocked server %s.', req.url)
|
|
|
|
|
|
|
|
return next()
|
|
|
|
})
|
|
|
|
|
|
|
|
app.get('/versions.json', (req: express.Request, res: express.Response) => {
|
|
|
|
return res.json({
|
|
|
|
peertube: {
|
|
|
|
latestVersion: this.latestVersion
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-15 07:52:27 -04:00
|
|
|
const port = 42201 + randomInt(1, 100)
|
|
|
|
app.listen(port, () => res(port))
|
2021-03-11 10:54:52 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
setLatestVersion (latestVersion: string) {
|
|
|
|
this.latestVersion = latestVersion
|
|
|
|
}
|
|
|
|
}
|