fix bug where share chatflow is not able to open on any other browser

This commit is contained in:
Henry
2023-06-29 23:47:20 +01:00
parent dc2f35bfad
commit 7141401e26
13 changed files with 183 additions and 73 deletions
+1
View File
@@ -3,4 +3,5 @@ PORT=3000
# FLOWISE_PASSWORD=1234
# DEBUG=true
# DATABASE_PATH=/your_database_path/.flowise
# APIKEY_PATH=/your_api_key_path/.flowise
# EXECUTION_MODE=child or main
+5 -5
View File
@@ -9,10 +9,10 @@ export interface IChatFlow {
id: string
name: string
flowData: string
apikeyid: string
deployed: boolean
isPublic: boolean
updatedDate: Date
createdDate: Date
apikeyid?: string
chatbotConfig?: string
}
@@ -22,7 +22,7 @@ export interface IChatMessage {
content: string
chatflowid: string
createdDate: Date
sourceDocuments: string
sourceDocuments?: string
}
export interface ITool {
@@ -30,8 +30,8 @@ export interface ITool {
name: string
description: string
color: string
schema: string
func: string
schema?: string
func?: string
updatedDate: Date
createdDate: Date
}
+4 -4
View File
@@ -13,11 +13,11 @@ export class ChatFlow implements IChatFlow {
@Column()
flowData: string
@Column({ nullable: true })
apikeyid: string
@Column()
deployed: boolean
isPublic: boolean
@Column({ nullable: true })
apikeyid?: string
@Column({ nullable: true })
chatbotConfig?: string
+1 -1
View File
@@ -18,7 +18,7 @@ export class ChatMessage implements IChatMessage {
content: string
@Column({ nullable: true })
sourceDocuments: string
sourceDocuments?: string
@CreateDateColumn()
createdDate: Date
+2 -2
View File
@@ -17,10 +17,10 @@ export class Tool implements ITool {
color: string
@Column({ nullable: true })
schema: string
schema?: string
@Column({ nullable: true })
func: string
func?: string
@CreateDateColumn()
createdDate: Date
+11 -1
View File
@@ -92,7 +92,7 @@ export class App {
const basicAuthMiddleware = basicAuth({
users: { [username]: password }
})
const whitelistURLs = ['/api/v1/prediction/', '/api/v1/node-icon/', '/api/v1/chatflows-streaming']
const whitelistURLs = ['/api/v1/public-chatflows', '/api/v1/prediction/', '/api/v1/node-icon/', '/api/v1/chatflows-streaming']
this.app.use((req, res, next) => {
if (req.url.includes('/api/v1/')) {
whitelistURLs.some((url) => req.url.includes(url)) ? next() : basicAuthMiddleware(req, res, next)
@@ -186,6 +186,16 @@ export class App {
return res.status(404).send(`Chatflow ${req.params.id} not found`)
})
// Get specific chatflow via id (PUBLIC endpoint, used when sharing chatbot link)
this.app.get('/api/v1/public-chatflows/:id', async (req: Request, res: Response) => {
const chatflow = await this.AppDataSource.getRepository(ChatFlow).findOneBy({
id: req.params.id
})
if (chatflow && chatflow.isPublic) return res.json(chatflow)
else if (chatflow && !chatflow.isPublic) return res.status(401).send(`Unauthorized`)
return res.status(404).send(`Chatflow ${req.params.id} not found`)
})
// Save chatflow
this.app.post('/api/v1/chatflows', async (req: Request, res: Response) => {
const body = req.body
+1 -1
View File
@@ -463,7 +463,7 @@ export const isSameOverrideConfig = (
* @returns {string}
*/
export const getAPIKeyPath = (): string => {
return path.join(__dirname, '..', '..', 'api.json')
return process.env.APIKEY_PATH ? path.join(process.env.APIKEY_PATH, 'api.json') : path.join(__dirname, '..', '..', 'api.json')
}
/**