add current version

This commit is contained in:
Henry
2023-08-24 15:46:14 +01:00
parent 51a1670b6a
commit 7a1d770b8e
2 changed files with 56 additions and 17 deletions
+28
View File
@@ -571,6 +571,34 @@ export class App {
return res.json(availableConfigs)
})
this.app.get('/api/v1/version', async (req: Request, res: Response) => {
const getPackageJsonPath = (): string => {
const checkPaths = [
path.join(__dirname, '..', 'package.json'),
path.join(__dirname, '..', '..', 'package.json'),
path.join(__dirname, '..', '..', '..', 'package.json'),
path.join(__dirname, '..', '..', '..', '..', 'package.json'),
path.join(__dirname, '..', '..', '..', '..', '..', 'package.json')
]
for (const checkPath of checkPaths) {
if (fs.existsSync(checkPath)) {
return checkPath
}
}
return ''
}
const packagejsonPath = getPackageJsonPath()
if (!packagejsonPath) return res.status(404).send('Version not found')
try {
const content = await fs.promises.readFile(packagejsonPath, 'utf8')
const parsedContent = JSON.parse(content)
return res.json({ version: parsedContent.version })
} catch (error) {
return res.status(500).send(`Version not found: ${error}`)
}
})
// ----------------------------------------
// Export Load Chatflow & ChatMessage & Apikeys
// ----------------------------------------