mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 19:42:24 +02:00
Add ability to remove a video from a plugin
This commit is contained in:
parent
1b05d82d86
commit
ab3ead3a6f
5 changed files with 68 additions and 9 deletions
|
@ -1,7 +1,10 @@
|
|||
async function register ({
|
||||
peertubeHelpers
|
||||
peertubeHelpers,
|
||||
registerHook
|
||||
}) {
|
||||
peertubeHelpers.logger.info('Hello world from plugin four')
|
||||
const logger = peertubeHelpers.logger
|
||||
|
||||
logger.info('Hello world from plugin four')
|
||||
|
||||
const username = 'root'
|
||||
const results = await peertubeHelpers.database.query(
|
||||
|
@ -12,7 +15,16 @@ async function register ({
|
|||
}
|
||||
)
|
||||
|
||||
peertubeHelpers.logger.info('root email is ' + results[0]['email'])
|
||||
logger.info('root email is ' + results[0]['email'])
|
||||
|
||||
registerHook({
|
||||
target: 'action:api.video.viewed',
|
||||
handler: async ({ video }) => {
|
||||
await peertubeHelpers.videos.removeVideo(video.id)
|
||||
|
||||
logger.info('Video deleted by plugin four.')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function unregister () {
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
||||
|
||||
import * as chai from 'chai'
|
||||
import 'mocha'
|
||||
import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers'
|
||||
import { getPluginTestPath, installPlugin, setAccessTokensToServers } from '../../../shared/extra-utils'
|
||||
|
||||
const expect = chai.expect
|
||||
import {
|
||||
checkVideoFilesWereRemoved,
|
||||
getPluginTestPath,
|
||||
getVideo,
|
||||
installPlugin,
|
||||
setAccessTokensToServers,
|
||||
uploadVideoAndGetId,
|
||||
viewVideo
|
||||
} from '../../../shared/extra-utils'
|
||||
|
||||
describe('Test plugin helpers', function () {
|
||||
let server: ServerInfo
|
||||
|
@ -32,6 +37,29 @@ describe('Test plugin helpers', function () {
|
|||
await waitUntilLog(server, `root email is admin${server.internalServerNumber}@example.com`, 1)
|
||||
})
|
||||
|
||||
it('Should remove a video after a view', async function () {
|
||||
this.timeout(20000)
|
||||
|
||||
const videoUUID = (await uploadVideoAndGetId({ server: server, videoName: 'video1' })).uuid
|
||||
|
||||
// Should not throw -> video exists
|
||||
await getVideo(server.url, videoUUID)
|
||||
// Should delete the video
|
||||
await viewVideo(server.url, videoUUID)
|
||||
|
||||
await waitUntilLog(server, 'Video deleted by plugin four.', 1)
|
||||
|
||||
try {
|
||||
// Should throw because the video should have been deleted
|
||||
await getVideo(server.url, videoUUID)
|
||||
throw new Error('Video exists')
|
||||
} catch (err) {
|
||||
if (err.message.includes('exists')) throw err
|
||||
}
|
||||
|
||||
await checkVideoFilesWereRemoved(videoUUID, server.internalServerNumber)
|
||||
})
|
||||
|
||||
after(async function () {
|
||||
await cleanupTests([ server ])
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue