remove import/export database
This commit is contained in:
parent
20f2da1743
commit
0ee47c2ccf
|
|
@ -190,12 +190,6 @@ export interface IOverrideConfig {
|
|||
type: string
|
||||
}
|
||||
|
||||
export interface IDatabaseExport {
|
||||
chatmessages: IChatMessage[]
|
||||
chatflows: IChatFlow[]
|
||||
apikeys: ICommonObject[]
|
||||
}
|
||||
|
||||
export type ICredentialDataDecrypted = ICommonObject
|
||||
|
||||
// Plain credential object sent to server
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ import {
|
|||
IReactFlowNode,
|
||||
IReactFlowObject,
|
||||
INodeData,
|
||||
IDatabaseExport,
|
||||
ICredentialReturnResponse,
|
||||
chatType,
|
||||
IChatMessage,
|
||||
|
|
@ -57,7 +56,7 @@ import { ChatflowPool } from './ChatflowPool'
|
|||
import { CachePool } from './CachePool'
|
||||
import { ICommonObject, INodeOptionsValue } from 'flowise-components'
|
||||
import { createRateLimiter, getRateLimiter, initializeRateLimiter } from './utils/rateLimit'
|
||||
import { addAPIKey, compareKeys, deleteAPIKey, getApiKey, getAPIKeys, replaceAllAPIKeys, updateAPIKey } from './utils/apiKey'
|
||||
import { addAPIKey, compareKeys, deleteAPIKey, getApiKey, getAPIKeys, updateAPIKey } from './utils/apiKey'
|
||||
|
||||
export class App {
|
||||
app: express.Application
|
||||
|
|
@ -1019,57 +1018,6 @@ export class App {
|
|||
}
|
||||
})
|
||||
|
||||
// ----------------------------------------
|
||||
// Export Load Chatflow & ChatMessage & Apikeys
|
||||
// ----------------------------------------
|
||||
|
||||
this.app.get('/api/v1/database/export', async (req: Request, res: Response) => {
|
||||
const chatmessages = await this.AppDataSource.getRepository(ChatMessage).find()
|
||||
const chatflows = await this.AppDataSource.getRepository(ChatFlow).find()
|
||||
const apikeys = await getAPIKeys()
|
||||
const result: IDatabaseExport = {
|
||||
chatmessages,
|
||||
chatflows,
|
||||
apikeys
|
||||
}
|
||||
return res.json(result)
|
||||
})
|
||||
|
||||
this.app.post('/api/v1/database/load', async (req: Request, res: Response) => {
|
||||
const databaseItems: IDatabaseExport = req.body
|
||||
|
||||
await this.AppDataSource.getRepository(ChatFlow).delete({})
|
||||
await this.AppDataSource.getRepository(ChatMessage).delete({})
|
||||
|
||||
let error = ''
|
||||
|
||||
// Get a new query runner instance
|
||||
const queryRunner = this.AppDataSource.createQueryRunner()
|
||||
|
||||
// Start a new transaction
|
||||
await queryRunner.startTransaction()
|
||||
|
||||
try {
|
||||
const chatflows: ChatFlow[] = databaseItems.chatflows
|
||||
const chatmessages: ChatMessage[] = databaseItems.chatmessages
|
||||
|
||||
await queryRunner.manager.insert(ChatFlow, chatflows)
|
||||
await queryRunner.manager.insert(ChatMessage, chatmessages)
|
||||
|
||||
await queryRunner.commitTransaction()
|
||||
} catch (err: any) {
|
||||
error = err?.message ?? 'Error loading database'
|
||||
await queryRunner.rollbackTransaction()
|
||||
} finally {
|
||||
await queryRunner.release()
|
||||
}
|
||||
|
||||
await replaceAllAPIKeys(databaseItems.apikeys)
|
||||
|
||||
if (error) return res.status(500).send(error)
|
||||
return res.status(201).send('OK')
|
||||
})
|
||||
|
||||
// ----------------------------------------
|
||||
// Upsert
|
||||
// ----------------------------------------
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
import client from './client'
|
||||
|
||||
const getExportDatabase = () => client.get('/database/export')
|
||||
const createLoadDatabase = (body) => client.post('/database/load', body)
|
||||
|
||||
export default {
|
||||
getExportDatabase,
|
||||
createLoadDatabase
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
import { useState, useRef, useEffect } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { useSelector, useDispatch } from 'react-redux'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useSelector } from 'react-redux'
|
||||
|
||||
// material-ui
|
||||
import { useTheme } from '@mui/material/styles'
|
||||
|
|
@ -26,16 +25,10 @@ import PerfectScrollbar from 'react-perfect-scrollbar'
|
|||
// project imports
|
||||
import MainCard from 'ui-component/cards/MainCard'
|
||||
import Transitions from 'ui-component/extended/Transitions'
|
||||
import { BackdropLoader } from 'ui-component/loading/BackdropLoader'
|
||||
import AboutDialog from 'ui-component/dialog/AboutDialog'
|
||||
|
||||
// assets
|
||||
import { IconLogout, IconSettings, IconFileExport, IconFileDownload, IconInfoCircle } from '@tabler/icons'
|
||||
|
||||
// API
|
||||
import databaseApi from 'api/database'
|
||||
|
||||
import { SET_MENU } from 'store/actions'
|
||||
import { IconLogout, IconSettings } from '@tabler/icons'
|
||||
|
||||
import './index.css'
|
||||
|
||||
|
|
@ -43,17 +36,13 @@ import './index.css'
|
|||
|
||||
const ProfileSection = ({ username, handleLogout }) => {
|
||||
const theme = useTheme()
|
||||
const dispatch = useDispatch()
|
||||
const navigate = useNavigate()
|
||||
|
||||
const customization = useSelector((state) => state.customization)
|
||||
|
||||
const [open, setOpen] = useState(false)
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [aboutDialogOpen, setAboutDialogOpen] = useState(false)
|
||||
|
||||
const anchorRef = useRef(null)
|
||||
const uploadRef = useRef(null)
|
||||
|
||||
const handleClose = (event) => {
|
||||
if (anchorRef.current && anchorRef.current.contains(event.target)) {
|
||||
|
|
@ -66,56 +55,6 @@ const ProfileSection = ({ username, handleLogout }) => {
|
|||
setOpen((prevOpen) => !prevOpen)
|
||||
}
|
||||
|
||||
const handleExportDB = async () => {
|
||||
setOpen(false)
|
||||
try {
|
||||
const response = await databaseApi.getExportDatabase()
|
||||
const exportItems = response.data
|
||||
let dataStr = JSON.stringify(exportItems, null, 2)
|
||||
let dataUri = 'data:application/json;charset=utf-8,' + encodeURIComponent(dataStr)
|
||||
|
||||
let exportFileDefaultName = `DB.json`
|
||||
|
||||
let linkElement = document.createElement('a')
|
||||
linkElement.setAttribute('href', dataUri)
|
||||
linkElement.setAttribute('download', exportFileDefaultName)
|
||||
linkElement.click()
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
const handleFileUpload = (e) => {
|
||||
if (!e.target.files) return
|
||||
|
||||
const file = e.target.files[0]
|
||||
const reader = new FileReader()
|
||||
reader.onload = async (evt) => {
|
||||
if (!evt?.target?.result) {
|
||||
return
|
||||
}
|
||||
const { result } = evt.target
|
||||
|
||||
if (result.includes(`"chatmessages":[`) && result.includes(`"chatflows":[`) && result.includes(`"apikeys":[`)) {
|
||||
dispatch({ type: SET_MENU, opened: false })
|
||||
setLoading(true)
|
||||
|
||||
try {
|
||||
await databaseApi.createLoadDatabase(JSON.parse(result))
|
||||
setLoading(false)
|
||||
navigate('/', { replace: true })
|
||||
navigate(0)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
setLoading(false)
|
||||
}
|
||||
} else {
|
||||
alert('Incorrect Flowise Database Format')
|
||||
}
|
||||
}
|
||||
reader.readAsText(file)
|
||||
}
|
||||
|
||||
const prevOpen = useRef(open)
|
||||
useEffect(() => {
|
||||
if (prevOpen.current === true && open === false) {
|
||||
|
|
@ -196,39 +135,6 @@ const ProfileSection = ({ username, handleLogout }) => {
|
|||
}
|
||||
}}
|
||||
>
|
||||
<ListItemButton
|
||||
sx={{ borderRadius: `${customization.borderRadius}px` }}
|
||||
onClick={() => {
|
||||
setOpen(false)
|
||||
uploadRef.current.click()
|
||||
}}
|
||||
>
|
||||
<ListItemIcon>
|
||||
<IconFileDownload stroke={1.5} size='1.3rem' />
|
||||
</ListItemIcon>
|
||||
<ListItemText primary={<Typography variant='body2'>Load Database</Typography>} />
|
||||
</ListItemButton>
|
||||
<ListItemButton
|
||||
sx={{ borderRadius: `${customization.borderRadius}px` }}
|
||||
onClick={handleExportDB}
|
||||
>
|
||||
<ListItemIcon>
|
||||
<IconFileExport stroke={1.5} size='1.3rem' />
|
||||
</ListItemIcon>
|
||||
<ListItemText primary={<Typography variant='body2'>Export Database</Typography>} />
|
||||
</ListItemButton>
|
||||
<ListItemButton
|
||||
sx={{ borderRadius: `${customization.borderRadius}px` }}
|
||||
onClick={() => {
|
||||
setOpen(false)
|
||||
setAboutDialogOpen(true)
|
||||
}}
|
||||
>
|
||||
<ListItemIcon>
|
||||
<IconInfoCircle stroke={1.5} size='1.3rem' />
|
||||
</ListItemIcon>
|
||||
<ListItemText primary={<Typography variant='body2'>About Flowise</Typography>} />
|
||||
</ListItemButton>
|
||||
{localStorage.getItem('username') && localStorage.getItem('password') && (
|
||||
<ListItemButton
|
||||
sx={{ borderRadius: `${customization.borderRadius}px` }}
|
||||
|
|
@ -249,8 +155,6 @@ const ProfileSection = ({ username, handleLogout }) => {
|
|||
</Transitions>
|
||||
)}
|
||||
</Popper>
|
||||
<input ref={uploadRef} type='file' hidden accept='.json' onChange={(e) => handleFileUpload(e)} />
|
||||
<BackdropLoader open={loading} />
|
||||
<AboutDialog show={aboutDialogOpen} onCancel={() => setAboutDialogOpen(false)} />
|
||||
</>
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue