PeerTube/shared/extra-utils/videos/video-abuses.ts

115 lines
2.4 KiB
TypeScript
Raw Normal View History

2017-09-04 14:21:47 -05:00
import * as request from 'supertest'
2020-07-01 09:05:30 -05:00
import { AbusePredefinedReasonsString, AbuseState, AbuseUpdate, AbuseVideoIs } from '@shared/models'
import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests'
// FIXME: deprecated in 2.3. Remove this file
2017-09-04 14:21:47 -05:00
function reportVideoAbuse (
url: string,
token: string,
videoId: number | string,
reason: string,
2020-07-01 09:05:30 -05:00
predefinedReasons?: AbusePredefinedReasonsString[],
startAt?: number,
endAt?: number,
specialStatus = 200
) {
2017-09-04 14:21:47 -05:00
const path = '/api/v1/videos/' + videoId + '/abuse'
return request(url)
.post(path)
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + token)
.send({ reason, predefinedReasons, startAt, endAt })
2017-09-04 14:21:47 -05:00
.expect(specialStatus)
}
2020-05-06 10:39:07 -05:00
function getVideoAbusesList (options: {
url: string
token: string
id?: number
2020-07-01 09:05:30 -05:00
predefinedReason?: AbusePredefinedReasonsString
2020-05-06 10:39:07 -05:00
search?: string
2020-07-01 09:05:30 -05:00
state?: AbuseState
videoIs?: AbuseVideoIs
2020-05-06 10:39:07 -05:00
searchReporter?: string
searchReportee?: string
searchVideo?: string
searchVideoChannel?: string
}) {
const {
url,
token,
id,
predefinedReason,
2020-05-06 10:39:07 -05:00
search,
state,
videoIs,
searchReporter,
searchReportee,
searchVideo,
searchVideoChannel
} = options
2017-09-04 14:21:47 -05:00
const path = '/api/v1/videos/abuse'
2020-05-06 10:39:07 -05:00
const query = {
sort: 'createdAt',
id,
predefinedReason,
2020-05-06 10:39:07 -05:00
search,
state,
videoIs,
searchReporter,
searchReportee,
searchVideo,
searchVideoChannel
}
return makeGetRequest({
url,
path,
token,
query,
statusCodeExpected: 200
})
2017-09-04 14:21:47 -05:00
}
function updateVideoAbuse (
url: string,
token: string,
videoId: string | number,
videoAbuseId: number,
2020-07-01 09:05:30 -05:00
body: AbuseUpdate,
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 14:21:47 -05:00
// ---------------------------------------------------------------------------
export {
reportVideoAbuse,
getVideoAbusesList,
updateVideoAbuse,
deleteVideoAbuse
2017-09-04 14:21:47 -05:00
}