From c47106315ae3c403239cda29c49b4bba51ddccb2 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 2 Apr 2019 18:30:26 +0200 Subject: tslint update --- client/src/app/+accounts/accounts.component.ts | 1 - .../video-channel-playlists.component.html | 2 +- client/src/app/shared/forms/form-reactive.ts | 2 +- client/src/app/shared/misc/utils.ts | 4 ++-- client/src/app/shared/renderer/markdown.service.ts | 2 +- ...video-playlist-element-miniature.component.html | 4 ++-- .../video-playlist-miniature.component.html | 2 +- .../videos/+video-watch/video-watch.component.html | 2 +- .../player/p2p-media-loader/segment-url-builder.ts | 4 ++-- client/src/assets/player/utils.ts | 4 ++-- .../videojs-components/resolution-menu-button.ts | 2 +- .../videojs-components/settings-menu-button.ts | 18 ++++++++-------- .../videojs-components/settings-menu-item.ts | 10 ++++----- .../player/webtorrent/peertube-chunk-store.ts | 6 +++--- .../src/assets/player/webtorrent/video-renderer.ts | 2 +- .../assets/player/webtorrent/webtorrent-plugin.ts | 2 +- client/src/polyfills.ts | 1 + client/src/standalone/player/definitions.ts | 4 +--- client/src/standalone/player/events.ts | 4 ++-- client/src/standalone/videos/embed.ts | 12 +++++------ client/src/standalone/videos/test-embed.ts | 24 +++++++++++----------- 21 files changed, 55 insertions(+), 57 deletions(-) (limited to 'client/src') diff --git a/client/src/app/+accounts/accounts.component.ts b/client/src/app/+accounts/accounts.component.ts index e8339b78b..d9786fb5c 100644 --- a/client/src/app/+accounts/accounts.component.ts +++ b/client/src/app/+accounts/accounts.component.ts @@ -7,7 +7,6 @@ import { catchError, distinctUntilChanged, map, switchMap, tap } from 'rxjs/oper import { Subscription } from 'rxjs' import { AuthService, Notifier, RedirectService } from '@app/core' import { User, UserRight } from '../../../../shared' -import { I18n } from '@ngx-translate/i18n-polyfill' @Component({ templateUrl: './accounts.component.html', diff --git a/client/src/app/+video-channels/video-channel-playlists/video-channel-playlists.component.html b/client/src/app/+video-channels/video-channel-playlists/video-channel-playlists.component.html index 0d9fba375..befc7143c 100644 --- a/client/src/app/+video-channels/video-channel-playlists/video-channel-playlists.component.html +++ b/client/src/app/+video-channels/video-channel-playlists/video-channel-playlists.component.html @@ -1,5 +1,5 @@
- Created {{pagination.totalItems}} playlists + Created {{ pagination.totalItems }} playlists
This channel does not have playlists.
diff --git a/client/src/app/shared/forms/form-reactive.ts b/client/src/app/shared/forms/form-reactive.ts index b9873af2c..0d40b6f4a 100644 --- a/client/src/app/shared/forms/form-reactive.ts +++ b/client/src/app/shared/forms/form-reactive.ts @@ -59,7 +59,7 @@ export abstract class FormReactive { const isDirty = control.dirty || forceCheck === true if (control && isDirty && !control.valid) { const messages = validationMessages[ field ] - for (const key in control.errors) { + for (const key of Object.keys(control.errors)) { formErrors[ field ] += messages[ key ] + ' ' } } diff --git a/client/src/app/shared/misc/utils.ts b/client/src/app/shared/misc/utils.ts index 8a1d342c9..85fc1c3a0 100644 --- a/client/src/app/shared/misc/utils.ts +++ b/client/src/app/shared/misc/utils.ts @@ -78,10 +78,10 @@ function objectToUrlEncoded (obj: any) { // Thanks: https://gist.github.com/ghinda/8442a57f22099bdb2e34 function objectToFormData (obj: any, form?: FormData, namespace?: string) { - let fd = form || new FormData() + const fd = form || new FormData() let formKey - for (let key of Object.keys(obj)) { + for (const key of Object.keys(obj)) { if (namespace) formKey = `${namespace}[${key}]` else formKey = key diff --git a/client/src/app/shared/renderer/markdown.service.ts b/client/src/app/shared/renderer/markdown.service.ts index 69dc60aaf..9a9066351 100644 --- a/client/src/app/shared/renderer/markdown.service.ts +++ b/client/src/app/shared/renderer/markdown.service.ts @@ -45,7 +45,7 @@ export class MarkdownService { const markdownIt = new MarkdownItClass('zero', { linkify: true, breaks: true }) - for (let rule of rules) { + for (const rule of rules) { markdownIt.enable(rule) } diff --git a/client/src/app/shared/video-playlist/video-playlist-element-miniature.component.html b/client/src/app/shared/video-playlist/video-playlist-element-miniature.component.html index 4764fc0e1..ab5a78928 100644 --- a/client/src/app/shared/video-playlist/video-playlist-element-miniature.component.html +++ b/client/src/app/shared/video-playlist/video-playlist-element-miniature.component.html @@ -19,7 +19,7 @@ {{ video.byAccount }} {{ video.byAccount }} - {{ formatTimestamp(video)}} + {{ formatTimestamp(video) }} @@ -66,7 +66,7 @@ - Delete from {{playlist?.displayName}} + Delete from {{ playlist?.displayName }} diff --git a/client/src/app/shared/video-playlist/video-playlist-miniature.component.html b/client/src/app/shared/video-playlist/video-playlist-miniature.component.html index c01c73012..faf906c59 100644 --- a/client/src/app/shared/video-playlist/video-playlist-miniature.component.html +++ b/client/src/app/shared/video-playlist/video-playlist-miniature.component.html @@ -6,7 +6,7 @@
- {playlist.videosLength, plural, =0 {No videos} =1 {1 video} other {{{playlist.videosLength}} videos}} + {playlist.videosLength, plural, =0 {No videos} =1 {1 video} other {{{ playlist.videosLength }} videos}}
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 91f77cbf3..ad1d04b70 100644 --- a/client/src/app/videos/+video-watch/video-watch.component.html +++ b/client/src/app/videos/+video-watch/video-watch.component.html @@ -22,7 +22,7 @@
{{ playlist.ownerBy }}
- {{currentPlaylistPosition}}{{playlistPagination.totalItems}} + {{ currentPlaylistPosition }}{{ playlistPagination.totalItems }}
diff --git a/client/src/assets/player/p2p-media-loader/segment-url-builder.ts b/client/src/assets/player/p2p-media-loader/segment-url-builder.ts index 32e7ce4f2..fb990a19d 100644 --- a/client/src/assets/player/p2p-media-loader/segment-url-builder.ts +++ b/client/src/assets/player/p2p-media-loader/segment-url-builder.ts @@ -8,8 +8,8 @@ function segmentUrlBuilderFactory (baseUrls: string[]) { if (i === max - 1) return segment.url - let newBaseUrl = baseUrls[i] - let middlePart = newBaseUrl.endsWith('/') ? '' : '/' + const newBaseUrl = baseUrls[i] + const middlePart = newBaseUrl.endsWith('/') ? '' : '/' return newBaseUrl + middlePart + basename(segment.url) } diff --git a/client/src/assets/player/utils.ts b/client/src/assets/player/utils.ts index 54f131310..0966027ac 100644 --- a/client/src/assets/player/utils.ts +++ b/client/src/assets/player/utils.ts @@ -61,12 +61,12 @@ function secondsToTime (seconds: number, full = false, symbol?: string) { const minuteSymbol = (symbol || 'm') const secondsSymbol = full ? '' : 's' - let hours = Math.floor(seconds / 3600) + const hours = Math.floor(seconds / 3600) if (hours >= 1) time = hours + hourSymbol else if (full) time = '0' + hourSymbol seconds %= 3600 - let minutes = Math.floor(seconds / 60) + const minutes = Math.floor(seconds / 60) if (minutes >= 1 && minutes < 10 && full) time += '0' + minutes + minuteSymbol else if (minutes >= 1) time += minutes + minuteSymbol else if (full) time += '00' + minuteSymbol diff --git a/client/src/assets/player/videojs-components/resolution-menu-button.ts b/client/src/assets/player/videojs-components/resolution-menu-button.ts index abcc16411..cff44de72 100644 --- a/client/src/assets/player/videojs-components/resolution-menu-button.ts +++ b/client/src/assets/player/videojs-components/resolution-menu-button.ts @@ -49,7 +49,7 @@ class ResolutionMenuButton extends MenuButton { private addClickListener (component: any) { component.on('click', () => { - let children = this.menu.children() + const children = this.menu.children() for (const child of children) { if (component !== child) { diff --git a/client/src/assets/player/videojs-components/settings-menu-button.ts b/client/src/assets/player/videojs-components/settings-menu-button.ts index 14cb8ba43..5e09032b4 100644 --- a/client/src/assets/player/videojs-components/settings-menu-button.ts +++ b/client/src/assets/player/videojs-components/settings-menu-button.ts @@ -53,7 +53,7 @@ class SettingsButton extends Button { onDisposeSettingsItem (event: any, name: string) { if (name === undefined) { - let children = this.menu.children() + const children = this.menu.children() while (children.length > 0) { children[0].dispose() @@ -62,7 +62,7 @@ class SettingsButton extends Button { this.addClass('vjs-hidden') } else { - let item = this.menu.getChild(name) + const item = this.menu.getChild(name) if (item) { item.dispose() @@ -148,8 +148,8 @@ class SettingsButton extends Button { return } - let offset = this.options_.setup.maxHeightOffset - let maxHeight = this.playerComponent.el_.offsetHeight - offset + const offset = this.options_.setup.maxHeightOffset + const maxHeight = this.playerComponent.el_.offsetHeight - offset if (height > maxHeight) { height = maxHeight @@ -166,7 +166,7 @@ class SettingsButton extends Button { buildMenu () { this.menu = new Menu(this.player()) this.menu.addClass('vjs-main-menu') - let entries = this.options_.entries + const entries = this.options_.entries if (entries.length === 0) { this.addClass('vjs-hidden') @@ -174,7 +174,7 @@ class SettingsButton extends Button { return } - for (let entry of entries) { + for (const entry of entries) { this.addMenuItem(entry, this.options_) } @@ -191,7 +191,7 @@ class SettingsButton extends Button { } options.name = toTitleCase(entry) - let settingsMenuItem = new SettingsMenuItem(this.player(), options, entry, this as any) + const settingsMenuItem = new SettingsMenuItem(this.player(), options, entry, this as any) this.menu.addChild(settingsMenuItem) @@ -204,7 +204,7 @@ class SettingsButton extends Button { } resetChildren () { - for (let menuChild of this.menu.children()) { + for (const menuChild of this.menu.children()) { menuChild.reset() } } @@ -213,7 +213,7 @@ class SettingsButton extends Button { * Hide all the sub menus */ hideChildren () { - for (let menuChild of this.menu.children()) { + for (const menuChild of this.menu.children()) { menuChild.hideSubMenu() } } diff --git a/client/src/assets/player/videojs-components/settings-menu-item.ts b/client/src/assets/player/videojs-components/settings-menu-item.ts index f14959f9c..78879a2ec 100644 --- a/client/src/assets/player/videojs-components/settings-menu-item.ts +++ b/client/src/assets/player/videojs-components/settings-menu-item.ts @@ -167,7 +167,7 @@ class SettingsMenuItem extends MenuItem { * @method PrefixedEvent */ PrefixedEvent (element: any, type: any, callback: any, action = 'addEvent') { - let prefix = ['webkit', 'moz', 'MS', 'o', ''] + const prefix = ['webkit', 'moz', 'MS', 'o', ''] for (let p = 0; p < prefix.length; p++) { if (!prefix[p]) { @@ -249,7 +249,7 @@ class SettingsMenuItem extends MenuItem { update (event?: any) { let target: HTMLElement = null - let subMenu = this.subMenu.name() + const subMenu = this.subMenu.name() if (event && event.type === 'tap') { target = event.target @@ -264,7 +264,7 @@ class SettingsMenuItem extends MenuItem { setTimeout(() => this.settingsSubMenuValueEl_.innerHTML = this.subMenu.labelEl_.innerHTML, 250) } else { // Loop trough the submenu items to find the selected child - for (let subMenuItem of this.subMenu.menu.children_) { + for (const subMenuItem of this.subMenu.menu.children_) { if (!(subMenuItem instanceof component)) { continue } @@ -287,7 +287,7 @@ class SettingsMenuItem extends MenuItem { } bindClickEvents () { - for (let item of this.subMenu.menu.children()) { + for (const item of this.subMenu.menu.children()) { if (!(item instanceof component)) { continue } @@ -307,7 +307,7 @@ class SettingsMenuItem extends MenuItem { } setMargin () { - let [width] = this.size + const [ width ] = this.size this.settingsSubMenuEl_.style.marginRight = `-${width}px` } diff --git a/client/src/assets/player/webtorrent/peertube-chunk-store.ts b/client/src/assets/player/webtorrent/peertube-chunk-store.ts index 54cc0ea64..66762bef8 100644 --- a/client/src/assets/player/webtorrent/peertube-chunk-store.ts +++ b/client/src/assets/player/webtorrent/peertube-chunk-store.ts @@ -131,7 +131,7 @@ export class PeertubeChunkStore extends EventEmitter { // Chunk in store this.db.transaction('r', this.db.chunks, async () => { const result = await this.db.chunks.get({ id: index }) - if (result === undefined) return cb(null, new Buffer(0)) + if (result === undefined) return cb(null, Buffer.alloc(0)) const buf = result.buf if (!opts) return this.nextTick(cb, null, buf) @@ -162,13 +162,13 @@ export class PeertubeChunkStore extends EventEmitter { } if (this.db) { - await this.db.close() + this.db.close() await this.dropDatabase(this.databaseName) } if (this.expirationDB) { - await this.expirationDB.close() + this.expirationDB.close() this.expirationDB = null } diff --git a/client/src/assets/player/webtorrent/video-renderer.ts b/client/src/assets/player/webtorrent/video-renderer.ts index a3415937b..4dce87112 100644 --- a/client/src/assets/player/webtorrent/video-renderer.ts +++ b/client/src/assets/player/webtorrent/video-renderer.ts @@ -29,7 +29,7 @@ function renderVideo ( function renderMedia (file: any, elem: HTMLVideoElement, opts: RenderMediaOptions, callback: (err: Error, renderer?: any) => void) { const extension = extname(file.name).toLowerCase() - let preparedElem: any = undefined + let preparedElem: any let currentTime = 0 let renderer: any diff --git a/client/src/assets/player/webtorrent/webtorrent-plugin.ts b/client/src/assets/player/webtorrent/webtorrent-plugin.ts index c7182acc9..eee3d4db9 100644 --- a/client/src/assets/player/webtorrent/webtorrent-plugin.ts +++ b/client/src/assets/player/webtorrent/webtorrent-plugin.ts @@ -347,7 +347,7 @@ class WebTorrentPlugin extends Plugin { if (!averageDownloadSpeed) averageDownloadSpeed = this.getAndSaveActualDownloadSpeed() // Limit resolution according to player height - const playerHeight = this.playerElement.offsetHeight as number + const playerHeight = this.playerElement.offsetHeight // We take the first resolution just above the player height // Example: player height is 530px, we want the 720p file instead of 480p diff --git a/client/src/polyfills.ts b/client/src/polyfills.ts index 368908432..b68c07fdb 100644 --- a/client/src/polyfills.ts +++ b/client/src/polyfills.ts @@ -76,6 +76,7 @@ import 'core-js/es7/object' /*************************************************************************************************** * Zone JS is required by default for Angular itself. */ +// tslint:disable import 'zone.js/dist/zone' // Included with Angular CLI. /*************************************************************************************************** diff --git a/client/src/standalone/player/definitions.ts b/client/src/standalone/player/definitions.ts index 7f9ef9b6f..afd10541b 100644 --- a/client/src/standalone/player/definitions.ts +++ b/client/src/standalone/player/definitions.ts @@ -1,6 +1,4 @@ -export interface EventHandler { - (ev: T): void -} +export type EventHandler = (ev: T) => void export type PlayerEventType = 'pause' | 'play' | diff --git a/client/src/standalone/player/events.ts b/client/src/standalone/player/events.ts index f1639ef19..28a13c727 100644 --- a/client/src/standalone/player/events.ts +++ b/client/src/standalone/player/events.ts @@ -13,13 +13,13 @@ export class EventRegistrar { private eventRegistrations: PlayerEventRegistrationMap = {} public bindToChannel (channel: Channel.MessagingChannel) { - for (let name of Object.keys(this.eventRegistrations)) { + for (const name of Object.keys(this.eventRegistrations)) { channel.bind(name, (txn, params) => this.fire(name, params)) } } public registerTypes (names: string[]) { - for (let name of names) { + for (const name of names) { this.eventRegistrations[ name ] = { registrations: [] } } } diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.ts index b55b4bace..626d55a7c 100644 --- a/client/src/standalone/videos/embed.ts +++ b/client/src/standalone/videos/embed.ts @@ -40,7 +40,7 @@ class PeerTubeEmbedApi { } private constructChannel () { - let channel = Channel.build({ window: window.parent, origin: '*', scope: this.embed.scope }) + const channel = Channel.build({ window: window.parent, origin: '*', scope: this.embed.scope }) channel.bind('play', (txn, params) => this.embed.player.play()) channel.bind('pause', (txn, params) => this.embed.player.pause()) @@ -82,8 +82,8 @@ class PeerTubeEmbedApi { let currentState: 'playing' | 'paused' | 'unstarted' = 'unstarted' setInterval(() => { - let position = this.element.currentTime - let volume = this.element.volume + const position = this.element.currentTime + const volume = this.element.volume this.channel.notify({ method: 'playbackStatusUpdate', @@ -114,8 +114,8 @@ class PeerTubeEmbedApi { } private loadWebTorrentResolutions () { - let resolutions = [] - let currentResolutionId = this.embed.player.webtorrent().getCurrentResolutionId() + const resolutions = [] + const currentResolutionId = this.embed.player.webtorrent().getCurrentResolutionId() for (const videoFile of this.embed.player.webtorrent().videoFiles) { let label = videoFile.resolution.label @@ -235,7 +235,7 @@ class PeerTubeEmbed { private loadParams () { try { - let params = new URL(window.location.toString()).searchParams + const params = new URL(window.location.toString()).searchParams this.autoplay = this.getParamToggle(params, 'autoplay') this.controls = this.getParamToggle(params, 'controls') diff --git a/client/src/standalone/videos/test-embed.ts b/client/src/standalone/videos/test-embed.ts index 30a298573..8e83d92a9 100644 --- a/client/src/standalone/videos/test-embed.ts +++ b/client/src/standalone/videos/test-embed.ts @@ -7,13 +7,13 @@ window.addEventListener('load', async () => { const lastPart = urlParts[ urlParts.length - 1 ] const videoId = lastPart.indexOf('?') === -1 ? lastPart : lastPart.split('?')[ 0 ] - let iframe = document.createElement('iframe') + const iframe = document.createElement('iframe') iframe.src = `/videos/embed/${videoId}?autoplay=1&controls=0&api=1` - let mainElement = document.querySelector('#host') + const mainElement = document.querySelector('#host') mainElement.appendChild(iframe) console.log(`Document finished loading.`) - let player = new PeerTubePlayer(document.querySelector('iframe')) + const player = new PeerTubePlayer(document.querySelector('iframe')) window[ 'player' ] = player @@ -21,7 +21,7 @@ window.addEventListener('load', async () => { await player.ready console.log(`Player is ready.`) - let monitoredEvents = [ + const monitoredEvents = [ 'pause', 'play', 'playbackStatusUpdate', @@ -36,18 +36,18 @@ window.addEventListener('load', async () => { let playbackRates: number[] = [] let currentRate = await player.getPlaybackRate() - let updateRates = async () => { - let rateListEl = document.querySelector('#rate-list') + const updateRates = async () => { + const rateListEl = document.querySelector('#rate-list') rateListEl.innerHTML = '' playbackRates.forEach(rate => { if (currentRate === rate) { - let itemEl = document.createElement('strong') + const itemEl = document.createElement('strong') itemEl.innerText = `${rate} (active)` itemEl.style.display = 'block' rateListEl.appendChild(itemEl) } else { - let itemEl = document.createElement('a') + const itemEl = document.createElement('a') itemEl.href = 'javascript:;' itemEl.innerText = rate.toString() itemEl.addEventListener('click', () => { @@ -66,18 +66,18 @@ window.addEventListener('load', async () => { updateRates() }) - let updateResolutions = ((resolutions: PeerTubeResolution[]) => { - let resolutionListEl = document.querySelector('#resolution-list') + const updateResolutions = ((resolutions: PeerTubeResolution[]) => { + const resolutionListEl = document.querySelector('#resolution-list') resolutionListEl.innerHTML = '' resolutions.forEach(resolution => { if (resolution.active) { - let itemEl = document.createElement('strong') + const itemEl = document.createElement('strong') itemEl.innerText = `${resolution.label} (active)` itemEl.style.display = 'block' resolutionListEl.appendChild(itemEl) } else { - let itemEl = document.createElement('a') + const itemEl = document.createElement('a') itemEl.href = 'javascript:;' itemEl.innerText = resolution.label itemEl.addEventListener('click', () => { -- cgit v1.2.3