1
0
Fork 0

Allow plugins to load a video by id

This commit is contained in:
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: # For additional information regarding the format and rule options, please see:
# https://github.com/browserslist/browserslist#queries # 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: # You can see what browsers were selected by your queries by running:
# npx browserslist # npx browserslist
> 0.5% last 1 Chrome version
last 2 versions last 1 Firefox version
last 2 Edge major versions
last 2 Safari major versions
last 2 iOS major versions
Firefox ESR Firefox ESR
not dead 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 9-11 # For IE 9-11 support, remove 'not'. 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) return VideoModel.loadByUrl(url)
}, },
loadByIdOrUUID: (id: number | string) => {
return VideoModel.load(id)
},
removeVideo: (id: number) => { removeVideo: (id: number) => {
return sequelizeTypescript.transaction(async t => { return sequelizeTypescript.transaction(async t => {
const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(id, t) const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(id, t)

View file

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

View file

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