1
0
Fork 0
peertube/shared/extra-utils/videos/video-abuses.ts

103 lines
2.2 KiB
TypeScript
Raw Normal View History

2017-09-04 15:21:47 -04:00
import * as request from 'supertest'
2018-10-29 13:06:09 -04:00
import { VideoAbuseUpdate } from '../../models/videos/abuse/video-abuse-update.model'
2020-05-06 11:39:07 -04:00
import { makeDeleteRequest, makePutBodyRequest, makeGetRequest } from '../requests/requests'
import { VideoAbuseState } from '@shared/models'
import { VideoAbuseVideoIs } from '@shared/models/videos/abuse/video-abuse-video-is.type'
2017-09-04 15:21:47 -04:00
function reportVideoAbuse (url: string, token: string, videoId: number | string, reason: string, specialStatus = 200) {
2017-09-04 15:21:47 -04:00
const path = '/api/v1/videos/' + videoId + '/abuse'
return request(url)
.post(path)
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + token)
.send({ reason })
.expect(specialStatus)
}
2020-05-06 11:39:07 -04:00
function getVideoAbusesList (options: {
url: string
token: string
id?: number
search?: string
state?: VideoAbuseState
videoIs?: VideoAbuseVideoIs
searchReporter?: string
searchReportee?: string
searchVideo?: string
searchVideoChannel?: string
}) {
const {
url,
token,
id,
search,
state,
videoIs,
searchReporter,
searchReportee,
searchVideo,
searchVideoChannel
} = options
2017-09-04 15:21:47 -04:00
const path = '/api/v1/videos/abuse'
2020-05-06 11:39:07 -04:00
const query = {
sort: 'createdAt',
id,
search,
state,
videoIs,
searchReporter,
searchReportee,
searchVideo,
searchVideoChannel
}
return makeGetRequest({
url,
path,
token,
query,
statusCodeExpected: 200
})
2017-09-04 15:21:47 -04:00
}
function updateVideoAbuse (
url: string,
token: string,
videoId: string | number,
videoAbuseId: number,
body: VideoAbuseUpdate,
statusCodeExpected = 204
) {
const path = '/api/v1/videos/' + videoId + '/abuse/' + videoAbuseId
return makePutBodyRequest({
url,
token,
path,
fields: body,
statusCodeExpected
})
}
function deleteVideoAbuse (url: string, token: string, videoId: string | number, videoAbuseId: number, statusCodeExpected = 204) {
const path = '/api/v1/videos/' + videoId + '/abuse/' + videoAbuseId
return makeDeleteRequest({
url,
token,
path,
statusCodeExpected
})
}
2017-09-04 15:21:47 -04:00
// ---------------------------------------------------------------------------
export {
reportVideoAbuse,
getVideoAbusesList,
updateVideoAbuse,
deleteVideoAbuse
2017-09-04 15:21:47 -04:00
}