Allow plugins to load a video by id

pull/3745/head
Chocobozzz 2021-02-11 10:23:52 +01:00
parent d93e43164a
commit 6559da2821
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
4 changed files with 22 additions and 6 deletions

View File

@ -2,11 +2,17 @@
# For additional information regarding the format and rule options, please see:
# https://github.com/browserslist/browserslist#queries
# For the full list of supported browsers by the Angular framework, please see:
# https://angular.io/guide/browser-support
# You can see what browsers were selected by your queries by running:
# npx browserslist
> 0.5%
last 2 versions
last 1 Chrome version
last 1 Firefox version
last 2 Edge major versions
last 2 Safari major versions
last 2 iOS major versions
Firefox ESR
not dead
not IE 9-11 # For IE 9-11 support, remove 'not'.
not IE 9-10 # Angular support for IE 9-10 has been deprecated and will be removed as of Angular v11. To opt-in, remove the 'not' prefix on this line.
not IE 11 # Angular supports IE 11 only as an opt-in. To opt-in, remove the 'not' prefix on this line.

View File

@ -63,6 +63,10 @@ function buildVideosHelpers () {
return VideoModel.loadByUrl(url)
},
loadByIdOrUUID: (id: number | string) => {
return VideoModel.load(id)
},
removeVideo: (id: number) => {
return sequelizeTypescript.transaction(async t => {
const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(id, t)

View File

@ -24,8 +24,13 @@ async function register ({
registerHook({
target: 'action:api.video.viewed',
handler: async ({ video }) => {
const videoFromDB = await peertubeHelpers.videos.loadByUrl(video.url)
logger.info('video from DB uuid is %s.', videoFromDB.uuid)
const videoFromDB1 = await peertubeHelpers.videos.loadByUrl(video.url)
const videoFromDB2 = await peertubeHelpers.videos.loadByIdOrUUID(video.id)
const videoFromDB3 = await peertubeHelpers.videos.loadByIdOrUUID(video.uuid)
if (videoFromDB1.uuid !== videoFromDB2.uuid || videoFromDB2.uuid !== videoFromDB3.uuid) return
logger.info('video from DB uuid is %s.', videoFromDB1.uuid)
await peertubeHelpers.videos.removeVideo(video.id)

View File

@ -30,6 +30,7 @@ export type PeerTubeHelpers = {
videos: {
loadByUrl: (url: string) => Promise<MVideoThumbnail>
loadByIdOrUUID: (id: number | string) => Promise<MVideoThumbnail>
removeVideo: (videoId: number) => Promise<void>
}