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

237 lines
4.1 KiB
TypeScript
Raw Normal View History

2020-07-01 09:05:30 -05:00
2020-07-07 03:57:04 -05: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 09:05:30 -05:00
}
2020-07-24 08:05:51 -05:00
function getAdminAbusesList (options: {
2020-07-01 09:05:30 -05:00
url: string
token: string
2020-07-08 08:51:46 -05:00
start?: number
count?: number
sort?: string
2020-07-01 09:05:30 -05:00
id?: number
predefinedReason?: AbusePredefinedReasonsString
search?: string
2020-07-08 08:51:46 -05:00
filter?: AbuseFilter
2020-07-01 09:05:30 -05:00
state?: AbuseState
videoIs?: AbuseVideoIs
searchReporter?: string
searchReportee?: string
searchVideo?: string
searchVideoChannel?: string
}) {
const {
url,
token,
2020-07-08 08:51:46 -05:00
start,
count,
sort,
2020-07-01 09:05:30 -05:00
id,
predefinedReason,
search,
2020-07-07 03:57:04 -05:00
filter,
2020-07-01 09:05:30 -05:00
state,
videoIs,
searchReporter,
searchReportee,
searchVideo,
searchVideoChannel
} = options
2020-07-07 03:57:04 -05:00
const path = '/api/v1/abuses'
2020-07-01 09:05:30 -05:00
const query = {
id,
predefinedReason,
search,
state,
2020-07-07 03:57:04 -05:00
filter,
2020-07-01 09:05:30 -05:00
videoIs,
2020-07-08 08:51:46 -05:00
start,
count,
sort: sort || 'createdAt',
2020-07-01 09:05:30 -05:00
searchReporter,
searchReportee,
searchVideo,
searchVideoChannel
}
return makeGetRequest({
url,
path,
token,
query,
statusCodeExpected: 200
})
}
2020-07-24 08:05:51 -05: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: 200
})
}
2020-07-01 09:05:30 -05:00
function updateAbuse (
url: string,
token: string,
2020-07-07 03:57:04 -05:00
abuseId: number,
2020-07-01 09:05:30 -05:00
body: AbuseUpdate,
statusCodeExpected = 204
) {
2020-07-07 03:57:04 -05:00
const path = '/api/v1/abuses/' + abuseId
2020-07-01 09:05:30 -05:00
return makePutBodyRequest({
url,
token,
path,
fields: body,
statusCodeExpected
})
}
2020-07-07 03:57:04 -05:00
function deleteAbuse (url: string, token: string, abuseId: number, statusCodeExpected = 204) {
const path = '/api/v1/abuses/' + abuseId
2020-07-01 09:05:30 -05:00
return makeDeleteRequest({
url,
token,
path,
statusCodeExpected
})
}
2020-07-24 08:05:51 -05:00
function listAbuseMessages (url: string, token: string, abuseId: number, statusCodeExpected = 200) {
const path = '/api/v1/abuses/' + abuseId + '/messages'
return makeGetRequest({
url,
token,
path,
statusCodeExpected
})
}
function deleteAbuseMessage (url: string, token: string, abuseId: number, messageId: number, statusCodeExpected = 204) {
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 = 200) {
const path = '/api/v1/abuses/' + abuseId + '/messages'
return makePostBodyRequest({
url,
token,
path,
fields: { message },
statusCodeExpected
})
}
2020-07-01 09:05:30 -05:00
// ---------------------------------------------------------------------------
export {
reportAbuse,
2020-07-24 08:05:51 -05:00
getAdminAbusesList,
2020-07-01 09:05:30 -05:00
updateAbuse,
2020-07-24 08:05:51 -05:00
deleteAbuse,
getUserAbusesList,
listAbuseMessages,
deleteAbuseMessage,
addAbuseMessage
2020-07-01 09:05:30 -05:00
}