1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
import * as express from 'express'
import { database } from '../../initializers'
import { getFormattedObjects } from '../../helpers'
import { BlacklistedVideo } from '../../../shared'
import { BlacklistedVideoInstance } from '../../models'
import {
removeVideoFromBlacklist
} from '../../lib'
import {
authenticate,
ensureIsAdmin,
paginationValidator,
blacklistSortValidator,
setBlacklistSort,
setPagination,
blacklistRemoveValidator
} from '../../middlewares'
const blacklistRouter = express.Router()
blacklistRouter.get('/',
authenticate,
ensureIsAdmin,
paginationValidator,
blacklistSortValidator,
setBlacklistSort,
setPagination,
listBlacklist
)
blacklistRouter.delete('/:id',
authenticate,
ensureIsAdmin,
blacklistRemoveValidator,
removeVideoFromBlacklistController
)
// ---------------------------------------------------------------------------
export {
blacklistRouter
}
// ---------------------------------------------------------------------------
function listBlacklist (req: express.Request, res: express.Response, next: express.NextFunction) {
database.BlacklistedVideo.listForApi(req.query.start, req.query.count, req.query.sort)
.then(resultList => res.json(getFormattedObjects<BlacklistedVideo, BlacklistedVideoInstance>(resultList.data, resultList.total)))
.catch(err => next(err))
}
function removeVideoFromBlacklistController (req: express.Request, res: express.Response, next: express.NextFunction) {
const entry = res.locals.blacklistEntryToRemove as BlacklistedVideoInstance
removeVideoFromBlacklist(entry)
.then(() => res.sendStatus(204))
.catch(err => next(err))
}
|