diff --git a/documentation/prosody.md b/documentation/prosody.md index 743df52b..01b93021 100644 --- a/documentation/prosody.md +++ b/documentation/prosody.md @@ -20,8 +20,6 @@ If you are not using prosody for anything else on your server, you can then disa sudo systemctl disable prosody && sudo systemctl stop prosody ``` -**NB:** with Peertube prior to version 3.2.0, the plugin will create a directory in the `/tmp/` folder. Please ensure that the `peertube` user has write access to this directory. - And that's it! The Prosody process launched by the plugin will listen on a specific port, and only on the localhost interface. diff --git a/server/lib/diagnostic/prosody.ts b/server/lib/diagnostic/prosody.ts index 007c4ed7..11e8885f 100644 --- a/server/lib/diagnostic/prosody.ts +++ b/server/lib/diagnostic/prosody.ts @@ -9,12 +9,7 @@ export async function diagProsody (test: string, options: RegisterServerOptions) try { const workingDir = await getWorkingDir(options) - result.messages.push('The working dir is: ' + workingDir.dir) - if (workingDir.permanent) { - result.messages.push('The working dir is permanent') - } else { - result.messages.push('The working dir is a temporary directory') - } + result.messages.push('The working dir is: ' + workingDir) } catch (error) { result.messages.push('Error when requiring the working dir: ' + (error as string)) return result diff --git a/server/lib/prosody/config.ts b/server/lib/prosody/config.ts index dd8fbcd2..5ec4be49 100644 --- a/server/lib/prosody/config.ts +++ b/server/lib/prosody/config.ts @@ -1,66 +1,27 @@ import * as fs from 'fs' import * as path from 'path' -import { pluginName, getBaseRouterRoute } from '../helpers' +import { getBaseRouterRoute } from '../helpers' import { ProsodyFilePaths } from './config/paths' import { ProsodyConfigContent } from './config/content' import { getProsodyDomain } from './config/domain' import { getAPIKey } from '../apikey' import type { ProsodyLogLevel } from './config/content' -async function _getTemporaryWorkingDir ({ peertubeHelpers, storageManager }: RegisterServerOptions): Promise { - const tmpBaseDir = '/tmp/' - let value: string = await storageManager.getData('tempDirId') - - function getPath (value: string): string { - return path.resolve(tmpBaseDir, pluginName + '-' + value) - } - - while (!value) { - peertubeHelpers.logger.info('Generating an id for temp dir') - value = Math.random().toString(36).slice(2, 12) - const name = getPath(value) - if (fs.existsSync(name)) { - peertubeHelpers.logger.info('The folder ' + name + ' already exists, generating another name...') - value = '' - continue - } - await storageManager.storeData('tempDirId', value) - } - - const dir = getPath(value) - return dir -} - -async function getWorkingDir (options: RegisterServerOptions): Promise<{ - dir: string - permanent: boolean -}> { +async function getWorkingDir (options: RegisterServerOptions): Promise { const peertubeHelpers = options.peertubeHelpers const logger = peertubeHelpers.logger logger.debug('Calling getWorkingDir') - if (peertubeHelpers.plugin?.getDataDirectoryPath) { - const dir = path.resolve(peertubeHelpers.plugin.getDataDirectoryPath(), 'prosody') - logger.debug('getWorkingDir will return the permanent dir ' + dir) - return { - dir: dir, - permanent: true - } - } - - const dir = await _getTemporaryWorkingDir(options) - logger.debug('getWorkingDir will return the temporary dir ' + dir) - return { - dir: dir, - permanent: false + if (!peertubeHelpers.plugin?.getDataDirectoryPath) { + throw new Error('Cant get the plugin Data Directory') } + const dir = path.resolve(peertubeHelpers.plugin.getDataDirectoryPath(), 'prosody') + logger.debug('getWorkingDir will return the dir ' + dir) + return dir } /** * Creates the working dir if needed, and returns it. - * NB: for now, I try to create a directory in /tmp/. - * To ensure that there is no conflict with another peertube instance, - * I used a randomly generated id that will be stored in database. */ async function ensureWorkingDir (options: RegisterServerOptions): Promise { const logger = options.peertubeHelpers.logger @@ -90,11 +51,9 @@ async function getProsodyFilePaths (options: RegisterServerOptions): Promise