mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 19:00:59 +03:00
Chore/refractor (#4454)
* markdown files and env examples cleanup * components update * update jsonlines description * server refractor * update telemetry * add execute custom node * add ui refractor * add username and password authenticate * correctly retrieve past images in agentflowv2 * disable e2e temporarily * add existing username and password authenticate * update migration to default workspace * update todo * blob storage migrating * throw error on agent tool call error * add missing execution import * add referral * chore: add error message when importData is undefined * migrate api keys to db * fix: data too long for column executionData * migrate api keys from json to db at init * add info on account setup * update docstore missing fields --------- Co-authored-by: chungyau97 <chungyau97@gmail.com>
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import path from 'path'
|
||||
import { NextFunction, Request, Response } from 'express'
|
||||
import { getFilesListFromStorage, getStoragePath, removeSpecificFileFromStorage } from 'flowise-components'
|
||||
import { updateStorageUsage } from '../../utils/quotaUsage'
|
||||
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
|
||||
import { StatusCodes } from 'http-status-codes'
|
||||
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
|
||||
|
||||
const getAllFiles = async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
const activeOrganizationId = req.user?.activeOrganizationId
|
||||
if (!activeOrganizationId) {
|
||||
throw new InternalFlowiseError(
|
||||
StatusCodes.NOT_FOUND,
|
||||
`Error: filesController.getAllFiles - organization ${activeOrganizationId} not found!`
|
||||
)
|
||||
}
|
||||
const apiResponse = await getFilesListFromStorage(activeOrganizationId)
|
||||
const filesList = apiResponse.map((file: any) => ({
|
||||
...file,
|
||||
// replace org id because we don't want to expose it
|
||||
path: file.path.replace(getStoragePath(), '').replace(`${path.sep}${activeOrganizationId}${path.sep}`, '')
|
||||
}))
|
||||
return res.json(filesList)
|
||||
} catch (error) {
|
||||
next(error)
|
||||
}
|
||||
}
|
||||
|
||||
const deleteFile = async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
const activeOrganizationId = req.user?.activeOrganizationId
|
||||
if (!activeOrganizationId) {
|
||||
throw new InternalFlowiseError(
|
||||
StatusCodes.NOT_FOUND,
|
||||
`Error: filesController.deleteFile - organization ${activeOrganizationId} not found!`
|
||||
)
|
||||
}
|
||||
const activeWorkspaceId = req.user?.activeWorkspaceId
|
||||
if (!activeWorkspaceId) {
|
||||
throw new InternalFlowiseError(
|
||||
StatusCodes.NOT_FOUND,
|
||||
`Error: filesController.deleteFile - workspace ${activeWorkspaceId} not found!`
|
||||
)
|
||||
}
|
||||
const filePath = req.query.path as string
|
||||
const paths = filePath.split(path.sep).filter((path) => path !== '')
|
||||
const { totalSize } = await removeSpecificFileFromStorage(activeOrganizationId, ...paths)
|
||||
await updateStorageUsage(activeOrganizationId, activeWorkspaceId, totalSize, getRunningExpressApp().usageCacheManager)
|
||||
return res.json({ message: 'file_deleted' })
|
||||
} catch (error) {
|
||||
next(error)
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
getAllFiles,
|
||||
deleteFile
|
||||
}
|
||||
Reference in New Issue
Block a user