]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/extra-utils/moderation/abuses.ts
Update dependencies.md
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / moderation / abuses.ts
index 62af9556e67a789e888592980b6fa5964156e05b..c0fda722f54cc5831301236737c694b336c31a5b 100644 (file)
@@ -1,6 +1,6 @@
-
 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'
 
 function reportAbuse (options: {
   url: string
@@ -21,19 +21,21 @@ function reportAbuse (options: {
 }) {
   const path = '/api/v1/abuses'
 
-  const video = options.videoId ? {
-    id: options.videoId,
-    startAt: options.startAt,
-    endAt: options.endAt
-  } : undefined
+  const video = options.videoId
+    ? {
+      id: options.videoId,
+      startAt: options.startAt,
+      endAt: options.endAt
+    }
+    : undefined
 
-  const comment = options.commentId ? {
-    id: options.commentId
-  } : undefined
+  const comment = options.commentId
+    ? { id: options.commentId }
+    : undefined
 
-  const account = options.accountId ? {
-    id: options.accountId
-  } : undefined
+  const account = options.accountId
+    ? { id: options.accountId }
+    : undefined
 
   const body = {
     account,
@@ -50,11 +52,11 @@ function reportAbuse (options: {
     token: options.token,
 
     fields: body,
-    statusCodeExpected: options.statusCodeExpected || 200
+    statusCodeExpected: options.statusCodeExpected || HttpStatusCode.OK_200
   })
 }
 
-function getAbusesList (options: {
+function getAdminAbusesList (options: {
   url: string
   token: string
 
@@ -113,7 +115,49 @@ function getAbusesList (options: {
     path,
     token,
     query,
-    statusCodeExpected: 200
+    statusCodeExpected: HttpStatusCode.OK_200
+  })
+}
+
+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
   })
 }
 
@@ -122,7 +166,7 @@ function updateAbuse (
   token: string,
   abuseId: number,
   body: AbuseUpdate,
-  statusCodeExpected = 204
+  statusCodeExpected = HttpStatusCode.NO_CONTENT_204
 ) {
   const path = '/api/v1/abuses/' + abuseId
 
@@ -135,7 +179,7 @@ function updateAbuse (
   })
 }
 
-function deleteAbuse (url: string, token: string, abuseId: number, statusCodeExpected = 204) {
+function deleteAbuse (url: string, token: string, abuseId: number, statusCodeExpected = HttpStatusCode.NO_CONTENT_204) {
   const path = '/api/v1/abuses/' + abuseId
 
   return makeDeleteRequest({
@@ -146,11 +190,55 @@ function deleteAbuse (url: string, token: string, abuseId: number, statusCodeExp
   })
 }
 
+function listAbuseMessages (url: string, token: string, abuseId: number, statusCodeExpected = HttpStatusCode.OK_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 = HttpStatusCode.NO_CONTENT_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 = HttpStatusCode.OK_200) {
+  const path = '/api/v1/abuses/' + abuseId + '/messages'
+
+  return makePostBodyRequest({
+    url,
+    token,
+    path,
+    fields: { message },
+    statusCodeExpected
+  })
+}
+
 // ---------------------------------------------------------------------------
 
 export {
   reportAbuse,
-  getAbusesList,
+  getAdminAbusesList,
   updateAbuse,
-  deleteAbuse
+  deleteAbuse,
+  getUserAbusesList,
+  listAbuseMessages,
+  deleteAbuseMessage,
+  addAbuseMessage
 }