stderrLevels: [],
format: winston.format.combine(
winston.format.splat(),
- labelFormatter,
+ labelFormatter(),
winston.format.colorize(),
loggerFormat
)
maxFiles: 5,
format: winston.format.combine(
winston.format.timestamp(),
- labelFormatter,
+ labelFormatter(),
winston.format.splat(),
jsonLoggerFormat
)
-import { PluginModel } from '@server/models/server/plugin'
import { PeerTubeHelpers } from '@server/typings/plugins'
+import { sequelizeTypescript } from '@server/initializers/database'
+import { buildLogger } from '@server/helpers/logger'
-function buildPluginHelpers (npmName: string, plugin: PluginModel): PeerTubeHelpers {
- const logger = buildLogger(npmName)
+function buildPluginHelpers (npmName: string): PeerTubeHelpers {
+ const logger = buildPluginLogger(npmName)
+
+ const database = buildDatabaseHelpers()
return {
- logger
+ logger,
+ database
}
}
// ---------------------------------------------------------------------------
-function buildLogger (npmName: string) {
+function buildPluginLogger (npmName: string) {
return buildLogger(npmName)
}
+
+function buildDatabaseHelpers () {
+ return {
+ query: sequelizeTypescript.query.bind(sequelizeTypescript)
+ }
+}
const videoCategoryManager = buildVideoCategoryManager(npmName)
const videoLicenceManager = buildVideoLicenceManager(npmName)
- const peertubeHelpers = buildPluginHelpers(npmName, plugin)
+ const peertubeHelpers = buildPluginHelpers(npmName)
return {
settingsManager,
--- /dev/null
+async function register ({
+ peertubeHelpers
+}) {
+ peertubeHelpers.logger.info('Hello world from plugin four')
+
+ const username = 'root'
+ const results = await peertubeHelpers.database.query(
+ 'SELECT "email" from "user" WHERE "username" = $username',
+ {
+ type: 'SELECT',
+ bind: { username }
+ }
+ )
+
+ peertubeHelpers.logger.info('root email is ' + results[0]['email'])
+}
+
+async function unregister () {
+ return
+}
+
+module.exports = {
+ register,
+ unregister
+}
+
+// ###########################################################################
--- /dev/null
+{
+ "name": "peertube-plugin-test-four",
+ "version": "0.0.1",
+ "description": "Plugin test 4",
+ "engine": {
+ "peertube": ">=1.3.0"
+ },
+ "keywords": [
+ "peertube",
+ "plugin"
+ ],
+ "homepage": "https://github.com/Chocobozzz/PeerTube",
+ "author": "Chocobozzz",
+ "bugs": "https://github.com/Chocobozzz/PeerTube/issues",
+ "library": "./main.js",
+ "staticDirs": {},
+ "css": [],
+ "clientScripts": [],
+ "translations": {}
+}
import './filter-hooks'
import './translations'
import './video-constants'
+import './plugin-helpers'
--- /dev/null
+/* 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
+
+describe('Test plugin helpers', function () {
+ let server: ServerInfo
+
+ before(async function () {
+ this.timeout(30000)
+
+ server = await flushAndRunServer(1)
+ await setAccessTokensToServers([ server ])
+
+ await installPlugin({
+ url: server.url,
+ accessToken: server.accessToken,
+ path: getPluginTestPath('-four')
+ })
+ })
+
+ it('Should have logged things', async function () {
+ await waitUntilLog(server, 'localhost:' + server.port + ' peertube-plugin-test-four', 1, false)
+ await waitUntilLog(server, 'Hello world from plugin four', 1)
+ })
+
+ it('Should have made a query', async function () {
+ await waitUntilLog(server, `root email is admin${server.internalServerNumber}@example.com`, 1)
+ })
+
+ after(async function () {
+ await cleanupTests([ server ])
+ })
+})
export type PeerTubeHelpers = {
logger: Logger
+
+ database: {
+ query: Function
+ }
}
export type RegisterServerOptions = {
return Promise.all(p)
}
-async function waitUntilLog (server: ServerInfo, str: string, count = 1) {
+async function waitUntilLog (server: ServerInfo, str: string, count = 1, strictCount = true) {
const logfile = join(root(), 'test' + server.internalServerNumber, 'logs/peertube.log')
while (true) {
const matches = buf.toString().match(new RegExp(str, 'g'))
if (matches && matches.length === count) return
+ if (matches && strictCount === false && matches.length >= count) return
await wait(1000)
}