From 608624252466acf9f1d9ee1c1170bd4fe4d18d18 Mon Sep 17 00:00:00 2001
From: Chocobozzz <florian.bigard@gmail.com>
Date: Wed, 15 Nov 2017 11:00:25 +0100
Subject: Rename Pod -> Server

---
 server/controllers/api/application/follows.ts | 127 --------------------------
 server/controllers/api/application/index.ts   |  12 ---
 server/controllers/api/index.ts               |   2 +-
 server/controllers/api/server/follows.ts      | 127 ++++++++++++++++++++++++++
 server/controllers/api/server/index.ts        |  12 +++
 server/controllers/api/videos/abuse.ts        |   6 +-
 server/controllers/api/videos/index.ts        |   6 +-
 server/controllers/api/videos/rate.ts         |   2 +-
 8 files changed, 147 insertions(+), 147 deletions(-)
 delete mode 100644 server/controllers/api/application/follows.ts
 delete mode 100644 server/controllers/api/application/index.ts
 create mode 100644 server/controllers/api/server/follows.ts
 create mode 100644 server/controllers/api/server/index.ts

(limited to 'server/controllers/api')

diff --git a/server/controllers/api/application/follows.ts b/server/controllers/api/application/follows.ts
deleted file mode 100644
index 000bbd23e..000000000
--- a/server/controllers/api/application/follows.ts
+++ /dev/null
@@ -1,127 +0,0 @@
-import * as express from 'express'
-import { UserRight } from '../../../../shared/models/users/user-right.enum'
-import { getFormattedObjects } from '../../../helpers'
-import { logger } from '../../../helpers/logger'
-import { getApplicationAccount } from '../../../helpers/utils'
-import { getAccountFromWebfinger } from '../../../helpers/webfinger'
-import { SERVER_ACCOUNT_NAME } from '../../../initializers/constants'
-import { database as db } from '../../../initializers/database'
-import { sendFollow } from '../../../lib/activitypub/send-request'
-import { asyncMiddleware, paginationValidator, setFollowersSort, setPagination } from '../../../middlewares'
-import { authenticate } from '../../../middlewares/oauth'
-import { setBodyHostsPort } from '../../../middlewares/pods'
-import { setFollowingSort } from '../../../middlewares/sort'
-import { ensureUserHasRight } from '../../../middlewares/user-right'
-import { followValidator } from '../../../middlewares/validators/pods'
-import { followersSortValidator, followingSortValidator } from '../../../middlewares/validators/sort'
-
-const applicationFollowsRouter = express.Router()
-
-applicationFollowsRouter.get('/following',
-  paginationValidator,
-  followingSortValidator,
-  setFollowingSort,
-  setPagination,
-  asyncMiddleware(listFollowing)
-)
-
-applicationFollowsRouter.post('/follow',
-  authenticate,
-  ensureUserHasRight(UserRight.MANAGE_APPLICATION_FOLLOW),
-  followValidator,
-  setBodyHostsPort,
-  asyncMiddleware(follow)
-)
-
-applicationFollowsRouter.get('/followers',
-  paginationValidator,
-  followersSortValidator,
-  setFollowersSort,
-  setPagination,
-  asyncMiddleware(listFollowers)
-)
-
-// ---------------------------------------------------------------------------
-
-export {
-  applicationFollowsRouter
-}
-
-// ---------------------------------------------------------------------------
-
-async function listFollowing (req: express.Request, res: express.Response, next: express.NextFunction) {
-  const applicationAccount = await getApplicationAccount()
-  const resultList = await db.AccountFollow.listFollowingForApi(applicationAccount.id, req.query.start, req.query.count, req.query.sort)
-
-  return res.json(getFormattedObjects(resultList.data, resultList.total))
-}
-
-async function listFollowers (req: express.Request, res: express.Response, next: express.NextFunction) {
-  const applicationAccount = await getApplicationAccount()
-  const resultList = await db.AccountFollow.listFollowersForApi(applicationAccount.id, req.query.start, req.query.count, req.query.sort)
-
-  return res.json(getFormattedObjects(resultList.data, resultList.total))
-}
-
-async function follow (req: express.Request, res: express.Response, next: express.NextFunction) {
-  const hosts = req.body.hosts as string[]
-  const fromAccount = await getApplicationAccount()
-
-  const tasks: Promise<any>[] = []
-  const accountName = SERVER_ACCOUNT_NAME
-
-  for (const host of hosts) {
-
-    // We process each host in a specific transaction
-    // First, we add the follow request in the database
-    // Then we send the follow request to other account
-    const p = loadLocalOrGetAccountFromWebfinger(accountName, host)
-      .then(accountResult => {
-        let targetAccount = accountResult.account
-
-        return db.sequelize.transaction(async t => {
-          if (accountResult.loadedFromDB === false) {
-            targetAccount = await targetAccount.save({ transaction: t })
-          }
-
-          const [ accountFollow ] = await db.AccountFollow.findOrCreate({
-            where: {
-              accountId: fromAccount.id,
-              targetAccountId: targetAccount.id
-            },
-            defaults: {
-              state: 'pending',
-              accountId: fromAccount.id,
-              targetAccountId: targetAccount.id
-            },
-            transaction: t
-          })
-
-          // Send a notification to remote server
-          if (accountFollow.state === 'pending') {
-            await sendFollow(fromAccount, targetAccount, t)
-          }
-        })
-      })
-      .catch(err => logger.warn('Cannot follow server %s.', `${accountName}@${host}`, err))
-
-    tasks.push(p)
-  }
-
-  await Promise.all(tasks)
-
-  return res.status(204).end()
-}
-
-async function loadLocalOrGetAccountFromWebfinger (name: string, host: string) {
-  let loadedFromDB = true
-  let account = await db.Account.loadByNameAndHost(name, host)
-
-  if (!account) {
-    const nameWithDomain = name + '@' + host
-    account = await getAccountFromWebfinger(nameWithDomain)
-    loadedFromDB = false
-  }
-
-  return { account, loadedFromDB }
-}
diff --git a/server/controllers/api/application/index.ts b/server/controllers/api/application/index.ts
deleted file mode 100644
index 011b971ed..000000000
--- a/server/controllers/api/application/index.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-import * as express from 'express'
-import { applicationFollowsRouter } from './follows'
-
-const applicationRouter = express.Router()
-
-applicationRouter.use('/', applicationFollowsRouter)
-
-// ---------------------------------------------------------------------------
-
-export {
-  applicationRouter
-}
diff --git a/server/controllers/api/index.ts b/server/controllers/api/index.ts
index a22c78cce..876c911c7 100644
--- a/server/controllers/api/index.ts
+++ b/server/controllers/api/index.ts
@@ -4,7 +4,7 @@ import { badRequest } from '../../helpers'
 
 import { oauthClientsRouter } from './oauth-clients'
 import { configRouter } from './config'
-import { applicationRouter } from './application'
+import { applicationRouter } from './server'
 import { usersRouter } from './users'
 import { videosRouter } from './videos'
 
diff --git a/server/controllers/api/server/follows.ts b/server/controllers/api/server/follows.ts
new file mode 100644
index 000000000..c9775ad21
--- /dev/null
+++ b/server/controllers/api/server/follows.ts
@@ -0,0 +1,127 @@
+import * as express from 'express'
+import { UserRight } from '../../../../shared/models/users/user-right.enum'
+import { getFormattedObjects } from '../../../helpers'
+import { logger } from '../../../helpers/logger'
+import { getApplicationAccount } from '../../../helpers/utils'
+import { getAccountFromWebfinger } from '../../../helpers/webfinger'
+import { SERVER_ACCOUNT_NAME } from '../../../initializers/constants'
+import { database as db } from '../../../initializers/database'
+import { sendFollow } from '../../../lib/activitypub/send-request'
+import { asyncMiddleware, paginationValidator, setFollowersSort, setPagination } from '../../../middlewares'
+import { authenticate } from '../../../middlewares/oauth'
+import { setBodyHostsPort } from '../../../middlewares/servers'
+import { setFollowingSort } from '../../../middlewares/sort'
+import { ensureUserHasRight } from '../../../middlewares/user-right'
+import { followValidator } from '../../../middlewares/validators/servers'
+import { followersSortValidator, followingSortValidator } from '../../../middlewares/validators/sort'
+
+const applicationFollowsRouter = express.Router()
+
+applicationFollowsRouter.get('/following',
+  paginationValidator,
+  followingSortValidator,
+  setFollowingSort,
+  setPagination,
+  asyncMiddleware(listFollowing)
+)
+
+applicationFollowsRouter.post('/follow',
+  authenticate,
+  ensureUserHasRight(UserRight.MANAGE_APPLICATION_FOLLOW),
+  followValidator,
+  setBodyHostsPort,
+  asyncMiddleware(follow)
+)
+
+applicationFollowsRouter.get('/followers',
+  paginationValidator,
+  followersSortValidator,
+  setFollowersSort,
+  setPagination,
+  asyncMiddleware(listFollowers)
+)
+
+// ---------------------------------------------------------------------------
+
+export {
+  applicationFollowsRouter
+}
+
+// ---------------------------------------------------------------------------
+
+async function listFollowing (req: express.Request, res: express.Response, next: express.NextFunction) {
+  const applicationAccount = await getApplicationAccount()
+  const resultList = await db.AccountFollow.listFollowingForApi(applicationAccount.id, req.query.start, req.query.count, req.query.sort)
+
+  return res.json(getFormattedObjects(resultList.data, resultList.total))
+}
+
+async function listFollowers (req: express.Request, res: express.Response, next: express.NextFunction) {
+  const applicationAccount = await getApplicationAccount()
+  const resultList = await db.AccountFollow.listFollowersForApi(applicationAccount.id, req.query.start, req.query.count, req.query.sort)
+
+  return res.json(getFormattedObjects(resultList.data, resultList.total))
+}
+
+async function follow (req: express.Request, res: express.Response, next: express.NextFunction) {
+  const hosts = req.body.hosts as string[]
+  const fromAccount = await getApplicationAccount()
+
+  const tasks: Promise<any>[] = []
+  const accountName = SERVER_ACCOUNT_NAME
+
+  for (const host of hosts) {
+
+    // We process each host in a specific transaction
+    // First, we add the follow request in the database
+    // Then we send the follow request to other account
+    const p = loadLocalOrGetAccountFromWebfinger(accountName, host)
+      .then(accountResult => {
+        let targetAccount = accountResult.account
+
+        return db.sequelize.transaction(async t => {
+          if (accountResult.loadedFromDB === false) {
+            targetAccount = await targetAccount.save({ transaction: t })
+          }
+
+          const [ accountFollow ] = await db.AccountFollow.findOrCreate({
+            where: {
+              accountId: fromAccount.id,
+              targetAccountId: targetAccount.id
+            },
+            defaults: {
+              state: 'pending',
+              accountId: fromAccount.id,
+              targetAccountId: targetAccount.id
+            },
+            transaction: t
+          })
+
+          // Send a notification to remote server
+          if (accountFollow.state === 'pending') {
+            await sendFollow(fromAccount, targetAccount, t)
+          }
+        })
+      })
+      .catch(err => logger.warn('Cannot follow server %s.', `${accountName}@${host}`, err))
+
+    tasks.push(p)
+  }
+
+  await Promise.all(tasks)
+
+  return res.status(204).end()
+}
+
+async function loadLocalOrGetAccountFromWebfinger (name: string, host: string) {
+  let loadedFromDB = true
+  let account = await db.Account.loadByNameAndHost(name, host)
+
+  if (!account) {
+    const nameWithDomain = name + '@' + host
+    account = await getAccountFromWebfinger(nameWithDomain)
+    loadedFromDB = false
+  }
+
+  return { account, loadedFromDB }
+}
diff --git a/server/controllers/api/server/index.ts b/server/controllers/api/server/index.ts
new file mode 100644
index 000000000..011b971ed
--- /dev/null
+++ b/server/controllers/api/server/index.ts
@@ -0,0 +1,12 @@
+import * as express from 'express'
+import { applicationFollowsRouter } from './follows'
+
+const applicationRouter = express.Router()
+
+applicationRouter.use('/', applicationFollowsRouter)
+
+// ---------------------------------------------------------------------------
+
+export {
+  applicationRouter
+}
diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts
index 7a3471116..29f901f60 100644
--- a/server/controllers/api/videos/abuse.ts
+++ b/server/controllers/api/videos/abuse.ts
@@ -70,12 +70,12 @@ async function reportVideoAbuse (req: express.Request, res: express.Response) {
     reporterUsername,
     reason: body.reason,
     videoId: videoInstance.id,
-    reporterPodId: null // This is our pod that reported this abuse
+    reporterServerId: null // This is our server that reported this abuse
   }
 
   await db.sequelize.transaction(async t => {
     const abuse = await db.VideoAbuse.create(abuseToCreate, { transaction: t })
-    // We send the information to the destination pod
+    // We send the information to the destination server
     if (videoInstance.isOwned() === false) {
       const reportData = {
         reporterUsername,
@@ -84,7 +84,7 @@ async function reportVideoAbuse (req: express.Request, res: express.Response) {
       }
 
       // await friends.reportAbuseVideoToFriend(reportData, videoInstance, t)
-      // TODO: send abuse to origin pod
+      // TODO: send abuse to origin server
     }
   })
 
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 063839223..ebc07e179 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -233,7 +233,7 @@ async function addVideo (req: express.Request, res: express.Response, videoPhysi
 
     // Let transcoding job send the video to friends because the video file extension might change
     if (CONFIG.TRANSCODING.ENABLED === true) return undefined
-    // Don't send video to remote pods, it is private
+    // Don't send video to remote servers, it is private
     if (video.privacy === VideoPrivacy.PRIVATE) return undefined
 
     await sendAddVideo(video, t)
@@ -287,7 +287,7 @@ async function updateVideo (req: express.Request, res: express.Response) {
         await sendUpdateVideoChannel(videoInstance, t)
       }
 
-      // Video is not private anymore, send a create action to remote pods
+      // Video is not private anymore, send a create action to remote servers
       if (wasPrivateVideo === true && videoInstance.privacy !== VideoPrivacy.PRIVATE) {
         await sendAddVideo(videoInstance, t)
       }
@@ -365,7 +365,7 @@ async function removeVideo (req: express.Request, res: express.Response) {
 }
 
 async function searchVideos (req: express.Request, res: express.Response, next: express.NextFunction) {
-  const resultList = await db.Video.searchAndPopulateAccountAndPodAndTags(
+  const resultList = await db.Video.searchAndPopulateAccountAndServerAndTags(
     req.params.value,
     req.query.field,
     req.query.start,
diff --git a/server/controllers/api/videos/rate.ts b/server/controllers/api/videos/rate.ts
index 955277d25..8216dffd2 100644
--- a/server/controllers/api/videos/rate.ts
+++ b/server/controllers/api/videos/rate.ts
@@ -83,7 +83,7 @@ async function rateVideo (req: express.Request, res: express.Response) {
     await videoInstance.increment(incrementQuery, sequelizeOptions)
 
     if (videoInstance.isOwned() === false) {
-      // TODO: Send a event to original pod
+      // TODO: Send a event to original server
     } else {
       // TODO: Send update to followers
     }
-- 
cgit v1.2.3