ActivityPub-federated video streaming platform using P2P directly in your web browser
Add bulk update videos in playlists
Chocobozzz02e328734302
diff --git a/client/src/app/+my-library/my-videos/my-videos.component.html b/client/src/app/+my-library/my-videos/my-videos.component.htmlindex 4bdae07712..ad7c18fc34 100644--- a/client/src/app/+my-library/my-videos/my-videos.component.html+++ b/client/src/app/+my-library/my-videos/my-videos.component.html@@ -140,3 +140,4 @@</my-table>+<my-bulk-update-videos-in-playlist-modal #bulkUpdateVideosInPlaylistModal (saved)="fetchVideosContainedInPlaylists($event)"></my-bulk-update-videos-in-playlist-modal>diff --git a/client/src/app/+my-library/my-videos/my-videos.component.ts b/client/src/app/+my-library/my-videos/my-videos.component.tsindex b4d774e7b4..7448ff8d49 100644--- a/client/src/app/+my-library/my-videos/my-videos.component.ts+++ b/client/src/app/+my-library/my-videos/my-videos.component.ts@@ -10,6 +10,7 @@ import { PeerTubeBadgeService } from '@app/shared/shared-main/common/peertube-baimport { Video } from '@app/shared/shared-main/video/video.model'import { VideoService } from '@app/shared/shared-main/video/video.service'import { TableColumnInfo, TableComponent, TableQueryParams } from '@app/shared/shared-tables/table.component'+import { BulkUpdateVideosInPlaylistModalComponent } from '@app/shared/shared-video-playlist/bulk-update-videos-in-playlist-modal.component'import { VideoPlaylistService } from '@app/shared/shared-video-playlist/video-playlist.service'import { NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap'import { arrayify } from '@peertube/peertube-core-utils'@@ -66,7 +67,8 @@ type DataLoaderParameter = Parameters<MyVideosComponent['_dataLoader']>[0]PTDatePipe,VideoNSFWBadgeComponent,TableComponent,- PrivacyBadgeComponent+ PrivacyBadgeComponent,+ BulkUpdateVideosInPlaylistModalComponent]})export class MyVideosComponent implements OnInit, OnDestroy {@@ -81,6 +83,7 @@ export class MyVideosComponent implements OnInit, OnDestroy {private route = inject(ActivatedRoute)readonly table = viewChild<TableComponent<Video, DataLoaderParameter, ColumnName, QueryParams>>('table')+ readonly bulkUpdateVideosInPlaylistModal = viewChild<BulkUpdateVideosInPlaylistModalComponent>('bulkUpdateVideosInPlaylistModal')videosContainedInPlaylists: VideosExistInPlaylists = {}@@ -254,7 +257,7 @@ export class MyVideosComponent implements OnInit, OnDestroy {}).pipe(tap(({ data }) => this.fetchVideosContainedInPlaylists(data)))}- fetchVideosContainedInPlaylists (videos: Video[]) {+ fetchVideosContainedInPlaylists (videos: Pick<Video, 'id'>[]) {this.playlistService.doVideosExistInPlaylist(videos.map(v => v.id)).subscribe(result => {this.videosContainedInPlaylists = Object.keys(result).reduce((acc, videoId) => ({@@ -296,6 +299,16 @@ export class MyVideosComponent implements OnInit, OnDestroy {private buildActions () {this.bulkActions = [+ [+ {+ label: $localize`Add to playlist...`,+ handler: videos => {+ this.bulkUpdateVideosInPlaylistModal().show({ videos, videosContainedInPlaylists: this.videosContainedInPlaylists })+ },+ iconName: 'playlist-add'+ }+ ],+[{label: $localize`Delete`,diff --git a/client/src/app/shared/form-validators/video-playlist-validators.ts b/client/src/app/shared/form-validators/video-playlist-validators.tsindex 3cddcaad24..cad5dfc06b 100644--- a/client/src/app/shared/form-validators/video-playlist-validators.ts+++ b/client/src/app/shared/form-validators/video-playlist-validators.ts@@ -1,6 +1,7 @@-import { Validators, AbstractControl } from '@angular/forms'-import { BuildFormValidator } from './form-validator.model'+import { AbstractControl, Validators } from '@angular/forms'+import { maxLength, minLength, required, SchemaPath } from '@angular/forms/signals'import { VideoPlaylistPrivacy, VideoPlaylistPrivacyType } from '@peertube/peertube-models'+import { BuildFormValidator } from './form-validator.model'export const VIDEO_PLAYLIST_DISPLAY_NAME_VALIDATOR: BuildFormValidator = {VALIDATORS: [@@ -15,6 +16,14 @@ export const VIDEO_PLAYLIST_DISPLAY_NAME_VALIDATOR: BuildFormValidator = {}}+export function playlistDisplayNameValidator (displayName: SchemaPath<string>) {+ required(displayName, { message: $localize`Display name is required.` })+ minLength(displayName, 1, { message: $localize`Display name must be at least 1 character long.` })+ maxLength(displayName, 120, { message: $localize`Display name cannot be more than 120 characters long.` })+}++// ---------------------------------------------------------------------------+export const VIDEO_PLAYLIST_PRIVACY_VALIDATOR: BuildFormValidator = {VALIDATORS: [Validators.requireddiff --git a/client/src/app/shared/shared-forms/form-input-error.directive.ts b/client/src/app/shared/shared-forms/form-input-error.directive.tsnew file mode 100644index 0000000000..0b1b39f49c--- /dev/null+++ b/client/src/app/shared/shared-forms/form-input-error.directive.ts@@ -0,0 +1,17 @@+import { Directive, input } from '@angular/core'+import { FieldState } from '@angular/forms/signals'++@Directive({+ selector: '[myFormInputError]',+ standalone: true,+ host: {+ '[class.input-error]': 'hasError()'+ }+})+export class FormInputErrorDirective {+ readonly myFormInputError = input.required<FieldState<any>>()++ hasError () {+ return this.myFormInputError().touched() && this.myFormInputError().invalid()+ }+}diff --git a/client/src/app/shared/shared-main/buttons/action-dropdown.component.html b/client/src/app/shared/shared-main/buttons/action-dropdown.component.htmlindex de3c0317e9..4eab7114c9 100644--- a/client/src/app/shared/shared-main/buttons/action-dropdown.component.html+++ b/client/src/app/shared/shared-main/buttons/action-dropdown.component.html@@ -43,6 +43,8 @@<my-global-icon [iconName]="action.iconName" [ngClass]="'icon-' + action.iconName" aria-hidden="true"></my-global-icon>} @else if (action.actorAvatar) {<my-actor-avatar size="24" [actor]="action.actorAvatar.actor" [actorType]="action.actorAvatar.type"></my-actor-avatar>+ } @else if (hasAtLeastAnIconOrAvatar) {+ <div class="icon-placeholder"></div>}<div class="item-label">diff --git a/client/src/app/shared/shared-main/buttons/action-dropdown.component.scss b/client/src/app/shared/shared-main/buttons/action-dropdown.component.scssindex eb28b12af4..ad8c0200e6 100644--- a/client/src/app/shared/shared-main/buttons/action-dropdown.component.scss+++ b/client/src/app/shared/shared-main/buttons/action-dropdown.component.scss@@ -97,3 +97,9 @@ button {@include margin-left(0.5rem !important);}++.icon-placeholder {+ width: 22px;++ @include margin-right(0.5rem);+}diff --git a/client/src/app/shared/shared-main/buttons/action-dropdown.component.ts b/client/src/app/shared/shared-main/buttons/action-dropdown.component.tsindex f41c09f0e4..fc175a064f 100644--- a/client/src/app/shared/shared-main/buttons/action-dropdown.component.ts+++ b/client/src/app/shared/shared-main/buttons/action-dropdown.component.ts@@ -78,6 +78,7 @@ export class ActionDropdownComponent<T, D = never> implements OnChanges {labelExtra: TemplateRef<any>buttonClasses: Record<string, boolean> = {}+ hasAtLeastAnIconOrAvatar = falsengOnChanges () {this.buttonClasses = {@@ -88,6 +89,8 @@ export class ActionDropdownComponent<T, D = never> implements OnChanges {'primary-button': this.buttonStyled() && this.theme() === 'primary','button-unstyle': !this.buttonStyled()}++ this.hasAtLeastAnIconOrAvatar = this.getActions().some(actions => actions.some(a => a.iconName || a.actorAvatar))}getActions (): DropdownAction<T, D>[][] {diff --git a/client/src/app/shared/shared-video-miniature/video-miniature.component.ts b/client/src/app/shared/shared-video-miniature/video-miniature.component.tsindex 3ccdfade35..6f355034a7 100644--- a/client/src/app/shared/shared-video-miniature/video-miniature.component.ts+++ b/client/src/app/shared/shared-video-miniature/video-miniature.component.ts@@ -275,23 +275,27 @@ export class VideoMiniatureComponent implements OnInit {this.videoPlaylistService.addVideoInPlaylist(this.watchLaterPlaylist.id, body).subscribe(- res => {+ ([ res ]) => {this.watchLaterPlaylist.playlistElementId = res.videoPlaylistElement.id})}removeFromWatchLater () {- this.videoPlaylistService.removeVideoFromPlaylist(- this.watchLaterPlaylist.id,- this.watchLaterPlaylist.playlistElementId,- this.video().id- )- .subscribe(- _ => {- // empty+ this.videoPlaylistService.removeElementsFromPlaylist({+ playlistId: this.watchLaterPlaylist.id,++ elements: [+ {+ playlistElementId: this.watchLaterPlaylist.playlistElementId,+ videoId: this.video().id}- )+ ]+ }).subscribe(+ _ => {+ // empty+ }+ )}isWatchLaterPlaylistDisplayed () {diff --git a/client/src/app/shared/shared-video-playlist/bulk-update-videos-in-playlist-modal.component.html b/client/src/app/shared/shared-video-playlist/bulk-update-videos-in-playlist-modal.component.htmlnew file mode 100644index 0000000000..751fe0ecf7--- /dev/null+++ b/client/src/app/shared/shared-video-playlist/bulk-update-videos-in-playlist-modal.component.html@@ -0,0 +1,47 @@+<ng-template #modal>+ <div class="modal-header">+ <h4 i18n class="modal-title">Update videos in playlists</h4>++ <button class="border-0 p-0" title="Close this modal" i18n-title (click)="hide()">+ <my-global-icon iconName="cross"></my-global-icon>+ </button>+ </div>++ <div class="modal-body">+ <div class="mb-4">+ <input type="text" placeholder="Search playlists" i18n-placeholder [(ngModel)]="videoPlaylistSearch" (ngModelChange)="onVideoPlaylistSearchChanged()" />+ </div>++ <div class="playlists">+ @for (playlist of currentPlaylists; track playlist) {+ <div class="playlist d-flex gap-2 mb-2">+ <my-peertube-checkbox [inputName]="getPrimaryInputName(playlist)" [(ngModel)]="playlistsEnabled[playlist.id]" [labelText]="playlist.displayName"></my-peertube-checkbox>++ @if (user.isCollaboratingToChannels()) {+ @if (user.isOwnerOfChannel(playlist.videoChannel)) {+ <my-collaborator-state class="ms-2" type="owner" small="true"></my-collaborator-state>+ } @else if (user.isEditorOfChannel(playlist.videoChannel)) {+ <my-collaborator-state class="ms-2" type="accepted" small="true"></my-collaborator-state>+ }+ }+ </div>+ }+ </div>++ <button class="mt-4 peertube-button secondary-button" (click)="isNewPlaylistBlockOpened = true" [hidden]="isNewPlaylistBlockOpened">+ <my-global-icon iconName="add" aria-hidden="true"></my-global-icon>++ <span i18n>Create a private playlist</span>+ </button>++ @if (isNewPlaylistBlockOpened) {+ <my-playlist-create-block class="d-block mt-3 pt-3" (playlistCreated)="onPlaylistCreated()" />+ }+ </div>++ <div class="modal-footer inputs">+ <input type="button" role="button" i18n-value value="Cancel" class="peertube-button secondary-button" (click)="hide()" (key.enter)="hide()">++ <my-button theme="primary" [loading]="updatingPlaylists" [disabled]="updatingPlaylists" (click)="save()" i18n>Save</my-button>+ </div>+</ng-template>diff --git a/client/src/app/shared/shared-video-playlist/bulk-update-videos-in-playlist-modal.component.scss b/client/src/app/shared/shared-video-playlist/bulk-update-videos-in-playlist-modal.component.scssnew file mode 100644index 0000000000..55cbaa056d--- /dev/null+++ b/client/src/app/shared/shared-video-playlist/bulk-update-videos-in-playlist-modal.component.scss@@ -0,0 +1,27 @@+@use "_variables" as *;+@use "_mixins" as *;+@use "_form-mixins" as *;++my-peertube-checkbox {+ align-self: center;++ @include margin-right(10px);+}++.display-name {+ display: flex;+ align-items: flex-end;+ flex-grow: 1;+ margin: 0;+ font-weight: $font-regular;+ cursor: pointer;+ font-size: 1rem;+}++my-playlist-create-block {+ border-top: 1px solid $separator-border-color;+}++input[type="text"] {+ @include peertube-input-text(100%);+}diff --git a/client/src/app/shared/shared-video-playlist/bulk-update-videos-in-playlist-modal.component.ts b/client/src/app/shared/shared-video-playlist/bulk-update-videos-in-playlist-modal.component.tsnew file mode 100644index 0000000000..b22748e800--- /dev/null+++ b/client/src/app/shared/shared-video-playlist/bulk-update-videos-in-playlist-modal.component.ts@@ -0,0 +1,264 @@+import { Component, ElementRef, inject, OnDestroy, OnInit, output, viewChild } from '@angular/core'+import { FormsModule } from '@angular/forms'+import { AuthService, Notifier } from '@app/core'+import { formatICU } from '@app/helpers'+import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal'+import { uniqify } from '@peertube/peertube-core-utils'+import { Video, VideoPlaylistElementCreate, VideosExistInPlaylists } from '@peertube/peertube-models'+import debug from 'debug'+import { concat, Observable, of, Subject, Subscription } from 'rxjs'+import { catchError, debounceTime, map, switchMap } from 'rxjs/operators'+import { PeertubeCheckboxComponent } from '../shared-forms/peertube-checkbox.component'+import { GlobalIconComponent } from '../shared-icons/global-icon.component'+import { ButtonComponent } from '../shared-main/buttons/button.component'+import { CollaboratorStateComponent } from '../shared-main/channel/collaborator-state.component'+import { PlaylistCreateBlockComponent } from './shared/playlist-create-block.component'+import { CachedPlaylist, VideoPlaylistService } from './video-playlist.service'++const debugLogger = debug('peertube:playlists:BulkUpdateVideosInPlaylistModalComponent')++type PlaylistElement = {+ playlistElementId: number+ videoId: number+}++@Component({+ selector: 'my-bulk-update-videos-in-playlist-modal',+ styleUrls: [ './bulk-update-videos-in-playlist-modal.component.scss' ],+ templateUrl: './bulk-update-videos-in-playlist-modal.component.html',+ imports: [+ FormsModule,+ PeertubeCheckboxComponent,+ GlobalIconComponent,+ CollaboratorStateComponent,+ ButtonComponent,+ PlaylistCreateBlockComponent+ ]+})+export class BulkUpdateVideosInPlaylistModalComponent implements OnInit, OnDestroy {+ private authService = inject(AuthService)+ private notifier = inject(Notifier)+ private videoPlaylistService = inject(VideoPlaylistService)+ private modalService = inject(NgbModal)++ readonly saved = output<Video[]>()++ videos: Video[]++ videoPlaylistSearch: string+ videoPlaylistSearchChanged = new Subject<void>()++ // playlistId => playlist+ seenPlaylists: Record<number, CachedPlaylist> = {}+ currentPlaylists: CachedPlaylist[] = []++ elementsPerPlaylist: Record<number, PlaylistElement[]> = {}++ playlistsEnabled: Record<number, boolean> = {}+ initialPlaylistsEnabled: Record<number, boolean> = {}++ isNewPlaylistBlockOpened = false+ updatingPlaylists = false++ readonly modal = viewChild<ElementRef>('modal')++ private openedModal: NgbModalRef+ private videosContainedInPlaylists: VideosExistInPlaylists++ private listenToAccountPlaylistsChangeSub: Subscription++ get user () {+ return this.authService.getUser()+ }++ get videoIds () {+ return this.videos.map(video => video.id)+ }++ ngOnInit () {+ this.videoPlaylistService.listMyPlaylistWithCache(this.user, this.videoPlaylistSearch)+ .subscribe(playlistsResult => this.currentPlaylists = playlistsResult.data)++ this.listenToAccountPlaylistsChangeSub = this.videoPlaylistService.listenToMyAccountPlaylistsChange()+ .subscribe(result => {+ this.currentPlaylists = result.data++ this.rebuildPlaylists()+ })++ this.videoPlaylistSearchChanged+ .pipe(+ debounceTime(500),+ switchMap(() => this.videoPlaylistService.listMyPlaylistWithCache(this.user, this.videoPlaylistSearch))+ ).subscribe(({ data }) => {+ this.currentPlaylists = data++ this.rebuildPlaylists()+ })+ }++ ngOnDestroy () {+ this.listenToAccountPlaylistsChangeSub?.unsubscribe()+ }++ show (options: {+ videos: Video[]+ videosContainedInPlaylists: VideosExistInPlaylists+ }) {+ this.videos = options.videos+ this.videosContainedInPlaylists = options.videosContainedInPlaylists++ this.elementsPerPlaylist = {}++ this.playlistsEnabled = {}+ this.initialPlaylistsEnabled = {}++ this.isNewPlaylistBlockOpened = false++ this.rebuildPlaylists()++ this.openedModal = this.modalService.open(this.modal(), { centered: true, keyboard: false })+ }++ hide () {+ this.openedModal.close()+ }++ private rebuildPlaylists () {+ if (!this.videosContainedInPlaylists) return++ for (const playlist of this.currentPlaylists) {+ this.elementsPerPlaylist[playlist.id] = []+ this.seenPlaylists[playlist.id] = playlist+ }++ // Populate videoId elements per playlist based on the videosContainedInPlaylists result+ for (const [ videoId, videoExistInPlaylist ] of Object.entries(this.videosContainedInPlaylists)) {+ for (const element of videoExistInPlaylist) {+ // Not one of the displayed playlists, move on+ if (!this.elementsPerPlaylist[element.playlistId]) continue++ this.elementsPerPlaylist[element.playlistId].push({+ videoId: +videoId,+ playlistElementId: element.playlistElementId+ })+ }+ }++ // Determine for which playlists all videos are already in, and enable those+ for (const [ playlistIdStr, elements ] of Object.entries(this.elementsPerPlaylist)) {+ const playlistId = +playlistIdStr++ if (this.playlistsEnabled[playlistId] !== undefined) continue++ this.playlistsEnabled[playlistId] = uniqify(elements.map(e => e.videoId)).length === this.videoIds.length+ this.initialPlaylistsEnabled[playlistId] = this.playlistsEnabled[playlistId]+ }++ debugLogger('Rebuilt playlists, enabled playlists:', this.playlistsEnabled)+ }++ onVideoPlaylistSearchChanged () {+ this.videoPlaylistSearchChanged.next()+ }++ getPrimaryInputName (playlist: CachedPlaylist) {+ return 'videos-update-playlist-' + playlist.id+ }++ // ---------------------------------------------------------------------------++ save () {+ const observableList: Observable<{ type: 'success' | 'error', message: string }>[] = []+ this.updatingPlaylists = true++ for (const [ playlistIdStr, enabled ] of Object.entries(this.playlistsEnabled)) {+ const playlistId = +playlistIdStr++ const playlist = this.seenPlaylists[playlistId]++ const isEnabledInitially = this.initialPlaylistsEnabled[playlistId]++ if (enabled && !isEnabledInitially) {+ observableList.push(this.addVideosInPlaylist(playlist))+ } else if (!enabled && isEnabledInitially) {+ observableList.push(this.removeVideosFromPlaylist(playlist))+ }+ }++ if (observableList.length === 0) {+ this.updatingPlaylists = false+ this.notifier.info($localize`No change to save`)+ this.hide()+ return+ }++ concat(...observableList)+ .subscribe({+ next: result => {+ if (result.type === 'success') {+ this.notifier.success(result.message)+ } else {+ this.notifier.error(result.message)+ }+ },++ error: err => this.notifier.handleError(err),++ complete: () => {+ this.updatingPlaylists = false+ this.hide()+ this.saved.emit(this.videos)+ }+ })+ }++ private addVideosInPlaylist (playlist: CachedPlaylist) {+ const existing = new Set(this.elementsPerPlaylist[playlist.id].map(e => e.videoId))+ const body: VideoPlaylistElementCreate[] = this.videos+ .filter(v => !existing.has(v.id))+ .map(v => ({ videoId: v.id }))++ return this.videoPlaylistService.addVideoInPlaylist(playlist.id, body)+ .pipe(+ map(results => {+ return {+ type: 'success' as const,+ message: formatICU(+ $localize`{count, plural, =1 {Video added} other {{count} videos added}} to {playlistName}`,+ { count: results.length, playlistName: playlist.displayName }+ )+ }+ }),+ catchError(err => of({ type: 'error' as const, message: err.message }))+ )+ }++ private removeVideosFromPlaylist (playlist: CachedPlaylist) {+ return this.videoPlaylistService.removeElementsFromPlaylist({+ playlistId: playlist.id,+ elements: this.elementsPerPlaylist[playlist.id].map(element => ({+ playlistElementId: element.playlistElementId,+ videoId: element.videoId+ }))+ }).pipe(+ map(results => {+ return {+ type: 'success' as const,+ message: formatICU(+ $localize`{count, plural, =1 {Video removed} other {{count} videos removed}} from {playlistName}`,+ { count: results.length, playlistName: playlist.displayName }+ )+ }+ }),+ catchError(err => of({ type: 'error' as const, message: err.message }))+ )+ }++ // ---------------------------------------------------------------------------++ onPlaylistCreated () {+ this.isNewPlaylistBlockOpened = false+ this.rebuildPlaylists()+ }+}diff --git a/client/src/app/shared/shared-video-playlist/shared/playlist-create-block.component.html b/client/src/app/shared/shared-video-playlist/shared/playlist-create-block.component.htmlnew file mode 100644index 0000000000..a82d02da38--- /dev/null+++ b/client/src/app/shared/shared-video-playlist/shared/playlist-create-block.component.html@@ -0,0 +1,16 @@+<form (ngSubmit)="createPlaylist()">+ <div class="form-group">+ <label i18n for="displayName">Display name</label>+ <input+ type="text"+ id="displayName"+ class="form-control"+ [formField]="playlistForm['displayName']"+ [myFormInputError]="playlistForm.displayName()"+ >++ <my-form-error [field]="playlistForm.displayName()"></my-form-error>+ </div>++ <input type="submit" class="peertube-button primary-button" i18n-value value="Create" [disabled]="!playlistForm().valid()">+</form>diff --git a/client/src/app/shared/shared-video-playlist/shared/playlist-create-block.component.scss b/client/src/app/shared/shared-video-playlist/shared/playlist-create-block.component.scssnew file mode 100644index 0000000000..3902ba8c81--- /dev/null+++ b/client/src/app/shared/shared-video-playlist/shared/playlist-create-block.component.scss@@ -0,0 +1,20 @@+@use "_variables" as *;+@use "_mixins" as *;+@use "_form-mixins" as *;++my-global-icon {+ position: relative;+ left: -1px;+ top: -1px;+ width: 21px;+ height: 21px;+ line-height: 21px;+ display: inline-block;+ color: pvar(--fg-400);++ @include margin-right(13px);+}++input[type="text"] {+ @include peertube-input-text(100%);+}diff --git a/client/src/app/shared/shared-video-playlist/shared/playlist-create-block.component.ts b/client/src/app/shared/shared-video-playlist/shared/playlist-create-block.component.tsnew file mode 100644index 0000000000..e124164682--- /dev/null+++ b/client/src/app/shared/shared-video-playlist/shared/playlist-create-block.component.ts@@ -0,0 +1,51 @@+import { Component, inject, output, signal } from '@angular/core'+import { FormsModule, ReactiveFormsModule } from '@angular/forms'+import { form, FormField } from '@angular/forms/signals'+import { Notifier } from '@app/core'+import { FormInputErrorDirective } from '@app/shared/shared-forms/form-input-error.directive'+import { VideoPlaylistCreate, VideoPlaylistPrivacy } from '@peertube/peertube-models'+import { playlistDisplayNameValidator } from '../../form-validators/video-playlist-validators'+import { FormErrorComponent } from '../../shared-forms/form-error.component'+import { VideoPlaylistService } from '../video-playlist.service'++@Component({+ selector: 'my-playlist-create-block',+ templateUrl: './playlist-create-block.component.html',+ styleUrls: [ './playlist-create-block.component.scss' ],+ imports: [+ FormsModule,+ ReactiveFormsModule,+ FormInputErrorDirective,+ FormField,+ FormErrorComponent+ ]+})+export class PlaylistCreateBlockComponent {+ private notifier = inject(Notifier)+ private videoPlaylistService = inject(VideoPlaylistService)++ readonly playlistCreated = output()++ readonly playlistModel = signal<{ displayName: string }>({ displayName: '' })+ readonly playlistForm = form(this.playlistModel, f => {+ playlistDisplayNameValidator(f.displayName)+ })++ createPlaylist () {+ const displayName = this.playlistModel().displayName.trim()++ const videoPlaylistCreate: VideoPlaylistCreate = {+ displayName,+ privacy: VideoPlaylistPrivacy.PRIVATE+ }++ this.videoPlaylistService.createVideoPlaylist(videoPlaylistCreate)+ .subscribe({+ next: () => {+ this.playlistCreated.emit()+ },++ error: err => this.notifier.handleError(err)+ })+ }+}diff --git a/client/src/app/shared/shared-video-playlist/video-add-to-playlist.component.html b/client/src/app/shared/shared-video-playlist/video-add-to-playlist.component.htmlindex e8a3b7eca6..f510b3473c 100644--- a/client/src/app/shared/shared-video-playlist/video-add-to-playlist.component.html+++ b/client/src/app/shared/shared-video-playlist/video-add-to-playlist.component.html@@ -75,20 +75,6 @@</button>@if (isNewPlaylistBlockOpened) {- <form class="new-playlist-block" (ngSubmit)="createPlaylist()" [formGroup]="form">- <div class="form-group">- <label i18n for="displayName">Display name</label>- <input- type="text" id="displayName" class="form-control"- formControlName="displayName" [ngClass]="{ 'input-error': formErrors['displayName'] }"- >-- @if (formErrors['displayName']) {- <div class="form-error" role="alert">{{ formErrors['displayName'] }}</div>- }- </div>-- <input type="submit" class="peertube-button primary-button" i18n-value value="Create" [disabled]="!form.valid">- </form>+ <my-playlist-create-block (playlistCreated)="onPlaylistCreated()" />}</div>diff --git a/client/src/app/shared/shared-video-playlist/video-add-to-playlist.component.scss b/client/src/app/shared/shared-video-playlist/video-add-to-playlist.component.scssindex 250ab5d4f7..29d68f84d6 100644--- a/client/src/app/shared/shared-video-playlist/video-add-to-playlist.component.scss+++ b/client/src/app/shared/shared-video-playlist/video-add-to-playlist.component.scss@@ -6,10 +6,14 @@ my-timestamp-input {width: 100px;}+my-playlist-create-block {+ display: block;+}+.header,.dropdown-item,.input-container,-.new-playlist-block {+my-playlist-create-block {padding: 8px 24px;}@@ -118,7 +122,7 @@ my-timestamp-input {}.new-playlist-button,-.new-playlist-block {+my-playlist-create-block {padding-top: 10px;border-top: 1px solid $separator-border-color;}diff --git a/client/src/app/shared/shared-video-playlist/video-add-to-playlist.component.ts b/client/src/app/shared/shared-video-playlist/video-add-to-playlist.component.tsindex 41d5f736d4..0419601565 100644--- a/client/src/app/shared/shared-video-playlist/video-add-to-playlist.component.ts+++ b/client/src/app/shared/shared-video-playlist/video-add-to-playlist.component.ts@@ -13,26 +13,16 @@ import {} from '@angular/core'import { FormsModule, ReactiveFormsModule } from '@angular/forms'import { AuthService, DisableForReuseHook, Notifier } from '@app/core'-import { FormReactive } from '@app/shared/shared-forms/form-reactive'-import { FormReactiveService } from '@app/shared/shared-forms/form-reactive.service'import { secondsToTime } from '@peertube/peertube-core-utils'-import {- CachedVideoExistInPlaylist,- Video,- VideoChannelSummary,- VideoPlaylistCreate,- VideoPlaylistElementCreate,- VideoPlaylistElementUpdate,- VideoPlaylistPrivacy-} from '@peertube/peertube-models'+import { CachedVideoExistInPlaylist, Video, VideoChannelSummary, VideoPlaylistElementCreate } from '@peertube/peertube-models'import debug from 'debug'import { Subject, Subscription } from 'rxjs'import { debounceTime, filter } from 'rxjs/operators'-import { VIDEO_PLAYLIST_DISPLAY_NAME_VALIDATOR } from '../form-validators/video-playlist-validators'import { PeertubeCheckboxComponent } from '../shared-forms/peertube-checkbox.component'import { TimestampInputComponent } from '../shared-forms/timestamp-input.component'import { GlobalIconComponent } from '../shared-icons/global-icon.component'import { CollaboratorStateComponent } from '../shared-main/channel/collaborator-state.component'+import { PlaylistCreateBlockComponent } from './shared/playlist-create-block.component'import { CachedPlaylist, VideoPlaylistService } from './video-playlist.service'const debugLogger = debug('peertube:playlists:VideoAddToPlaylistComponent')@@ -65,11 +55,11 @@ type PlaylistSummary = {GlobalIconComponent,TimestampInputComponent,ReactiveFormsModule,- CollaboratorStateComponent+ CollaboratorStateComponent,+ PlaylistCreateBlockComponent]})-export class VideoAddToPlaylistComponent extends FormReactive implements OnInit, OnChanges, OnDestroy, DisableForReuseHook {- protected formReactiveService = inject(FormReactiveService)+export class VideoAddToPlaylistComponent implements OnInit, OnChanges, OnDestroy, DisableForReuseHook {private authService = inject(AuthService)private notifier = inject(Notifier)private videoPlaylistService = inject(VideoPlaylistService)@@ -100,10 +90,6 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit,}ngOnInit () {- this.buildForm({- displayName: VIDEO_PLAYLIST_DISPLAY_NAME_VALIDATOR- })-this.listenToAccountPlaylistsChangeSub = this.videoPlaylistService.listenToMyAccountPlaylistsChange().subscribe(result => {this.playlistsData = result.data@@ -166,6 +152,12 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit,this.isNewPlaylistBlockOpened = true}+ onPlaylistCreated () {+ this.isNewPlaylistBlockOpened = false++ this.cd.markForCheck()+ }+toggleMainPlaylist (e: Event, playlist: PlaylistSummary) {e.preventDefault()@@ -213,26 +205,6 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit,this.cd.markForCheck()}- createPlaylist () {- const displayName = this.form.value['displayName']-- const videoPlaylistCreate: VideoPlaylistCreate = {- displayName,- privacy: VideoPlaylistPrivacy.PRIVATE- }-- this.videoPlaylistService.createVideoPlaylist(videoPlaylistCreate)- .subscribe({- next: () => {- this.isNewPlaylistBlockOpened = false-- this.cd.markForCheck()- },-- error: err => this.notifier.handleError(err)- })- }-onVideoPlaylistSearchChanged () {this.videoPlaylistSearchChanged.next()}@@ -287,23 +259,28 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit,onElementTimestampUpdate (playlist: PlaylistSummary, element: PlaylistElement) {if (!element.playlistElementId || element.enabled === false) return- const body: VideoPlaylistElementUpdate = {- startTimestamp: element.startTimestamp,- stopTimestamp: element.stopTimestamp- }+ this.videoPlaylistService.updateVideoOfPlaylist({+ playlistId: playlist.id,- this.videoPlaylistService.updateVideoOfPlaylist(playlist.id, element.playlistElementId, body, this.video().id)- .subscribe({- next: () => {- this.notifier.success($localize`Timestamps updated`)+ elements: [+ {+ playlistElementId: element.playlistElementId,+ videoId: this.video().id,+ startTimestamp: element.startTimestamp,+ stopTimestamp: element.stopTimestamp+ }+ ]+ }).subscribe({+ next: () => {+ this.notifier.success($localize`Timestamps updated`)- this.videoExistsInPlaylistChange.emit()- },+ this.videoExistsInPlaylistChange.emit()+ },- error: err => this.notifier.handleError(err),+ error: err => this.notifier.handleError(err),- complete: () => this.cd.markForCheck()- })+ complete: () => this.cd.markForCheck()+ })}private isOptionalRowDisplayed (playlist: PlaylistSummary) {@@ -326,18 +303,23 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit,}private removeVideoFromPlaylist (playlist: PlaylistSummary, elementId: number) {- this.videoPlaylistService.removeVideoFromPlaylist(playlist.id, elementId, this.video().id)- .subscribe({- next: () => {- this.notifier.success($localize`Video removed from ${playlist.displayName}`)-- this.videoExistsInPlaylistChange.emit()- },-- error: err => this.notifier.handleError(err),-- complete: () => this.cd.markForCheck()- })+ this.videoPlaylistService.removeElementsFromPlaylist({+ playlistId: playlist.id,+ elements: [ {+ playlistElementId: elementId,+ videoId: this.video().id+ } ]+ }).subscribe({+ next: () => {+ this.notifier.success($localize`Video removed from ${playlist.displayName}`)++ this.videoExistsInPlaylistChange.emit()+ },++ error: err => this.notifier.handleError(err),++ complete: () => this.cd.markForCheck()+ })}private listenToVideoPlaylistChange () {@@ -401,7 +383,7 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit,this.videoPlaylistService.addVideoInPlaylist(playlist.id, body).subscribe({- next: res => {+ next: ([ res ]) => {const message = body.startTimestamp || body.stopTimestamp? $localize`Video added in ${playlist.displayName} at timestamps ${this.formatTimestamp(element)}`: $localize`Video added in ${playlist.displayName}`diff --git a/client/src/app/shared/shared-video-playlist/video-playlist-element-miniature.component.ts b/client/src/app/shared/shared-video-playlist/video-playlist-element-miniature.component.tsindex 3781d4177e..9bec3d0639 100644--- a/client/src/app/shared/shared-video-playlist/video-playlist-element-miniature.component.ts+++ b/client/src/app/shared/shared-video-playlist/video-playlist-element-miniature.component.ts@@ -141,15 +141,22 @@ export class VideoPlaylistElementMiniatureComponent implements OnInit {const playlistElementValue = this.playlistElement()const videoId = playlistElementValue.video ? playlistElementValue.video.id : undefined- this.videoPlaylistService.removeVideoFromPlaylist(this.playlist().id, playlistElement.id, videoId)- .subscribe({- next: () => {- this.notifier.success($localize`Video removed from ${this.playlist().displayName}`)- this.elementRemoved.emit(playlistElement)- },-- error: err => this.notifier.handleError(err)- })+ this.videoPlaylistService.removeElementsFromPlaylist({+ playlistId: this.playlist().id,+ elements: [+ {+ playlistElementId: playlistElement.id,+ videoId+ }+ ]+ }).subscribe({+ next: () => {+ this.notifier.success($localize`Video removed from ${this.playlist().displayName}`)+ this.elementRemoved.emit(playlistElement)+ },++ error: err => this.notifier.handleError(err)+ })this.moreDropdown().close()}@@ -157,22 +164,34 @@ export class VideoPlaylistElementMiniatureComponent implements OnInit {updateTimestamps (playlistElement: VideoPlaylistElement) {const body: VideoPlaylistElementUpdate = {}- body.startTimestamp = this.timestampOptions.startTimestampEnabled ? this.timestampOptions.startTimestamp : null- body.stopTimestamp = this.timestampOptions.stopTimestampEnabled ? this.timestampOptions.stopTimestamp : null-- this.videoPlaylistService.updateVideoOfPlaylist(this.playlist().id, playlistElement.id, body, this.playlistElement().video.id)- .subscribe({- next: () => {- this.notifier.success($localize`Timestamps updated`)-- playlistElement.startTimestamp = body.startTimestamp- playlistElement.stopTimestamp = body.stopTimestamp-- this.cdr.detectChanges()- },-- error: err => this.notifier.handleError(err)- })+ this.videoPlaylistService.updateVideoOfPlaylist({+ playlistId: this.playlist().id,+ elements: [+ {+ playlistElementId: playlistElement.id,++ startTimestamp: this.timestampOptions.startTimestampEnabled+ ? this.timestampOptions.startTimestamp+ : null,+ stopTimestamp: this.timestampOptions.stopTimestampEnabled+ ? this.timestampOptions.stopTimestamp+ : null,++ videoId: this.playlistElement().video.id+ }+ ]+ }).subscribe({+ next: () => {+ this.notifier.success($localize`Timestamps updated`)++ playlistElement.startTimestamp = body.startTimestamp+ playlistElement.stopTimestamp = body.stopTimestamp++ this.cdr.detectChanges()+ },++ error: err => this.notifier.handleError(err)+ })this.moreDropdown().close()}diff --git a/client/src/app/shared/shared-video-playlist/video-playlist.service.ts b/client/src/app/shared/shared-video-playlist/video-playlist.service.tsindex a697a354a5..7756ce6c4d 100644--- a/client/src/app/shared/shared-video-playlist/video-playlist.service.ts+++ b/client/src/app/shared/shared-video-playlist/video-playlist.service.ts@@ -3,6 +3,7 @@ import { inject, Injectable } from '@angular/core'import { AuthService, AuthUser, ComponentPaginationLight, RestExtractor, RestPagination, RestService, ServerService } from '@app/core'import { buildBulkObservable, objectToFormData } from '@app/helpers'import { NGX_LOADING_BAR_IGNORED } from '@ngx-loading-bar/http-client'+import { arrayify } from '@peertube/peertube-core-utils'import {CachedVideoExistInPlaylist,CachedVideosExistInPlaylists,@@ -20,8 +21,8 @@ import {} from '@peertube/peertube-models'import debug from 'debug'import { SortMeta } from 'primeng/api'-import { merge, Observable, of, ReplaySubject, Subject } from 'rxjs'-import { catchError, filter, map, share, switchMap, tap } from 'rxjs/operators'+import { from, merge, Observable, of, ReplaySubject, Subject } from 'rxjs'+import { catchError, concatMap, filter, map, share, switchMap, tap, toArray } from 'rxjs/operators'import { environment } from '../../../environments/environment'import { Account } from '../shared-main/account/account.model'import { AccountService } from '../shared-main/account/account.service'@@ -224,19 +225,25 @@ export class VideoPlaylistService {)}- addVideoInPlaylist (playlistId: number, body: VideoPlaylistElementCreate) {+ // ---------------------------------------------------------------------------++ addVideoInPlaylist (playlistId: number, bodyArg: VideoPlaylistElementCreate | VideoPlaylistElementCreate[]) {const url = VideoPlaylistService.BASE_VIDEO_PLAYLIST_URL + playlistId + '/videos'- return this.authHttp.post<{ videoPlaylistElement: { id: number } }>(url, body)+ return from(arrayify(bodyArg)).pipe(- tap(res => {+ concatMap(body => this.authHttp.post<{ videoPlaylistElement: { id: number } }>(url, body).pipe(map(res => ({ res, body })))),+ tap(({ res, body }) => {const existsResult = this.videoExistsCache[body.videoId]- existsResult.push({- playlistId,- playlistElementId: res.videoPlaylistElement.id,- startTimestamp: body.startTimestamp,- stopTimestamp: body.stopTimestamp- })++ if (existsResult) {+ existsResult.push({+ playlistId,+ playlistElementId: res.videoPlaylistElement.id,+ startTimestamp: body.startTimestamp,+ stopTimestamp: body.stopTimestamp+ })+ }this.runVideoExistsInPlaylistCheck(body.videoId)@@ -248,14 +255,29 @@ export class VideoPlaylistService {this.myAccountPlaylistCache.data = [ playlist, ...otherPlaylists ]}}),+ map(({ res }) => res),+ toArray(),catchError(err => this.restExtractor.handleError(err)))}- updateVideoOfPlaylist (playlistId: number, playlistElementId: number, body: VideoPlaylistElementUpdate, videoId: number) {- return this.authHttp.put(VideoPlaylistService.BASE_VIDEO_PLAYLIST_URL + playlistId + '/videos/' + playlistElementId, body)+ updateVideoOfPlaylist (options: {+ playlistId: number++ elements: ({+ playlistElementId: number+ videoId: number+ } & VideoPlaylistElementUpdate)[]+ }) {+ const { playlistId, elements } = options++ return from(elements).pipe(- tap(() => {+ concatMap(({ playlistElementId, videoId, ...body }) => {+ return this.authHttp.put(VideoPlaylistService.BASE_VIDEO_PLAYLIST_URL + playlistId + '/videos/' + playlistElementId, body)+ .pipe(map(() => ({ playlistElementId, videoId, body })))+ }),+ tap(({ playlistElementId, videoId, body }) => {const existsResult = this.videoExistsCache[videoId]if (existsResult) {@@ -267,16 +289,28 @@ export class VideoPlaylistService {this.runVideoExistsInPlaylistCheck(videoId)}),+ toArray(),catchError(err => this.restExtractor.handleError(err)))}- removeVideoFromPlaylist (playlistId: number, playlistElementId: number, videoId?: number) {- return this.authHttp.delete(VideoPlaylistService.BASE_VIDEO_PLAYLIST_URL + playlistId + '/videos/' + playlistElementId)- .pipe(- tap(() => {- if (!videoId) return+ removeElementsFromPlaylist (options: {+ playlistId: number+ elements: {+ playlistElementId: number+ videoId: number+ }[]+ }) {+ const { playlistId, elements } = options++ return from(elements)+ .pipe(+ concatMap(({ playlistElementId, videoId }) =>+ this.authHttp.delete(VideoPlaylistService.BASE_VIDEO_PLAYLIST_URL + playlistId + '/videos/' + playlistElementId)+ .pipe(map(() => ({ playlistElementId, videoId })))+ ),+ tap(({ playlistElementId, videoId }) => {if (this.videoExistsCache[videoId]) {this.videoExistsCache[videoId] = this.videoExistsCache[videoId].filter(e => e.playlistElementId !== playlistElementId)@@ -284,6 +318,7 @@ export class VideoPlaylistService {this.runVideoExistsInPlaylistCheck(videoId)}),+ toArray(),catchError(err => this.restExtractor.handleError(err)))}@@ -350,17 +385,20 @@ export class VideoPlaylistService {return obs}- runVideoExistsInPlaylistCheck (videoId: number) {+ runVideoExistsInPlaylistCheck (videoIds: number | number[]) {debugLogger('Running playlist check.')- if (this.videoExistsCache[videoId]) {- debugLogger('Found cache for %d.', videoId)+ for (const videoId of arrayify(videoIds)) {+ if (this.videoExistsCache[videoId]) {+ debugLogger('Found cache for %d.', videoId)- return this.videoExistsInPlaylistCacheSubject.next({ [videoId]: this.videoExistsCache[videoId] })- }+ this.videoExistsInPlaylistCacheSubject.next({ [videoId]: this.videoExistsCache[videoId] })+ continue+ }- debugLogger('Fetching from network for %d.', videoId)- return this.videoExistsInPlaylistNotifier.next(videoId)+ debugLogger('Fetching from network for %d.', videoId)+ this.videoExistsInPlaylistNotifier.next(videoId)+ }}extractPlaylists (result: ResultList<VideoPlaylistServerModel>) {diff --git a/server/core/initializers/constants.ts b/server/core/initializers/constants.tsindex d2ed30231f..2a8cd56f69 100644--- a/server/core/initializers/constants.ts+++ b/server/core/initializers/constants.ts@@ -49,7 +49,7 @@ import {VideoState,VideoStateType} from '@peertube/peertube-models'-import { isTestInstance, isTestOrDevInstance, root } from '@peertube/peertube-node-utils'+import { isDevInstance, isTestInstance, isTestOrDevInstance, root } from '@peertube/peertube-node-utils'import { RepeatOptions } from 'bullmq'import { Encoding, randomBytes } from 'crypto'import { readJsonSync } from 'fs-extra/esm'@@ -1298,8 +1298,7 @@ if (process.env.PRODUCTION_CONSTANTS !== 'true') {SCHEDULER_INTERVALS_MS.REMOVE_OLD_HISTORY = 5000SCHEDULER_INTERVALS_MS.UPDATE_VIDEOS = 5000SCHEDULER_INTERVALS_MS.AUTO_FOLLOW_INDEX_INSTANCES = 5000- SCHEDULER_INTERVALS_MS.BLOCKLIST_SUBSCRIPTIONS_SYNC = 5000- SCHEDULER_INTERVALS_MS.WATCHED_WORDS_SUBSCRIPTIONS_SYNC = 5000+SCHEDULER_INTERVALS_MS.UPDATE_INBOX_STATS = 5000SCHEDULER_INTERVALS_MS.CHECK_PEERTUBE_VERSION = 2000SCHEDULER_INTERVALS_MS.UPDATE_TOKEN_SESSION = 2000@@ -1328,7 +1327,10 @@ if (process.env.PRODUCTION_CONSTANTS !== 'true') {VIEWER_SYNC_REDIS = 1000}- if (isTestInstance()) {+ if (isDevInstance()) {+ SCHEDULER_INTERVALS_MS.BLOCKLIST_SUBSCRIPTIONS_SYNC = 60000+ SCHEDULER_INTERVALS_MS.WATCHED_WORDS_SUBSCRIPTIONS_SYNC = 60000+ } else if (isTestInstance()) {SCHEDULER_INTERVALS_MS.ACTOR_FOLLOW_SCORES = 1000ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE = 2@@ -1348,6 +1350,9 @@ if (process.env.PRODUCTION_CONSTANTS !== 'true') {VIDEO_LIVE.SEGMENT_TIME_SECONDS.SMALL_LATENCY = 1VIDEO_LIVE.EDGE_LIVE_DELAY_SEGMENTS_NOTIFICATION = 1+ SCHEDULER_INTERVALS_MS.BLOCKLIST_SUBSCRIPTIONS_SYNC = 5000+ SCHEDULER_INTERVALS_MS.WATCHED_WORDS_SUBSCRIPTIONS_SYNC = 5000+RUNNER_JOBS.LAST_CONTACT_UPDATE_INTERVAL = 2000JWT_TOKEN_USER_EXPORT_FILE_LIFETIME = '2 seconds'