Chore deprecate importChatflows method (#4965)

chore: remove importchatflows
This commit is contained in:
Ong Chung Yau
2025-07-29 22:58:58 +08:00
committed by GitHub
parent bbb03b7b3b
commit 46816c7c1e
4 changed files with 2 additions and 92 deletions
@@ -157,32 +157,6 @@ const saveChatflow = async (req: Request, res: Response, next: NextFunction) =>
}
}
const importChatflows = async (req: Request, res: Response, next: NextFunction) => {
try {
const chatflows: Partial<ChatFlow>[] = req.body.Chatflows
const orgId = req.user?.activeOrganizationId
if (!orgId) {
throw new InternalFlowiseError(
StatusCodes.NOT_FOUND,
`Error: chatflowsController.saveChatflow - organization ${orgId} not found!`
)
}
const workspaceId = req.user?.activeWorkspaceId
if (!workspaceId) {
throw new InternalFlowiseError(
StatusCodes.NOT_FOUND,
`Error: chatflowsController.saveChatflow - workspace ${workspaceId} not found!`
)
}
const subscriptionId = req.user?.activeOrganizationSubscriptionId || ''
req.body.workspaceId = req.user?.activeWorkspaceId
const apiResponse = await chatflowsService.importChatflows(chatflows, orgId, workspaceId, subscriptionId)
return res.json(apiResponse)
} catch (error) {
next(error)
}
}
const updateChatflow = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params === 'undefined' || !req.params.id) {
@@ -281,7 +255,6 @@ export default {
getChatflowByApiKey,
getChatflowById,
saveChatflow,
importChatflows,
updateChatflow,
getSinglePublicChatflow,
getSinglePublicChatbotConfig,
@@ -5,7 +5,6 @@ const router = express.Router()
// CREATE
router.post('/', checkAnyPermission('chatflows:create,chatflows:update'), chatflowsController.saveChatflow)
router.post('/importchatflows', checkPermission('chatflows:import'), chatflowsController.importChatflows)
// READ
router.get('/', checkAnyPermission('chatflows:view,chatflows:update'), chatflowsController.getAllChatflows)
@@ -1,6 +1,6 @@
import { ICommonObject, removeFolderFromStorage } from 'flowise-components'
import { StatusCodes } from 'http-status-codes'
import { In, QueryRunner } from 'typeorm'
import { In } from 'typeorm'
import { ChatflowType, IReactFlowObject } from '../../Interface'
import { FLOWISE_COUNTER_STATUS, FLOWISE_METRIC_COUNTERS } from '../../Interface.Metrics'
import { UsageCacheManager } from '../../UsageCacheManager'
@@ -18,7 +18,7 @@ import { containsBase64File, updateFlowDataWithFilePaths } from '../../utils/fil
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { utilGetUploadsConfig } from '../../utils/getUploadsConfig'
import logger from '../../utils/logger'
import { checkUsageLimit, updateStorageUsage } from '../../utils/quotaUsage'
import { updateStorageUsage } from '../../utils/quotaUsage'
// Check if chatflow valid for streaming
const checkIfChatflowIsValidForStreaming = async (chatflowId: string): Promise<any> => {
@@ -307,64 +307,6 @@ const saveChatflow = async (
}
}
const importChatflows = async (
newChatflows: Partial<ChatFlow>[],
orgId: string,
_: string,
subscriptionId: string,
queryRunner?: QueryRunner
): Promise<any> => {
try {
const appServer = getRunningExpressApp()
const repository = queryRunner ? queryRunner.manager.getRepository(ChatFlow) : appServer.AppDataSource.getRepository(ChatFlow)
// step 1 - check whether file chatflows array is zero
if (newChatflows.length == 0) return
await checkUsageLimit('flows', subscriptionId, appServer.usageCacheManager, newChatflows.length)
// step 2 - check whether ids are duplicate in database
let ids = '('
let count: number = 0
const lastCount = newChatflows.length - 1
newChatflows.forEach((newChatflow) => {
ids += `'${newChatflow.id}'`
if (lastCount != count) ids += ','
if (lastCount == count) ids += ')'
count += 1
})
const selectResponse = await repository.createQueryBuilder('cf').select('cf.id').where(`cf.id IN ${ids}`).getMany()
const foundIds = selectResponse.map((response) => {
return response.id
})
// step 3 - remove ids that are only duplicate
const prepChatflows: Partial<ChatFlow>[] = newChatflows.map((newChatflow) => {
let id: string = ''
if (newChatflow.id) id = newChatflow.id
let flowData: string = ''
if (newChatflow.flowData) flowData = newChatflow.flowData
if (foundIds.includes(id)) {
newChatflow.id = undefined
newChatflow.name += ' (1)'
}
newChatflow.flowData = JSON.stringify(JSON.parse(flowData))
return newChatflow
})
// step 4 - transactional insert array of entities
const insertResponse = await repository.insert(prepChatflows)
return insertResponse
} catch (error) {
throw new InternalFlowiseError(
StatusCodes.INTERNAL_SERVER_ERROR,
`Error: chatflowsService.saveChatflows - ${getErrorMessage(error)}`
)
}
}
const updateChatflow = async (
chatflow: ChatFlow,
updateChatFlow: ChatFlow,
@@ -495,7 +437,6 @@ export default {
getChatflowByApiKey,
getChatflowById,
saveChatflow,
importChatflows,
updateChatflow,
getSinglePublicChatflow,
getSinglePublicChatbotConfig,
-3
View File
@@ -10,8 +10,6 @@ const getSpecificChatflowFromPublicEndpoint = (id) => client.get(`/public-chatfl
const createNewChatflow = (body) => client.post(`/chatflows`, body)
const importChatflows = (body) => client.post(`/chatflows/importchatflows`, body)
const updateChatflow = (id, body) => client.put(`/chatflows/${id}`, body)
const deleteChatflow = (id) => client.delete(`/chatflows/${id}`)
@@ -30,7 +28,6 @@ export default {
getSpecificChatflow,
getSpecificChatflowFromPublicEndpoint,
createNewChatflow,
importChatflows,
updateChatflow,
deleteChatflow,
getIsChatflowStreaming,