mirror of
https://github.com/hanzoai/chat.git
synced 2026-09-30 20:51:17 +00:00
librechat-data-provider → @hanzochat/data-provider @librechat/data-schemas → @hanzochat/data-schemas @librechat/client → @hanzochat/client (@hanzochat/api already forked; external @librechat/agents fork follows) All imports, package.json names/deps, tsconfig path aliases, jest moduleNameMapper, and rollup/vite build aliases updated. The data-provider react-query subpath resolves via the exports map. Lockfiles regenerated in a follow-on once the canonical package manager is confirmed.
50 lines
1.6 KiB
JavaScript
50 lines
1.6 KiB
JavaScript
const fs = require('fs').promises;
|
|
const express = require('express');
|
|
const { logger } = require('@hanzochat/data-schemas');
|
|
const { getStrategyFunctions } = require('~/server/services/Files/strategies');
|
|
const { resizeAvatar } = require('~/server/services/Files/images/avatar');
|
|
const { getFileStrategy } = require('~/server/utils/getFileStrategy');
|
|
const { filterFile } = require('~/server/services/Files/process');
|
|
|
|
const router = express.Router();
|
|
|
|
router.post('/', async (req, res) => {
|
|
try {
|
|
const appConfig = req.config;
|
|
filterFile({ req, file: req.file, image: true, isAvatar: true });
|
|
const userId = req.user.id;
|
|
const { manual } = req.body;
|
|
const input = await fs.readFile(req.file.path);
|
|
|
|
if (!userId) {
|
|
throw new Error('User ID is undefined');
|
|
}
|
|
|
|
const fileStrategy = getFileStrategy(appConfig, { isAvatar: true });
|
|
const desiredFormat = appConfig.imageOutputType;
|
|
const resizedBuffer = await resizeAvatar({
|
|
userId,
|
|
input,
|
|
desiredFormat,
|
|
});
|
|
|
|
const { processAvatar } = getStrategyFunctions(fileStrategy);
|
|
const url = await processAvatar({ buffer: resizedBuffer, userId, manual });
|
|
|
|
res.json({ url });
|
|
} catch (error) {
|
|
const message = 'An error occurred while uploading the profile picture';
|
|
logger.error(message, error);
|
|
res.status(500).json({ message });
|
|
} finally {
|
|
try {
|
|
await fs.unlink(req.file.path);
|
|
logger.debug('[/files/images/avatar] Temp. image upload file deleted');
|
|
} catch {
|
|
logger.debug('[/files/images/avatar] Temp. image upload file already deleted');
|
|
}
|
|
}
|
|
});
|
|
|
|
module.exports = router;
|