mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 10:49:28 +02:00
Playlist server API
This commit is contained in:
parent
b427febb4d
commit
418d092afa
63 changed files with 2758 additions and 226 deletions
|
@ -9,6 +9,7 @@ import { isViewActivityValid } from './view'
|
|||
import { exists } from '../misc'
|
||||
import { isCacheFileObjectValid } from './cache-file'
|
||||
import { isFlagActivityValid } from './flag'
|
||||
import { isPlaylistObjectValid } from './playlist'
|
||||
|
||||
function isRootActivityValid (activity: any) {
|
||||
return Array.isArray(activity['@context']) && (
|
||||
|
@ -78,6 +79,7 @@ function checkCreateActivity (activity: any) {
|
|||
isViewActivityValid(activity.object) ||
|
||||
isDislikeActivityValid(activity.object) ||
|
||||
isFlagActivityValid(activity.object) ||
|
||||
isPlaylistObjectValid(activity.object) ||
|
||||
|
||||
isCacheFileObjectValid(activity.object) ||
|
||||
sanitizeAndCheckVideoCommentObject(activity.object) ||
|
||||
|
@ -89,6 +91,7 @@ function checkUpdateActivity (activity: any) {
|
|||
return isBaseActivityValid(activity, 'Update') &&
|
||||
(
|
||||
isCacheFileObjectValid(activity.object) ||
|
||||
isPlaylistObjectValid(activity.object) ||
|
||||
sanitizeAndCheckVideoTorrentObject(activity.object) ||
|
||||
sanitizeAndCheckActorObject(activity.object)
|
||||
)
|
||||
|
|
25
server/helpers/custom-validators/activitypub/playlist.ts
Normal file
25
server/helpers/custom-validators/activitypub/playlist.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import { exists } from '../misc'
|
||||
import { PlaylistObject } from '../../../../shared/models/activitypub/objects/playlist-object'
|
||||
import * as validator from 'validator'
|
||||
import { PlaylistElementObject } from '../../../../shared/models/activitypub/objects/playlist-element-object'
|
||||
import { isActivityPubUrlValid } from './misc'
|
||||
|
||||
function isPlaylistObjectValid (object: PlaylistObject) {
|
||||
return exists(object) &&
|
||||
object.type === 'Playlist' &&
|
||||
validator.isInt(object.totalItems + '')
|
||||
}
|
||||
|
||||
function isPlaylistElementObjectValid (object: PlaylistElementObject) {
|
||||
return exists(object) &&
|
||||
object.type === 'PlaylistElement' &&
|
||||
validator.isInt(object.position + '') &&
|
||||
isActivityPubUrlValid(object.url)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
isPlaylistObjectValid,
|
||||
isPlaylistElementObjectValid
|
||||
}
|
44
server/helpers/custom-validators/video-playlists.ts
Normal file
44
server/helpers/custom-validators/video-playlists.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
import { exists } from './misc'
|
||||
import * as validator from 'validator'
|
||||
import { CONSTRAINTS_FIELDS, VIDEO_PLAYLIST_PRIVACIES } from '../../initializers'
|
||||
import * as express from 'express'
|
||||
import { VideoPlaylistModel } from '../../models/video/video-playlist'
|
||||
import { VideoPlaylistElementModel } from '../../models/video/video-playlist-element'
|
||||
|
||||
const PLAYLISTS_CONSTRAINT_FIELDS = CONSTRAINTS_FIELDS.VIDEO_PLAYLISTS
|
||||
|
||||
function isVideoPlaylistNameValid (value: any) {
|
||||
return exists(value) && validator.isLength(value, PLAYLISTS_CONSTRAINT_FIELDS.NAME)
|
||||
}
|
||||
|
||||
function isVideoPlaylistDescriptionValid (value: any) {
|
||||
return value === null || (exists(value) && validator.isLength(value, PLAYLISTS_CONSTRAINT_FIELDS.DESCRIPTION))
|
||||
}
|
||||
|
||||
function isVideoPlaylistPrivacyValid (value: number) {
|
||||
return validator.isInt(value + '') && VIDEO_PLAYLIST_PRIVACIES[ value ] !== undefined
|
||||
}
|
||||
|
||||
async function isVideoPlaylistExist (id: number | string, res: express.Response) {
|
||||
const videoPlaylist = await VideoPlaylistModel.load(id, undefined)
|
||||
|
||||
if (!videoPlaylist) {
|
||||
res.status(404)
|
||||
.json({ error: 'Video playlist not found' })
|
||||
.end()
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
res.locals.videoPlaylist = videoPlaylist
|
||||
return true
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
isVideoPlaylistExist,
|
||||
isVideoPlaylistNameValid,
|
||||
isVideoPlaylistDescriptionValid,
|
||||
isVideoPlaylistPrivacyValid
|
||||
}
|
|
@ -165,7 +165,7 @@ function checkUserCanManageVideo (user: UserModel, video: VideoModel, right: Use
|
|||
return true
|
||||
}
|
||||
|
||||
async function isVideoExist (id: string, res: Response, fetchType: VideoFetchType = 'all') {
|
||||
async function isVideoExist (id: number | string, res: Response, fetchType: VideoFetchType = 'all') {
|
||||
const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined
|
||||
|
||||
const video = await fetchVideo(id, fetchType, userId)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue