diff --git a/CHANGELOG.md b/CHANGELOG.md index fd196262..83de5124 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Not Released Yet + +### Features + +* Builtin prosody use a working dir provided by Peertube (needs Peertube >= 3.2.0) + ## v2.2.0 ### Features diff --git a/server/@types/peertube.d.ts b/server/@types/peertube.d.ts index f0212a04..8184eb04 100644 --- a/server/@types/peertube.d.ts +++ b/server/@types/peertube.d.ts @@ -154,6 +154,12 @@ interface PeerTubeHelpers { user?: { getAuthUser: (res: express.Response) => Promise } + // Added in Peertube 3.2.0 + plugin?: { + getBaseStaticRoute: () => string + getBaseRouterRoute: () => string + getDataDirectoryPath: () => string + } } interface RegisterServerOptions { diff --git a/server/lib/diagnostic/prosody.ts b/server/lib/diagnostic/prosody.ts index 87db55d3..007c4ed7 100644 --- a/server/lib/diagnostic/prosody.ts +++ b/server/lib/diagnostic/prosody.ts @@ -8,8 +8,13 @@ export async function diagProsody (test: string, options: RegisterServerOptions) result.label = 'Builtin Prosody and ConverseJS' try { - const dir = await getWorkingDir(options) - result.messages.push('The working dir is: ' + dir) + 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') + } } 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 6fac737a..282fe994 100644 --- a/server/lib/prosody/config.ts +++ b/server/lib/prosody/config.ts @@ -6,10 +6,7 @@ import { ProsodyConfigContent } from './config/content' import { getProsodyDomain } from './config/domain' import { getAPIKey } from '../apikey' -async function getWorkingDir ({ peertubeHelpers, storageManager }: RegisterServerOptions): Promise { - const logger = peertubeHelpers.logger - logger.debug('Calling getWorkingDir') - +async function _getTemporaryWorkingDir ({ peertubeHelpers, storageManager }: RegisterServerOptions): Promise { const tmpBaseDir = '/tmp/' let value: string = await storageManager.getData('tempDirId') @@ -30,10 +27,34 @@ async function getWorkingDir ({ peertubeHelpers, storageManager }: RegisterServe } const dir = getPath(value) - logger.debug('getWorkingDir will return ' + dir) return dir } +async function getWorkingDir (options: RegisterServerOptions): Promise<{ + dir: string + permanent: boolean +}> { + 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 + } +} + /** * Creates the working dir if needed, and returns it. * NB: for now, I try to create a directory in /tmp/. @@ -68,9 +89,11 @@ async function getProsodyFilePaths (options: RegisterServerOptions): Promise