Skip to content

Commit

Permalink
feat(plugins): add peertubeHelpers.loadByIdOrUUIDWithFiles (#6302)
Browse files Browse the repository at this point in the history
  • Loading branch information
kontrollanten authored Apr 4, 2024
1 parent cd42491 commit 6f6abca
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
7 changes: 7 additions & 0 deletions packages/tests/fixtures/peertube-plugin-test-four/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ async function register ({

if (videoFromDB1.uuid !== videoFromDB2.uuid || videoFromDB2.uuid !== videoFromDB3.uuid) return

const videoWithFiles = await peertubeHelpers.videos.loadByIdOrUUIDWithFiles(video.id)

if (videoWithFiles.getHLSPlaylist().getMasterPlaylistUrl(videoWithFiles) === null) {
logger.error('Video with files could not be loaded.')
return
}

logger.info('video from DB uuid is %s.', videoFromDB1.uuid)

await peertubeHelpers.videos.removeVideo(video.id)
Expand Down
4 changes: 4 additions & 0 deletions server/core/lib/plugins/plugin-helpers-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ function buildVideosHelpers () {
return VideoModel.load(id)
},

loadByIdOrUUIDWithFiles: (id: number | string) => {
return VideoModel.loadWithFiles(id)
},

removeVideo: (id: number) => {
return sequelizeTypescript.transaction(async t => {
const video = await VideoModel.loadFull(id, t)
Expand Down
3 changes: 2 additions & 1 deletion server/core/types/plugins/register-server-option.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
VideoBlacklistCreate
} from '@peertube/peertube-models'
import { ActorModel } from '@server/models/actor/actor.js'
import { MUserDefault, MVideo, MVideoThumbnail, UserNotificationModelForApi } from '../models/index.js'
import { MUserDefault, MVideo, MVideoThumbnail, MVideoWithAllFiles, UserNotificationModelForApi } from '../models/index.js'
import {
RegisterServerAuthExternalOptions,
RegisterServerAuthExternalResult,
Expand All @@ -34,6 +34,7 @@ export type PeerTubeHelpers = {

videos: {
loadByUrl: (url: string) => Promise<MVideoThumbnail>
loadByIdOrUUIDWithFiles: (id: number | string) => Promise<MVideoWithAllFiles>
loadByIdOrUUID: (id: number | string) => Promise<MVideoThumbnail>

removeVideo: (videoId: number) => Promise<void>
Expand Down

0 comments on commit 6f6abca

Please sign in to comment.