<div *ngIf="error" class="alert alert-danger">{{ error }}</div>
<form (ngSubmit)="makeFriends()" [formGroup]="form">
- <div class="form-group" *ngFor="let url of urls; let id = index; trackBy:customTrackBy">
- <label for="username">Url</label>
+ <div class="form-group" *ngFor="let host of hosts; let id = index; trackBy:customTrackBy">
+ <label for="username">Host</label>
<div class="input-group">
<input
- type="text" class="form-control" placeholder="http://domain.com"
- [id]="'url-' + id" [formControlName]="'url-' + id"
+ type="text" class="form-control" placeholder="domain.tld"
+ [id]="'host-' + id" [formControlName]="'host-' + id"
/>
<span class="input-group-btn">
<button *ngIf="displayAddField(id)" (click)="addField()" class="btn btn-default" type="button">+</button>
</span>
</div>
- <div [hidden]="form.controls['url-' + id].valid || form.controls['url-' + id].pristine" class="alert alert-warning">
- It should be a valid url.
+ <div [hidden]="form.controls['host-' + id].valid || form.controls['host-' + id].pristine" class="alert alert-warning">
+ It should be a valid host.
</div>
</div>
import { FormControl, FormGroup } from '@angular/forms';
import { Router } from '@angular/router';
-import { validateUrl } from '../../../shared';
+import { validateHost } from '../../../shared';
import { FriendService } from '../shared';
@Component({
})
export class FriendAddComponent implements OnInit {
form: FormGroup;
- urls = [ ];
+ hosts = [ ];
error: string = null;
constructor(private router: Router, private friendService: FriendService) {}
}
addField() {
- this.form.addControl(`url-${this.urls.length}`, new FormControl('', [ validateUrl ]));
- this.urls.push('');
+ this.form.addControl(`host-${this.hosts.length}`, new FormControl('', [ validateHost ]));
+ this.hosts.push('');
}
customTrackBy(index: number, obj: any): any {
}
displayAddField(index: number) {
- return index === (this.urls.length - 1);
+ return index === (this.hosts.length - 1);
}
displayRemoveField(index: number) {
- return (index !== 0 || this.urls.length > 1) && index !== (this.urls.length - 1);
+ return (index !== 0 || this.hosts.length > 1) && index !== (this.hosts.length - 1);
}
isFormValid() {
// Do not check the last input
- for (let i = 0; i < this.urls.length - 1; i++) {
- if (!this.form.controls[`url-${i}`].valid) return false;
+ for (let i = 0; i < this.hosts.length - 1; i++) {
+ if (!this.form.controls[`host-${i}`].valid) return false;
}
- const lastIndex = this.urls.length - 1;
+ const lastIndex = this.hosts.length - 1;
// If the last input (which is not the first) is empty, it's ok
- if (this.urls[lastIndex] === '' && lastIndex !== 0) {
+ if (this.hosts[lastIndex] === '' && lastIndex !== 0) {
return true;
} else {
- return this.form.controls[`url-${lastIndex}`].valid;
+ return this.form.controls[`host-${lastIndex}`].valid;
}
}
removeField(index: number) {
// Remove the last control
- this.form.removeControl(`url-${this.urls.length - 1}`);
- this.urls.splice(index, 1);
+ this.form.removeControl(`host-${this.hosts.length - 1}`);
+ this.hosts.splice(index, 1);
}
makeFriends() {
this.error = '';
- const notEmptyUrls = this.getNotEmptyUrls();
- if (notEmptyUrls.length === 0) {
- this.error = 'You need to specify at less 1 url.';
+ const notEmptyHosts = this.getNotEmptyHosts();
+ if (notEmptyHosts.length === 0) {
+ this.error = 'You need to specify at least 1 host.';
return;
}
- if (!this.isUrlsUnique(notEmptyUrls)) {
- this.error = 'Urls need to be unique.';
+ if (!this.isHostsUnique(notEmptyHosts)) {
+ this.error = 'Hosts need to be unique.';
return;
}
- const confirmMessage = 'Are you sure to make friends with:\n - ' + notEmptyUrls.join('\n - ');
+ const confirmMessage = 'Are you sure to make friends with:\n - ' + notEmptyHosts.join('\n - ');
if (!confirm(confirmMessage)) return;
- this.friendService.makeFriends(notEmptyUrls).subscribe(
+ this.friendService.makeFriends(notEmptyHosts).subscribe(
status => {
// TODO: extractdatastatus
// if (status === 409) {
);
}
- private getNotEmptyUrls() {
- const notEmptyUrls = [];
+ private getNotEmptyHosts() {
+ const notEmptyHosts = [];
- Object.keys(this.form.value).forEach((urlKey) => {
- const url = this.form.value[urlKey];
- if (url !== '') notEmptyUrls.push(url);
+ Object.keys(this.form.value).forEach((hostKey) => {
+ const host = this.form.value[hostKey];
+ if (host !== '') notEmptyHosts.push(host);
});
- return notEmptyUrls;
+ return notEmptyHosts;
}
- private isUrlsUnique(urls: string[]) {
- return urls.every(url => urls.indexOf(url) === urls.lastIndexOf(url));
+ private isHostsUnique(hosts: string[]) {
+ return hosts.every(host => hosts.indexOf(host) === hosts.lastIndexOf(host));
}
}
<thead>
<tr>
<th class="table-column-id">ID</th>
- <th>Url</th>
+ <th>Host</th>
<th>Score</th>
<th>Created Date</th>
</tr>
<tbody>
<tr *ngFor="let friend of friends">
<td>{{ friend.id }}</td>
- <td>{{ friend.url }}</td>
+ <td>{{ friend.host }}</td>
<td>{{ friend.score }}</td>
<td>{{ friend.createdDate | date: 'medium' }}</td>
</tr>
export interface Friend {
id: string;
- url: string;
+ host: string;
score: number;
createdDate: Date;
}
.catch((res) => this.restExtractor.handleError(res));
}
- makeFriends(notEmptyUrls) {
+ makeFriends(notEmptyHosts) {
const body = {
- urls: notEmptyUrls
+ hosts: notEmptyHosts
};
return this.authHttp.post(FriendService.BASE_FRIEND_URL + 'makefriends', body)
--- /dev/null
+import { FormControl } from '@angular/forms';
+
+export function validateHost(c: FormControl) {
+ let HOST_REGEXP = new RegExp('^(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)$');
+
+ return HOST_REGEXP.test(c.value) ? null : {
+ validateHost: {
+ valid: false
+ }
+ };
+}
-export * from './url.validator';
+export * from './host.validator';
export * from './user';
export * from './video';
+++ /dev/null
-import { FormControl } from '@angular/forms';
-
-export function validateUrl(c: FormControl) {
- let URL_REGEXP = new RegExp('^https?://(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)$');
-
- return URL_REGEXP.test(c.value) ? null : {
- validateUrl: {
- valid: false
- }
- };
-}
isLocal: boolean;
magnetUri: string;
name: string;
- podUrl: string;
+ podHost: string;
tags: string[];
thumbnailPath: string;
- private static createByString(author: string, podUrl: string) {
- let [ host, port ] = podUrl.replace(/^https?:\/\//, '').split(':');
-
- if (port === '80' || port === '443') {
- port = '';
- } else {
- port = ':' + port;
- }
-
-
- return author + '@' + host + port;
+ private static createByString(author: string, podHost: string) {
+ return author + '@' + podHost;
}
private static createDurationString(duration: number) {
isLocal: boolean,
magnetUri: string,
name: string,
- podUrl: string,
+ podHost: string,
tags: string[],
thumbnailPath: string
}) {
this.isLocal = hash.isLocal;
this.magnetUri = hash.magnetUri;
this.name = hash.name;
- this.podUrl = hash.podUrl;
+ this.podHost = hash.podHost;
this.tags = hash.tags;
this.thumbnailPath = hash.thumbnailPath;
- this.by = Video.createByString(hash.author, hash.podUrl);
+ this.by = Video.createByString(hash.author, hash.podHost);
}
isRemovableBy(user) {
<div class="alert alert-danger">
The video load seems to be abnormally long.
<ul>
- <li>Maybe the server {{ video.podUrl }} is down :(</li>
+ <li>Maybe the server {{ video.podHost }} is down :(</li>
<li>
If not, you can report an issue on
<a href="https://github.com/Chocobozzz/PeerTube/issues" title="Report an issue">
router.get('/', listPods)
router.post('/',
validators.podsAdd,
- podsMiddleware.setBodyUrlPort,
+ podsMiddleware.setBodyHostPort,
addPods
)
router.post('/makefriends',
oAuth.authenticate,
admin.ensureIsAdmin,
validators.makeFriends,
- podsMiddleware.setBodyUrlsPort,
+ podsMiddleware.setBodyHostsPort,
makeFriends
)
router.get('/quitfriends',
}
function listPods (req, res, next) {
- Pod.list(function (err, podsUrlList) {
+ Pod.list(function (err, podsList) {
if (err) return next(err)
- res.json(getFormatedPods(podsUrlList))
+ res.json(getFormatedPods(podsList))
})
}
function makeFriends (req, res, next) {
- const urls = req.body.urls
+ const hosts = req.body.hosts
- friends.makeFriends(urls, function (err) {
+ friends.makeFriends(hosts, function (err) {
if (err) {
logger.error('Could not make friends.', { error: err })
return
}
function removePods (req, res, next) {
- const url = req.body.signature.url
+ const host = req.body.signature.host
waterfall([
function loadPod (callback) {
- Pod.loadByUrl(url, callback)
+ Pod.loadByHost(host, callback)
},
function removePod (pod, callback) {
function remoteVideos (req, res, next) {
const requests = req.body.data
- const fromUrl = req.body.signature.url
+ const fromHost = req.body.signature.host
// We need to process in the same order to keep consistency
// TODO: optimization
if (request.type === 'add') {
addRemoteVideo(videoData, callbackEach)
} else if (request.type === 'remove') {
- removeRemoteVideo(videoData, fromUrl, callbackEach)
+ removeRemoteVideo(videoData, fromHost, callbackEach)
} else {
logger.error('Unkown remote request type %s.', request.type)
}
video.save(callback)
}
-function removeRemoteVideo (videoToRemoveData, fromUrl, callback) {
+function removeRemoteVideo (videoToRemoveData, fromHost, callback) {
// We need the list because we have to remove some other stuffs (thumbnail etc)
- Video.listByUrlAndRemoteId(fromUrl, videoToRemoveData.remoteId, function (err, videosList) {
+ Video.listByHostAndRemoteId(fromHost, videoToRemoveData.remoteId, function (err, videosList) {
if (err) {
- logger.error('Cannot list videos from url and magnets.', { error: err })
+ logger.error('Cannot list videos from host and magnets.', { error: err })
return callback(err)
}
if (videosList.length === 0) {
- logger.error('No remote video was found for this pod.', { magnetUri: videoToRemoveData.magnetUri, podUrl: fromUrl })
+ logger.error('No remote video was found for this pod.', { magnetUri: videoToRemoveData.magnetUri, podHost: fromHost })
}
each(videosList, function (video, callbackEach) {
const miscValidators = require('./misc')
const podsValidators = {
- isEachUniqueUrlValid
+ isEachUniqueHostValid
}
-function isEachUniqueUrlValid (urls) {
- return miscValidators.isArray(urls) &&
- urls.length !== 0 &&
- urls.every(function (url) {
- return validator.isURL(url) && urls.indexOf(url) === urls.lastIndexOf(url)
+function isEachUniqueHostValid (hosts) {
+ return miscValidators.isArray(hosts) &&
+ hosts.length !== 0 &&
+ hosts.every(function (host) {
+ return validator.isURL(host) && host.split('://').length === 1 && hosts.indexOf(host) === hosts.lastIndexOf(host)
})
}
isVideoDurationValid,
isVideoMagnetValid,
isVideoNameValid,
- isVideoPodUrlValid,
+ isVideoPodHostValid,
isVideoTagsValid,
isVideoThumbnailValid,
isVideoThumbnail64Valid
isVideoDurationValid(video.duration) &&
isVideoMagnetValid(video.magnet) &&
isVideoNameValid(video.name) &&
- isVideoPodUrlValid(video.podUrl) &&
+ isVideoPodHostValid(video.podHost) &&
isVideoTagsValid(video.tags) &&
isVideoThumbnail64Valid(video.thumbnailBase64) &&
isVideoRemoteIdValid(video.remoteId)
return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.NAME)
}
-function isVideoPodUrlValid (value) {
+function isVideoPodHostValid (value) {
// TODO: set options (TLD...)
return validator.isURL(value)
}
function makeSecureRequest (params, callback) {
const requestParams = {
- url: params.toPod.url + params.path
+ url: constants.REMOTE_SCHEME.HTTP + '://' + params.toPod.host + params.path
}
// Add data with POST requst ?
// Add signature if it is specified in the params
if (params.sign === true) {
+ const host = constants.CONFIG.WEBSERVER.HOST
+
requestParams.json.signature = {
- url: constants.CONFIG.WEBSERVER.URL,
- signature: peertubeCrypto.sign(constants.CONFIG.WEBSERVER.URL)
+ host,
+ signature: peertubeCrypto.sign(host)
}
}
// Sortable columns per schema
const SEARCHABLE_COLUMNS = {
- VIDEOS: [ 'name', 'magnetUri', 'podUrl', 'author', 'tags' ]
+ VIDEOS: [ 'name', 'magnetUri', 'podHost', 'author', 'tags' ]
}
// Sortable columns per schema
}
}
CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
+CONFIG.WEBSERVER.HOST = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
// ---------------------------------------------------------------------------
const fs = require('fs')
const mongoose = require('mongoose')
const request = require('request')
-const urlUtil = require('url')
const waterfall = require('async/waterfall')
const constants = require('../initializers/constants')
fs.readFile(constants.CONFIG.STORAGE.CERT_DIR + 'peertube.pub', 'utf8', callback)
}
-function makeFriends (urls, callback) {
+function makeFriends (hosts, callback) {
const podsScore = {}
logger.info('Make friends!')
return callback(err)
}
- eachSeries(urls, function (url, callbackEach) {
- computeForeignPodsList(url, podsScore, callbackEach)
+ eachSeries(hosts, function (host, callbackEach) {
+ computeForeignPodsList(host, podsScore, callbackEach)
}, function (err) {
if (err) return callback(err)
logger.debug('Pods scores computed.', { podsScore: podsScore })
- const podsList = computeWinningPods(urls, podsScore)
+ const podsList = computeWinningPods(hosts, podsScore)
logger.debug('Pods that we keep.', { podsToKeep: podsList })
makeRequestsToWinningPods(cert, podsList, callback)
// ---------------------------------------------------------------------------
-function computeForeignPodsList (url, podsScore, callback) {
- getForeignPodsList(url, function (err, foreignPodsList) {
+function computeForeignPodsList (host, podsScore, callback) {
+ getForeignPodsList(host, function (err, foreignPodsList) {
if (err) return callback(err)
if (!foreignPodsList) foreignPodsList = []
// Let's give 1 point to the pod we ask the friends list
- foreignPodsList.push({ url: url })
+ foreignPodsList.push({ host })
foreignPodsList.forEach(function (foreignPod) {
- const foreignPodUrl = foreignPod.url
+ const foreignPodHost = foreignPod.host
- if (podsScore[foreignPodUrl]) podsScore[foreignPodUrl]++
- else podsScore[foreignPodUrl] = 1
+ if (podsScore[foreignPodHost]) podsScore[foreignPodHost]++
+ else podsScore[foreignPodHost] = 1
})
callback()
})
}
-function computeWinningPods (urls, podsScore) {
+function computeWinningPods (hosts, podsScore) {
// Build the list of pods to add
// Only add a pod if it exists in more than a half base pods
const podsList = []
- const baseScore = urls.length / 2
- Object.keys(podsScore).forEach(function (podUrl) {
+ const baseScore = hosts.length / 2
+ Object.keys(podsScore).forEach(function (podHost) {
// If the pod is not me and with a good score we add it
- if (isMe(podUrl) === false && podsScore[podUrl] > baseScore) {
- podsList.push({ url: podUrl })
+ if (isMe(podHost) === false && podsScore[podHost] > baseScore) {
+ podsList.push({ host: podHost })
}
})
return podsList
}
-function getForeignPodsList (url, callback) {
+function getForeignPodsList (host, callback) {
const path = '/api/' + constants.API_VERSION + '/pods'
- request.get(url + path, function (err, response, body) {
+ request.get(constants.REMOTE_SCHEME.HTTP + '://' + host + path, function (err, response, body) {
if (err) return callback(err)
try {
eachLimit(podsList, constants.REQUESTS_IN_PARALLEL, function (pod, callbackEach) {
const params = {
- url: pod.url + '/api/' + constants.API_VERSION + '/pods/',
+ url: constants.REMOTE_SCHEME.HTTP + '://' + pod.host + '/api/' + constants.API_VERSION + '/pods/',
method: 'POST',
json: {
- url: constants.CONFIG.WEBSERVER.URL,
+ host: constants.CONFIG.WEBSERVER.HOST,
publicKey: cert
}
}
requests.makeRetryRequest(params, function (err, res, body) {
if (err) {
- logger.error('Error with adding %s pod.', pod.url, { error: err })
+ logger.error('Error with adding %s pod.', pod.host, { error: err })
// Don't break the process
return callbackEach()
}
if (res.statusCode === 200) {
- const podObj = new Pod({ url: pod.url, publicKey: body.cert })
+ const podObj = new Pod({ host: pod.host, publicKey: body.cert })
podObj.save(function (err, podCreated) {
if (err) {
- logger.error('Cannot add friend %s pod.', pod.url, { error: err })
+ logger.error('Cannot add friend %s pod.', pod.host, { error: err })
return callbackEach()
}
return callbackEach()
})
} else {
- logger.error('Status not 200 for %s pod.', pod.url)
+ logger.error('Status not 200 for %s pod.', pod.host)
return callbackEach()
}
})
})
}
-function isMe (url) {
- const parsedUrl = urlUtil.parse(url)
-
- const hostname = parsedUrl.hostname
- const port = parseInt(parsedUrl.port)
-
- const myHostname = constants.CONFIG.WEBSERVER.HOSTNAME
- const myPort = constants.CONFIG.WEBSERVER.PORT
-
- return hostname === myHostname && port === myPort
+function isMe (host) {
+ return host === constants.CONFIG.WEBSERVER.HOST
}
'use strict'
-const urlModule = require('url')
-
-const logger = require('../helpers/logger')
+const constants = require('../initializers/constants')
const podsMiddleware = {
- setBodyUrlsPort,
- setBodyUrlPort
+ setBodyHostsPort,
+ setBodyHostPort
}
-function setBodyUrlsPort (req, res, next) {
- for (let i = 0; i < req.body.urls.length; i++) {
- const urlWithPort = getUrlWithPort(req.body.urls[i])
+function setBodyHostsPort (req, res, next) {
+ for (let i = 0; i < req.body.hosts.length; i++) {
+ const hostWithPort = getHostWithPort(req.body.hosts[i])
// Problem with the url parsing?
- if (urlWithPort === null) {
+ if (hostWithPort === null) {
return res.sendStatus(500)
}
- req.body.urls[i] = urlWithPort
+ req.body.hosts[i] = hostWithPort
}
return next()
}
-function setBodyUrlPort (req, res, next) {
- const urlWithPort = getUrlWithPort(req.body.url)
+function setBodyHostPort (req, res, next) {
+ const hostWithPort = getHostWithPort(req.body.host)
// Problem with the url parsing?
- if (urlWithPort === null) {
+ if (hostWithPort === null) {
return res.sendStatus(500)
}
- req.body.url = urlWithPort
+ req.body.host = hostWithPort
return next()
}
// ---------------------------------------------------------------------------
-function getUrlWithPort (url) {
- const urlObj = urlModule.parse(url)
-
- // Add the port if it is not specified
- if (urlObj.port === null) {
- if (urlObj.protocol === 'http:') {
- return url + ':80'
- } else if (urlObj.protocol === 'https:') {
- return url + ':443'
- } else {
- logger.error('Unknown url protocol: ' + urlObj.protocol)
- return null
- }
+function getHostWithPort (host) {
+ const splitted = host.split(':')
+
+ console.log(splitted)
+ // The port was not specified
+ if (splitted.length === 1) {
+ if (constants.REMOTE_SCHEME.HTTP === 'https') return host + ':443'
+
+ return host + ':80'
}
- return url
+ return host
}
}
function checkSignature (req, res, next) {
- const url = req.body.signature.url
- Pod.loadByUrl(url, function (err, pod) {
+ const host = req.body.signature.host
+ Pod.loadByHost(host, function (err, pod) {
if (err) {
- logger.error('Cannot get signed url in decryptBody.', { error: err })
+ logger.error('Cannot get signed host in decryptBody.', { error: err })
return res.sendStatus(500)
}
if (pod === null) {
- logger.error('Unknown pod %s.', url)
+ logger.error('Unknown pod %s.', host)
return res.sendStatus(403)
}
- logger.debug('Decrypting body from %s.', url)
+ logger.debug('Decrypting body from %s.', host)
- const signatureOk = peertubeCrypto.checkSignature(pod.publicKey, url, req.body.signature.signature)
+ const signatureOk = peertubeCrypto.checkSignature(pod.publicKey, host, req.body.signature.signature)
if (signatureOk === true) {
return next()
}
- logger.error('Signature is not okay in decryptBody for %s.', req.body.signature.url)
+ logger.error('Signature is not okay in decryptBody for %s.', req.body.signature.host)
return res.sendStatus(403)
})
}
}
function makeFriends (req, res, next) {
- req.checkBody('urls', 'Should have an array of unique urls').isEachUniqueUrlValid()
+ req.checkBody('hosts', 'Should have an array of unique hosts').isEachUniqueHostValid()
logger.debug('Checking makeFriends parameters', { parameters: req.body })
}
function podsAdd (req, res, next) {
- req.checkBody('url', 'Should have an url').notEmpty().isURL({ require_protocol: true })
+ req.checkBody('host', 'Should have an host').notEmpty().isURL()
req.checkBody('publicKey', 'Should have a public key').notEmpty()
// TODO: check we don't have it already
}
function signature (req, res, next) {
- req.checkBody('signature.url', 'Should have a signature url').isURL()
+ req.checkBody('signature.host', 'Should have a signature host').isURL()
req.checkBody('signature.signature', 'Should have a signature').notEmpty()
- logger.debug('Checking signature parameters', { parameters: { signatureUrl: req.body.signature.url } })
+ logger.debug('Checking signature parameters', { parameters: { signatureHost: req.body.signature.host } })
checkErrors(req, res, next)
}
// ---------------------------------------------------------------------------
const PodSchema = mongoose.Schema({
- url: String,
+ host: String,
publicKey: String,
score: { type: Number, max: constants.FRIEND_SCORE.MAX },
createdDate: {
}
})
-// TODO: set options (TLD...)
-PodSchema.path('url').validate(validator.isURL)
+PodSchema.path('host').validate(validator.isURL)
PodSchema.path('publicKey').required(true)
PodSchema.path('score').validate(function (value) { return !isNaN(value) })
listAllIds,
listBadPods,
load,
- loadByUrl,
+ loadByHost,
removeAll
}
PodSchema.pre('save', function (next) {
const self = this
- Pod.loadByUrl(this.url, function (err, pod) {
+ Pod.loadByHost(this.host, function (err, pod) {
if (err) return next(err)
if (pod) return next(new Error('Pod already exists.'))
PodSchema.pre('remove', function (next) {
// Remove the videos owned by this pod too
- Video.listByUrl(this.url, function (err, videos) {
+ Video.listByHost(this.host, function (err, videos) {
if (err) return next(err)
each(videos, function (video, callbackEach) {
function toFormatedJSON () {
const json = {
id: this._id,
- url: this.url,
+ host: this.host,
score: this.score,
createdDate: this.createdDate
}
return this.findById(id, callback)
}
-function loadByUrl (url, callback) {
- return this.findOne({ url: url }, callback)
+function loadByHost (host, callback) {
+ return this.findOne({ host }, callback)
}
function removeAll (callback) {
if (err || (res.statusCode !== 200 && res.statusCode !== 201 && res.statusCode !== 204)) {
logger.error(
'Error sending secure request to %s pod.',
- toPod.url,
+ toPod.host,
{
error: err || new Error('Status code not 20x : ' + res.statusCode)
}
magnet: {
infoHash: String
},
- podUrl: String,
+ podHost: String,
author: String,
duration: Number,
- thumbnail: String,
tags: [ String ],
createdDate: {
type: Date,
VideoSchema.path('name').validate(customVideosValidators.isVideoNameValid)
VideoSchema.path('description').validate(customVideosValidators.isVideoDescriptionValid)
-VideoSchema.path('podUrl').validate(customVideosValidators.isVideoPodUrlValid)
+VideoSchema.path('podHost').validate(customVideosValidators.isVideoPodHostValid)
VideoSchema.path('author').validate(customVideosValidators.isVideoAuthorValid)
VideoSchema.path('duration').validate(customVideosValidators.isVideoDurationValid)
-// The tumbnail can be the path or the data in base 64
-// The pre save hook will convert the base 64 data in a file on disk and replace the thumbnail key by the filename
-VideoSchema.path('thumbnail').validate(function (value) {
- return customVideosValidators.isVideoThumbnailValid(value) || customVideosValidators.isVideoThumbnail64Valid(value)
-})
VideoSchema.path('tags').validate(customVideosValidators.isVideoTagsValid)
VideoSchema.methods = {
VideoSchema.statics = {
getDurationFromFile,
listForApi,
- listByUrlAndRemoteId,
- listByUrl,
+ listByHostAndRemoteId,
+ listByHost,
listOwned,
listOwnedByAuthor,
listRemotes,
if (video.isOwned()) {
const videoPath = pathUtils.join(constants.CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename())
- this.podUrl = constants.CONFIG.WEBSERVER.HOSTNAME + ':' + constants.CONFIG.WEBSERVER.PORT
+ this.podHost = constants.CONFIG.WEBSERVER.HOST
tasks.push(
// TODO: refractoring
baseUrlHttp = constants.CONFIG.WEBSERVER.URL
baseUrlWs = constants.CONFIG.WEBSERVER.WS + '://' + constants.CONFIG.WEBSERVER.HOSTNAME + ':' + constants.CONFIG.WEBSERVER.PORT
} else {
- baseUrlHttp = constants.REMOTE_SCHEME.HTTP + '://' + this.podUrl
- baseUrlWs = constants.REMOTE_SCHEME.WS + this.podUrl
+ baseUrlHttp = constants.REMOTE_SCHEME.HTTP + '://' + this.podHost
+ baseUrlWs = constants.REMOTE_SCHEME.WS + this.podHost
}
const xs = baseUrlHttp + constants.STATIC_PATHS.TORRENTS + this.getTorrentName()
id: this._id,
name: this.name,
description: this.description,
- podUrl: this.podUrl,
+ podHost: this.podHost,
isLocal: this.isOwned(),
magnetUri: this.generateMagnetUri(),
author: this.author,
thumbnailBase64: new Buffer(thumbnailData).toString('base64'),
tags: self.tags,
createdDate: self.createdDate,
- podUrl: self.podUrl
+ podHost: self.podHost
}
return callback(null, remoteVideo)
return modelUtils.listForApiWithCount.call(this, query, start, count, sort, callback)
}
-function listByUrlAndRemoteId (fromUrl, remoteId, callback) {
- this.find({ podUrl: fromUrl, remoteId: remoteId }, callback)
+function listByHostAndRemoteId (fromHost, remoteId, callback) {
+ this.find({ podHost: fromHost, remoteId: remoteId }, callback)
}
-function listByUrl (fromUrl, callback) {
- this.find({ podUrl: fromUrl }, callback)
+function listByHost (fromHost, callback) {
+ this.find({ podHost: fromHost }, callback)
}
function listOwned (callback) {