Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Add ability to set custom privacy to channel sync

Chocobozzz926654b0ec70
diff --git a/client/src/app/+my-library/my-video-channel-syncs/my-video-channel-syncs.component.html b/client/src/app/+my-library/my-video-channel-syncs/my-video-channel-syncs.component.html
index aaf94a04e8..00ec6b132f 100644
--- a/client/src/app/+my-library/my-video-channel-syncs/my-video-channel-syncs.component.html
+++ b/client/src/app/+my-library/my-video-channel-syncs/my-video-channel-syncs.component.html
@@ -40,7 +40,13 @@
</td>
<td>{{ sync.createdAt | ptDate: 'short' }}</td>
- <td>{{ sync.lastSyncAt | ptDate: 'short' }}</td>
+ <td>
+ @if (sync.lastSyncAt) {
+ {{ sync.lastSyncAt | ptDate: 'short' }}
+ } @else {
+ <ng-container i18n>Never</ng-container>
+ }
+ </td>
</ng-template>
<ng-template #actionCell let-sync>
diff --git a/client/src/app/+my-library/my-video-channel-syncs/video-channel-sync-edit/video-channel-sync-edit.component.html b/client/src/app/+my-library/my-video-channel-syncs/video-channel-sync-edit/video-channel-sync-edit.component.html
index fa63bdd4fe..565bb7b294 100644
--- a/client/src/app/+my-library/my-video-channel-syncs/video-channel-sync-edit/video-channel-sync-edit.component.html
+++ b/client/src/app/+my-library/my-video-channel-syncs/video-channel-sync-edit/video-channel-sync-edit.component.html
@@ -54,6 +54,11 @@
</div>
</div>
+ <div class="form-group">
+ <label i18n for="videoPrivacy">Privacy of imported videos</label>
+ <my-select-options inputId="videoPrivacy" [items]="videoPrivacies" formControlName="videoPrivacy"></my-select-options>
+ </div>
+
<input type="submit" class="peertube-button primary-button" value="{{ getFormButtonTitle() }}" [disabled]="!form.valid">
</form>
</div>
diff --git a/client/src/app/+my-library/my-video-channel-syncs/video-channel-sync-edit/video-channel-sync-edit.component.scss b/client/src/app/+my-library/my-video-channel-syncs/video-channel-sync-edit/video-channel-sync-edit.component.scss
index 05ae81b176..6f6644fb27 100644
--- a/client/src/app/+my-library/my-video-channel-syncs/video-channel-sync-edit/video-channel-sync-edit.component.scss
+++ b/client/src/app/+my-library/my-video-channel-syncs/video-channel-sync-edit/video-channel-sync-edit.component.scss
@@ -8,7 +8,8 @@ input[type="text"] {
@include peertube-input-text($form-base-input-width);
}
-my-select-channel-user {
+my-select-channel-user,
+my-select-options {
display: block;
max-width: $form-base-input-width;
}
diff --git a/client/src/app/+my-library/my-video-channel-syncs/video-channel-sync-edit/video-channel-sync-edit.component.ts b/client/src/app/+my-library/my-video-channel-syncs/video-channel-sync-edit/video-channel-sync-edit.component.ts
index b0da36914d..1729995c61 100644
--- a/client/src/app/+my-library/my-video-channel-syncs/video-channel-sync-edit/video-channel-sync-edit.component.ts
+++ b/client/src/app/+my-library/my-video-channel-syncs/video-channel-sync-edit/video-channel-sync-edit.component.ts
@@ -2,17 +2,20 @@ import { NgClass } from '@angular/common'
import { ChangeDetectionStrategy, Component, OnInit, inject } from '@angular/core'
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
import { Router } from '@angular/router'
-import { AuthService, Notifier } from '@app/core'
+import { AuthService, Notifier, ServerService } from '@app/core'
import { REQUIRED_VALIDATOR } from '@app/shared/form-validators/common-validators'
import { VIDEO_CHANNEL_EXTERNAL_URL_VALIDATOR } from '@app/shared/form-validators/video-channel-validators'
+import { VIDEO_PRIVACY_VALIDATOR } from '@app/shared/form-validators/video-validators'
import { FormReactive } from '@app/shared/shared-forms/form-reactive'
import { FormReactiveService } from '@app/shared/shared-forms/form-reactive.service'
import { listChannelsForSelect } from '@app/shared/shared-forms/select/channel/select-channel-helpers'
+import { SelectOptionsComponent } from '@app/shared/shared-forms/select/select-options.component'
import { VideoChannelSyncService } from '@app/shared/shared-main/channel/video-channel-sync.service'
import { VideoChannelService } from '@app/shared/shared-main/channel/video-channel.service'
import { AlertComponent } from '@app/shared/shared-main/common/alert.component'
-import { VideoChannelSyncCreate } from '@peertube/peertube-models'
-import { SelectChannelItem } from '@pt-types'
+import { VideoService } from '@app/shared/shared-main/video/video.service'
+import { VideoChannelSyncCreate, VideoPrivacy } from '@peertube/peertube-models'
+import { SelectChannelItem, SelectOptionsItem } from '@pt-types'
import { mergeMap } from 'rxjs'
import { SelectChannelUserComponent } from '../../../shared/shared-forms/select/channel/select-channel-user.component'
@@ -21,7 +24,7 @@ import { SelectChannelUserComponent } from '../../../shared/shared-forms/select/
templateUrl: './video-channel-sync-edit.component.html',
styleUrls: [ './video-channel-sync-edit.component.scss' ],
changeDetection: ChangeDetectionStrategy.Eager,
- imports: [ FormsModule, ReactiveFormsModule, NgClass, SelectChannelUserComponent, AlertComponent ]
+ imports: [ FormsModule, ReactiveFormsModule, NgClass, SelectChannelUserComponent, AlertComponent, SelectOptionsComponent ]
})
export class VideoChannelSyncEditComponent extends FormReactive implements OnInit {
protected formReactiveService = inject(FormReactiveService)
@@ -30,22 +33,33 @@ export class VideoChannelSyncEditComponent extends FormReactive implements OnIni
private notifier = inject(Notifier)
private videoChannelSyncService = inject(VideoChannelSyncService)
private videoChannelService = inject(VideoChannelService)
+ private serverService = inject(ServerService)
+ private videoService = inject(VideoService)
error: string
channels: SelectChannelItem[] = []
existingVideosStrategy: string
+ videoPrivacies: SelectOptionsItem[] = []
ngOnInit () {
this.buildForm({
externalChannelUrl: VIDEO_CHANNEL_EXTERNAL_URL_VALIDATOR,
videoChannel: REQUIRED_VALIDATOR,
- existingVideoStrategy: REQUIRED_VALIDATOR
+ existingVideoStrategy: REQUIRED_VALIDATOR,
+ videoPrivacy: VIDEO_PRIVACY_VALIDATOR
})
listChannelsForSelect({
authService: this.authService,
includeCollaborations: true
}).subscribe(channels => this.channels = channels)
+
+ this.serverService.getVideoPrivacies()
+ .subscribe(privacies => {
+ const allowedPrivacies = privacies.filter(p => p.id !== VideoPrivacy.PASSWORD_PROTECTED)
+
+ this.videoPrivacies = this.videoService.explainedPrivacyLabels(allowedPrivacies).videoPrivacies
+ })
}
getFormButtonTitle () {
@@ -58,7 +72,8 @@ export class VideoChannelSyncEditComponent extends FormReactive implements OnIni
const body = this.form.value
const videoChannelSyncCreate: VideoChannelSyncCreate = {
externalChannelUrl: body.externalChannelUrl,
- videoChannelId: body.videoChannel
+ videoChannelId: body.videoChannel,
+ videoPrivacy: body.videoPrivacy
}
const importExistingVideos = body['existingVideoStrategy'] === 'import'
diff --git a/packages/models/src/videos/channel-sync/video-channel-sync-create.model.ts b/packages/models/src/videos/channel-sync/video-channel-sync-create.model.ts
index 753a8ee4cc..fa0b7e8db3 100644
--- a/packages/models/src/videos/channel-sync/video-channel-sync-create.model.ts
+++ b/packages/models/src/videos/channel-sync/video-channel-sync-create.model.ts
@@ -1,4 +1,8 @@
+import { VideoPrivacyType } from '../../videos/video-privacy.enum.js'
+
export interface VideoChannelSyncCreate {
externalChannelUrl: string
videoChannelId: number
+
+ videoPrivacy?: VideoPrivacyType
}
diff --git a/packages/models/src/videos/channel-sync/video-channel-sync.model.ts b/packages/models/src/videos/channel-sync/video-channel-sync.model.ts
index d1a89dd2a5..736d6cb2c9 100644
--- a/packages/models/src/videos/channel-sync/video-channel-sync.model.ts
+++ b/packages/models/src/videos/channel-sync/video-channel-sync.model.ts
@@ -1,6 +1,7 @@
-import { VideoChannelSummary } from '../channel/video-channel.model.js'
import { ConstantLabel } from '../../common/constant-label.model.js'
import { StreamSyncStateType } from '../../common/stream-sync-state.enum.js'
+import { VideoPrivacyType } from '../../videos/video-privacy.enum.js'
+import { VideoChannelSummary } from '../channel/video-channel.model.js'
export interface VideoChannelSync {
id: number
@@ -11,4 +12,6 @@ export interface VideoChannelSync {
channel: VideoChannelSummary
state: ConstantLabel<StreamSyncStateType>
lastSyncAt: string
+
+ videoPrivacy: VideoPrivacyType | null
}
diff --git a/packages/tests/src/api/check-params/channel-syncs.ts b/packages/tests/src/api/check-params/channel-syncs.ts
index 7e71f8dd75..d51c7e3c84 100644
--- a/packages/tests/src/api/check-params/channel-syncs.ts
+++ b/packages/tests/src/api/check-params/channel-syncs.ts
@@ -1,6 +1,4 @@
-import { checkBadCountPagination, checkBadSort, checkBadStartPagination } from '@tests/shared/checks.js'
-import { FIXTURE_URLS } from '@tests/shared/fixture-urls.js'
-import { HttpStatusCode, VideoChannelSyncCreate } from '@peertube/peertube-models'
+import { HttpStatusCode, VideoChannelSyncCreate, VideoPrivacy } from '@peertube/peertube-models'
import {
ChannelSyncsCommand,
createSingleServer,
@@ -10,6 +8,8 @@ import {
setAccessTokensToServers,
setDefaultVideoChannel
} from '@peertube/peertube-server-commands'
+import { checkBadCountPagination, checkBadSort, checkBadStartPagination } from '@tests/shared/checks.js'
+import { FIXTURE_URLS } from '@tests/shared/fixture-urls.js'
describe('Test video channel sync API validator', () => {
const path = '/api/v1/video-channel-syncs'
@@ -86,7 +86,8 @@ describe('Test video channel sync API validator', () => {
before(function () {
baseCorrectParams = {
externalChannelUrl: FIXTURE_URLS.youtubeChannel,
- videoChannelId: rootChannelId
+ videoChannelId: rootChannelId,
+ videoPrivacy: VideoPrivacy.PUBLIC
}
})
@@ -187,6 +188,30 @@ describe('Test video channel sync API validator', () => {
userInfo.syncId = sync.id
})
+ it('Should fail with an invalid privacy value', async function () {
+ await command.create({
+ token: server.accessToken,
+ attributes: {
+ ...baseCorrectParams,
+
+ videoPrivacy: 999 as any
+ },
+ expectedStatus: HttpStatusCode.BAD_REQUEST_400
+ })
+ })
+
+ it('Should fail with password protected privacy', async function () {
+ await command.create({
+ token: server.accessToken,
+ attributes: {
+ ...baseCorrectParams,
+
+ videoPrivacy: VideoPrivacy.PASSWORD_PROTECTED
+ },
+ expectedStatus: HttpStatusCode.BAD_REQUEST_400
+ })
+ })
+
it('Should succeed with the correct parameters', async function () {
const { videoChannelSync } = await command.create({
token: server.accessToken,
diff --git a/packages/tests/src/api/videos/video-channel-syncs.ts b/packages/tests/src/api/videos/video-channel-syncs.ts
index bd811a7620..77680d1428 100644
--- a/packages/tests/src/api/videos/video-channel-syncs.ts
+++ b/packages/tests/src/api/videos/video-channel-syncs.ts
@@ -1,5 +1,6 @@
/* oxlint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
+import { getAllPrivacies } from '@peertube/peertube-core-utils'
import { StreamSyncState, VideoImportState, VideoInclude, VideoPrivacy } from '@peertube/peertube-models'
import { areHttpImportTestsDisabled, areYoutubeImportTestsDisabled } from '@peertube/peertube-node-utils'
import {
@@ -50,7 +51,8 @@ describe('Test channel synchronizations', function () {
async function listAllVideosOfChannel (channelName: string) {
return servers[0].videos.listByChannel({
handle: channelName,
- include: VideoInclude.NOT_PUBLISHED_STATE
+ include: VideoInclude.NOT_PUBLISHED_STATE,
+ privacyOneOf: getAllPrivacies()
})
}
@@ -376,6 +378,36 @@ describe('Test channel synchronizations', function () {
}
})
+ it('Should import videos with the sync default privacy', async function () {
+ this.timeout(120_000)
+
+ const { id: channelId } = await servers[0].channels.create({
+ attributes: {
+ name: 'channel3',
+ support: 'my support test'
+ }
+ })
+
+ const { videoChannelSync } = await servers[0].channelSyncs.create({
+ attributes: {
+ externalChannelUrl: FIXTURE_URLS.youtubePlaylist,
+ videoChannelId: channelId,
+ videoPrivacy: VideoPrivacy.UNLISTED
+ }
+ })
+
+ await forceSyncAll(videoChannelSync.id)
+
+ {
+ const { total, data } = await listAllVideosOfChannel('channel3')
+ expect(total).to.be.at.least(1)
+
+ for (const video of data) {
+ expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED)
+ }
+ }
+ })
+
after(async function () {
for (const sqlCommand of sqlCommands) {
await sqlCommand.cleanup()
diff --git a/server/core/controllers/api/video-channel-sync.ts b/server/core/controllers/api/video-channel-sync.ts
index 8db887d212..0a0d1ce690 100644
--- a/server/core/controllers/api/video-channel-sync.ts
+++ b/server/core/controllers/api/video-channel-sync.ts
@@ -44,6 +44,7 @@ async function createVideoChannelSync (req: express.Request, res: express.Respon
const syncCreated: MChannelSyncFormattable = new VideoChannelSyncModel({
externalChannelUrl: req.body.externalChannelUrl,
videoChannelId: req.body.videoChannelId,
+ videoPrivacy: req.body.videoPrivacy,
state: StreamSyncState.WAITING_FIRST_RUN
})
diff --git a/server/core/helpers/custom-validators/video-channel-syncs.ts b/server/core/helpers/custom-validators/video-channel-syncs.ts
index 5e51408645..230c82e853 100644
--- a/server/core/helpers/custom-validators/video-channel-syncs.ts
+++ b/server/core/helpers/custom-validators/video-channel-syncs.ts
@@ -1,6 +1,11 @@
-import { STREAM_SYNC_STATE } from '@server/initializers/constants.js'
+import { VideoPrivacy } from '@peertube/peertube-models'
+import { STREAM_SYNC_STATE, VIDEO_PRIVACIES } from '@server/initializers/constants.js'
import { exists } from './misc.js'
export function isVideoChannelSyncStateValid (value: any) {
return exists(value) && STREAM_SYNC_STATE[value] !== undefined
}
+
+export function isVideoChannelSyncPrivacyValid (value: any) {
+ return VIDEO_PRIVACIES[value] !== undefined && value !== VideoPrivacy.PASSWORD_PROTECTED
+}
diff --git a/server/core/initializers/constants.ts b/server/core/initializers/constants.ts
index fc804b0d95..31c271df3e 100644
--- a/server/core/initializers/constants.ts
+++ b/server/core/initializers/constants.ts
@@ -62,7 +62,7 @@ import { CONFIG, registerConfigChangedHandler } from './config.js'
// ---------------------------------------------------------------------------
-export const LAST_MIGRATION_VERSION = 1075
+export const LAST_MIGRATION_VERSION = 1080
// ---------------------------------------------------------------------------
diff --git a/server/core/initializers/migrations/1080-video-channel-sync-privacy.ts b/server/core/initializers/migrations/1080-video-channel-sync-privacy.ts
new file mode 100644
index 0000000000..cbdb32dc06
--- /dev/null
+++ b/server/core/initializers/migrations/1080-video-channel-sync-privacy.ts
@@ -0,0 +1,22 @@
+import * as Sequelize from 'sequelize'
+
+async function up (utils: {
+ transaction: Sequelize.Transaction
+ queryInterface: Sequelize.QueryInterface
+ sequelize: Sequelize.Sequelize
+}): Promise<void> {
+ await utils.queryInterface.addColumn('videoChannelSync', 'videoPrivacy', {
+ type: Sequelize.INTEGER,
+ allowNull: true,
+ defaultValue: null
+ }, { transaction: utils.transaction })
+}
+
+function down (options) {
+ throw new Error('Not implemented.')
+}
+
+export {
+ down,
+ up
+}
diff --git a/server/core/lib/sync-channel.ts b/server/core/lib/sync-channel.ts
index 8f2ec5b206..7276ef5252 100644
--- a/server/core/lib/sync-channel.ts
+++ b/server/core/lib/sync-channel.ts
@@ -66,7 +66,7 @@ export async function synchronizeChannel (options: {
channelSync,
skipPublishedBeforeOrEq,
importDataOverride: {
- privacy: getLeastPrivatePrivacy(),
+ privacy: channelSync?.videoPrivacy || getLeastPrivatePrivacy(),
support: channel.support
}
})
diff --git a/server/core/middlewares/validators/videos/video-channel-sync.ts b/server/core/middlewares/validators/videos/video-channel-sync.ts
index 0430728562..0c10564ee4 100644
--- a/server/core/middlewares/validators/videos/video-channel-sync.ts
+++ b/server/core/middlewares/validators/videos/video-channel-sync.ts
@@ -1,6 +1,7 @@
import { HttpStatusCode, VideoChannelSyncCreate } from '@peertube/peertube-models'
import { isUrlValid } from '@server/helpers/custom-validators/activitypub/misc.js'
-import { toBooleanOrNull } from '@server/helpers/custom-validators/misc.js'
+import { toBooleanOrNull, toIntOrNull } from '@server/helpers/custom-validators/misc.js'
+import { isVideoChannelSyncPrivacyValid } from '@server/helpers/custom-validators/video-channel-syncs.js'
import { CONFIG } from '@server/initializers/config.js'
import { VideoChannelSyncModel } from '@server/models/video/video-channel-sync.js'
import * as express from 'express'
@@ -26,6 +27,11 @@ export const videoChannelSyncValidator = [
body('videoChannelId')
.isInt(),
+ body('videoPrivacy')
+ .optional()
+ .customSanitizer(toIntOrNull)
+ .custom(isVideoChannelSyncPrivacyValid),
+
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
if (areValidationErrors(req, res)) return
diff --git a/server/core/models/video/video-channel-sync.ts b/server/core/models/video/video-channel-sync.ts
index 59f5ee3dcf..897180f13c 100644
--- a/server/core/models/video/video-channel-sync.ts
+++ b/server/core/models/video/video-channel-sync.ts
@@ -1,4 +1,4 @@
-import { VideoChannelSync, StreamSyncState, type StreamSyncStateType } from '@peertube/peertube-models'
+import { StreamSyncState, VideoChannelSync, type StreamSyncStateType, type VideoPrivacyType } from '@peertube/peertube-models'
import { isUrlValid } from '@server/helpers/custom-validators/activitypub/misc.js'
import { isVideoChannelSyncStateValid } from '@server/helpers/custom-validators/video-channel-syncs.js'
import { CONSTRAINTS_FIELDS, STREAM_SYNC_STATE } from '@server/initializers/constants.js'
@@ -46,6 +46,10 @@ export class VideoChannelSyncModel extends SequelizeModel<VideoChannelSyncModel>
@Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_CHANNEL_SYNCS.EXTERNAL_CHANNEL_URL.max))
declare externalChannelUrl: string
+ @AllowNull(true)
+ @Column(DataType.INTEGER)
+ declare videoPrivacy: VideoPrivacyType
+
@AllowNull(false)
@Default(StreamSyncState.WAITING_FIRST_RUN)
@Is('VideoChannelSyncState', value => throwIfNotValid(value, isVideoChannelSyncStateValid, 'state'))
@@ -152,7 +156,8 @@ export class VideoChannelSyncModel extends SequelizeModel<VideoChannelSyncModel>
externalChannelUrl: this.externalChannelUrl,
createdAt: this.createdAt.toISOString(),
channel: this.VideoChannel.toFormattedSummaryJSON(),
- lastSyncAt: this.lastSyncAt?.toISOString()
+ lastSyncAt: this.lastSyncAt?.toISOString(),
+ videoPrivacy: this.videoPrivacy
}
}
}
diff --git a/support/doc/api/openapi.yaml b/support/doc/api/openapi.yaml
index 713987598d..5f399248fe 100644
--- a/support/doc/api/openapi.yaml
+++ b/support/doc/api/openapi.yaml
@@ -13312,6 +13312,10 @@ components:
nullable: true
channel:
$ref: '#/components/schemas/VideoChannel'
+ videoPrivacy:
+ type: integer
+ nullable: true
+ description: Default privacy of videos imported by this synchronization
VideoChannelSyncList:
type: object
properties:
@@ -13331,6 +13335,11 @@ components:
example: https://youtube.com/c/UC_myfancychannel
videoChannelId:
$ref: '#/components/schemas/id'
+ videoPrivacy:
+ type: integer
+ description: |
+ Privacy of imported videos (1 = PUBLIC, 2 = UNLISTED, 3 = PRIVATE, 4 = INTERNAL).
+ Password protected privacy is not supported
MRSSPeerLink:
type: object
xml: