From 26ff0279d08bc5d4cb13a2f71e314b05d544da89 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 22 Aug 2019 14:52:41 +0200 Subject: [PATCH 1/5] Fix lazy static route with unknown avatars --- server/controllers/lazy-static.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/controllers/lazy-static.ts b/server/controllers/lazy-static.ts index 28d2f862a..1ff99e90c 100644 --- a/server/controllers/lazy-static.ts +++ b/server/controllers/lazy-static.ts @@ -44,6 +44,8 @@ async function getAvatar (req: express.Request, res: express.Response) { } const avatar = await AvatarModel.loadByName(filename) + if (!avatar) return res.sendStatus(404) + if (avatar.onDisk === false) { if (!avatar.fileUrl) return res.sendStatus(404) From 446d9f8cc7f12fbbf3d8643f5d3414822a18c51d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 22 Aug 2019 15:12:44 +0200 Subject: [PATCH 2/5] Fix e2e tests --- client/angular.json | 6 ++++-- client/e2e/proxy.config.json | 37 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 client/e2e/proxy.config.json diff --git a/client/angular.json b/client/angular.json index e1e4f4850..950ac059e 100644 --- a/client/angular.json +++ b/client/angular.json @@ -86,7 +86,8 @@ "options": { "baseHref": "/", "deployUrl": "client/", - "browserTarget": "PeerTube:build" + "browserTarget": "PeerTube:build", + "proxyConfig": "proxy.config.json" }, "configurations": { "production": { @@ -96,7 +97,8 @@ "browserTarget": "PeerTube:build:hmr" }, "e2e": { - "browserTarget": "PeerTube:build:e2e" + "browserTarget": "PeerTube:build:e2e", + "proxyConfig": "e2e/proxy.config.json" } } }, diff --git a/client/e2e/proxy.config.json b/client/e2e/proxy.config.json new file mode 100644 index 000000000..00bda5eb7 --- /dev/null +++ b/client/e2e/proxy.config.json @@ -0,0 +1,37 @@ +{ + "/api": { + "target": "http://localhost:9000", + "secure": false + }, + "/plugins": { + "target": "http://localhost:9000", + "secure": false + }, + "/themes": { + "target": "http://localhost:9000", + "secure": false + }, + "/static": { + "target": "http://localhost:9000", + "secure": false + }, + "/lazy-static": { + "target": "http://localhost:9000", + "secure": false + }, + "/socket.io": { + "target": "ws://localhost:9000", + "secure": false, + "ws": true + }, + "/!(client)**": { + "target": "http://localhost:3333/client/index.html", + "secure": false, + "logLevel": "debug" + }, + "/!(client)**/**": { + "target": "http://localhost:3333/client/index.html", + "secure": false, + "logLevel": "debug" + } +} From f9e387ed05d79d3f88f95056720fb244d04805d2 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 22 Aug 2019 16:01:06 +0200 Subject: [PATCH 3/5] Fix plugin card background color with dark theme --- client/src/app/+admin/plugins/shared/plugin-list.component.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/client/src/app/+admin/plugins/shared/plugin-list.component.scss b/client/src/app/+admin/plugins/shared/plugin-list.component.scss index f1516240e..3663d3fdd 100644 --- a/client/src/app/+admin/plugins/shared/plugin-list.component.scss +++ b/client/src/app/+admin/plugins/shared/plugin-list.component.scss @@ -3,6 +3,7 @@ .plugin { margin: 15px 0; + background-color: var(--submenuColor); } .first-row { From 4334445d043252661e62cf97f76b67a2c43e3750 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 22 Aug 2019 16:13:26 +0200 Subject: [PATCH 4/5] Dismiss modals on pop state --- client/src/app/app.component.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/client/src/app/app.component.ts b/client/src/app/app.component.ts index 50c5f5b9b..065bdcaa4 100644 --- a/client/src/app/app.component.ts +++ b/client/src/app/app.component.ts @@ -8,9 +8,10 @@ import { debounceTime, filter, map, pairwise, skip } from 'rxjs/operators' import { Hotkey, HotkeysService } from 'angular2-hotkeys' import { I18n } from '@ngx-translate/i18n-polyfill' import { fromEvent } from 'rxjs' -import { ViewportScroller } from '@angular/common' +import { PlatformLocation, ViewportScroller } from '@angular/common' import { PluginService } from '@app/core/plugins/plugin.service' import { HooksService } from '@app/core/plugins/hooks.service' +import { NgbModal } from '@ng-bootstrap/ng-bootstrap' @Component({ selector: 'my-app', @@ -35,7 +36,9 @@ export class AppComponent implements OnInit { private screenService: ScreenService, private hotkeysService: HotkeysService, private themeService: ThemeService, - private hooks: HooksService + private hooks: HooksService, + private location: PlatformLocation, + private modalService: NgbModal ) { } get serverVersion () { @@ -90,6 +93,8 @@ export class AppComponent implements OnInit { fromEvent(window, 'resize') .pipe(debounceTime(200)) .subscribe(() => this.onResize()) + + this.location.onPopState(() => this.modalService.dismissAll()) } isUserLoggedIn () { From 60c2bc80b82c71bd63bdb1fcf64d4d49491ce5c8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 22 Aug 2019 17:13:58 +0200 Subject: [PATCH 5/5] Go back when cancel NSFW modal Instead of redirecting on the homepage --- client/src/app/app.component.ts | 6 ++++-- client/src/app/core/confirm/confirm.service.ts | 8 ++++++-- client/src/app/shared/confirm/confirm.component.ts | 8 +++++++- client/src/app/shared/misc/constants.ts | 1 + .../src/app/videos/+video-watch/video-watch.component.ts | 6 ++++-- 5 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 client/src/app/shared/misc/constants.ts diff --git a/client/src/app/app.component.ts b/client/src/app/app.component.ts index 065bdcaa4..64bfb9671 100644 --- a/client/src/app/app.component.ts +++ b/client/src/app/app.component.ts @@ -12,6 +12,7 @@ import { PlatformLocation, ViewportScroller } from '@angular/common' import { PluginService } from '@app/core/plugins/plugin.service' import { HooksService } from '@app/core/plugins/hooks.service' import { NgbModal } from '@ng-bootstrap/ng-bootstrap' +import { POP_STATE_MODAL_DISMISS } from '@app/shared/misc/constants' @Component({ selector: 'my-app', @@ -94,7 +95,7 @@ export class AppComponent implements OnInit { .pipe(debounceTime(200)) .subscribe(() => this.onResize()) - this.location.onPopState(() => this.modalService.dismissAll()) + this.location.onPopState(() => this.modalService.dismissAll(POP_STATE_MODAL_DISMISS)) } isUserLoggedIn () { @@ -115,7 +116,6 @@ export class AppComponent implements OnInit { const eventsObs = this.router.events const scrollEvent = eventsObs.pipe(filter((e: Event): e is Scroll => e instanceof Scroll)) - const navigationEndEvent = eventsObs.pipe(filter((e: Event): e is NavigationEnd => e instanceof NavigationEnd)) scrollEvent.subscribe(e => { if (e.position) { @@ -131,6 +131,8 @@ export class AppComponent implements OnInit { } }) + const navigationEndEvent = eventsObs.pipe(filter((e: Event): e is NavigationEnd => e instanceof NavigationEnd)) + // When we add the a-state parameter, we don't want to alter the scroll navigationEndEvent.pipe(pairwise()) .subscribe(([ e1, e2 ]) => { diff --git a/client/src/app/core/confirm/confirm.service.ts b/client/src/app/core/confirm/confirm.service.ts index 8419f622b..6e042c16b 100644 --- a/client/src/app/core/confirm/confirm.service.ts +++ b/client/src/app/core/confirm/confirm.service.ts @@ -18,12 +18,16 @@ export class ConfirmService { confirm (message: string, title = '', confirmButtonText?: string) { this.showConfirm.next({ title, message, confirmButtonText }) - return this.confirmResponse.asObservable().pipe(first()).toPromise() + return this.confirmResponse.asObservable() + .pipe(first()) + .toPromise() } confirmWithInput (message: string, inputLabel: string, expectedInputValue: string, title = '', confirmButtonText?: string) { this.showConfirm.next({ title, message, inputLabel, expectedInputValue, confirmButtonText }) - return this.confirmResponse.asObservable().pipe(first()).toPromise() + return this.confirmResponse.asObservable() + .pipe(first()) + .toPromise() } } diff --git a/client/src/app/shared/confirm/confirm.component.ts b/client/src/app/shared/confirm/confirm.component.ts index 53aed14d7..763454c4f 100644 --- a/client/src/app/shared/confirm/confirm.component.ts +++ b/client/src/app/shared/confirm/confirm.component.ts @@ -3,6 +3,7 @@ import { ConfirmService } from '@app/core/confirm/confirm.service' import { I18n } from '@ngx-translate/i18n-polyfill' import { NgbModal } from '@ng-bootstrap/ng-bootstrap' import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' +import { POP_STATE_MODAL_DISMISS } from '@app/shared/misc/constants' @Component({ selector: 'my-confirm', @@ -63,6 +64,11 @@ export class ConfirmComponent implements OnInit { this.openedModal.result .then(() => this.confirmService.confirmResponse.next(true)) - .catch(() => this.confirmService.confirmResponse.next(false)) + .catch((reason: string) => { + // If the reason was that the user used the back button, we don't care about the confirm dialog result + if (!reason || reason !== POP_STATE_MODAL_DISMISS) { + this.confirmService.confirmResponse.next(false) + } + }) } } diff --git a/client/src/app/shared/misc/constants.ts b/client/src/app/shared/misc/constants.ts new file mode 100644 index 000000000..bb4a0884e --- /dev/null +++ b/client/src/app/shared/misc/constants.ts @@ -0,0 +1 @@ +export const POP_STATE_MODAL_DISMISS = 'pop state dismiss' diff --git a/client/src/app/videos/+video-watch/video-watch.component.ts b/client/src/app/videos/+video-watch/video-watch.component.ts index d7c7b7497..21a24113f 100644 --- a/client/src/app/videos/+video-watch/video-watch.component.ts +++ b/client/src/app/videos/+video-watch/video-watch.component.ts @@ -34,6 +34,7 @@ import { VideoWatchPlaylistComponent } from '@app/videos/+video-watch/video-watc import { getStoredTheater } from '../../../assets/player/peertube-player-local-storage' import { PluginService } from '@app/core/plugins/plugin.service' import { HooksService } from '@app/core/plugins/hooks.service' +import { PlatformLocation } from '@angular/common' @Component({ selector: 'my-video-watch', @@ -95,6 +96,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { private i18n: I18n, private hotkeysService: HotkeysService, private hooks: HooksService, + private location: PlatformLocation, @Inject(LOCALE_ID) private localeId: string ) {} @@ -374,13 +376,13 @@ export class VideoWatchComponent implements OnInit, OnDestroy { this.i18n('This video contains mature or explicit content. Are you sure you want to watch it?'), this.i18n('Mature or explicit content') ) - if (res === false) return this.redirectService.redirectToHomepage() + if (res === false) return this.location.back() } // Flush old player if needed this.flushPlayer() - // Build video element, because videojs remove it on dispose + // Build video element, because videojs removes it on dispose const playerElementWrapper = this.elementRef.nativeElement.querySelector('#videojs-wrapper') this.playerElement = document.createElement('video') this.playerElement.className = 'video-js vjs-peertube-skin'