Builtin prosody use a working dir provided by Peertube.

This commit is contained in:
John Livingston 2021-05-11 15:37:34 +02:00
parent 0305b849cf
commit 094193a3b1
5 changed files with 49 additions and 8 deletions

View File

@ -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

View File

@ -154,6 +154,12 @@ interface PeerTubeHelpers {
user?: {
getAuthUser: (res: express.Response) => Promise<MUserDefault | undefined>
}
// Added in Peertube 3.2.0
plugin?: {
getBaseStaticRoute: () => string
getBaseRouterRoute: () => string
getDataDirectoryPath: () => string
}
}
interface RegisterServerOptions {

View File

@ -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

View File

@ -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<string> {
const logger = peertubeHelpers.logger
logger.debug('Calling getWorkingDir')
async function _getTemporaryWorkingDir ({ peertubeHelpers, storageManager }: RegisterServerOptions): Promise<string> {
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<Pro
const logger = options.peertubeHelpers.logger
logger.debug('Calling getProsodyFilePaths')
const dir = await getWorkingDir(options)
const workingDir = await getWorkingDir(options)
const dir = workingDir.dir
return {
dir: dir,
permanent: workingDir.permanent,
pid: path.resolve(dir, 'prosody.pid'),
error: path.resolve(dir, 'prosody.err'),
log: path.resolve(dir, 'prosody.log'),

View File

@ -6,6 +6,7 @@ interface ProsodyFilePaths {
config: string
data: string
modules: string
permanent: boolean
}
export {