Skip to content

Commit

Permalink
Chore/Update multer path if blob storage path is set (#3609)
Browse files Browse the repository at this point in the history
update multer path if blob storage path is set
  • Loading branch information
HenryHengZJ authored Dec 3, 2024
1 parent bd203a1 commit 7482e7f
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/server/src/routes/attachments/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import express from 'express'
import multer from 'multer'
import path from 'path'
import attachmentsController from '../../controllers/attachments'
import { getUploadPath } from '../../utils'

const router = express.Router()

const upload = multer({ dest: `${path.join(__dirname, '..', '..', '..', 'uploads')}/` })
const upload = multer({ dest: getUploadPath() })

// CREATE
router.post('/:chatflowId/:chatId', upload.array('files'), attachmentsController.createAttachment)
Expand Down
6 changes: 3 additions & 3 deletions packages/server/src/routes/documentstore/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import express from 'express'
import documentStoreController from '../../controllers/documentstore'
import multer from 'multer'
import path from 'path'
import { getUploadPath } from '../../utils'
import documentStoreController from '../../controllers/documentstore'

const router = express.Router()
const upload = multer({ dest: `${path.join(__dirname, '..', '..', '..', 'uploads')}/` })
const upload = multer({ dest: getUploadPath() })

router.post(['/upsert/', '/upsert/:id'], upload.array('files'), documentStoreController.upsertDocStoreMiddleware)

Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/routes/openai-assistants-files/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import express from 'express'
import multer from 'multer'
import path from 'path'
import openaiAssistantsController from '../../controllers/openai-assistants'
import { getUploadPath } from '../../utils'

const router = express.Router()
const upload = multer({ dest: `${path.join(__dirname, '..', '..', '..', 'uploads')}/` })
const upload = multer({ dest: getUploadPath() })

router.post('/download/', openaiAssistantsController.getFileFromAssistant)
router.post('/upload/', upload.array('files'), openaiAssistantsController.uploadAssistantFiles)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import express from 'express'
import multer from 'multer'
import path from 'path'
import openaiAssistantsVectorStoreController from '../../controllers/openai-assistants-vector-store'
import { getUploadPath } from '../../utils'

const router = express.Router()
const upload = multer({ dest: `${path.join(__dirname, '..', '..', '..', 'uploads')}/` })
const upload = multer({ dest: getUploadPath() })

// CREATE
router.post('/', openaiAssistantsVectorStoreController.createAssistantVectorStore)
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/routes/predictions/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import express from 'express'
import multer from 'multer'
import path from 'path'
import predictionsController from '../../controllers/predictions'
import { getUploadPath } from '../../utils'

const router = express.Router()

const upload = multer({ dest: `${path.join(__dirname, '..', '..', '..', 'uploads')}/` })
const upload = multer({ dest: getUploadPath() })

// CREATE
router.post(['/', '/:id'], upload.array('files'), predictionsController.getRateLimiterMiddleware, predictionsController.createPrediction)
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/routes/vectors/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import express from 'express'
import multer from 'multer'
import path from 'path'
import vectorsController from '../../controllers/vectors'
import { getUploadPath } from '../../utils'

const router = express.Router()

const upload = multer({ dest: `${path.join(__dirname, '..', '..', '..', 'uploads')}/` })
const upload = multer({ dest: getUploadPath() })

// CREATE
router.post(
Expand Down
6 changes: 6 additions & 0 deletions packages/server/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1680,3 +1680,9 @@ export const getAPIOverrideConfig = (chatflow: IChatFlow) => {
return { nodeOverrides: {}, variableOverrides: [], apiOverrideStatus: false }
}
}

export const getUploadPath = (): string => {
return process.env.BLOB_STORAGE_PATH
? path.join(process.env.BLOB_STORAGE_PATH, 'uploads')
: path.join(getUserHome(), '.flowise', 'uploads')
}

0 comments on commit 7482e7f

Please sign in to comment.