PeerTube/shared/extra-utils/moderation/abuses.ts

157 lines
2.7 KiB
TypeScript
Raw Normal View History

2020-07-01 16:05:30 +02:00
2020-07-07 10:57:04 +02:00
import { AbuseFilter, AbusePredefinedReasonsString, AbuseState, AbuseUpdate, AbuseVideoIs } from '@shared/models'
import { makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests'
function reportAbuse (options: {
url: string
token: string
reason: string
accountId?: number
videoId?: number
commentId?: number
predefinedReasons?: AbusePredefinedReasonsString[]
startAt?: number
endAt?: number
statusCodeExpected?: number
}) {
const path = '/api/v1/abuses'
const video = options.videoId ? {
id: options.videoId,
startAt: options.startAt,
endAt: options.endAt
} : undefined
const comment = options.commentId ? {
id: options.commentId
} : undefined
const account = options.accountId ? {
id: options.accountId
} : undefined
const body = {
account,
video,
comment,
reason: options.reason,
predefinedReasons: options.predefinedReasons
}
return makePostBodyRequest({
url: options.url,
path,
token: options.token,
fields: body,
statusCodeExpected: options.statusCodeExpected || 200
})
2020-07-01 16:05:30 +02:00
}
function getAbusesList (options: {
url: string
token: string
2020-07-08 15:51:46 +02:00
start?: number
count?: number
sort?: string
2020-07-01 16:05:30 +02:00
id?: number
predefinedReason?: AbusePredefinedReasonsString
search?: string
2020-07-08 15:51:46 +02:00
filter?: AbuseFilter
2020-07-01 16:05:30 +02:00
state?: AbuseState
videoIs?: AbuseVideoIs
searchReporter?: string
searchReportee?: string
searchVideo?: string
searchVideoChannel?: string
}) {
const {
url,
token,
2020-07-08 15:51:46 +02:00
start,
count,
sort,
2020-07-01 16:05:30 +02:00
id,
predefinedReason,
search,
2020-07-07 10:57:04 +02:00
filter,
2020-07-01 16:05:30 +02:00
state,
videoIs,
searchReporter,
searchReportee,
searchVideo,
searchVideoChannel
} = options
2020-07-07 10:57:04 +02:00
const path = '/api/v1/abuses'
2020-07-01 16:05:30 +02:00
const query = {
id,
predefinedReason,
search,
state,
2020-07-07 10:57:04 +02:00
filter,
2020-07-01 16:05:30 +02:00
videoIs,
2020-07-08 15:51:46 +02:00
start,
count,
sort: sort || 'createdAt',
2020-07-01 16:05:30 +02:00
searchReporter,
searchReportee,
searchVideo,
searchVideoChannel
}
return makeGetRequest({
url,
path,
token,
query,
statusCodeExpected: 200
})
}
function updateAbuse (
url: string,
token: string,
2020-07-07 10:57:04 +02:00
abuseId: number,
2020-07-01 16:05:30 +02:00
body: AbuseUpdate,
statusCodeExpected = 204
) {
2020-07-07 10:57:04 +02:00
const path = '/api/v1/abuses/' + abuseId
2020-07-01 16:05:30 +02:00
return makePutBodyRequest({
url,
token,
path,
fields: body,
statusCodeExpected
})
}
2020-07-07 10:57:04 +02:00
function deleteAbuse (url: string, token: string, abuseId: number, statusCodeExpected = 204) {
const path = '/api/v1/abuses/' + abuseId
2020-07-01 16:05:30 +02:00
return makeDeleteRequest({
url,
token,
path,
statusCodeExpected
})
}
// ---------------------------------------------------------------------------
export {
reportAbuse,
getAbusesList,
updateAbuse,
deleteAbuse
}