Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Add email to pods

Chocobozzz4793c343fd3c
diff --git a/client/src/app/+admin/friends/friend-list/friend-list.component.ts b/client/src/app/+admin/friends/friend-list/friend-list.component.ts
index 9783adf16a..525a9fbc38 100644
--- a/client/src/app/+admin/friends/friend-list/friend-list.component.ts
+++ b/client/src/app/+admin/friends/friend-list/friend-list.component.ts
@@ -35,6 +35,10 @@ export class FriendListComponent {
title: 'Host',
sort: false
},
+ email: {
+ title: 'Email',
+ sort: false
+ },
score: {
title: 'Score',
sort: false
diff --git a/client/src/app/+admin/friends/shared/friend.model.ts b/client/src/app/+admin/friends/shared/friend.model.ts
index 462cc82ed7..f72156d05b 100644
--- a/client/src/app/+admin/friends/shared/friend.model.ts
+++ b/client/src/app/+admin/friends/shared/friend.model.ts
@@ -2,5 +2,6 @@ export interface Friend {
id: string;
host: string;
score: number;
+ email: string;
createdAt: Date;
}
diff --git a/config/default.yaml b/config/default.yaml
index ad87191fd7..172bbef1e3 100644
--- a/config/default.yaml
+++ b/config/default.yaml
@@ -22,3 +22,6 @@ storage:
previews: 'previews/'
thumbnails: 'thumbnails/'
torrents: 'torrents/'
+
+admin:
diff --git a/config/production.yaml.example b/config/production.yaml.example
index ba7ff8f2e1..cbfb0f46ce 100644
--- a/config/production.yaml.example
+++ b/config/production.yaml.example
@@ -23,3 +23,6 @@ storage:
previews: 'previews/'
thumbnails: 'thumbnails/'
torrents: 'torrents/'
+
+admin:
diff --git a/config/test-1.yaml b/config/test-1.yaml
index b2a0a5422c..dbe408a8cb 100644
--- a/config/test-1.yaml
+++ b/config/test-1.yaml
@@ -15,3 +15,6 @@ storage:
logs: 'test1/logs/'
thumbnails: 'test1/thumbnails/'
torrents: 'test1/torrents/'
+
+admin:
diff --git a/config/test-2.yaml b/config/test-2.yaml
index 7285f33943..13e09ff4ca 100644
--- a/config/test-2.yaml
+++ b/config/test-2.yaml
@@ -15,3 +15,6 @@ storage:
logs: 'test2/logs/'
thumbnails: 'test2/thumbnails/'
torrents: 'test2/torrents/'
+
+admin:
diff --git a/config/test-3.yaml b/config/test-3.yaml
index 138a2cd53d..2eb9846928 100644
--- a/config/test-3.yaml
+++ b/config/test-3.yaml
@@ -15,3 +15,6 @@ storage:
logs: 'test3/logs/'
thumbnails: 'test3/thumbnails/'
torrents: 'test3/torrents/'
+
+admin:
diff --git a/config/test-4.yaml b/config/test-4.yaml
index 7425f4af7e..a0a9bde21e 100644
--- a/config/test-4.yaml
+++ b/config/test-4.yaml
@@ -15,3 +15,6 @@ storage:
logs: 'test4/logs/'
thumbnails: 'test4/thumbnails/'
torrents: 'test4/torrents/'
+
+admin:
diff --git a/config/test-5.yaml b/config/test-5.yaml
index 1bf0de6582..af8654e140 100644
--- a/config/test-5.yaml
+++ b/config/test-5.yaml
@@ -15,3 +15,6 @@ storage:
logs: 'test5/logs/'
thumbnails: 'test5/thumbnails/'
torrents: 'test5/torrents/'
+
+admin:
diff --git a/config/test-6.yaml b/config/test-6.yaml
index 7303a08fc6..d74d3b0521 100644
--- a/config/test-6.yaml
+++ b/config/test-6.yaml
@@ -15,3 +15,6 @@ storage:
logs: 'test6/logs/'
thumbnails: 'test6/thumbnails/'
torrents: 'test6/torrents/'
+
+admin:
diff --git a/server/controllers/api/pods.js b/server/controllers/api/pods.js
index da991f8d97..1c3eefcc13 100644
--- a/server/controllers/api/pods.js
+++ b/server/controllers/api/pods.js
@@ -4,6 +4,7 @@ const express = require('express')
const waterfall = require('async/waterfall')
const db = require('../../initializers/database')
+const constants = require('../../initializers/constants')
const logger = require('../../helpers/logger')
const peertubeCrypto = require('../../helpers/peertube-crypto')
const utils = require('../../helpers/utils')
@@ -80,7 +81,7 @@ function addPods (req, res, next) {
], function (err, cert) {
if (err) return next(err)
- return res.json({ cert: cert })
+ return res.json({ cert: cert, email: constants.CONFIG.ADMIN.EMAIL })
})
}
diff --git a/server/initializers/checker.js b/server/initializers/checker.js
index 6471bb4f11..7adbbb37a2 100644
--- a/server/initializers/checker.js
+++ b/server/initializers/checker.js
@@ -28,7 +28,8 @@ function checkMissedConfig () {
const required = [ 'listen.port',
'webserver.https', 'webserver.hostname', 'webserver.port',
'database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password',
- 'storage.certs', 'storage.videos', 'storage.logs', 'storage.thumbnails', 'storage.previews'
+ 'storage.certs', 'storage.videos', 'storage.logs', 'storage.thumbnails', 'storage.previews',
+ 'admin.email'
]
const miss = []
diff --git a/server/initializers/constants.js b/server/initializers/constants.js
index ad7cf4f4da..eb0509efe8 100644
--- a/server/initializers/constants.js
+++ b/server/initializers/constants.js
@@ -54,6 +54,9 @@ const CONFIG = {
WS: config.get('webserver.https') === true ? 'wss' : 'ws',
HOSTNAME: config.get('webserver.hostname'),
PORT: config.get('webserver.port')
+ },
+ ADMIN: {
+ EMAIL: config.get('admin.email')
}
}
CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
@@ -92,7 +95,7 @@ const FRIEND_SCORE = {
// ---------------------------------------------------------------------------
-const LAST_MIGRATION_VERSION = 0
+const LAST_MIGRATION_VERSION = 5
// ---------------------------------------------------------------------------
diff --git a/server/initializers/migrations/0005-email-pod.js b/server/initializers/migrations/0005-email-pod.js
new file mode 100644
index 0000000000..d90b674a13
--- /dev/null
+++ b/server/initializers/migrations/0005-email-pod.js
@@ -0,0 +1,20 @@
+/*
+ This is just an example.
+*/
+
+// utils = { transaction, queryInterface }
+exports.up = function (utils, callback) {
+ const q = utils.queryInterface
+ const Sequelize = utils.Sequelize
+
+ const data = {
+ type: Sequelize.STRING(400),
+ allowNull: false
+ }
+
+ q.addColumn('Pods', 'email', data, { transaction: utils.transaction }).asCallback(callback)
+}
+
+exports.down = function (options, callback) {
+ throw new Error('Not implemented.')
+}
diff --git a/server/initializers/migrations/0005-example.js b/server/initializers/migrations/0005-example.js
deleted file mode 100644
index cedc429196..0000000000
--- a/server/initializers/migrations/0005-example.js
+++ /dev/null
@@ -1,14 +0,0 @@
-// /*
-// This is just an example.
-// */
-
-// const db = require('../database')
-
-// // options contains the transaction
-// exports.up = function (options, callback) {
-// db.Application.create({ migrationVersion: 42 }, { transaction: options.transaction }).asCallback(callback)
-// }
-
-// exports.down = function (options, callback) {
-// throw new Error('Not implemented.')
-// }
diff --git a/server/initializers/migrator.js b/server/initializers/migrator.js
index e5288b6158..233ee2bddf 100644
--- a/server/initializers/migrator.js
+++ b/server/initializers/migrator.js
@@ -64,7 +64,7 @@ function getMigrationScripts (callback) {
}
function executeMigration (actualVersion, entity, callback) {
- const versionScript = entity.version
+ const versionScript = parseInt(entity.version)
// Do not execute old migration scripts
if (versionScript <= actualVersion) return callback(null)
@@ -78,7 +78,12 @@ function executeMigration (actualVersion, entity, callback) {
db.sequelize.transaction().asCallback(function (err, t) {
if (err) return callback(err)
- migrationScript.up({ transaction: t }, function (err) {
+ const options = {
+ transaction: t,
+ queryInterface: db.sequelize.getQueryInterface(),
+ Sequelize: db.Sequelize
+ }
+ migrationScript.up(options, function (err) {
if (err) {
t.rollback()
return callback(err)
diff --git a/server/lib/friends.js b/server/lib/friends.js
index 2ea837c999..9b38693c70 100644
--- a/server/lib/friends.js
+++ b/server/lib/friends.js
@@ -245,6 +245,7 @@ function makeRequestsToWinningPods (cert, podsList, callback) {
method: 'POST',
json: {
host: constants.CONFIG.WEBSERVER.HOST,
+ email: constants.CONFIG.ADMIN.EMAIL,
publicKey: cert
}
}
@@ -257,7 +258,7 @@ function makeRequestsToWinningPods (cert, podsList, callback) {
}
if (res.statusCode === 200) {
- const podObj = db.Pod.build({ host: pod.host, publicKey: body.cert })
+ const podObj = db.Pod.build({ host: pod.host, publicKey: body.cert, email: body.email })
podObj.save().asCallback(function (err, podCreated) {
if (err) {
logger.error('Cannot add friend %s pod.', pod.host, { error: err })
diff --git a/server/middlewares/validators/pods.js b/server/middlewares/validators/pods.js
index b9b30e7a1b..0bf4b18446 100644
--- a/server/middlewares/validators/pods.js
+++ b/server/middlewares/validators/pods.js
@@ -40,7 +40,8 @@ function makeFriends (req, res, next) {
}
function podsAdd (req, res, next) {
- req.checkBody('host', 'Should have an host').isHostValid()
+ req.checkBody('host', 'Should have a host').isHostValid()
+ req.checkBody('email', 'Should have an email').isEmail()
req.checkBody('publicKey', 'Should have a public key').notEmpty()
logger.debug('Checking podsAdd parameters', { parameters: req.body })
diff --git a/server/models/pod.js b/server/models/pod.js
index b3c6db8e88..6ae4b0999e 100644
--- a/server/models/pod.js
+++ b/server/models/pod.js
@@ -32,6 +32,10 @@ module.exports = function (sequelize, DataTypes) {
isInt: true,
max: constants.FRIEND_SCORE.MAX
}
+ },
+ email: {
+ type: DataTypes.STRING(400),
+ allowNull: false
}
},
{
@@ -71,6 +75,7 @@ function toFormatedJSON () {
const json = {
id: this.id,
host: this.host,
+ email: this.email,
score: this.score,
createdAt: this.createdAt
}
diff --git a/server/tests/api/friends-basic.js b/server/tests/api/friends-basic.js
index 6f37ff2910..62c40df7b9 100644
--- a/server/tests/api/friends-basic.js
+++ b/server/tests/api/friends-basic.js
@@ -96,6 +96,7 @@ describe('Test basic friends', function () {
const pod = result[0]
expect(pod.host).to.equal(servers[2].host)
+ expect(pod.email).to.equal('[email protected]')
expect(pod.score).to.equal(20)
expect(miscsUtils.dateIsValid(pod.createdAt)).to.be.true
@@ -113,6 +114,7 @@ describe('Test basic friends', function () {
const pod = result[0]
expect(pod.host).to.equal(servers[1].host)
+ expect(pod.email).to.equal('[email protected]')
expect(pod.score).to.equal(20)
expect(miscsUtils.dateIsValid(pod.createdAt)).to.be.true