Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/Update multer path if blob storage path is set #3609

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
}
Loading