]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Better typescript typing for a better world
authorChocobozzz <florian.bigard@gmail.com>
Mon, 10 Jul 2017 17:43:21 +0000 (19:43 +0200)
committerChocobozzz <florian.bigard@gmail.com>
Mon, 10 Jul 2017 17:43:21 +0000 (19:43 +0200)
59 files changed:
client/src/app/+admin/friends/friend-add/friend-add.component.ts
client/src/app/+admin/users/shared/user.service.ts
client/src/app/+admin/users/user-add/user-add.component.ts
client/src/app/account/account-details/account-details.component.ts
client/src/app/core/auth/auth-user.model.ts
client/src/app/shared/users/user.service.ts
client/src/app/signup/signup.component.ts
client/src/app/videos/shared/video.service.ts
client/src/app/videos/video-edit/video-add.component.ts
scripts/watch/client.sh
scripts/watch/server.sh
server/controllers/api/remote/pods.ts
server/controllers/api/remote/videos.ts
server/controllers/api/users.ts
server/controllers/api/videos/abuse.ts
server/controllers/api/videos/index.ts
server/controllers/api/videos/rate.ts
server/helpers/requests.ts
server/lib/friends.ts
server/lib/request/abstract-request-scheduler.ts
server/lib/request/request-scheduler.ts
server/lib/request/request-video-event-scheduler.ts
server/lib/request/request-video-qadu-scheduler.ts
server/middlewares/secure.ts
server/models/pod/pod-interface.ts
server/models/user/user-interface.ts
server/models/user/user-video-rate-interface.ts
server/models/video/video-abuse-interface.ts
server/models/video/video-blacklist-interface.ts
server/models/video/video-interface.ts
shared/models/index.ts
shared/models/pods/index.ts [new file with mode: 0644]
shared/models/pods/pod-signature.model.ts [new file with mode: 0644]
shared/models/pods/pod.model.ts [moved from shared/models/pod.model.ts with 100% similarity]
shared/models/pods/remote-video/index.ts [new file with mode: 0644]
shared/models/pods/remote-video/remote-qadu-video-request.model.ts [new file with mode: 0644]
shared/models/pods/remote-video/remote-video-create-request.model.ts [new file with mode: 0644]
shared/models/pods/remote-video/remote-video-event-request.model.ts [new file with mode: 0644]
shared/models/pods/remote-video/remote-video-remove-request.model.ts [new file with mode: 0644]
shared/models/pods/remote-video/remote-video-report-abuse-request.model.ts [new file with mode: 0644]
shared/models/pods/remote-video/remote-video-request.model.ts [new file with mode: 0644]
shared/models/pods/remote-video/remote-video-update-request.model.ts [new file with mode: 0644]
shared/models/user-video-rate.model.ts [deleted file]
shared/models/users/index.ts [new file with mode: 0644]
shared/models/users/user-create.model.ts [new file with mode: 0644]
shared/models/users/user-role.type.ts [new file with mode: 0644]
shared/models/users/user-update.model.ts [new file with mode: 0644]
shared/models/users/user.model.ts [moved from shared/models/user.model.ts with 75% similarity]
shared/models/videos/index.ts [new file with mode: 0644]
shared/models/videos/user-video-rate-update.model.ts [new file with mode: 0644]
shared/models/videos/user-video-rate.model.ts [new file with mode: 0644]
shared/models/videos/user-video-rate.type.ts [new file with mode: 0644]
shared/models/videos/video-abuse-create.model.ts [new file with mode: 0644]
shared/models/videos/video-abuse.model.ts [moved from shared/models/video-abuse.model.ts with 100% similarity]
shared/models/videos/video-blacklist.model.ts [moved from shared/models/video-blacklist.model.ts with 100% similarity]
shared/models/videos/video-create.model.ts [new file with mode: 0644]
shared/models/videos/video-rate.type.ts [new file with mode: 0644]
shared/models/videos/video-update.model.ts [new file with mode: 0644]
shared/models/videos/video.model.ts [moved from shared/models/video.model.ts with 100% similarity]

index 35cf4a1f7673f9cb9b3c1789ff32779b590798a4..0449d26a96c9304e4e849e91e1287fb49a8d9c8b 100644 (file)
@@ -15,7 +15,7 @@ import { FriendService } from '../shared'
 })
 export class FriendAddComponent implements OnInit {
   form: FormGroup
-  hosts = [ ]
+  hosts: string[] = [ ]
   error: string = null
 
   constructor (
index d52993a29efbbb66133cc20050e5fd0398c64526..1c1cd575edf312d5cfb53c357424f3cf8b8c0d9e 100644 (file)
@@ -3,6 +3,7 @@ import 'rxjs/add/operator/catch'
 import 'rxjs/add/operator/map'
 
 import { AuthHttp, RestExtractor, RestDataSource, User } from '../../../shared'
+import { UserCreate } from '../../../../../../shared'
 
 @Injectable()
 export class UserService {
@@ -13,14 +14,8 @@ export class UserService {
     private restExtractor: RestExtractor
   ) {}
 
-  addUser (username: string, password: string, email: string) {
-    const body = {
-      username,
-      email,
-      password
-    }
-
-    return this.authHttp.post(UserService.BASE_USERS_URL, body)
+  addUser (userCreate: UserCreate) {
+    return this.authHttp.post(UserService.BASE_USERS_URL, userCreate)
                         .map(this.restExtractor.extractDataBool)
                         .catch(this.restExtractor.handleError)
   }
index 2d25ab46929e4a8991ff942d7acc6b0dbad7594a..0dd99eccd8aa81b25a9dacc6914af4bb1395a851 100644 (file)
@@ -11,6 +11,7 @@ import {
   USER_EMAIL,
   USER_PASSWORD
 } from '../../../shared'
+import { UserCreate } from '../../../../../../shared'
 
 @Component({
   selector: 'my-user-add',
@@ -57,11 +58,11 @@ export class UserAddComponent extends FormReactive implements OnInit {
   addUser () {
     this.error = null
 
-    const { username, password, email } = this.form.value
+    const userCreate: UserCreate = this.form.value
 
-    this.userService.addUser(username, password, email).subscribe(
+    this.userService.addUser(userCreate).subscribe(
       () => {
-        this.notificationsService.success('Success', `User ${username} created.`)
+        this.notificationsService.success('Success', `User ${userCreate.username} created.`)
         this.router.navigate([ '/admin/users/list' ])
       },
 
index d7531cb559eba2af4af7e8a5de8d2be4f7aeb206..547f045c4c6fce9e59a92691cf0501da7e03acaf 100644 (file)
@@ -11,6 +11,7 @@ import {
   UserService,
   USER_PASSWORD
 } from '../../shared'
+import { UserUpdate } from '../../../../../shared'
 
 @Component({
   selector: 'my-account-details',
@@ -50,7 +51,7 @@ export class AccountDetailsComponent extends FormReactive implements OnInit {
 
   updateDetails () {
     const displayNSFW = this.form.value['displayNSFW']
-    const details = {
+    const details: UserUpdate = {
       displayNSFW
     }
 
index 65c37bcfa6e2626ea03df8e2606079904b7e3da3..9cb2019072df8fdf68b00847a354641585685f80 100644 (file)
@@ -1,5 +1,5 @@
 // Do not use the barrel (dependency loop)
-import { UserRole } from '../../../../../shared/models/user.model'
+import { UserRole } from '../../../../../shared/models/users/user-role.type'
 import { User } from '../../shared/users/user.model'
 
 export type TokenOptions = {
index e956df5b1c14c38589221b4d22e4a3da7527ee80..b479ac0348d14155f90e74d7ae2566c0ef5f4fa0 100644 (file)
@@ -6,6 +6,7 @@ import 'rxjs/add/operator/map'
 import { AuthService } from '../../core'
 import { AuthHttp } from '../auth'
 import { RestExtractor } from '../rest'
+import { UserCreate, UserUpdate } from '../../../../../shared'
 
 @Injectable()
 export class UserService {
@@ -27,7 +28,7 @@ export class UserService {
 
   changePassword (newPassword: string) {
     const url = UserService.BASE_USERS_URL + this.authService.getUser().id
-    const body = {
+    const body: UserUpdate = {
       password: newPassword
     }
 
@@ -36,7 +37,7 @@ export class UserService {
                         .catch((res) => this.restExtractor.handleError(res))
   }
 
-  updateDetails (details: { displayNSFW: boolean }) {
+  updateDetails (details: UserUpdate) {
     const url = UserService.BASE_USERS_URL + this.authService.getUser().id
 
     return this.authHttp.put(url, details)
@@ -44,14 +45,8 @@ export class UserService {
                         .catch((res) => this.restExtractor.handleError(res))
   }
 
-  signup (username: string, password: string, email: string) {
-    const body = {
-      username,
-      email,
-      password
-    }
-
-    return this.http.post(UserService.BASE_USERS_URL + 'register', body)
+  signup (userCreate: UserCreate) {
+    return this.http.post(UserService.BASE_USERS_URL + 'register', userCreate)
                         .map(this.restExtractor.extractDataBool)
                         .catch(this.restExtractor.handleError)
   }
index bcbc8ded3b620c195a1ac68512c2d5539a5d7a82..981fe3c3bf5190eaa606f8e0a682bbfd54653887 100644 (file)
@@ -12,6 +12,7 @@ import {
   USER_EMAIL,
   USER_PASSWORD
 } from '../shared'
+import { UserCreate } from '../../../../shared'
 
 @Component({
   selector: 'my-signup',
@@ -58,11 +59,11 @@ export class SignupComponent extends FormReactive implements OnInit {
   signup () {
     this.error = null
 
-    const { username, password, email } = this.form.value
+    const userCreate: UserCreate = this.form.value
 
-    this.userService.signup(username, password, email).subscribe(
+    this.userService.signup(userCreate).subscribe(
       () => {
-        this.notificationsService.success('Success', `Registration for ${username} complete.`)
+        this.notificationsService.success('Success', `Registration for ${userCreate.username} complete.`)
         this.router.navigate([ '/videos/list' ])
       },
 
index 7658d8ff035e8a5eca8399573aa60fcee79a1273..dc12c0637b22f0ef3b6cf02db96accadc96f5be4 100644 (file)
@@ -16,7 +16,13 @@ import {
   UserService
 } from '../../shared'
 import { Video } from './video.model'
-import { UserVideoRate, VideoRateType } from '../../../../../shared'
+import {
+  UserVideoRate,
+  VideoRateType,
+  VideoUpdate,
+  VideoAbuseCreate,
+  UserVideoRateUpdate
+} from '../../../../../shared'
 
 @Injectable()
 export class VideoService {
@@ -35,42 +41,15 @@ export class VideoService {
   ) {}
 
   loadVideoCategories () {
-    return this.http.get(VideoService.BASE_VIDEO_URL + 'categories')
-                    .map(this.restExtractor.extractDataGet)
-                    .subscribe(data => {
-                      Object.keys(data).forEach(categoryKey => {
-                        this.videoCategories.push({
-                          id: parseInt(categoryKey, 10),
-                          label: data[categoryKey]
-                        })
-                      })
-                    })
+    return this.loadVideoAttributeEnum('categories', this.videoCategories)
   }
 
   loadVideoLicences () {
-    return this.http.get(VideoService.BASE_VIDEO_URL + 'licences')
-                    .map(this.restExtractor.extractDataGet)
-                    .subscribe(data => {
-                      Object.keys(data).forEach(licenceKey => {
-                        this.videoLicences.push({
-                          id: parseInt(licenceKey, 10),
-                          label: data[licenceKey]
-                        })
-                      })
-                    })
+    return this.loadVideoAttributeEnum('licences', this.videoLicences)
   }
 
   loadVideoLanguages () {
-    return this.http.get(VideoService.BASE_VIDEO_URL + 'languages')
-                    .map(this.restExtractor.extractDataGet)
-                    .subscribe(data => {
-                      Object.keys(data).forEach(languageKey => {
-                        this.videoLanguages.push({
-                          id: parseInt(languageKey, 10),
-                          label: data[languageKey]
-                        })
-                      })
-                    })
+    return this.loadVideoAttributeEnum('languages', this.videoLanguages)
   }
 
   getVideo (id: string): Observable<Video> {
@@ -83,13 +62,14 @@ export class VideoService {
   updateVideo (video: Video) {
     const language = video.language ? video.language : null
 
-    const body = {
+    const body: VideoUpdate = {
       name: video.name,
       category: video.category,
       licence: video.licence,
       language,
       description: video.description,
-      tags: video.tags
+      tags: video.tags,
+      nsfw: video.nsfw
     }
 
     const headers = new Headers({ 'Content-Type': 'application/json' })
@@ -128,7 +108,7 @@ export class VideoService {
 
   reportVideo (id: string, reason: string) {
     const url = VideoService.BASE_VIDEO_URL + id + '/abuse'
-    const body = {
+    const body: VideoAbuseCreate = {
       reason
     }
 
@@ -161,7 +141,7 @@ export class VideoService {
 
   private setVideoRate (id: string, rateType: VideoRateType) {
     const url = VideoService.BASE_VIDEO_URL + id + '/rate'
-    const body = {
+    const body: UserVideoRateUpdate = {
       rating: rateType
     }
 
@@ -180,4 +160,17 @@ export class VideoService {
 
     return { videos, totalVideos }
   }
+
+  private loadVideoAttributeEnum (attributeName: 'categories' | 'licences' | 'languages', hashToPopulate: { id: number, label: string }[]) {
+    return this.http.get(VideoService.BASE_VIDEO_URL + attributeName)
+                    .map(this.restExtractor.extractDataGet)
+                    .subscribe(data => {
+                      Object.keys(data).forEach(dataKey => {
+                        hashToPopulate.push({
+                          id: parseInt(dataKey, 10),
+                          label: data[dataKey]
+                        })
+                      })
+                    })
+  }
 }
index 0653f5ac4aff38e80470d28673f15e44b7eb870a..5d6c0e0c7038a3329e95e7aee05aa79e49c1074e 100644 (file)
@@ -16,6 +16,7 @@ import {
   VIDEO_TAGS
 } from '../../shared'
 import { VideoService } from '../shared'
+import { VideoCreate } from '../../../../../shared'
 
 @Component({
   selector: 'my-videos-add',
@@ -98,23 +99,25 @@ export class VideoAddComponent extends FormReactive implements OnInit {
       removeAfterUpload: true
     })
 
-    this.uploader.onBuildItemForm = (item, form) => {
-      const name = this.form.value['name']
-      const nsfw = this.form.value['nsfw']
-      const category = this.form.value['category']
-      const licence = this.form.value['licence']
-      const language = this.form.value['language']
-      const description = this.form.value['description']
-      const tags = this.form.value['tags']
+    this.uploader.onBuildItemForm = (item, form: FormData) => {
+      const formValue: VideoCreate = this.form.value
+
+      const name = formValue.name
+      const nsfw = formValue.nsfw
+      const category = formValue.category
+      const licence = formValue.licence
+      const language = formValue.language
+      const description = formValue.description
+      const tags = formValue.tags
 
       form.append('name', name)
-      form.append('category', category)
-      form.append('nsfw', nsfw)
-      form.append('licence', licence)
+      form.append('category', '' + category)
+      form.append('nsfw', '' + nsfw)
+      form.append('licence', '' + licence)
 
       // Language is optional
       if (language) {
-        form.append('language', language)
+        form.append('language', '' + language)
       }
 
       form.append('description', description)
index c99ed14e685ab827f899c90d9bb6198ec89764d8..313f66670e61d33f579a0f213f4d183643b9313e 100755 (executable)
@@ -2,4 +2,4 @@
 
 cd client || exit -1
 
-npm run webpack-dev-server -- --config config/webpack.dev.js --progress --profile --colors --watch --content-base src/ --inline --hot
+npm run webpack-dev-server -- --config config/webpack.dev.js --progress --profile --colors --watch --content-base src/ --inline --hot --open
index 55570138e4057d21fa899966d94c4ffa84978bec..448f695521c31bb1eb8856f5b7c825c67f624b6f 100755 (executable)
@@ -1,5 +1,5 @@
 #!/usr/bin/env sh
 
-NODE_ENV=test concurrently \
+NODE_ENV=test concurrently -k \
   "npm run tsc -- --sourceMap && npm run nodemon -- --delay 2 --watch ./dist dist/server" \
   "npm run tsc -- --sourceMap -w"
index 6319957d3b7744f5c2e499f516e98398b728bad8..69bbd43780b4e8babcb395451f84f9ce12959aa3 100644 (file)
@@ -2,6 +2,7 @@ import * as express from 'express'
 
 import { database as db } from '../../../initializers/database'
 import { checkSignature, signatureValidator } from '../../../middlewares'
+import { PodSignature } from '../../../../shared'
 
 const remotePodsRouter = express.Router()
 
@@ -21,12 +22,11 @@ export {
 // ---------------------------------------------------------------------------
 
 function removePods (req: express.Request, res: express.Response, next: express.NextFunction) {
-  const host = req.body.signature.host
+  const signature: PodSignature = req.body.signature
+  const host = signature.host
 
   db.Pod.loadByHost(host)
-    .then(pod => {
-      return pod.destroy()
-    })
+    .then(pod => pod.destroy())
     .then(() => res.type('json').status(204).end())
     .catch(err => next(err))
 }
index fac85c3a852a645f9ea2e166c3ba12ef876e0ff7..96eab6d52c058f2bfcfef0acc3a4d07a27f57a8b 100644 (file)
@@ -18,6 +18,17 @@ import {
 import { logger, retryTransactionWrapper } from '../../../helpers'
 import { quickAndDirtyUpdatesVideoToFriends } from '../../../lib'
 import { PodInstance, VideoInstance } from '../../../models'
+import {
+  RemoteVideoRequest,
+  RemoteVideoCreateData,
+  RemoteVideoUpdateData,
+  RemoteVideoRemoveData,
+  RemoteVideoReportAbuseData,
+  RemoteQaduVideoRequest,
+  RemoteQaduVideoData,
+  RemoteVideoEventRequest,
+  RemoteVideoEventData
+} from '../../../../shared'
 
 const ENDPOINT_ACTIONS = REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS]
 
@@ -60,11 +71,11 @@ export {
 // ---------------------------------------------------------------------------
 
 function remoteVideos (req: express.Request, res: express.Response, next: express.NextFunction) {
-  const requests = req.body.data
+  const requests: RemoteVideoRequest[] = req.body.data
   const fromPod = res.locals.secure.pod
 
   // We need to process in the same order to keep consistency
-  Promise.each(requests, (request: any) => {
+  Promise.each(requests, request => {
     const data = request.data
 
     // Get the function we need to call in order to process the request
@@ -83,10 +94,10 @@ function remoteVideos (req: express.Request, res: express.Response, next: expres
 }
 
 function remoteVideosQadu (req: express.Request, res: express.Response, next: express.NextFunction) {
-  const requests = req.body.data
+  const requests: RemoteQaduVideoRequest[] = req.body.data
   const fromPod = res.locals.secure.pod
 
-  Promise.each(requests, (request: any) => {
+  Promise.each(requests, request => {
     const videoData = request.data
 
     return quickAndDirtyUpdateVideoRetryWrapper(videoData, fromPod)
@@ -97,10 +108,10 @@ function remoteVideosQadu (req: express.Request, res: express.Response, next: ex
 }
 
 function remoteVideosEvents (req: express.Request, res: express.Response, next: express.NextFunction) {
-  const requests = req.body.data
+  const requests: RemoteVideoEventRequest[] = req.body.data
   const fromPod = res.locals.secure.pod
 
-  Promise.each(requests, (request: any) => {
+  Promise.each(requests, request => {
     const eventData = request.data
 
     return processVideosEventsRetryWrapper(eventData, fromPod)
@@ -110,7 +121,7 @@ function remoteVideosEvents (req: express.Request, res: express.Response, next:
   return res.type('json').status(204).end()
 }
 
-function processVideosEventsRetryWrapper (eventData: any, fromPod: PodInstance) {
+function processVideosEventsRetryWrapper (eventData: RemoteVideoEventData, fromPod: PodInstance) {
   const options = {
     arguments: [ eventData, fromPod ],
     errorMessage: 'Cannot process videos events with many retries.'
@@ -119,7 +130,7 @@ function processVideosEventsRetryWrapper (eventData: any, fromPod: PodInstance)
   return retryTransactionWrapper(processVideosEvents, options)
 }
 
-function processVideosEvents (eventData: any, fromPod: PodInstance) {
+function processVideosEvents (eventData: RemoteVideoEventData, fromPod: PodInstance) {
 
   return db.sequelize.transaction(t => {
     return fetchOwnedVideo(eventData.remoteId)
@@ -172,7 +183,7 @@ function processVideosEvents (eventData: any, fromPod: PodInstance) {
   })
 }
 
-function quickAndDirtyUpdateVideoRetryWrapper (videoData: any, fromPod: PodInstance) {
+function quickAndDirtyUpdateVideoRetryWrapper (videoData: RemoteQaduVideoData, fromPod: PodInstance) {
   const options = {
     arguments: [ videoData, fromPod ],
     errorMessage: 'Cannot update quick and dirty the remote video with many retries.'
@@ -181,7 +192,7 @@ function quickAndDirtyUpdateVideoRetryWrapper (videoData: any, fromPod: PodInsta
   return retryTransactionWrapper(quickAndDirtyUpdateVideo, options)
 }
 
-function quickAndDirtyUpdateVideo (videoData: any, fromPod: PodInstance) {
+function quickAndDirtyUpdateVideo (videoData: RemoteQaduVideoData, fromPod: PodInstance) {
   let videoName
 
   return db.sequelize.transaction(t => {
@@ -211,7 +222,7 @@ function quickAndDirtyUpdateVideo (videoData: any, fromPod: PodInstance) {
 }
 
 // Handle retries on fail
-function addRemoteVideoRetryWrapper (videoToCreateData: any, fromPod: PodInstance) {
+function addRemoteVideoRetryWrapper (videoToCreateData: RemoteVideoCreateData, fromPod: PodInstance) {
   const options = {
     arguments: [ videoToCreateData, fromPod ],
     errorMessage: 'Cannot insert the remote video with many retries.'
@@ -220,7 +231,7 @@ function addRemoteVideoRetryWrapper (videoToCreateData: any, fromPod: PodInstanc
   return retryTransactionWrapper(addRemoteVideo, options)
 }
 
-function addRemoteVideo (videoToCreateData: any, fromPod: PodInstance) {
+function addRemoteVideo (videoToCreateData: RemoteVideoCreateData, fromPod: PodInstance) {
   logger.debug('Adding remote video "%s".', videoToCreateData.remoteId)
 
   return db.sequelize.transaction(t => {
@@ -293,7 +304,7 @@ function addRemoteVideo (videoToCreateData: any, fromPod: PodInstance) {
 }
 
 // Handle retries on fail
-function updateRemoteVideoRetryWrapper (videoAttributesToUpdate: any, fromPod: PodInstance) {
+function updateRemoteVideoRetryWrapper (videoAttributesToUpdate: RemoteVideoUpdateData, fromPod: PodInstance) {
   const options = {
     arguments: [ videoAttributesToUpdate, fromPod ],
     errorMessage: 'Cannot update the remote video with many retries'
@@ -302,7 +313,7 @@ function updateRemoteVideoRetryWrapper (videoAttributesToUpdate: any, fromPod: P
   return retryTransactionWrapper(updateRemoteVideo, options)
 }
 
-function updateRemoteVideo (videoAttributesToUpdate: any, fromPod: PodInstance) {
+function updateRemoteVideo (videoAttributesToUpdate: RemoteVideoUpdateData, fromPod: PodInstance) {
   logger.debug('Updating remote video "%s".', videoAttributesToUpdate.remoteId)
 
   return db.sequelize.transaction(t => {
@@ -346,7 +357,7 @@ function updateRemoteVideo (videoAttributesToUpdate: any, fromPod: PodInstance)
   })
 }
 
-function removeRemoteVideo (videoToRemoveData: any, fromPod: PodInstance) {
+function removeRemoteVideo (videoToRemoveData: RemoteVideoRemoveData, fromPod: PodInstance) {
   // We need the instance because we have to remove some other stuffs (thumbnail etc)
   return fetchRemoteVideo(fromPod.host, videoToRemoveData.remoteId)
     .then(video => {
@@ -358,7 +369,7 @@ function removeRemoteVideo (videoToRemoveData: any, fromPod: PodInstance) {
     })
 }
 
-function reportAbuseRemoteVideo (reportData: any, fromPod: PodInstance) {
+function reportAbuseRemoteVideo (reportData: RemoteVideoReportAbuseData, fromPod: PodInstance) {
   return fetchOwnedVideo(reportData.videoRemoteId)
     .then(video => {
       logger.debug('Reporting remote abuse for video %s.', video.id)
index 845facd55847dd53fc3d99defde794a4f28e0b47..e794805214084d8b03e69919e759f5a627915557 100644 (file)
@@ -17,7 +17,7 @@ import {
   setUsersSort,
   token
 } from '../../middlewares'
-import { UserVideoRate as FormatedUserVideoRate } from '../../../shared'
+import { UserVideoRate as FormatedUserVideoRate, UserCreate, UserUpdate } from '../../../shared'
 
 const usersRouter = express.Router()
 
@@ -78,10 +78,12 @@ export {
 // ---------------------------------------------------------------------------
 
 function createUser (req: express.Request, res: express.Response, next: express.NextFunction) {
+  const body: UserCreate = req.body
+
   const user = db.User.build({
-    username: req.body.username,
-    password: req.body.password,
-    email: req.body.email,
+    username: body.username,
+    password: body.password,
+    email: body.email,
     displayNSFW: false,
     role: USER_ROLES.USER
   })
@@ -132,10 +134,12 @@ function removeUser (req: express.Request, res: express.Response, next: express.
 }
 
 function updateUser (req: express.Request, res: express.Response, next: express.NextFunction) {
+  const body: UserUpdate = req.body
+
   db.User.loadByUsername(res.locals.oauth.token.user.username)
     .then(user => {
-      if (req.body.password) user.password = req.body.password
-      if (req.body.displayNSFW !== undefined) user.displayNSFW = req.body.displayNSFW
+      if (body.password) user.password = body.password
+      if (body.displayNSFW !== undefined) user.displayNSFW = body.displayNSFW
 
       return user.save()
     })
index 3b1b7f58e07583ae71663fb6a38002d3a8b20c7e..7d2e3bcfbd2c792907cc430678bc9a6f0d24e583 100644 (file)
@@ -17,6 +17,7 @@ import {
   setPagination
 } from '../../../middlewares'
 import { VideoInstance } from '../../../models'
+import { VideoAbuseCreate } from '../../../../shared'
 
 const abuseVideoRouter = express.Router()
 
@@ -63,10 +64,11 @@ function reportVideoAbuseRetryWrapper (req: express.Request, res: express.Respon
 function reportVideoAbuse (req: express.Request, res: express.Response) {
   const videoInstance = res.locals.video
   const reporterUsername = res.locals.oauth.token.User.username
+  const body: VideoAbuseCreate = req.body
 
   const abuse = {
     reporterUsername,
-    reason: req.body.reason,
+    reason: body.reason,
     videoId: videoInstance.id,
     reporterPodId: null // This is our pod that reported this abuse
   }
index 3532c753eb4417f1d3c87735aba5754b5ca757fb..4ae7ea2edbd90f9e878fa80968703cf2b01dfdb3 100644 (file)
@@ -39,6 +39,7 @@ import {
   renamePromise
 } from '../../../helpers'
 import { TagInstance } from '../../../models'
+import { VideoCreate, VideoUpdate } from '../../../../shared'
 
 import { abuseVideoRouter } from './abuse'
 import { blacklistRouter } from './blacklist'
@@ -155,7 +156,7 @@ function addVideoRetryWrapper (req: express.Request, res: express.Response, next
 }
 
 function addVideo (req: express.Request, res: express.Response, videoFile: Express.Multer.File) {
-  const videoInfos = req.body
+  const videoInfos: VideoCreate = req.body
 
   return db.sequelize.transaction(t => {
     const user = res.locals.oauth.token.User
@@ -257,7 +258,7 @@ function updateVideoRetryWrapper (req: express.Request, res: express.Response, n
 function updateVideo (req: express.Request, res: express.Response) {
   const videoInstance = res.locals.video
   const videoFieldsSave = videoInstance.toJSON()
-  const videoInfosToUpdate = req.body
+  const videoInfosToUpdate: VideoUpdate = req.body
 
   return db.sequelize.transaction(t => {
     let tagsPromise: Promise<TagInstance[]>
index dfb5a450f857e7644c6e8f98f2fc0b00cb23b00e..8456cbaf24ec48685b6d2ed0348f57545fdefcaf 100644 (file)
@@ -1,4 +1,5 @@
 import * as express from 'express'
+import * as Promise from 'bluebird'
 
 import { database as db } from '../../../initializers/database'
 import {
@@ -18,6 +19,7 @@ import {
   authenticate,
   videoRateValidator
 } from '../../../middlewares'
+import { UserVideoRateUpdate, VideoRateType } from '../../../../shared'
 
 const rateVideoRouter = express.Router()
 
@@ -47,7 +49,8 @@ function rateVideoRetryWrapper (req: express.Request, res: express.Response, nex
 }
 
 function rateVideo (req: express.Request, res: express.Response) {
-  const rateType = req.body.rating
+  const body: UserVideoRateUpdate = req.body
+  const rateType = body.rating
   const videoInstance = res.locals.video
   const userInstance = res.locals.oauth.token.User
 
@@ -62,24 +65,34 @@ function rateVideo (req: express.Request, res: express.Response) {
         if (rateType === VIDEO_RATE_TYPES.LIKE) likesToIncrement++
         else if (rateType === VIDEO_RATE_TYPES.DISLIKE) dislikesToIncrement++
 
+        let promise: Promise<any>
+
         // There was a previous rate, update it
         if (previousRate) {
           // We will remove the previous rate, so we will need to remove it from the video attribute
           if (previousRate.type === VIDEO_RATE_TYPES.LIKE) likesToIncrement--
           else if (previousRate.type === VIDEO_RATE_TYPES.DISLIKE) dislikesToIncrement--
 
-          previousRate.type = rateType
+          if (rateType === 'none') { // Destroy previous rate
+            promise = previousRate.destroy()
+          } else { // Update previous rate
+            previousRate.type = rateType as VideoRateType
 
-          return previousRate.save(options).then(() => ({ t, likesToIncrement, dislikesToIncrement }))
-        } else { // There was not a previous rate, insert a new one
+            promise = previousRate.save()
+          }
+        } else if (rateType !== 'none') { // There was not a previous rate, insert a new one if there is a rate
           const query = {
             userId: userInstance.id,
             videoId: videoInstance.id,
             type: rateType
           }
 
-          return db.UserVideoRate.create(query, options).then(() => ({ likesToIncrement, dislikesToIncrement }))
+          promise = db.UserVideoRate.create(query, options)
+        } else {
+          promise = Promise.resolve()
         }
+
+        return promise.then(() => ({ likesToIncrement, dislikesToIncrement }))
       })
       .then(({ likesToIncrement, dislikesToIncrement }) => {
         const options = { transaction: t }
index 183f6df0daf2b9de488c7740799310bd8b3b97ee..d67d460446e99a2aa22d6116f7928af90f5e05f8 100644 (file)
@@ -8,6 +8,7 @@ import {
   CONFIG
 } from '../initializers'
 import { PodInstance } from '../models'
+import { PodSignature } from '../../shared'
 import { sign } from './peertube-crypto'
 
 type MakeRetryRequestParams = {
@@ -37,9 +38,18 @@ type MakeSecureRequestParams = {
 }
 function makeSecureRequest (params: MakeSecureRequestParams) {
   return new Promise<{ response: request.RequestResponse, body: any }>((res, rej) => {
-    const requestParams = {
+    const requestParams: {
+      url: string,
+      json: {
+        signature: PodSignature,
+        data: any
+      }
+    } = {
       url: REMOTE_SCHEME.HTTP + '://' + params.toPod.host + params.path,
-      json: {}
+      json: {
+        signature: null,
+        data: null
+      }
     }
 
     if (params.method !== 'POST') {
@@ -58,14 +68,14 @@ function makeSecureRequest (params: MakeSecureRequestParams) {
     }
 
     sign(dataToSign).then(signature => {
-      requestParams.json['signature'] = {
+      requestParams.json.signature = {
         host, // Which host we pretend to be
         signature
       }
 
       // If there are data informations
       if (params.data) {
-        requestParams.json['data'] = params.data
+        requestParams.json.data = params.data
       }
 
       request.post(requestParams, (err, response, body) => err ? rej(err) : res({ response, body }))
index 3487addbeb9f2d8ac8db66b0299047a5c0e06527..4d56e9eb22a9fd72611e1ec8955a95d40ad2a532 100644 (file)
@@ -34,7 +34,11 @@ import {
 import {
   RequestEndpoint,
   RequestVideoEventType,
-  RequestVideoQaduType
+  RequestVideoQaduType,
+  RemoteVideoCreateData,
+  RemoteVideoUpdateData,
+  RemoteVideoRemoveData,
+  RemoteVideoReportAbuseData
 } from '../../shared'
 
 type QaduParam = { videoId: string, type: RequestVideoQaduType }
@@ -52,7 +56,7 @@ function activateSchedulers () {
   requestVideoEventScheduler.activate()
 }
 
-function addVideoToFriends (videoData: Object, transaction: Sequelize.Transaction) {
+function addVideoToFriends (videoData: RemoteVideoCreateData, transaction: Sequelize.Transaction) {
   const options = {
     type: ENDPOINT_ACTIONS.ADD,
     endpoint: REQUEST_ENDPOINTS.VIDEOS,
@@ -62,7 +66,7 @@ function addVideoToFriends (videoData: Object, transaction: Sequelize.Transactio
   return createRequest(options)
 }
 
-function updateVideoToFriends (videoData: Object, transaction: Sequelize.Transaction) {
+function updateVideoToFriends (videoData: RemoteVideoUpdateData, transaction: Sequelize.Transaction) {
   const options = {
     type: ENDPOINT_ACTIONS.UPDATE,
     endpoint: REQUEST_ENDPOINTS.VIDEOS,
@@ -72,7 +76,7 @@ function updateVideoToFriends (videoData: Object, transaction: Sequelize.Transac
   return createRequest(options)
 }
 
-function removeVideoToFriends (videoParams: Object) {
+function removeVideoToFriends (videoParams: RemoteVideoRemoveData) {
   const options = {
     type: ENDPOINT_ACTIONS.REMOVE,
     endpoint: REQUEST_ENDPOINTS.VIDEOS,
@@ -82,7 +86,7 @@ function removeVideoToFriends (videoParams: Object) {
   return createRequest(options)
 }
 
-function reportAbuseVideoToFriend (reportData: Object, video: VideoInstance, transaction: Sequelize.Transaction) {
+function reportAbuseVideoToFriend (reportData: RemoteVideoReportAbuseData, video: VideoInstance, transaction: Sequelize.Transaction) {
   const options = {
     type: ENDPOINT_ACTIONS.REPORT_ABUSE,
     endpoint: REQUEST_ENDPOINTS.VIDEOS,
index 0a9ff65d56d1b428c9676f0192a3b0c400f05202..ce4e2ffd2bc0d90e49c374a6162135c9faf5c094 100644 (file)
@@ -10,6 +10,15 @@ import {
   REQUESTS_INTERVAL
 } from '../../initializers'
 
+interface RequestsObjects<U> {
+  [ id: string ]: {
+    toPod: PodInstance
+    endpoint: string
+    ids: number[] // ids
+    datas: U[]
+  }
+}
+
 abstract class AbstractRequestScheduler <T> {
   requestInterval: number
   limitPods: number
@@ -27,7 +36,7 @@ abstract class AbstractRequestScheduler <T> {
 
   abstract getRequestModel (): AbstractRequestClass<T>
   abstract getRequestToPodModel (): AbstractRequestToPodClass
-  abstract buildRequestObjects (requestsGrouped: T): {}
+  abstract buildRequestsObjects (requestsGrouped: T): RequestsObjects<any>
 
   activate () {
     logger.info('Requests scheduler activated.')
@@ -67,7 +76,7 @@ abstract class AbstractRequestScheduler <T> {
   // ---------------------------------------------------------------------------
 
   // Make a requests to friends of a certain type
-  protected makeRequest (toPod: PodInstance, requestEndpoint: string, requestsToMake: Object) {
+  protected makeRequest (toPod: PodInstance, requestEndpoint: string, requestsToMake: any) {
     const params = {
       toPod: toPod,
       method: 'POST' as 'POST',
@@ -95,7 +104,7 @@ abstract class AbstractRequestScheduler <T> {
     return this.getRequestModel().listWithLimitAndRandom(this.limitPods, this.limitPerPod)
       .then((requestsGrouped: T) => {
         // We want to group requests by destinations pod and endpoint
-        const requestsToMake = this.buildRequestObjects(requestsGrouped)
+        const requestsToMake = this.buildRequestsObjects(requestsGrouped)
 
         // If there are no requests, abort
         if (isEmpty(requestsToMake) === true) {
@@ -105,8 +114,8 @@ abstract class AbstractRequestScheduler <T> {
 
         logger.info('Making "%s" to friends.', this.description)
 
-        const goodPods = []
-        const badPods = []
+        const goodPods: number[] = []
+        const badPods: number[] = []
 
         return Promise.map(Object.keys(requestsToMake), hashKey => {
           const requestToMake = requestsToMake[hashKey]
@@ -149,5 +158,6 @@ abstract class AbstractRequestScheduler <T> {
 // ---------------------------------------------------------------------------
 
 export {
-  AbstractRequestScheduler
+  AbstractRequestScheduler,
+  RequestsObjects
 }
index 3945ace200aa9bc1a5a0ec24bae5c9bff094c650..696875dcf4e27317771581d8b9d8e55ca92e3882 100644 (file)
@@ -1,11 +1,11 @@
 import * as Sequelize from 'sequelize'
 
 import { database as db } from '../../initializers/database'
-import { AbstractRequestScheduler } from './abstract-request-scheduler'
+import { AbstractRequestScheduler, RequestsObjects } from './abstract-request-scheduler'
 import { logger } from '../../helpers'
 import { REQUESTS_LIMIT_PODS, REQUESTS_LIMIT_PER_POD } from '../../initializers'
 import { RequestsGrouped } from '../../models'
-import { RequestEndpoint } from '../../../shared'
+import { RequestEndpoint, RemoteVideoRequest } from '../../../shared'
 
 export type RequestSchedulerOptions = {
   type: string
@@ -34,8 +34,8 @@ class RequestScheduler extends AbstractRequestScheduler<RequestsGrouped> {
     return db.RequestToPod
   }
 
-  buildRequestObjects (requestsGrouped: RequestsGrouped) {
-    const requestsToMakeGrouped = {}
+  buildRequestsObjects (requestsGrouped: RequestsGrouped) {
+    const requestsToMakeGrouped: RequestsObjects<RemoteVideoRequest> = {}
 
     Object.keys(requestsGrouped).forEach(toPodId => {
       requestsGrouped[toPodId].forEach(data => {
index d4d714c02facd5271c460190e51886d11e26f04e..8a008c51bbae9d3c15bb0bfc5152285c28c6c4e5 100644 (file)
@@ -1,14 +1,14 @@
 import * as Sequelize from 'sequelize'
 
 import { database as db } from '../../initializers/database'
-import { AbstractRequestScheduler } from './abstract-request-scheduler'
+import { AbstractRequestScheduler, RequestsObjects } from './abstract-request-scheduler'
 import {
   REQUESTS_VIDEO_EVENT_LIMIT_PODS,
   REQUESTS_VIDEO_EVENT_LIMIT_PER_POD,
   REQUEST_VIDEO_EVENT_ENDPOINT
 } from '../../initializers'
 import { RequestsVideoEventGrouped } from '../../models'
-import { RequestVideoEventType } from '../../../shared'
+import { RequestVideoEventType, RemoteVideoEventRequest, RemoteVideoEventType } from '../../../shared'
 
 export type RequestVideoEventSchedulerOptions = {
   type: RequestVideoEventType
@@ -36,8 +36,8 @@ class RequestVideoEventScheduler extends AbstractRequestScheduler<RequestsVideoE
     return db.RequestVideoEvent
   }
 
-  buildRequestObjects (eventRequests: RequestsVideoEventGrouped) {
-    const requestsToMakeGrouped = {}
+  buildRequestsObjects (eventRequests: RequestsVideoEventGrouped) {
+    const requestsToMakeGrouped: RequestsObjects<RemoteVideoEventRequest> = {}
 
     /* Example:
         {
@@ -47,7 +47,15 @@ class RequestVideoEventScheduler extends AbstractRequestScheduler<RequestsVideoE
           }
         }
     */
-    const eventsPerVideoPerPod = {}
+    const eventsPerVideoPerPod: {
+      [ podId: string ]: {
+        [ videoRemoteId: string ]: {
+          views?: number
+          likes?: number
+          dislikes?: number
+        }
+      }
+    } = {}
 
     // We group video events per video and per pod
     // We add the counts of the same event types
@@ -87,8 +95,8 @@ class RequestVideoEventScheduler extends AbstractRequestScheduler<RequestsVideoE
           requestsToMakeGrouped[toPodId].datas.push({
             data: {
               remoteId,
-              eventType,
-              count: eventsForVideo[eventType]
+              eventType: eventType as RemoteVideoEventType,
+              count: +eventsForVideo[eventType]
             }
           })
         })
index 5ec7de9c206e1291aa2a6bb4bd9f13d0473f3991..98816517015b7bc4ea81347e4f6fb6ff6464a21f 100644 (file)
@@ -1,7 +1,7 @@
 import * as Sequelize from 'sequelize'
 
 import { database as db } from '../../initializers/database'
-import { AbstractRequestScheduler } from './abstract-request-scheduler'
+import { AbstractRequestScheduler, RequestsObjects } from './abstract-request-scheduler'
 import { logger } from '../../helpers'
 import {
   REQUESTS_VIDEO_QADU_LIMIT_PODS,
@@ -9,8 +9,27 @@ import {
   REQUEST_VIDEO_QADU_ENDPOINT,
   REQUEST_VIDEO_QADU_TYPES
 } from '../../initializers'
-import { RequestsVideoQaduGrouped } from '../../models'
-import { RequestVideoQaduType } from '../../../shared'
+import { RequestsVideoQaduGrouped, PodInstance } from '../../models'
+import { RemoteQaduVideoRequest, RequestVideoQaduType } from '../../../shared'
+
+// We create a custom interface because we need "videos" attribute for our computations
+interface RequestsObjectsCustom<U> extends RequestsObjects<U> {
+  [ id: string ]: {
+    toPod: PodInstance
+    endpoint: string
+    ids: number[] // ids
+    datas: U[]
+
+    videos: {
+      [ id: string ]: {
+        remoteId: string
+        likes?: number
+        dislikes?: number
+        views?: number
+      }
+    }
+  }
+}
 
 export type RequestVideoQaduSchedulerOptions = {
   type: RequestVideoQaduType
@@ -37,8 +56,8 @@ class RequestVideoQaduScheduler extends AbstractRequestScheduler<RequestsVideoQa
     return db.RequestVideoQadu
   }
 
-  buildRequestObjects (requests: RequestsVideoQaduGrouped) {
-    const requestsToMakeGrouped = {}
+  buildRequestsObjects (requests: RequestsVideoQaduGrouped) {
+    const requestsToMakeGrouped: RequestsObjectsCustom<RemoteQaduVideoRequest> = {}
 
     Object.keys(requests).forEach(toPodId => {
       requests[toPodId].forEach(data => {
@@ -59,7 +78,7 @@ class RequestVideoQaduScheduler extends AbstractRequestScheduler<RequestsVideoQa
 
         // Maybe another attribute was filled for this video
         let videoData = requestsToMakeGrouped[hashKey].videos[video.id]
-        if (!videoData) videoData = {}
+        if (!videoData) videoData = { remoteId: null }
 
         switch (request.type) {
           case REQUEST_VIDEO_QADU_TYPES.LIKES:
index f58bea734b535f117c980229b9f841511a45cc52..f7424c9c3e7b47c45025a75ae9d5dcebbe22860d 100644 (file)
@@ -6,9 +6,12 @@ import {
   logger,
   checkSignature as peertubeCryptoCheckSignature
 } from '../helpers'
+import { PodSignature } from '../../shared'
 
 function checkSignature (req: express.Request, res: express.Response, next: express.NextFunction) {
-  const host = req.body.signature.host
+  const signatureObject: PodSignature = req.body.signature
+  const host = signatureObject.host
+
   db.Pod.loadByHost(host)
     .then(pod => {
       if (pod === null) {
@@ -27,7 +30,7 @@ function checkSignature (req: express.Request, res: express.Response, next: expr
         signatureShouldBe = host
       }
 
-      const signatureOk = peertubeCryptoCheckSignature(pod.publicKey, signatureShouldBe, req.body.signature.signature)
+      const signatureOk = peertubeCryptoCheckSignature(pod.publicKey, signatureShouldBe, signatureObject.signature)
 
       if (signatureOk === true) {
         res.locals.secure = {
@@ -37,11 +40,11 @@ function checkSignature (req: express.Request, res: express.Response, next: expr
         return next()
       }
 
-      logger.error('Signature is not okay in body for %s.', req.body.signature.host)
+      logger.error('Signature is not okay in body for %s.', signatureObject.host)
       return res.sendStatus(403)
     })
     .catch(err => {
-      logger.error('Cannot get signed host in body.', { error: err.stack, signature: req.body.signature.signature })
+      logger.error('Cannot get signed host in body.', { error: err.stack, signature: signatureObject.signature })
       return res.sendStatus(500)
     })
 }
index f6963d47eecd27bba44beb8731b7e1ced9fd8929..340d4f1a784cbe0791cdfbc1a364891940147b05 100644 (file)
@@ -2,7 +2,7 @@ import * as Sequelize from 'sequelize'
 import * as Promise from 'bluebird'
 
 // Don't use barrel, import just what we need
-import { Pod as FormatedPod } from '../../../shared/models/pod.model'
+import { Pod as FormatedPod } from '../../../shared/models/pods/pod.model'
 
 export namespace PodMethods {
   export type ToFormatedJSON = (this: PodInstance) => FormatedPod
index f743945f83e798fee385dd4f2690c11d4c3c68cf..9bd3d2ebb24e2d67ded2d3319f8cac5cefab5dc3 100644 (file)
@@ -2,7 +2,8 @@ import * as Sequelize from 'sequelize'
 import * as Promise from 'bluebird'
 
 // Don't use barrel, import just what we need
-import { UserRole, User as FormatedUser } from '../../../shared/models/user.model'
+import { User as FormatedUser } from '../../../shared/models/users/user.model'
+import { UserRole } from '../../../shared/models/users/user-role.type'
 import { ResultList } from '../../../shared/models/result-list.model'
 
 export namespace UserMethods {
index e0b65a13d5c714f5bc3796bc1ab43d18a80c0dc0..f501f08b7630f37c4b870330caf94817ff0795de 100644 (file)
@@ -1,7 +1,7 @@
 import * as Sequelize from 'sequelize'
 import * as Promise from 'bluebird'
 
-import { VideoRateType } from '../../../shared/models/user-video-rate.model'
+import { VideoRateType } from '../../../shared/models/videos/video-rate.type'
 
 export namespace UserVideoRateMethods {
   export type Load = (userId: number, videoId: string, transaction: Sequelize.Transaction) => Promise<UserVideoRateInstance>
index 75647fe0eac8deb58c75c066c10df2081ce361c5..d6724d36f3fe4b16c56cbc2e6fe96c6785817855 100644 (file)
@@ -5,7 +5,7 @@ import { PodInstance } from '../pod'
 import { ResultList } from '../../../shared'
 
 // Don't use barrel, import just what we need
-import { VideoAbuse as FormatedVideoAbuse } from '../../../shared/models/video-abuse.model'
+import { VideoAbuse as FormatedVideoAbuse } from '../../../shared/models/videos/video-abuse.model'
 
 export namespace VideoAbuseMethods {
   export type ToFormatedJSON = (this: VideoAbuseInstance) => FormatedVideoAbuse
index 5ca4238016cda88b7fe4e1e4970c7989093ecd17..47a510231b5183cb83a6b9693ef1f90caec535b0 100644 (file)
@@ -4,7 +4,7 @@ import * as Promise from 'bluebird'
 import { ResultList } from '../../../shared'
 
 // Don't use barrel, import just what we need
-import { BlacklistedVideo as FormatedBlacklistedVideo } from '../../../shared/models/video-blacklist.model'
+import { BlacklistedVideo as FormatedBlacklistedVideo } from '../../../shared/models/videos/video-blacklist.model'
 
 export namespace BlacklistedVideoMethods {
   export type ToFormatedJSON = (this: BlacklistedVideoInstance) => FormatedBlacklistedVideo
index c3e3365d595f280bbfdd893fafcf34e91ee0d97e..b836d6da6e8ed79f7ae4fba73d326a2bb01539db 100644 (file)
@@ -5,7 +5,7 @@ import { AuthorInstance } from './author-interface'
 import { TagAttributes, TagInstance } from './tag-interface'
 
 // Don't use barrel, import just what we need
-import { Video as FormatedVideo } from '../../../shared/models/video.model'
+import { Video as FormatedVideo } from '../../../shared/models/videos/video.model'
 import { ResultList } from '../../../shared/models/result-list.model'
 
 export type FormatedAddRemoteVideo = {
index cd885af89fb316ff041f89377d6e0d022430053b..02665a3e6cb8039b80e0f12c549006bc92779736 100644 (file)
@@ -1,11 +1,8 @@
+export * from './pods'
+export * from './users'
+export * from './videos'
 export * from './job.model'
 export * from './oauth-client-local.model'
-export * from './pod.model'
 export * from './result-list.model'
 export * from './request-scheduler.model'
-export * from './user-video-rate.model'
-export * from './user.model'
-export * from './video-abuse.model'
-export * from './video-blacklist.model'
-export * from './video.model'
 export * from './server-config.model'
diff --git a/shared/models/pods/index.ts b/shared/models/pods/index.ts
new file mode 100644 (file)
index 0000000..f59d015
--- /dev/null
@@ -0,0 +1,3 @@
+export * from './pod-signature.model'
+export * from './pod.model'
+export * from './remote-video'
diff --git a/shared/models/pods/pod-signature.model.ts b/shared/models/pods/pod-signature.model.ts
new file mode 100644 (file)
index 0000000..b7988a4
--- /dev/null
@@ -0,0 +1,4 @@
+export interface PodSignature {
+  host: string
+  signature: string
+}
diff --git a/shared/models/pods/remote-video/index.ts b/shared/models/pods/remote-video/index.ts
new file mode 100644 (file)
index 0000000..c881168
--- /dev/null
@@ -0,0 +1,7 @@
+export * from './remote-qadu-video-request.model'
+export * from './remote-video-event-request.model'
+export * from './remote-video-request.model'
+export * from './remote-video-create-request.model'
+export * from './remote-video-update-request.model'
+export * from './remote-video-remove-request.model'
+export * from './remote-video-report-abuse-request.model'
diff --git a/shared/models/pods/remote-video/remote-qadu-video-request.model.ts b/shared/models/pods/remote-video/remote-qadu-video-request.model.ts
new file mode 100644 (file)
index 0000000..0f84e3f
--- /dev/null
@@ -0,0 +1,10 @@
+export interface RemoteQaduVideoData {
+  remoteId: string
+  views?: number
+  likes?: number
+  dislikes?: number
+}
+
+export interface RemoteQaduVideoRequest {
+  data: RemoteQaduVideoData
+}
diff --git a/shared/models/pods/remote-video/remote-video-create-request.model.ts b/shared/models/pods/remote-video/remote-video-create-request.model.ts
new file mode 100644 (file)
index 0000000..6babb00
--- /dev/null
@@ -0,0 +1,27 @@
+import { RemoteVideoRequest } from './remote-video-request.model'
+
+export interface RemoteVideoCreateData {
+  remoteId: string
+  author: string
+  tags: string[]
+  name: string
+  extname: string
+  infoHash: string
+  category: number
+  licence: number
+  language: number
+  nsfw: boolean
+  description: string
+  duration: number
+  createdAt: Date
+  updatedAt: Date
+  views: number
+  likes: number
+  dislikes: number
+  thumbnailData: string
+}
+
+export interface RemoteVideoCreateRequest extends RemoteVideoRequest {
+  type: 'add'
+  data: RemoteVideoCreateData
+}
diff --git a/shared/models/pods/remote-video/remote-video-event-request.model.ts b/shared/models/pods/remote-video/remote-video-event-request.model.ts
new file mode 100644 (file)
index 0000000..84df1ca
--- /dev/null
@@ -0,0 +1,11 @@
+export type RemoteVideoEventType = 'views' | 'likes' | 'dislikes'
+
+export interface RemoteVideoEventData {
+  remoteId: string
+  eventType: RemoteVideoEventType
+  count: number
+}
+
+export interface RemoteVideoEventRequest {
+  data: RemoteVideoEventData
+}
diff --git a/shared/models/pods/remote-video/remote-video-remove-request.model.ts b/shared/models/pods/remote-video/remote-video-remove-request.model.ts
new file mode 100644 (file)
index 0000000..95ee386
--- /dev/null
@@ -0,0 +1,10 @@
+import { RemoteVideoRequest } from './remote-video-request.model'
+
+export interface RemoteVideoRemoveData {
+  remoteId: string
+}
+
+export interface RemoteVideoRemoveRequest extends RemoteVideoRequest {
+  type: 'remove'
+  data: RemoteVideoRemoveData
+}
diff --git a/shared/models/pods/remote-video/remote-video-report-abuse-request.model.ts b/shared/models/pods/remote-video/remote-video-report-abuse-request.model.ts
new file mode 100644 (file)
index 0000000..9059c92
--- /dev/null
@@ -0,0 +1,12 @@
+import { RemoteVideoRequest } from './remote-video-request.model'
+
+export interface RemoteVideoReportAbuseData {
+  videoRemoteId: string
+  reporterUsername: string
+  reportReason: string
+}
+
+export interface RemoteVideoReportAbuseRequest extends RemoteVideoRequest {
+  type: 'report-abuse'
+  data: RemoteVideoReportAbuseData
+}
diff --git a/shared/models/pods/remote-video/remote-video-request.model.ts b/shared/models/pods/remote-video/remote-video-request.model.ts
new file mode 100644 (file)
index 0000000..e5052a2
--- /dev/null
@@ -0,0 +1,4 @@
+export interface RemoteVideoRequest {
+  type: 'add' | 'update' | 'remove' | 'report-abuse'
+  data: any
+}
diff --git a/shared/models/pods/remote-video/remote-video-update-request.model.ts b/shared/models/pods/remote-video/remote-video-update-request.model.ts
new file mode 100644 (file)
index 0000000..67ddbc1
--- /dev/null
@@ -0,0 +1,23 @@
+export interface RemoteVideoUpdateData {
+  remoteId: string
+  tags: string[]
+  name: string
+  extname: string
+  infoHash: string
+  category: number
+  licence: number
+  language: number
+  nsfw: boolean
+  description: string
+  duration: number
+  createdAt: Date
+  updatedAt: Date
+  views: number
+  likes: number
+  dislikes: number
+}
+
+export interface RemoteVideoUpdateRequest {
+  type: 'update'
+  data: RemoteVideoUpdateData
+}
diff --git a/shared/models/user-video-rate.model.ts b/shared/models/user-video-rate.model.ts
deleted file mode 100644 (file)
index b770f40..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-export type VideoRateType = 'like' | 'dislike'
-export type UserVideoRateType = 'like' | 'dislike' | 'none'
-
-export interface UserVideoRate {
-  videoId: string
-  rating: UserVideoRateType
-}
diff --git a/shared/models/users/index.ts b/shared/models/users/index.ts
new file mode 100644 (file)
index 0000000..414aaab
--- /dev/null
@@ -0,0 +1,4 @@
+export * from './user.model'
+export * from './user-create.model'
+export * from './user-update.model'
+export * from './user-role.type'
diff --git a/shared/models/users/user-create.model.ts b/shared/models/users/user-create.model.ts
new file mode 100644 (file)
index 0000000..2cddcdc
--- /dev/null
@@ -0,0 +1,5 @@
+export interface UserCreate {
+  username: string
+  password: string
+  email: string
+}
diff --git a/shared/models/users/user-role.type.ts b/shared/models/users/user-role.type.ts
new file mode 100644 (file)
index 0000000..b38c4c8
--- /dev/null
@@ -0,0 +1 @@
+export type UserRole = 'admin' | 'user'
diff --git a/shared/models/users/user-update.model.ts b/shared/models/users/user-update.model.ts
new file mode 100644 (file)
index 0000000..8b9abfb
--- /dev/null
@@ -0,0 +1,4 @@
+export interface UserUpdate {
+  displayNSFW?: boolean
+  password?: string
+}
similarity index 75%
rename from shared/models/user.model.ts
rename to shared/models/users/user.model.ts
index 92dc73ec2a2fb35f5c3f38e43013aefbdf6fdfcd..5c48a17b28c48ad373f22e16c901bad56a3d90d3 100644 (file)
@@ -1,4 +1,4 @@
-export type UserRole = 'admin' | 'user'
+import { UserRole } from './user-role.type'
 
 export interface User {
   id: number
diff --git a/shared/models/videos/index.ts b/shared/models/videos/index.ts
new file mode 100644 (file)
index 0000000..64d1676
--- /dev/null
@@ -0,0 +1,10 @@
+export * from './user-video-rate-update.model'
+export * from './user-video-rate.model'
+export * from './user-video-rate.type'
+export * from './video-abuse-create.model'
+export * from './video-abuse.model'
+export * from './video-blacklist.model'
+export * from './video-create.model'
+export * from './video-rate.type'
+export * from './video-update.model'
+export * from './video.model'
diff --git a/shared/models/videos/user-video-rate-update.model.ts b/shared/models/videos/user-video-rate-update.model.ts
new file mode 100644 (file)
index 0000000..85e8927
--- /dev/null
@@ -0,0 +1,5 @@
+import { UserVideoRateType } from './user-video-rate.type'
+
+export interface UserVideoRateUpdate {
+  rating: UserVideoRateType
+}
diff --git a/shared/models/videos/user-video-rate.model.ts b/shared/models/videos/user-video-rate.model.ts
new file mode 100644 (file)
index 0000000..4b9c574
--- /dev/null
@@ -0,0 +1,6 @@
+import { UserVideoRateType } from './user-video-rate.type'
+
+export interface UserVideoRate {
+  videoId: string
+  rating: UserVideoRateType
+}
diff --git a/shared/models/videos/user-video-rate.type.ts b/shared/models/videos/user-video-rate.type.ts
new file mode 100644 (file)
index 0000000..a4d9c7e
--- /dev/null
@@ -0,0 +1 @@
+export type UserVideoRateType = 'like' | 'dislike' | 'none'
diff --git a/shared/models/videos/video-abuse-create.model.ts b/shared/models/videos/video-abuse-create.model.ts
new file mode 100644 (file)
index 0000000..db64582
--- /dev/null
@@ -0,0 +1,3 @@
+export interface VideoAbuseCreate {
+  reason: string
+}
diff --git a/shared/models/videos/video-create.model.ts b/shared/models/videos/video-create.model.ts
new file mode 100644 (file)
index 0000000..5c0b498
--- /dev/null
@@ -0,0 +1,9 @@
+export interface VideoCreate {
+  category: number
+  licence: number
+  language: number
+  description: string
+  nsfw: boolean
+  name: string
+  tags: string[]
+}
diff --git a/shared/models/videos/video-rate.type.ts b/shared/models/videos/video-rate.type.ts
new file mode 100644 (file)
index 0000000..d48774a
--- /dev/null
@@ -0,0 +1 @@
+export type VideoRateType = 'like' | 'dislike'
diff --git a/shared/models/videos/video-update.model.ts b/shared/models/videos/video-update.model.ts
new file mode 100644 (file)
index 0000000..29a8262
--- /dev/null
@@ -0,0 +1,9 @@
+export interface VideoUpdate {
+  name?: string
+  category?: number
+  licence?: number
+  language?: number
+  description?: string
+  tags?: string[]
+  nsfw?: boolean
+}