1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 19:42:24 +02:00

Add channelUpdatedAt list subscriptions sort

This commit is contained in:
Chocobozzz 2025-02-12 14:37:24 +01:00
parent 56419fd515
commit e002b6fcd6
No known key found for this signature in database
GPG key ID: 583A612D890159BE
5 changed files with 36 additions and 26 deletions

View file

@ -53,7 +53,8 @@ describe('Test users subscriptions', function () {
command = servers[0].subscriptions command = servers[0].subscriptions
}) })
describe('Destinction between server videos and user videos', function () { describe('Distinction between server videos and user videos', function () {
it('Should display videos of server 2 on server 1', async function () { it('Should display videos of server 2 on server 1', async function () {
const { total } = await servers[0].videos.list() const { total } = await servers[0].videos.list()
@ -161,6 +162,15 @@ describe('Test users subscriptions', function () {
expect(body.data).to.have.lengthOf(0) expect(body.data).to.have.lengthOf(0)
} }
}) })
it('Should sort subscriptions by channelUpdatedAt', async function () {
const body = await command.list({ token: users[0].accessToken, sort: '-channelUpdatedAt' })
expect(body.total).to.equal(2)
const subscriptions = body.data
expect(subscriptions[0].name).to.equal('user3_channel')
expect(subscriptions[1].name).to.equal('root_channel')
})
}) })
describe('Subscription videos', function () { describe('Subscription videos', function () {

View file

@ -57,7 +57,7 @@ mySubscriptionsRouter.get('/me/subscriptions',
setDefaultSort, setDefaultSort,
setDefaultPagination, setDefaultPagination,
userSubscriptionListValidator, userSubscriptionListValidator,
asyncMiddleware(getUserSubscriptions) asyncMiddleware(listUserSubscriptions)
) )
mySubscriptionsRouter.post('/me/subscriptions', mySubscriptionsRouter.post('/me/subscriptions',
@ -151,7 +151,7 @@ async function deleteUserSubscription (req: express.Request, res: express.Respon
.end() .end()
} }
async function getUserSubscriptions (req: express.Request, res: express.Response) { async function listUserSubscriptions (req: express.Request, res: express.Response) {
const user = res.locals.oauth.token.User const user = res.locals.oauth.token.User
const actorId = user.Account.Actor.id const actorId = user.Account.Actor.id

View file

@ -85,7 +85,7 @@ export const WEBSERVER = {
// Sortable columns per schema // Sortable columns per schema
export const SORTABLE_COLUMNS = { export const SORTABLE_COLUMNS = {
ADMIN_USERS: [ 'id', 'username', 'videoQuotaUsed', 'createdAt', 'lastLoginDate', 'role' ], ADMIN_USERS: [ 'id', 'username', 'videoQuotaUsed', 'createdAt', 'lastLoginDate', 'role' ],
USER_SUBSCRIPTIONS: [ 'id', 'createdAt' ], USER_SUBSCRIPTIONS: [ 'id', 'createdAt', 'channelUpdatedAt' ],
ACCOUNTS: [ 'createdAt' ], ACCOUNTS: [ 'createdAt' ],
JOBS: [ 'createdAt' ], JOBS: [ 'createdAt' ],
VIDEO_CHANNELS: [ 'id', 'name', 'updatedAt', 'createdAt' ], VIDEO_CHANNELS: [ 'id', 'name', 'updatedAt', 'createdAt' ],

View file

@ -40,7 +40,7 @@ import {
} from '../../initializers/constants.js' } from '../../initializers/constants.js'
import { AccountModel } from '../account/account.js' import { AccountModel } from '../account/account.js'
import { ServerModel } from '../server/server.js' import { ServerModel } from '../server/server.js'
import { SequelizeModel, buildSQLAttributes, createSafeIn, getSort, searchAttribute, throwIfNotValid } from '../shared/index.js' import { SequelizeModel, buildSQLAttributes, createSafeIn, getSubscriptionSort, searchAttribute, throwIfNotValid } from '../shared/index.js'
import { doesExist } from '../shared/query.js' import { doesExist } from '../shared/query.js'
import { VideoChannelModel } from '../video/video-channel.js' import { VideoChannelModel } from '../video/video-channel.js'
import { ActorModel, unusedActorAttributesForAPI } from './actor.js' import { ActorModel, unusedActorAttributesForAPI } from './actor.js'
@ -428,11 +428,11 @@ export class ActorFollowModel extends SequelizeModel<ActorFollowModel> {
return { return {
attributes: forCount === true attributes: forCount === true
? [] ? []
: SORTABLE_COLUMNS.USER_SUBSCRIPTIONS, : SORTABLE_COLUMNS.USER_SUBSCRIPTIONS.filter(s => s !== 'channelUpdatedAt'),
distinct: true, distinct: true,
offset: start, offset: start,
limit: count, limit: count,
order: getSort(sort), order: getSubscriptionSort(sort),
where, where,
include: [ include: [
{ {

View file

@ -1,7 +1,7 @@
import { literal, OrderItem, Sequelize } from 'sequelize' import { literal, OrderItem, Sequelize } from 'sequelize'
// Translate for example "-name" to [ [ 'name', 'DESC' ], [ 'id', 'ASC' ] ] // Translate for example "-name" to [ [ 'name', 'DESC' ], [ 'id', 'ASC' ] ]
function getSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] { export function getSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
const { direction, field } = buildSortDirectionAndField(value) const { direction, field } = buildSortDirectionAndField(value)
let finalField: string | ReturnType<typeof Sequelize.col> let finalField: string | ReturnType<typeof Sequelize.col>
@ -15,7 +15,7 @@ function getSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderIt
return [ [ finalField, direction ], lastSort ] return [ [ finalField, direction ], lastSort ]
} }
function getAdminUsersSort (value: string): OrderItem[] { export function getAdminUsersSort (value: string): OrderItem[] {
const { direction, field } = buildSortDirectionAndField(value) const { direction, field } = buildSortDirectionAndField(value)
let finalField: string | ReturnType<typeof Sequelize.col> let finalField: string | ReturnType<typeof Sequelize.col>
@ -34,7 +34,7 @@ function getAdminUsersSort (value: string): OrderItem[] {
return [ [ finalField as any, direction, nullPolicy ], [ 'id', 'ASC' ] ] return [ [ finalField as any, direction, nullPolicy ], [ 'id', 'ASC' ] ]
} }
function getPlaylistSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] { export function getPlaylistSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
const { direction, field } = buildSortDirectionAndField(value) const { direction, field } = buildSortDirectionAndField(value)
if (field.toLowerCase() === 'name') { if (field.toLowerCase() === 'name') {
@ -44,7 +44,7 @@ function getPlaylistSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]):
return getSort(value, lastSort) return getSort(value, lastSort)
} }
function getVideoSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] { export function getVideoSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
const { direction, field } = buildSortDirectionAndField(value) const { direction, field } = buildSortDirectionAndField(value)
if (field.toLowerCase() === 'trending') { // Sort by aggregation if (field.toLowerCase() === 'trending') { // Sort by aggregation
@ -81,7 +81,7 @@ function getVideoSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): Or
return [ firstSort, lastSort ] return [ firstSort, lastSort ]
} }
function getBlacklistSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] { export function getBlacklistSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
const { direction, field } = buildSortDirectionAndField(value) const { direction, field } = buildSortDirectionAndField(value)
const videoFields = new Set([ 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid' ]) const videoFields = new Set([ 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid' ])
@ -96,7 +96,7 @@ function getBlacklistSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ])
return getSort(value, lastSort) return getSort(value, lastSort)
} }
function getInstanceFollowsSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] { export function getInstanceFollowsSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
const { direction, field } = buildSortDirectionAndField(value) const { direction, field } = buildSortDirectionAndField(value)
if (field === 'redundancyAllowed') { if (field === 'redundancyAllowed') {
@ -109,7 +109,7 @@ function getInstanceFollowsSort (value: string, lastSort: OrderItem = [ 'id', 'A
return getSort(value, lastSort) return getSort(value, lastSort)
} }
function getChannelSyncSort (value: string): OrderItem[] { export function getChannelSyncSort (value: string): OrderItem[] {
const { direction, field } = buildSortDirectionAndField(value) const { direction, field } = buildSortDirectionAndField(value)
if (field.toLowerCase() === 'videochannel') { if (field.toLowerCase() === 'videochannel') {
return [ return [
@ -119,7 +119,18 @@ function getChannelSyncSort (value: string): OrderItem[] {
return [ [ field, direction ] ] return [ [ field, direction ] ]
} }
function buildSortDirectionAndField (value: string) { export function getSubscriptionSort (value: string): OrderItem[] {
const { direction, field } = buildSortDirectionAndField(value)
if (field === 'channelUpdatedAt') {
return [
[ literal('"ActorFollowing.VideoChannel.updatedAt"'), direction ]
]
}
return [ [ field, direction ] ]
}
export function buildSortDirectionAndField (value: string) {
let field: string let field: string
let direction: 'ASC' | 'DESC' let direction: 'ASC' | 'DESC'
@ -133,14 +144,3 @@ function buildSortDirectionAndField (value: string) {
return { direction, field } return { direction, field }
} }
export {
buildSortDirectionAndField,
getPlaylistSort,
getSort,
getAdminUsersSort,
getVideoSort,
getBlacklistSort,
getChannelSyncSort,
getInstanceFollowsSort
}