Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat(sitemap): remove empty accounts/channels
closes #6607
  • Loading branch information
kontrollanten authored and Chocobozzz committed Oct 22, 2024
commit c033d29f9b1ad8abf74d1b05574ea22751a6d0d9
15 changes: 9 additions & 6 deletions packages/server-commands/src/videos/videos-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,22 +417,25 @@ export class VideosCommand extends AbstractCommand {
mode?: 'legacy' | 'resumable' // default legacy
waitTorrentGeneration?: boolean // default true
completedExpectedStatus?: HttpStatusCodeType
videoChannelId?: number
} = {}) {
const { mode = 'legacy', waitTorrentGeneration = true } = options
const { mode = 'legacy', videoChannelId, waitTorrentGeneration = true } = options
let defaultChannelId = 1

try {
const { videoChannels } = await this.server.users.getMyInfo({ token: options.token })
defaultChannelId = videoChannels[0].id
} catch (e) { /* empty */ }
if (!videoChannelId) {
try {
const { videoChannels } = await this.server.users.getMyInfo({ token: options.token })
defaultChannelId = videoChannels[0].id
} catch (e) { /* empty */ }
}

// Override default attributes
const attributes = {
name: 'my super video',
category: 5,
licence: 4,
language: 'zh',
channelId: defaultChannelId,
channelId: videoChannelId || defaultChannelId,
nsfw: true,
waitTranscoding: false,
description: 'my super description',
Expand Down
27 changes: 20 additions & 7 deletions packages/tests/src/misc-endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,26 @@ describe('Test misc endpoints', function () {
it('Should add videos, channel and accounts and get sitemap', async function () {
this.timeout(35000)

await server.videos.upload({ attributes: { name: 'video 1', nsfw: false } })
await server.videos.upload({ attributes: { name: 'video 2', nsfw: false } })
await server.videos.upload({ attributes: { name: 'video 3', privacy: VideoPrivacy.PRIVATE } })
const { token: user1Token } = await server.users.generate('user1')
const { token: user2Token } = await server.users.generate('user2')
const { token: user3Token } = await server.users.generate('user3')

await server.channels.create({ attributes: { name: 'channel1', displayName: 'channel 1' } })
await server.channels.create({ attributes: { name: 'channel2', displayName: 'channel 2' } })
const { id: channel1Id } = await server.channels.create({
attributes: { name: 'channel1', displayName: 'channel 1' },
token: user1Token
})
const { id: channel2Id } = await server.channels.create({
attributes: { name: 'channel2', displayName: 'channel 2' },
token: user2Token
})
const { id: channel3Id } = await server.channels.create({
attributes: { name: 'channel3', displayName: 'channel 3' },
token: user3Token
})

await server.users.create({ username: 'user1', password: 'password' })
await server.users.create({ username: 'user2', password: 'password' })
await server.videos.upload({ attributes: { name: 'video 1', nsfw: false }, videoChannelId: channel1Id })
await server.videos.upload({ attributes: { name: 'video 2', nsfw: false }, videoChannelId: channel2Id })
await server.videos.upload({ attributes: { name: 'video 3', privacy: VideoPrivacy.PRIVATE }, videoChannelId: channel3Id })

const res = await makeGetRequest({
url: server.url,
Expand All @@ -218,9 +229,11 @@ describe('Test misc endpoints', function () {

expect(res.text).to.contain('<url><loc>' + server.url + '/c/channel1/videos</loc></url>')
expect(res.text).to.contain('<url><loc>' + server.url + '/c/channel2/videos</loc></url>')
expect(res.text).to.not.contain('<url><loc>' + server.url + '/c/channel3/videos</loc></url>')

expect(res.text).to.contain('<url><loc>' + server.url + '/a/user1/video-channels</loc></url>')
expect(res.text).to.contain('<url><loc>' + server.url + '/a/user2/video-channels</loc></url>')
expect(res.text).to.not.contain('<url><loc>' + server.url + '/a/user3/video-channels</loc></url>')
})

it('Should not fail with big title/description videos', async function () {
Expand Down
17 changes: 16 additions & 1 deletion server/core/models/account/account.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Account, AccountSummary } from '@peertube/peertube-models'
import { Account, AccountSummary, VideoPrivacy } from '@peertube/peertube-models'
import { ModelCache } from '@server/models/shared/model-cache.js'
import { FindOptions, IncludeOptions, Includeable, Op, Transaction, WhereOptions } from 'sequelize'
import {
Expand Down Expand Up @@ -433,6 +433,21 @@ export class AccountModel extends SequelizeModel<AccountModel> {
where: {
serverId: null
}
},
{
attributes: [ 'id' ],
model: VideoChannelModel.unscoped(),
required: true,
include: [
{
attributes: [ 'id' ],
model: VideoModel.unscoped(),
required: true,
where: {
privacy: VideoPrivacy.PUBLIC
}
}
]
}
]
}
Expand Down
10 changes: 9 additions & 1 deletion server/core/models/video/video-channel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { forceNumber, pick } from '@peertube/peertube-core-utils'
import { ActivityPubActor, VideoChannel, VideoChannelSummary } from '@peertube/peertube-models'
import { ActivityPubActor, VideoChannel, VideoChannelSummary, VideoPrivacy } from '@peertube/peertube-models'
import { CONFIG } from '@server/initializers/config.js'
import { InternalEventEmitter } from '@server/lib/internal-event-emitter.js'
import { MAccountHost } from '@server/types/models/index.js'
Expand Down Expand Up @@ -522,6 +522,14 @@ export class VideoChannelModel extends SequelizeModel<VideoChannelModel> {
where: {
serverId: null
}
},
{
attributes: [ 'id' ],
model: VideoModel.unscoped(),
required: true,
where: {
privacy: VideoPrivacy.PUBLIC
}
}
]
}
Expand Down