diff --git a/packages/server/src/index.ts b/packages/server/src/index.ts index c3b85483..66c7b000 100644 --- a/packages/server/src/index.ts +++ b/packages/server/src/index.ts @@ -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 // ---------------------------------------- diff --git a/packages/ui/src/ui-component/dialog/AboutDialog.js b/packages/ui/src/ui-component/dialog/AboutDialog.js index 54c077d1..4f480a58 100644 --- a/packages/ui/src/ui-component/dialog/AboutDialog.js +++ b/packages/ui/src/ui-component/dialog/AboutDialog.js @@ -4,18 +4,7 @@ import PropTypes from 'prop-types' import { Dialog, DialogContent, DialogTitle, TableContainer, Table, TableHead, TableRow, TableCell, TableBody, Paper } from '@mui/material' import moment from 'moment' import axios from 'axios' - -const fetchLatestVer = async ({ api }) => { - let apiReturn = await axios - .get(api) - .then(async function (response) { - return response.data - }) - .catch(function (error) { - console.error(error) - }) - return apiReturn -} +import { baseURL } from 'store/constant' const AboutDialog = ({ show, onCancel }) => { const portalElement = document.getElementById('portal') @@ -24,12 +13,30 @@ const AboutDialog = ({ show, onCancel }) => { useEffect(() => { if (show) { - const fetchData = async (api) => { - let response = await fetchLatestVer({ api }) - setData(response) - } + const username = localStorage.getItem('username') + const password = localStorage.getItem('password') - fetchData('https://api.github.com/repos/FlowiseAI/Flowise/releases/latest') + const config = {} + if (username && password) { + config.auth = { + username, + password + } + } + const latestReleaseReq = axios.get('https://api.github.com/repos/FlowiseAI/Flowise/releases/latest') + const currentVersionReq = axios.get(`${baseURL}/api/v1/version`, { ...config }) + + Promise.all([latestReleaseReq, currentVersionReq]) + .then(([latestReleaseData, currentVersionData]) => { + const finalData = { + ...latestReleaseData.data, + currentVersion: currentVersionData.data.version + } + setData(finalData) + }) + .catch((error) => { + console.error('Error fetching data:', error) + }) } // eslint-disable-next-line react-hooks/exhaustive-deps @@ -53,12 +60,16 @@ const AboutDialog = ({ show, onCancel }) => {