MCPcopy
hub / github.com/FlowiseAI/Flowise / saveChatflow

Function saveChatflow

packages/server/src/controllers/chatflows/index.ts:146–188  ·  view source on GitHub ↗
(req: Request, res: Response, next: NextFunction)

Source from the content-addressed store, hash-verified

144}
145
146const saveChatflow = async (req: Request, res: Response, next: NextFunction) => {
147 try {
148 if (!req.body) {
149 throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: chatflowsController.saveChatflow - body not provided!`)
150 }
151 const orgId = req.user?.activeOrganizationId
152 if (!orgId) {
153 throw new InternalFlowiseError(
154 StatusCodes.NOT_FOUND,
155 `Error: chatflowsController.saveChatflow - organization ${orgId} not found!`
156 )
157 }
158 const workspaceId = req.user?.activeWorkspaceId
159 if (!workspaceId) {
160 throw new InternalFlowiseError(
161 StatusCodes.NOT_FOUND,
162 `Error: chatflowsController.saveChatflow - workspace ${workspaceId} not found!`
163 )
164 }
165 const subscriptionId = req.user?.activeOrganizationSubscriptionId || ''
166 const body = req.body
167
168 const existingChatflowCount = await chatflowsService.getAllChatflowsCountByOrganization(body.type, orgId)
169 const newChatflowCount = 1
170 await checkUsageLimit('flows', subscriptionId, getRunningExpressApp().usageCacheManager, existingChatflowCount + newChatflowCount)
171
172 const newChatFlow = new ChatFlow()
173 Object.assign(newChatFlow, stripProtectedFields(body))
174
175 newChatFlow.workspaceId = workspaceId
176 const apiResponse = await chatflowsService.saveChatflow(
177 newChatFlow,
178 orgId,
179 workspaceId,
180 subscriptionId,
181 getRunningExpressApp().usageCacheManager
182 )
183
184 return res.json(apiResponse)
185 } catch (error) {
186 next(error)
187 }
188}
189
190const updateChatflow = async (req: Request, res: Response, next: NextFunction) => {
191 try {

Callers

nothing calls this directly

Calls 3

checkUsageLimitFunction · 0.90
getRunningExpressAppFunction · 0.90
stripProtectedFieldsFunction · 0.90

Tested by

no test coverage detected