anything-llm/server/utils/files/multer.js
Timothy Carambat 6d651db6d3
Enabled importing and exporting of entire AnythingLLM instance data (#146)
* WIP on imports

* undo nodismiss for testing

* remove old keys modal screen
add helper text on import complete

* return default setting modal to keys
2023-07-14 17:32:30 -07:00

48 lines
1.3 KiB
JavaScript

function setupMulter() {
const multer = require("multer");
// Handle File uploads for auto-uploading.
const storage = multer.diskStorage({
destination: function (_, _, cb) {
const path = require("path");
const uploadOutput =
process.env.NODE_ENV === "development"
? path.resolve(__dirname, `../../../collector/hotdir`)
: path.resolve(process.env.STORAGE_DIR, `../../collector/hotdir`);
cb(null, uploadOutput);
},
filename: function (_, file, cb) {
cb(null, file.originalname);
},
});
const upload = multer({
storage,
});
return { handleUploads: upload };
}
function setupDataImports() {
const multer = require("multer");
// Handle File uploads for auto-uploading.
const storage = multer.diskStorage({
destination: function (_, _, cb) {
const path = require("path");
const fs = require("fs");
const uploadOutput = path.resolve(__dirname, `../../storage/imports`);
fs.mkdirSync(uploadOutput, { recursive: true });
return cb(null, uploadOutput);
},
filename: function (_, file, cb) {
cb(null, file.originalname);
},
});
const upload = multer({
storage,
});
return { handleImports: upload };
}
module.exports = {
setupMulter,
setupDataImports,
};