Bugfix - Validating IDs for all imports (#4226)
This commit is contained in:
parent
ca69a39b82
commit
f963e5aa48
|
|
@ -16,6 +16,7 @@ import { ICommonObject } from 'flowise-components'
|
|||
import logger from '../../utils/logger'
|
||||
import { ASSISTANT_PROMPT_GENERATOR } from '../../utils/prompt'
|
||||
import { INPUT_PARAMS_TYPE } from '../../utils/constants'
|
||||
import { validate } from 'uuid'
|
||||
|
||||
const createAssistant = async (requestBody: any): Promise<Assistant> => {
|
||||
try {
|
||||
|
|
@ -339,6 +340,12 @@ const updateAssistant = async (assistantId: string, requestBody: any): Promise<A
|
|||
|
||||
const importAssistants = async (newAssistants: Partial<Assistant>[], queryRunner?: QueryRunner): Promise<any> => {
|
||||
try {
|
||||
for (const data of newAssistants) {
|
||||
if (data.id && !validate(data.id)) {
|
||||
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: importAssistants - invalid id!`)
|
||||
}
|
||||
}
|
||||
|
||||
const appServer = getRunningExpressApp()
|
||||
const repository = queryRunner ? queryRunner.manager.getRepository(Assistant) : appServer.AppDataSource.getRepository(Assistant)
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import { containsBase64File, updateFlowDataWithFilePaths } from '../../utils/fil
|
|||
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
|
||||
import { utilGetUploadsConfig } from '../../utils/getUploadsConfig'
|
||||
import logger from '../../utils/logger'
|
||||
import { validate } from 'uuid'
|
||||
|
||||
// Check if chatflow valid for streaming
|
||||
const checkIfChatflowIsValidForStreaming = async (chatflowId: string): Promise<any> => {
|
||||
|
|
@ -220,6 +221,12 @@ const saveChatflow = async (newChatFlow: ChatFlow): Promise<any> => {
|
|||
|
||||
const importChatflows = async (newChatflows: Partial<ChatFlow>[], queryRunner?: QueryRunner): Promise<any> => {
|
||||
try {
|
||||
for (const data of newChatflows) {
|
||||
if (data.id && !validate(data.id)) {
|
||||
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: importChatflows - invalid id!`)
|
||||
}
|
||||
}
|
||||
|
||||
const appServer = getRunningExpressApp()
|
||||
const repository = queryRunner ? queryRunner.manager.getRepository(ChatFlow) : appServer.AppDataSource.getRepository(ChatFlow)
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import { getAppVersion } from '../../utils'
|
|||
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
|
||||
import { FLOWISE_METRIC_COUNTERS, FLOWISE_COUNTER_STATUS } from '../../Interface.Metrics'
|
||||
import { QueryRunner } from 'typeorm'
|
||||
import { validate } from 'uuid'
|
||||
|
||||
const createTool = async (requestBody: any): Promise<any> => {
|
||||
try {
|
||||
|
|
@ -84,6 +85,12 @@ const updateTool = async (toolId: string, toolBody: any): Promise<any> => {
|
|||
|
||||
const importTools = async (newTools: Partial<Tool>[], queryRunner?: QueryRunner) => {
|
||||
try {
|
||||
for (const data of newTools) {
|
||||
if (data.id && !validate(data.id)) {
|
||||
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: importTools - invalid id!`)
|
||||
}
|
||||
}
|
||||
|
||||
const appServer = getRunningExpressApp()
|
||||
const repository = queryRunner ? queryRunner.manager.getRepository(Tool) : appServer.AppDataSource.getRepository(Tool)
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { Variable } from '../../database/entities/Variable'
|
|||
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
|
||||
import { getErrorMessage } from '../../errors/utils'
|
||||
import { QueryRunner } from 'typeorm'
|
||||
import { validate } from 'uuid'
|
||||
|
||||
const createVariable = async (newVariable: Variable) => {
|
||||
try {
|
||||
|
|
@ -76,6 +77,12 @@ const updateVariable = async (variable: Variable, updatedVariable: Variable) =>
|
|||
|
||||
const importVariables = async (newVariables: Partial<Variable>[], queryRunner?: QueryRunner): Promise<any> => {
|
||||
try {
|
||||
for (const data of newVariables) {
|
||||
if (data.id && !validate(data.id)) {
|
||||
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: importVariables - invalid id!`)
|
||||
}
|
||||
}
|
||||
|
||||
const appServer = getRunningExpressApp()
|
||||
const repository = queryRunner ? queryRunner.manager.getRepository(Variable) : appServer.AppDataSource.getRepository(Variable)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue