mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-11-09 00:10:10 +01:00
fcb591d364
* fix sizing of onboarding modals & lint * fix extra scrolling on mobile onboarding flow * added message to use desktop for onboarding * linting * add arrow to scroll to bottom (debounced) and fix chat scrolling to always scroll to very bottom on message history change * fix for empty chat * change mobile alert copy * WIP adding PFP upload support * WIP pfp for users * edit account menu complete with change username/password and upload profile picture * add pfp context to update all instances of usePfp hook on update * linting * add context for logo change to immediately update logo * fix div with bullet points to use list-disc instead * fix: small changes * update multer file storage locations * fix: use STORAGE_DIR for filepathing --------- Co-authored-by: timothycarambat <rambat1010@gmail.com>
45 lines
1005 B
JavaScript
45 lines
1005 B
JavaScript
const path = require("path");
|
|
const fs = require("fs");
|
|
const { getType } = require("mime");
|
|
const { User } = require("../../models/user");
|
|
|
|
function fetchPfp(pfpPath) {
|
|
if (!fs.existsSync(pfpPath)) {
|
|
return {
|
|
found: false,
|
|
buffer: null,
|
|
size: 0,
|
|
mime: "none/none",
|
|
};
|
|
}
|
|
|
|
const mime = getType(pfpPath);
|
|
const buffer = fs.readFileSync(pfpPath);
|
|
return {
|
|
found: true,
|
|
buffer,
|
|
size: buffer.length,
|
|
mime,
|
|
};
|
|
}
|
|
|
|
async function determinePfpFilepath(id) {
|
|
const numberId = Number(id);
|
|
const user = await User.get({ id: numberId });
|
|
const pfpFilename = user.pfpFilename;
|
|
if (!pfpFilename) return null;
|
|
|
|
const basePath = process.env.STORAGE_DIR
|
|
? path.join(process.env.STORAGE_DIR, "assets/pfp")
|
|
: path.join(__dirname, "../../storage/assets/pfp");
|
|
const pfpFilepath = path.join(basePath, pfpFilename);
|
|
|
|
if (!fs.existsSync(pfpFilepath)) return null;
|
|
return pfpFilepath;
|
|
}
|
|
|
|
module.exports = {
|
|
fetchPfp,
|
|
determinePfpFilepath,
|
|
};
|