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

245 lines
4.4 KiB
TypeScript
Raw Normal View History

2020-07-07 04:57:04 -04:00
import { AbuseFilter, AbusePredefinedReasonsString, AbuseState, AbuseUpdate, AbuseVideoIs } from '@shared/models'
import { makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests'
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
2020-07-07 04:57:04 -04:00
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'
2021-02-03 03:33:05 -05:00
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
2020-07-07 04:57:04 -04:00
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 || HttpStatusCode.OK_200
2020-07-07 04:57:04 -04:00
})
2020-07-01 10:05:30 -04:00
}
2020-07-24 09:05:51 -04:00
function getAdminAbusesList (options: {
2020-07-01 10:05:30 -04:00
url: string
token: string
2020-07-08 09:51:46 -04:00
start?: number
count?: number
sort?: string
2020-07-01 10:05:30 -04:00
id?: number
predefinedReason?: AbusePredefinedReasonsString
search?: string
2020-07-08 09:51:46 -04:00
filter?: AbuseFilter
2020-07-01 10:05:30 -04:00
state?: AbuseState
videoIs?: AbuseVideoIs
searchReporter?: string
searchReportee?: string
searchVideo?: string
searchVideoChannel?: string
}) {
const {
url,
token,
2020-07-08 09:51:46 -04:00
start,
count,
sort,
2020-07-01 10:05:30 -04:00
id,
predefinedReason,
search,
2020-07-07 04:57:04 -04:00
filter,
2020-07-01 10:05:30 -04:00
state,
videoIs,
searchReporter,
searchReportee,
searchVideo,
searchVideoChannel
} = options
2020-07-07 04:57:04 -04:00
const path = '/api/v1/abuses'
2020-07-01 10:05:30 -04:00
const query = {
id,
predefinedReason,
search,
state,
2020-07-07 04:57:04 -04:00
filter,
2020-07-01 10:05:30 -04:00
videoIs,
2020-07-08 09:51:46 -04:00
start,
count,
sort: sort || 'createdAt',
2020-07-01 10:05:30 -04:00
searchReporter,
searchReportee,
searchVideo,
searchVideoChannel
}
return makeGetRequest({
url,
path,
token,
query,
statusCodeExpected: HttpStatusCode.OK_200
2020-07-01 10:05:30 -04:00
})
}
2020-07-24 09:05:51 -04:00
function getUserAbusesList (options: {
url: string
token: string
start?: number
count?: number
sort?: string
id?: number
search?: string
state?: AbuseState
}) {
const {
url,
token,
start,
count,
sort,
id,
search,
state
} = options
const path = '/api/v1/users/me/abuses'
const query = {
id,
search,
state,
start,
count,
sort: sort || 'createdAt'
}
return makeGetRequest({
url,
path,
token,
query,
statusCodeExpected: HttpStatusCode.OK_200
2020-07-24 09:05:51 -04:00
})
}
2020-07-01 10:05:30 -04:00
function updateAbuse (
url: string,
token: string,
2020-07-07 04:57:04 -04:00
abuseId: number,
2020-07-01 10:05:30 -04:00
body: AbuseUpdate,
statusCodeExpected = HttpStatusCode.NO_CONTENT_204
2020-07-01 10:05:30 -04:00
) {
2020-07-07 04:57:04 -04:00
const path = '/api/v1/abuses/' + abuseId
2020-07-01 10:05:30 -04:00
return makePutBodyRequest({
url,
token,
path,
fields: body,
statusCodeExpected
})
}
function deleteAbuse (url: string, token: string, abuseId: number, statusCodeExpected = HttpStatusCode.NO_CONTENT_204) {
2020-07-07 04:57:04 -04:00
const path = '/api/v1/abuses/' + abuseId
2020-07-01 10:05:30 -04:00
return makeDeleteRequest({
url,
token,
path,
statusCodeExpected
})
}
function listAbuseMessages (url: string, token: string, abuseId: number, statusCodeExpected = HttpStatusCode.OK_200) {
2020-07-24 09:05:51 -04:00
const path = '/api/v1/abuses/' + abuseId + '/messages'
return makeGetRequest({
url,
token,
path,
statusCodeExpected
})
}
function deleteAbuseMessage (
url: string,
token: string,
abuseId: number,
messageId: number,
statusCodeExpected = HttpStatusCode.NO_CONTENT_204
) {
2020-07-24 09:05:51 -04:00
const path = '/api/v1/abuses/' + abuseId + '/messages/' + messageId
return makeDeleteRequest({
url,
token,
path,
statusCodeExpected
})
}
function addAbuseMessage (url: string, token: string, abuseId: number, message: string, statusCodeExpected = HttpStatusCode.OK_200) {
2020-07-24 09:05:51 -04:00
const path = '/api/v1/abuses/' + abuseId + '/messages'
return makePostBodyRequest({
url,
token,
path,
fields: { message },
statusCodeExpected
})
}
2020-07-01 10:05:30 -04:00
// ---------------------------------------------------------------------------
export {
reportAbuse,
2020-07-24 09:05:51 -04:00
getAdminAbusesList,
2020-07-01 10:05:30 -04:00
updateAbuse,
2020-07-24 09:05:51 -04:00
deleteAbuse,
getUserAbusesList,
listAbuseMessages,
deleteAbuseMessage,
addAbuseMessage
2020-07-01 10:05:30 -04:00
}