From 5d00a3d7aa4309f1da5ac7d6e3ed63181eb34952 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 19 Mar 2018 12:36:41 +0100 Subject: [PATCH] Update the api documentation --- server/helpers/custom-validators/videos.ts | 7 +- server/lib/activitypub/process/process.ts | 1 + server/models/video/video.ts | 2 +- server/tests/api/videos/multiple-servers.ts | 9 +- server/tests/cli/update-host.ts | 5 +- server/tests/utils/videos/videos.ts | 6 +- support/doc/api/html/index.html | 443 ++++++++++++-------- support/doc/api/openapi.yaml | 40 +- 8 files changed, 305 insertions(+), 208 deletions(-) diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index c08ddd24e..a46d715ba 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts @@ -26,12 +26,8 @@ function isVideoLicenceValid (value: number) { return value === null || VIDEO_LICENCES[value] !== undefined } -function areVideoLanguagesValid (value: number[]) { - return value === null || (isArray(value) && value.every(v => isVideoLanguageValid(v))) -} - function isVideoLanguageValid (value: number) { - return VIDEO_LANGUAGES[value] !== undefined + return value === null || VIDEO_LANGUAGES[value] !== undefined } function isVideoDurationValid (value: string) { @@ -137,7 +133,6 @@ export { isVideoDescriptionValid, isVideoFileInfoHashValid, isVideoNameValid, - areVideoLanguagesValid, isVideoTagsValid, isVideoAbuseReasonValid, isVideoFile, diff --git a/server/lib/activitypub/process/process.ts b/server/lib/activitypub/process/process.ts index 810c28e26..7edf3bba0 100644 --- a/server/lib/activitypub/process/process.ts +++ b/server/lib/activitypub/process/process.ts @@ -40,6 +40,7 @@ async function processActivities (activities: Activity[], signatureActor?: Actor try { await activityProcessor(activity, inboxActor) } catch (err) { + logger.warn(err.stack) logger.warn('Cannot process activity %s.', activity.type, err) } } diff --git a/server/models/video/video.ts b/server/models/video/video.ts index a4d4c42f0..78789ba2c 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -1010,7 +1010,7 @@ export class VideoModel extends Model { let language if (this.language) { language = { - id: this.language + '', + identifier: this.language + '', name: VideoModel.getLanguageLabel(this.language) } } diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index 42a1241f7..74c6b8462 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -452,7 +452,7 @@ describe('Test multiple servers', function () { const res2 = await getVideo(servers[0].url, video.id) const videoDetails = res2.body - const file = videoDetails.files.find(f => f.resolution === 360) + const file = videoDetails.files.find(f => f.resolution.id === 360) expect(file).not.to.be.undefined const torrent = await webtorrentAdd(file.magnetUri) @@ -705,10 +705,9 @@ describe('Test multiple servers', function () { expect(baseVideo.name).to.equal(video.name) expect(baseVideo.uuid).to.equal(video.uuid) - expect(baseVideo.category).to.equal(video.category) - expect(baseVideo.language).to.equal(video.language) - expect(baseVideo.licence).to.equal(video.licence) - expect(baseVideo.category).to.equal(video.category) + expect(baseVideo.category.id).to.equal(video.category.id) + expect(baseVideo.language.id).to.equal(video.language.id) + expect(baseVideo.licence.id).to.equal(video.licence.id) expect(baseVideo.nsfw).to.equal(video.nsfw) expect(baseVideo.account.name).to.equal(video.account.name) expect(baseVideo.account.displayName).to.equal(video.account.displayName) diff --git a/server/tests/cli/update-host.ts b/server/tests/cli/update-host.ts index 39242c494..ad56f7b1b 100644 --- a/server/tests/cli/update-host.ts +++ b/server/tests/cli/update-host.ts @@ -2,6 +2,7 @@ import 'mocha' import * as chai from 'chai' +import { VideoDetails } from '../../../shared/models/videos' const expect = chai.expect import { @@ -59,7 +60,7 @@ describe('Test update host scripts', function () { for (const video of videos) { const res2 = await getVideo(server.url, video.id) - const videoDetails = res2.body + const videoDetails: VideoDetails = res2.body expect(videoDetails.files).to.have.lengthOf(4) @@ -67,7 +68,7 @@ describe('Test update host scripts', function () { expect(file.magnetUri).to.contain('localhost%3A9002%2Ftracker%2Fsocket') expect(file.magnetUri).to.contain('localhost%3A9002%2Fstatic%2Fwebseed%2F') - const torrent = await parseTorrentVideo(server, videoDetails.uuid, file.resolution) + const torrent = await parseTorrentVideo(server, videoDetails.uuid, file.resolution.id) const announceWS = torrent.announce.find(a => a === 'ws://localhost:9002/tracker/socket') expect(announceWS).to.not.be.undefined diff --git a/server/tests/utils/videos/videos.ts b/server/tests/utils/videos/videos.ts index 3c63bedb2..424f41ed8 100644 --- a/server/tests/utils/videos/videos.ts +++ b/server/tests/utils/videos/videos.ts @@ -442,7 +442,7 @@ async function completeVideoCheck ( expect(dateIsValid(videoDetails.channel.updatedAt)).to.be.true for (const attributeFile of attributes.files) { - const file = videoDetails.files.find(f => f.resolution === attributeFile.resolution) + const file = videoDetails.files.find(f => f.resolution.id === attributeFile.resolution) expect(file).not.to.be.undefined let extension = extname(attributes.fixture) @@ -451,8 +451,8 @@ async function completeVideoCheck ( const magnetUri = file.magnetUri expect(file.magnetUri).to.have.lengthOf.above(2) - expect(file.torrentUrl).to.equal(`http://${attributes.account.host}/static/torrents/${videoDetails.uuid}-${file.resolution}.torrent`) - expect(file.fileUrl).to.equal(`http://${attributes.account.host}/static/webseed/${videoDetails.uuid}-${file.resolution}${extension}`) + expect(file.torrentUrl).to.equal(`http://${attributes.account.host}/static/torrents/${videoDetails.uuid}-${file.resolution.id}.torrent`) + expect(file.fileUrl).to.equal(`http://${attributes.account.host}/static/webseed/${videoDetails.uuid}-${file.resolution.id}${extension}`) expect(file.resolution.id).to.equal(attributeFile.resolution) expect(file.resolution.label).to.equal(attributeFile.resolution + 'p') diff --git a/support/doc/api/html/index.html b/support/doc/api/html/index.html index ae4020def..7e8adb2df 100644 --- a/support/doc/api/html/index.html +++ b/support/doc/api/html/index.html @@ -223,6 +223,7 @@
Schema Definitions
+ VideoConstant Video VideoAbuse VideoBlacklist @@ -1429,20 +1430,24 @@ { "id": "number", "uuid": "string", - "accountName": "string", "createdAt": "string", "updatedAt": "string", - "categoryLabel": "string", - "category": "number", - "licenceLabel": "string", - "licence": "number", - "languageLabel": "string", - "language": "number", + "category": { + "id": "number", + "label": "string" + }, + "licence": { + "id": "number", + "label": "string" + }, + "language": { + "id": "number", + "label": "string" + }, "description": "string", "duration": "number", "isLocal": "boolean", "name": "string", - "serverHost": "string", "thumbnailPath": "string", "previewPath": "string", "embedPath": "string", @@ -1632,20 +1637,24 @@ { "id": "number", "uuid": "string", - "accountName": "string", "createdAt": "string", "updatedAt": "string", - "categoryLabel": "string", - "category": "number", - "licenceLabel": "string", - "licence": "number", - "languageLabel": "string", - "language": "number", + "category": { + "id": "number", + "label": "string" + }, + "licence": { + "id": "number", + "label": "string" + }, + "language": { + "id": "number", + "label": "string" + }, "description": "string", "duration": "number", "isLocal": "boolean", "name": "string", - "serverHost": "string", "thumbnailPath": "string", "previewPath": "string", "embedPath": "string", @@ -1842,20 +1851,24 @@ { "id": "number", "uuid": "string", - "accountName": "string", "createdAt": "string", "updatedAt": "string", - "categoryLabel": "string", - "category": "number", - "licenceLabel": "string", - "licence": "number", - "languageLabel": "string", - "language": "number", + "category": { + "id": "number", + "label": "string" + }, + "licence": { + "id": "number", + "label": "string" + }, + "language": { + "id": "number", + "label": "string" + }, "description": "string", "duration": "number", "isLocal": "boolean", "name": "string", - "serverHost": "string", "thumbnailPath": "string", "previewPath": "string", "embedPath": "string", @@ -2183,20 +2196,24 @@ { "id": "number", "uuid": "string", - "accountName": "string", "createdAt": "string", "updatedAt": "string", - "categoryLabel": "string", - "category": "number", - "licenceLabel": "string", - "licence": "number", - "languageLabel": "string", - "language": "number", + "category": { + "id": "number", + "label": "string" + }, + "licence": { + "id": "number", + "label": "string" + }, + "language": { + "id": "number", + "label": "string" + }, "description": "string", "duration": "number", "isLocal": "boolean", "name": "string", - "serverHost": "string", "thumbnailPath": "string", "previewPath": "string", "embedPath": "string", @@ -2471,20 +2488,24 @@ { "id": "number", "uuid": "string", - "accountName": "string", "createdAt": "string", "updatedAt": "string", - "categoryLabel": "string", - "category": "number", - "licenceLabel": "string", - "licence": "number", - "languageLabel": "string", - "language": "number", + "category": { + "id": "number", + "label": "string" + }, + "licence": { + "id": "number", + "label": "string" + }, + "language": { + "id": "number", + "label": "string" + }, "description": "string", "duration": "number", "isLocal": "boolean", "name": "string", - "serverHost": "string", "thumbnailPath": "string", "previewPath": "string", "embedPath": "string", @@ -2814,20 +2835,24 @@ { "id": "number", "uuid": "string", - "accountName": "string", "createdAt": "string", "updatedAt": "string", - "categoryLabel": "string", - "category": "number", - "licenceLabel": "string", - "licence": "number", - "languageLabel": "string", - "language": "number", + "category": { + "id": "number", + "label": "string" + }, + "licence": { + "id": "number", + "label": "string" + }, + "language": { + "id": "number", + "label": "string" + }, "description": "string", "duration": "number", "isLocal": "boolean", "name": "string", - "serverHost": "string", "thumbnailPath": "string", "previewPath": "string", "embedPath": "string", @@ -2915,20 +2940,24 @@
{
   "id": "number",
   "uuid": "string",
-  "accountName": "string",
   "createdAt": "string",
   "updatedAt": "string",
-  "categoryLabel": "string",
-  "category": "number",
-  "licenceLabel": "string",
-  "licence": "number",
-  "languageLabel": "string",
-  "language": "number",
+  "category": {
+    "id": "number",
+    "label": "string"
+  },
+  "licence": {
+    "id": "number",
+    "label": "string"
+  },
+  "language": {
+    "id": "number",
+    "label": "string"
+  },
   "description": "string",
   "duration": "number",
   "isLocal": "boolean",
   "name": "string",
-  "serverHost": "string",
   "thumbnailPath": "string",
   "previewPath": "string",
   "embedPath": "string",
@@ -3015,20 +3044,24 @@
                   
{
   "id": "number",
   "uuid": "string",
-  "accountName": "string",
   "createdAt": "string",
   "updatedAt": "string",
-  "categoryLabel": "string",
-  "category": "number",
-  "licenceLabel": "string",
-  "licence": "number",
-  "languageLabel": "string",
-  "language": "number",
+  "category": {
+    "id": "number",
+    "label": "string"
+  },
+  "licence": {
+    "id": "number",
+    "label": "string"
+  },
+  "language": {
+    "id": "number",
+    "label": "string"
+  },
   "description": "string",
   "duration": "number",
   "isLocal": "boolean",
   "name": "string",
-  "serverHost": "string",
   "thumbnailPath": "string",
   "previewPath": "string",
   "embedPath": "string",
@@ -3428,11 +3461,23 @@
   {
     "id": "number",
     "reason": "string",
-    "reporterUsername": "string",
-    "reporterServerHost": "string",
-    "videoId": "number",
-    "videoUUID": "string",
-    "videoName": "string",
+    "reporterAccount": {
+      "displayName": "string",
+      "id": "number",
+      "uuid": "string",
+      "url": "string",
+      "name": "string",
+      "host": "string",
+      "followingCount": "number",
+      "followersCount": "number",
+      "createdAt": "string",
+      "updatedAt": "string",
+      "avatar": {
+        "path": "string",
+        "createdAt": "string",
+        "updatedAt": "string"
+      }
+    },
     "createdAt": "string"
   }
 ]
@@ -3877,20 +3922,24 @@
       {
         "id": "number",
         "uuid": "string",
-        "accountName": "string",
         "createdAt": "string",
         "updatedAt": "string",
-        "categoryLabel": "string",
-        "category": "number",
-        "licenceLabel": "string",
-        "licence": "number",
-        "languageLabel": "string",
-        "language": "number",
+        "category": {
+          "id": "number",
+          "label": "string"
+        },
+        "licence": {
+          "id": "number",
+          "label": "string"
+        },
+        "language": {
+          "id": "number",
+          "label": "string"
+        },
         "description": "string",
         "duration": "number",
         "isLocal": "boolean",
         "name": "string",
-        "serverHost": "string",
         "thumbnailPath": "string",
         "previewPath": "string",
         "embedPath": "string",
@@ -4057,20 +4106,24 @@
     {
       "id": "number",
       "uuid": "string",
-      "accountName": "string",
       "createdAt": "string",
       "updatedAt": "string",
-      "categoryLabel": "string",
-      "category": "number",
-      "licenceLabel": "string",
-      "licence": "number",
-      "languageLabel": "string",
-      "language": "number",
+      "category": {
+        "id": "number",
+        "label": "string"
+      },
+      "licence": {
+        "id": "number",
+        "label": "string"
+      },
+      "language": {
+        "id": "number",
+        "label": "string"
+      },
       "description": "string",
       "duration": "number",
       "isLocal": "boolean",
       "name": "string",
-      "serverHost": "string",
       "thumbnailPath": "string",
       "previewPath": "string",
       "embedPath": "string",
@@ -4321,20 +4374,24 @@
       {
         "id": "number",
         "uuid": "string",
-        "accountName": "string",
         "createdAt": "string",
         "updatedAt": "string",
-        "categoryLabel": "string",
-        "category": "number",
-        "licenceLabel": "string",
-        "licence": "number",
-        "languageLabel": "string",
-        "language": "number",
+        "category": {
+          "id": "number",
+          "label": "string"
+        },
+        "licence": {
+          "id": "number",
+          "label": "string"
+        },
+        "language": {
+          "id": "number",
+          "label": "string"
+        },
         "description": "string",
         "duration": "number",
         "isLocal": "boolean",
         "name": "string",
-        "serverHost": "string",
         "thumbnailPath": "string",
         "previewPath": "string",
         "embedPath": "string",
@@ -5082,6 +5139,45 @@
             
           
           

Schema Definitions

+
+

+ VideoConstant: + +

+
+
+
+
+
+ id: + number + +
+
+ label: + string + +
+
+
+
+
+
+
Example
+
{
+  "id": "number",
+  "label": "string"
+}
+
+ +
+
+
+

Video: @@ -5105,11 +5201,6 @@ string -
- accountName: - string - -
createdAt: string @@ -5120,34 +5211,31 @@ string
-
- categoryLabel: - string - -
category: - number - -
-
- licenceLabel: - string + + + VideoConstant + +
licence: - number - -
-
- languageLabel: - string + + + VideoConstant + +
language: - number + + + VideoConstant + +
@@ -5170,11 +5258,6 @@ string
-
- serverHost: - string - -
thumbnailPath: string @@ -5210,6 +5293,11 @@ boolean
+
+ account: + object + +

@@ -5219,20 +5307,24 @@
{
   "id": "number",
   "uuid": "string",
-  "accountName": "string",
   "createdAt": "string",
   "updatedAt": "string",
-  "categoryLabel": "string",
-  "category": "number",
-  "licenceLabel": "string",
-  "licence": "number",
-  "languageLabel": "string",
-  "language": "number",
+  "category": {
+    "id": "number",
+    "label": "string"
+  },
+  "licence": {
+    "id": "number",
+    "label": "string"
+  },
+  "language": {
+    "id": "number",
+    "label": "string"
+  },
   "description": "string",
   "duration": "number",
   "isLocal": "boolean",
   "name": "string",
-  "serverHost": "string",
   "thumbnailPath": "string",
   "previewPath": "string",
   "embedPath": "string",
@@ -5270,29 +5362,18 @@
                       string
                       
                     
-                    
- reporterUsername: - string - -
-
- reporterServerHost: - string - -
-
- videoId: - number - -
-
- videoUUID: - string +
+ reporterAccount: + + + Account + +
-
- videoName: - string +
+ video: + object
@@ -5309,11 +5390,23 @@
{
   "id": "number",
   "reason": "string",
-  "reporterUsername": "string",
-  "reporterServerHost": "string",
-  "videoId": "number",
-  "videoUUID": "string",
-  "videoName": "string",
+  "reporterAccount": {
+    "displayName": "string",
+    "id": "number",
+    "uuid": "string",
+    "url": "string",
+    "name": "string",
+    "host": "string",
+    "followingCount": "number",
+    "followersCount": "number",
+    "createdAt": "string",
+    "updatedAt": "string",
+    "avatar": {
+      "path": "string",
+      "createdAt": "string",
+      "updatedAt": "string"
+    }
+  },
   "createdAt": "string"
 }
 
@@ -5481,20 +5574,24 @@ { "id": "number", "uuid": "string", - "accountName": "string", "createdAt": "string", "updatedAt": "string", - "categoryLabel": "string", - "category": "number", - "licenceLabel": "string", - "licence": "number", - "languageLabel": "string", - "language": "number", + "category": { + "id": "number", + "label": "string" + }, + "licence": { + "id": "number", + "label": "string" + }, + "language": { + "id": "number", + "label": "string" + }, "description": "string", "duration": "number", "isLocal": "boolean", "name": "string", - "serverHost": "string", "thumbnailPath": "string", "previewPath": "string", "embedPath": "string", @@ -6074,20 +6171,24 @@ { "id": "number", "uuid": "string", - "accountName": "string", "createdAt": "string", "updatedAt": "string", - "categoryLabel": "string", - "category": "number", - "licenceLabel": "string", - "licence": "number", - "languageLabel": "string", - "language": "number", + "category": { + "id": "number", + "label": "string" + }, + "licence": { + "id": "number", + "label": "string" + }, + "language": { + "id": "number", + "label": "string" + }, "description": "string", "duration": "number", "isLocal": "boolean", "name": "string", - "serverHost": "string", "thumbnailPath": "string", "previewPath": "string", "embedPath": "string", diff --git a/support/doc/api/openapi.yaml b/support/doc/api/openapi.yaml index 99bf0fd2d..634da66e8 100644 --- a/support/doc/api/openapi.yaml +++ b/support/doc/api/openapi.yaml @@ -69,7 +69,7 @@ paths: '200': description: successful operation schema: - $ref: '#/definitions/ServerConfig' + $ref: '#/definitions/ServerConfig' /jobs: get: tags: @@ -105,7 +105,7 @@ paths: schema: type: array items: - $ref: '#/definitions/Job' + $ref: '#/definitions/Job' '/server/following/{host}': delete: tags: @@ -1037,6 +1037,12 @@ paths: '204': description: successful operation definitions: + VideoConstant: + properties: + id: + type: number + label: + type: string Video: properties: id: @@ -1047,18 +1053,12 @@ definitions: type: string updatedAt: type: string - categoryLabel: - type: string category: - type: number - licenceLabel: - type: string + $ref: "#/definitions/VideoConstant" licence: - type: number - languageLabel: - type: string + $ref: "#/definitions/VideoConstant" language: - type: number + $ref: "#/definitions/VideoConstant" description: type: string duration: @@ -1139,14 +1139,14 @@ definitions: type: boolean owner: type: object - properties: - name: + properties: + name: type: string - uuid: + uuid: type: string videos: type: array - items: + items: $ref: "#/definitions/Video" VideoComment: properties: @@ -1228,7 +1228,7 @@ definitions: type: boolean role: type: string - enum: [User, Moderator, Administrator] + enum: [User, Moderator, Administrator] videoQuota: type: number createdAt: @@ -1241,7 +1241,7 @@ definitions: $ref: "#/definitions/VideoChannel" ServerConfig: properties: - signup: + signup: type: object properties: allowed: @@ -1264,7 +1264,7 @@ definitions: properties: max: type: number - extensions: + extensions: type: array items: type: string @@ -1273,8 +1273,8 @@ definitions: properties: file: type: object - properties: - extensions: + properties: + extensions: type: array items: type: string -- 2.25.1