mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +01:00
🛠️ fix: Ensure imageOutputType is Always Defined (#2438)
* avatar fix * chore: ensure `imageOutputType` is always defined * ci(AppService): extra test for default value * chore: replace default value for `desiredFormat` with `EImageOutputType` enum
This commit is contained in:
parent
bf4e64ce63
commit
3c184e9410
3 changed files with 15 additions and 5 deletions
|
|
@ -36,6 +36,7 @@ const AppService = async (app) => {
|
||||||
const config = (await loadCustomConfig()) ?? {};
|
const config = (await loadCustomConfig()) ?? {};
|
||||||
|
|
||||||
const fileStrategy = config.fileStrategy ?? FileSources.local;
|
const fileStrategy = config.fileStrategy ?? FileSources.local;
|
||||||
|
const imageOutputType = config?.imageOutputType ?? EImageOutputType.PNG;
|
||||||
process.env.CDN_PROVIDER = fileStrategy;
|
process.env.CDN_PROVIDER = fileStrategy;
|
||||||
|
|
||||||
if (fileStrategy === FileSources.firebase) {
|
if (fileStrategy === FileSources.firebase) {
|
||||||
|
|
@ -58,9 +59,10 @@ const AppService = async (app) => {
|
||||||
|
|
||||||
if (!Object.keys(config).length) {
|
if (!Object.keys(config).length) {
|
||||||
app.locals = {
|
app.locals = {
|
||||||
availableTools,
|
|
||||||
fileStrategy,
|
fileStrategy,
|
||||||
socialLogins,
|
socialLogins,
|
||||||
|
availableTools,
|
||||||
|
imageOutputType,
|
||||||
paths,
|
paths,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -177,12 +179,12 @@ const AppService = async (app) => {
|
||||||
|
|
||||||
app.locals = {
|
app.locals = {
|
||||||
socialLogins,
|
socialLogins,
|
||||||
availableTools,
|
|
||||||
fileStrategy,
|
fileStrategy,
|
||||||
|
availableTools,
|
||||||
|
imageOutputType,
|
||||||
fileConfig: config?.fileConfig,
|
fileConfig: config?.fileConfig,
|
||||||
interface: config?.interface,
|
interface: config?.interface,
|
||||||
secureImageLinks: config?.secureImageLinks,
|
secureImageLinks: config?.secureImageLinks,
|
||||||
imageOutputType: config?.imageOutputType?.toLowerCase() ?? EImageOutputType.PNG,
|
|
||||||
paths,
|
paths,
|
||||||
...endpointLocals,
|
...endpointLocals,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,6 @@ describe('AppService', () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
await AppService(app);
|
await AppService(app);
|
||||||
|
|
||||||
expect(app.locals.imageOutputType).toEqual(EImageOutputType.WEBP);
|
expect(app.locals.imageOutputType).toEqual(EImageOutputType.WEBP);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -151,7 +150,15 @@ describe('AppService', () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
await AppService(app);
|
await AppService(app);
|
||||||
|
expect(app.locals.imageOutputType).toEqual(EImageOutputType.PNG);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should default to `PNG` `imageOutputType` with no provided config', async () => {
|
||||||
|
require('./Config/loadCustomConfig').mockImplementationOnce(() =>
|
||||||
|
Promise.resolve(undefined),
|
||||||
|
);
|
||||||
|
|
||||||
|
await AppService(app);
|
||||||
expect(app.locals.imageOutputType).toEqual(EImageOutputType.PNG);
|
expect(app.locals.imageOutputType).toEqual(EImageOutputType.PNG);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
const sharp = require('sharp');
|
const sharp = require('sharp');
|
||||||
const fs = require('fs').promises;
|
const fs = require('fs').promises;
|
||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
|
const { EImageOutputType } = require('librechat-data-provider');
|
||||||
const { resizeAndConvert } = require('./resize');
|
const { resizeAndConvert } = require('./resize');
|
||||||
const { logger } = require('~/config');
|
const { logger } = require('~/config');
|
||||||
|
|
||||||
|
|
@ -20,7 +21,7 @@ const { logger } = require('~/config');
|
||||||
* @throws {Error} Throws an error if the user ID is undefined, the input type is invalid, the image fetching fails,
|
* @throws {Error} Throws an error if the user ID is undefined, the input type is invalid, the image fetching fails,
|
||||||
* or any other error occurs during the processing.
|
* or any other error occurs during the processing.
|
||||||
*/
|
*/
|
||||||
async function resizeAvatar({ userId, input, desiredFormat }) {
|
async function resizeAvatar({ userId, input, desiredFormat = EImageOutputType.PNG }) {
|
||||||
try {
|
try {
|
||||||
if (userId === undefined) {
|
if (userId === undefined) {
|
||||||
throw new Error('User ID is undefined');
|
throw new Error('User ID is undefined');
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue