From 49abbbbedca83b9031d3e2eb3ae9ad9b6a7d96ed Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 14 Nov 2016 20:03:04 +0100 Subject: Pod URL -> pod host. HTTPS is required to make friends. Reason: in a network with mix http/https pods, https pods won't be able to play videos from http pod (insecure requests). --- .../friends/friend-add/friend-add.component.html | 12 ++--- .../friends/friend-add/friend-add.component.ts | 56 +++++++++++----------- .../friends/friend-list/friend-list.component.html | 4 +- .../src/app/admin/friends/shared/friend.model.ts | 2 +- .../src/app/admin/friends/shared/friend.service.ts | 4 +- .../shared/forms/form-validators/host.validator.ts | 11 +++++ .../src/app/shared/forms/form-validators/index.ts | 2 +- .../shared/forms/form-validators/url.validator.ts | 11 ----- client/src/app/videos/shared/video.model.ts | 21 +++----- .../videos/video-watch/video-watch.component.html | 2 +- 10 files changed, 58 insertions(+), 67 deletions(-) create mode 100644 client/src/app/shared/forms/form-validators/host.validator.ts delete mode 100644 client/src/app/shared/forms/form-validators/url.validator.ts (limited to 'client') diff --git a/client/src/app/admin/friends/friend-add/friend-add.component.html b/client/src/app/admin/friends/friend-add/friend-add.component.html index 788f3b44d..621822860 100644 --- a/client/src/app/admin/friends/friend-add/friend-add.component.html +++ b/client/src/app/admin/friends/friend-add/friend-add.component.html @@ -3,13 +3,13 @@
{{ error }}
-
- +
+
@@ -17,8 +17,8 @@
-
- It should be a valid url. +
+ It should be a valid host.
diff --git a/client/src/app/admin/friends/friend-add/friend-add.component.ts b/client/src/app/admin/friends/friend-add/friend-add.component.ts index 64165a9a5..86b018de2 100644 --- a/client/src/app/admin/friends/friend-add/friend-add.component.ts +++ b/client/src/app/admin/friends/friend-add/friend-add.component.ts @@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core'; import { FormControl, FormGroup } from '@angular/forms'; import { Router } from '@angular/router'; -import { validateUrl } from '../../../shared'; +import { validateHost } from '../../../shared'; import { FriendService } from '../shared'; @Component({ @@ -12,7 +12,7 @@ import { FriendService } from '../shared'; }) export class FriendAddComponent implements OnInit { form: FormGroup; - urls = [ ]; + hosts = [ ]; error: string = null; constructor(private router: Router, private friendService: FriendService) {} @@ -23,8 +23,8 @@ export class FriendAddComponent implements OnInit { } 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 { @@ -32,52 +32,52 @@ export class FriendAddComponent implements OnInit { } 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) { @@ -91,18 +91,18 @@ export class FriendAddComponent implements OnInit { ); } - 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)); } } diff --git a/client/src/app/admin/friends/friend-list/friend-list.component.html b/client/src/app/admin/friends/friend-list/friend-list.component.html index 20b4d12db..4236fc5f6 100644 --- a/client/src/app/admin/friends/friend-list/friend-list.component.html +++ b/client/src/app/admin/friends/friend-list/friend-list.component.html @@ -4,7 +4,7 @@ ID - Url + Host Score Created Date @@ -13,7 +13,7 @@ {{ friend.id }} - {{ friend.url }} + {{ friend.host }} {{ friend.score }} {{ friend.createdDate | date: 'medium' }} diff --git a/client/src/app/admin/friends/shared/friend.model.ts b/client/src/app/admin/friends/shared/friend.model.ts index 7cb28f440..3c23feebc 100644 --- a/client/src/app/admin/friends/shared/friend.model.ts +++ b/client/src/app/admin/friends/shared/friend.model.ts @@ -1,6 +1,6 @@ export interface Friend { id: string; - url: string; + host: string; score: number; createdDate: Date; } diff --git a/client/src/app/admin/friends/shared/friend.service.ts b/client/src/app/admin/friends/shared/friend.service.ts index 75826fc17..8a1ba6b02 100644 --- a/client/src/app/admin/friends/shared/friend.service.ts +++ b/client/src/app/admin/friends/shared/friend.service.ts @@ -21,9 +21,9 @@ export class FriendService { .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) diff --git a/client/src/app/shared/forms/form-validators/host.validator.ts b/client/src/app/shared/forms/form-validators/host.validator.ts new file mode 100644 index 000000000..9cb46d361 --- /dev/null +++ b/client/src/app/shared/forms/form-validators/host.validator.ts @@ -0,0 +1,11 @@ +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 + } + }; +} diff --git a/client/src/app/shared/forms/form-validators/index.ts b/client/src/app/shared/forms/form-validators/index.ts index 1d2ae6f68..4c6cc6637 100644 --- a/client/src/app/shared/forms/form-validators/index.ts +++ b/client/src/app/shared/forms/form-validators/index.ts @@ -1,3 +1,3 @@ -export * from './url.validator'; +export * from './host.validator'; export * from './user'; export * from './video'; diff --git a/client/src/app/shared/forms/form-validators/url.validator.ts b/client/src/app/shared/forms/form-validators/url.validator.ts deleted file mode 100644 index 67163b4e9..000000000 --- a/client/src/app/shared/forms/form-validators/url.validator.ts +++ /dev/null @@ -1,11 +0,0 @@ -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 - } - }; -} diff --git a/client/src/app/videos/shared/video.model.ts b/client/src/app/videos/shared/video.model.ts index 873c83ff1..b51a0e9de 100644 --- a/client/src/app/videos/shared/video.model.ts +++ b/client/src/app/videos/shared/video.model.ts @@ -8,21 +8,12 @@ export class Video { 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) { @@ -43,7 +34,7 @@ export class Video { isLocal: boolean, magnetUri: string, name: string, - podUrl: string, + podHost: string, tags: string[], thumbnailPath: string }) { @@ -55,11 +46,11 @@ export class Video { 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) { diff --git a/client/src/app/videos/video-watch/video-watch.component.html b/client/src/app/videos/video-watch/video-watch.component.html index f3a416367..cb91bae7e 100644 --- a/client/src/app/videos/video-watch/video-watch.component.html +++ b/client/src/app/videos/video-watch/video-watch.component.html @@ -2,7 +2,7 @@
The video load seems to be abnormally long.
    -
  • Maybe the server {{ video.podUrl }} is down :(
  • +
  • Maybe the server {{ video.podHost }} is down :(
  • If not, you can report an issue on -- cgit v1.2.3