diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/lib/plugins/plugin-helpers-builder.ts | 4 | ||||
-rw-r--r-- | server/tests/fixtures/peertube-plugin-test-four/main.js | 9 | ||||
-rw-r--r-- | server/types/plugins/register-server-option.model.ts | 1 |
3 files changed, 12 insertions, 2 deletions
diff --git a/server/lib/plugins/plugin-helpers-builder.ts b/server/lib/plugins/plugin-helpers-builder.ts index 39773f693..dac6b3185 100644 --- a/server/lib/plugins/plugin-helpers-builder.ts +++ b/server/lib/plugins/plugin-helpers-builder.ts | |||
@@ -63,6 +63,10 @@ function buildVideosHelpers () { | |||
63 | return VideoModel.loadByUrl(url) | 63 | return VideoModel.loadByUrl(url) |
64 | }, | 64 | }, |
65 | 65 | ||
66 | loadByIdOrUUID: (id: number | string) => { | ||
67 | return VideoModel.load(id) | ||
68 | }, | ||
69 | |||
66 | removeVideo: (id: number) => { | 70 | removeVideo: (id: number) => { |
67 | return sequelizeTypescript.transaction(async t => { | 71 | return sequelizeTypescript.transaction(async t => { |
68 | const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(id, t) | 72 | const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(id, t) |
diff --git a/server/tests/fixtures/peertube-plugin-test-four/main.js b/server/tests/fixtures/peertube-plugin-test-four/main.js index 067c3fe15..8df456c8a 100644 --- a/server/tests/fixtures/peertube-plugin-test-four/main.js +++ b/server/tests/fixtures/peertube-plugin-test-four/main.js | |||
@@ -24,8 +24,13 @@ async function register ({ | |||
24 | registerHook({ | 24 | registerHook({ |
25 | target: 'action:api.video.viewed', | 25 | target: 'action:api.video.viewed', |
26 | handler: async ({ video }) => { | 26 | handler: async ({ video }) => { |
27 | const videoFromDB = await peertubeHelpers.videos.loadByUrl(video.url) | 27 | const videoFromDB1 = await peertubeHelpers.videos.loadByUrl(video.url) |
28 | logger.info('video from DB uuid is %s.', videoFromDB.uuid) | 28 | const videoFromDB2 = await peertubeHelpers.videos.loadByIdOrUUID(video.id) |
29 | const videoFromDB3 = await peertubeHelpers.videos.loadByIdOrUUID(video.uuid) | ||
30 | |||
31 | if (videoFromDB1.uuid !== videoFromDB2.uuid || videoFromDB2.uuid !== videoFromDB3.uuid) return | ||
32 | |||
33 | logger.info('video from DB uuid is %s.', videoFromDB1.uuid) | ||
29 | 34 | ||
30 | await peertubeHelpers.videos.removeVideo(video.id) | 35 | await peertubeHelpers.videos.removeVideo(video.id) |
31 | 36 | ||
diff --git a/server/types/plugins/register-server-option.model.ts b/server/types/plugins/register-server-option.model.ts index ccd5a060d..1ca17e4ab 100644 --- a/server/types/plugins/register-server-option.model.ts +++ b/server/types/plugins/register-server-option.model.ts | |||
@@ -30,6 +30,7 @@ export type PeerTubeHelpers = { | |||
30 | 30 | ||
31 | videos: { | 31 | videos: { |
32 | loadByUrl: (url: string) => Promise<MVideoThumbnail> | 32 | loadByUrl: (url: string) => Promise<MVideoThumbnail> |
33 | loadByIdOrUUID: (id: number | string) => Promise<MVideoThumbnail> | ||
33 | 34 | ||
34 | removeVideo: (videoId: number) => Promise<void> | 35 | removeVideo: (videoId: number) => Promise<void> |
35 | } | 36 | } |