Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion metrics/prometheus/prometheus.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ scrape_configs:
- targets: ["localhost:8080","localhost:3000"]

metrics_path: /api/v1/metrics/
scheme: http
scheme: http

authorization:
type: Bearer
credentials: 'your-api-key-here'
1 change: 0 additions & 1 deletion packages/server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ JWT_REFRESH_TOKEN_EXPIRY_IN_MINUTES=43200
# REDIS_KEEP_ALIVE=
# ENABLE_BULLMQ_DASHBOARD=


############################################################################################################
############################################## SECURITY ####################################################
############################################################################################################
Expand Down
40 changes: 39 additions & 1 deletion packages/server/src/controllers/export-import/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,45 @@ const importData = async (req: Request, res: Response, next: NextFunction) => {
}
}

const exportChatflowMessages = async (req: Request, res: Response, next: NextFunction) => {
try {
const workspaceId = req.user?.activeWorkspaceId
if (!workspaceId) {
throw new InternalFlowiseError(
StatusCodes.NOT_FOUND,
`Error: exportImportController.exportChatflowMessages - workspace ${workspaceId} not found!`
)
}

const { chatflowId, chatType, feedbackType, startDate, endDate } = req.body
if (!chatflowId) {
throw new InternalFlowiseError(
StatusCodes.BAD_REQUEST,
'Error: exportImportController.exportChatflowMessages - chatflowId is required!'
)
}

const apiResponse = await exportImportService.exportChatflowMessages(
chatflowId,
chatType,
feedbackType,
startDate,
endDate,
workspaceId
)

// Set headers for file download
res.setHeader('Content-Type', 'application/json')
res.setHeader('Content-Disposition', `attachment; filename="${chatflowId}-Message.json"`)

return res.json(apiResponse)
} catch (error) {
next(error)
}
}

export default {
exportData,
importData
importData,
exportChatflowMessages
}
17 changes: 0 additions & 17 deletions packages/server/src/controllers/get-upload-path/index.ts

This file was deleted.

28 changes: 28 additions & 0 deletions packages/server/src/enterprise/middleware/passport/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,34 @@ export const verifyToken = (req: Request, res: Response, next: NextFunction) =>
})(req, res, next)
}

export const verifyTokenForBullMQDashboard = (req: Request, res: Response, next: NextFunction) => {
passport.authenticate('jwt', { session: true }, (err: any, user: LoggedInUser, info: object) => {
if (err) {
return next(err)
}

// @ts-ignore
if (info && info.name === 'TokenExpiredError') {
if (req.cookies && req.cookies.refreshToken) {
return res.redirect('/signin?retry=true')
}
return res.redirect('/signin')
}

if (!user) {
return res.redirect('/signin')
}

const identityManager = getRunningExpressApp().identityManager
if (identityManager.isEnterprise() && !identityManager.isLicenseValid()) {
return res.redirect('/license-expired')
}

req.user = user
next()
})(req, res, next)
}

const storeSSOUserPayload = (ssoToken: string, returnUser: any) => {
const app = getRunningExpressApp()
app.cachePool.addSSOTokenCache(ssoToken, returnUser)
Expand Down
7 changes: 5 additions & 2 deletions packages/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cors from 'cors'
import http from 'http'
import cookieParser from 'cookie-parser'
import basicAuth from 'express-basic-auth'

Check warning on line 6 in packages/server/src/index.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.15.0)

'basicAuth' is defined but never used
import { DataSource, IsNull } from 'typeorm'
import { MODE, Platform } from './Interface'
import { getNodeModulesPackagePath, getEncryptionKey } from './utils'
Expand All @@ -18,7 +19,7 @@
import flowiseApiV1Router from './routes'
import errorHandlerMiddleware from './middlewares/errors'
import { WHITELIST_URLS } from './utils/constants'
import { initializeJwtCookieMiddleware, verifyToken } from './enterprise/middleware/passport'
import { initializeJwtCookieMiddleware, verifyToken, verifyTokenForBullMQDashboard } from './enterprise/middleware/passport'
import { IdentityManager } from './IdentityManager'
import { SSEStreamer } from './utils/SSEStreamer'
import { validateAPIKey } from './utils/validateKey'
Expand All @@ -35,6 +36,8 @@
import { GeneralRole, Role } from './enterprise/database/entities/role.entity'
import { migrateApiKeysFromJsonToDb } from './utils/apiKey'
import { ExpressAdapter } from '@bull-board/express'
import { InternalFlowiseError } from './errors/internalFlowiseError'

Check warning on line 39 in packages/server/src/index.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.15.0)

'InternalFlowiseError' is defined but never used
import { StatusCodes } from 'http-status-codes'

Check warning on line 40 in packages/server/src/index.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.15.0)

'StatusCodes' is defined but never used

declare global {
namespace Express {
Expand Down Expand Up @@ -331,7 +334,7 @@
})

if (process.env.MODE === MODE.QUEUE && process.env.ENABLE_BULLMQ_DASHBOARD === 'true' && !this.identityManager.isCloud()) {
this.app.use('/admin/queues', this.queueManager.getBullBoardRouter())
this.app.use('/admin/queues', verifyTokenForBullMQDashboard, this.queueManager.getBullBoardRouter())
}

// ----------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions packages/server/src/routes/export-import/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const router = express.Router()

router.post('/export', checkPermission('workspace:export'), exportImportController.exportData)

router.post('/chatflow-messages', checkPermission('workspace:export'), exportImportController.exportChatflowMessages)

router.post('/import', checkPermission('workspace:import'), exportImportController.importData)

export default router
8 changes: 0 additions & 8 deletions packages/server/src/routes/get-upload-path/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/server/src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import fetchLinksRouter from './fetch-links'
import filesRouter from './files'
import flowConfigRouter from './flow-config'
import getUploadFileRouter from './get-upload-file'
import getUploadPathRouter from './get-upload-path'
import internalChatmessagesRouter from './internal-chat-messages'
import internalPredictionRouter from './internal-predictions'
import leadsRouter from './leads'
Expand Down Expand Up @@ -93,7 +92,6 @@ router.use('/flow-config', flowConfigRouter)
router.use('/internal-chatmessage', internalChatmessagesRouter)
router.use('/internal-prediction', internalPredictionRouter)
router.use('/get-upload-file', getUploadFileRouter)
router.use('/get-upload-path', getUploadPathRouter)
router.use('/leads', leadsRouter)
router.use('/load-prompt', loadPromptRouter)
router.use('/marketplaces', marketplacesRouter)
Expand Down
Loading