From 2a491182e483b97afb1b65c908b23cb48d591807 Mon Sep 17 00:00:00 2001 From: Florent Date: Wed, 10 Aug 2022 09:53:39 +0200 Subject: Channel sync (#5135) * Add external channel URL for channel update / creation (#754) * Disallow synchronisation if user has no video quota (#754) * More constraints serverside (#754) * Disable sync if server configuration does not allow HTTP import (#754) * Working version synchronizing videos with a job (#754) TODO: refactoring, too much code duplication * More logs and try/catch (#754) * Fix eslint error (#754) * WIP: support synchronization time change (#754) * New frontend #754 * WIP: Create sync front (#754) * Enhance UI, sync creation form (#754) * Warning message when HTTP upload is disallowed * More consistent names (#754) * Binding Front with API (#754) * Add a /me API (#754) * Improve list UI (#754) * Implement creation and deletion routes (#754) * Lint (#754) * Lint again (#754) * WIP: UI for triggering import existing videos (#754) * Implement jobs for syncing and importing channels * Don't sync videos before sync creation + avoid concurrency issue (#754) * Cleanup (#754) * Cleanup: OpenAPI + API rework (#754) * Remove dead code (#754) * Eslint (#754) * Revert the mess with whitespaces in constants.ts (#754) * Some fixes after rebase (#754) * Several fixes after PR remarks (#754) * Front + API: Rename video-channels-sync to video-channel-syncs (#754) * Allow enabling channel sync through UI (#754) * getChannelInfo (#754) * Minor fixes: openapi + model + sql (#754) * Simplified API validators (#754) * Rename MChannelSync to MChannelSyncChannel (#754) * Add command for VideoChannelSync (#754) * Use synchronization.enabled config (#754) * Check parameters test + some fixes (#754) * Fix conflict mistake (#754) * Restrict access to video channel sync list API (#754) * Start adding unit test for synchronization (#754) * Continue testing (#754) * Tests finished + convertion of job to scheduler (#754) * Add lastSyncAt field (#754) * Fix externalRemoteUrl sort + creation date not well formatted (#754) * Small fix (#754) * Factorize addYoutubeDLImport and buildVideo (#754) * Check duplicates on channel not on users (#754) * factorize thumbnail generation (#754) * Fetch error should return status 400 (#754) * Separate video-channel-import and video-channel-sync-latest (#754) * Bump DB migration version after rebase (#754) * Prettier states in UI table (#754) * Add DefaultScope in VideoChannelSyncModel (#754) * Fix audit logs (#754) * Ensure user can upload when importing channel + minor fixes (#754) * Mark synchronization as failed on exception + typos (#754) * Change REST API for importing videos into channel (#754) * Add option for fully synchronize a chnanel (#754) * Return a whole sync object on creation to avoid tricks in Front (#754) * Various remarks (#754) * Single quotes by default (#754) * Rename synchronization to video_channel_synchronization * Add check.latest_videos_count and max_per_user options (#754) * Better channel rendering in list #754 * Allow sorting with channel name and state (#754) * Add missing tests for channel imports (#754) * Prefer using a parent job for channel sync * Styling * Client styling Co-authored-by: Chocobozzz --- .../form-validators/video-channel-validators.ts | 13 ++++++ .../instance-features-table.component.html | 7 +++ client/src/app/shared/shared-main/index.ts | 1 + .../shared/shared-main/video-channel-sync/index.ts | 1 + .../video-channel-sync.service.ts | 50 ++++++++++++++++++++++ .../video-channel/video-channel.service.ts | 6 +++ 6 files changed, 78 insertions(+) create mode 100644 client/src/app/shared/shared-main/video-channel-sync/index.ts create mode 100644 client/src/app/shared/shared-main/video-channel-sync/video-channel-sync.service.ts (limited to 'client/src/app/shared') diff --git a/client/src/app/shared/form-validators/video-channel-validators.ts b/client/src/app/shared/form-validators/video-channel-validators.ts index 163faf270..b12b3caaf 100644 --- a/client/src/app/shared/form-validators/video-channel-validators.ts +++ b/client/src/app/shared/form-validators/video-channel-validators.ts @@ -48,3 +48,16 @@ export const VIDEO_CHANNEL_SUPPORT_VALIDATOR: BuildFormValidator = { maxlength: $localize`Support text cannot be more than 1000 characters long.` } } + +export const VIDEO_CHANNEL_EXTERNAL_URL_VALIDATOR: BuildFormValidator = { + VALIDATORS: [ + Validators.required, + Validators.pattern(/^https?:\/\//), + Validators.maxLength(1000) + ], + MESSAGES: { + required: $localize`Remote channel url is required.`, + pattern: $localize`External channel URL must begin with "https://" or "http://"`, + maxlength: $localize`External channel URL cannot be more than 1000 characters long` + } +} diff --git a/client/src/app/shared/shared-instance/instance-features-table.component.html b/client/src/app/shared/shared-instance/instance-features-table.component.html index 761243bfe..6c05764df 100644 --- a/client/src/app/shared/shared-instance/instance-features-table.component.html +++ b/client/src/app/shared/shared-instance/instance-features-table.component.html @@ -106,6 +106,13 @@ + + Channel synchronization with other platforms (YouTube, Vimeo, ...) + + + + + Search diff --git a/client/src/app/shared/shared-main/index.ts b/client/src/app/shared/shared-main/index.ts index 3a7fd4c34..9faa28e32 100644 --- a/client/src/app/shared/shared-main/index.ts +++ b/client/src/app/shared/shared-main/index.ts @@ -13,3 +13,4 @@ export * from './video' export * from './video-caption' export * from './video-channel' export * from './shared-main.module' +export * from './video-channel-sync' diff --git a/client/src/app/shared/shared-main/video-channel-sync/index.ts b/client/src/app/shared/shared-main/video-channel-sync/index.ts new file mode 100644 index 000000000..7134bcd18 --- /dev/null +++ b/client/src/app/shared/shared-main/video-channel-sync/index.ts @@ -0,0 +1 @@ +export * from './video-channel-sync.service' diff --git a/client/src/app/shared/shared-main/video-channel-sync/video-channel-sync.service.ts b/client/src/app/shared/shared-main/video-channel-sync/video-channel-sync.service.ts new file mode 100644 index 000000000..a4e216869 --- /dev/null +++ b/client/src/app/shared/shared-main/video-channel-sync/video-channel-sync.service.ts @@ -0,0 +1,50 @@ +import { SortMeta } from 'primeng/api' +import { catchError, Observable } from 'rxjs' +import { environment } from 'src/environments/environment' +import { HttpClient, HttpParams } from '@angular/common/http' +import { Injectable } from '@angular/core' +import { RestExtractor, RestPagination, RestService } from '@app/core' +import { ResultList } from '@shared/models/common' +import { VideoChannelSync, VideoChannelSyncCreate } from '@shared/models/videos' +import { Account, AccountService } from '../account' + +@Injectable({ + providedIn: 'root' +}) +export class VideoChannelSyncService { + static BASE_VIDEO_CHANNEL_URL = environment.apiUrl + '/api/v1/video-channel-syncs' + + constructor ( + private authHttp: HttpClient, + private restExtractor: RestExtractor, + private restService: RestService + ) { } + + listAccountVideoChannelsSyncs (parameters: { + sort: SortMeta + pagination: RestPagination + account: Account + }): Observable> { + const { pagination, sort, account } = parameters + + let params = new HttpParams() + params = this.restService.addRestGetParams(params, pagination, sort) + + const url = AccountService.BASE_ACCOUNT_URL + account.nameWithHost + '/video-channel-syncs' + + return this.authHttp.get>(url, { params }) + .pipe(catchError(err => this.restExtractor.handleError(err))) + } + + createSync (body: VideoChannelSyncCreate) { + return this.authHttp.post<{ videoChannelSync: VideoChannelSync }>(VideoChannelSyncService.BASE_VIDEO_CHANNEL_URL, body) + .pipe(catchError(err => this.restExtractor.handleError(err))) + } + + deleteSync (videoChannelsSyncId: number) { + const url = `${VideoChannelSyncService.BASE_VIDEO_CHANNEL_URL}/${videoChannelsSyncId}` + + return this.authHttp.delete(url) + .pipe(catchError(err => this.restExtractor.handleError(err))) + } +} diff --git a/client/src/app/shared/shared-main/video-channel/video-channel.service.ts b/client/src/app/shared/shared-main/video-channel/video-channel.service.ts index 480d250fb..fa97025ac 100644 --- a/client/src/app/shared/shared-main/video-channel/video-channel.service.ts +++ b/client/src/app/shared/shared-main/video-channel/video-channel.service.ts @@ -95,4 +95,10 @@ export class VideoChannelService { return this.authHttp.delete(VideoChannelService.BASE_VIDEO_CHANNEL_URL + videoChannel.nameWithHost) .pipe(catchError(err => this.restExtractor.handleError(err))) } + + importVideos (videoChannelName: string, externalChannelUrl: string) { + const path = VideoChannelService.BASE_VIDEO_CHANNEL_URL + videoChannelName + '/import-videos' + return this.authHttp.post(path, { externalChannelUrl }) + .pipe(catchError(err => this.restExtractor.handleError(err))) + } } -- cgit v1.2.3