Skip to content

Commit

Permalink
fix heic format rotate image (#7430)
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael18811380328 authored Feb 6, 2025
1 parent fef0d63 commit a96990e
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
3 changes: 2 additions & 1 deletion frontend/src/components/dialog/image-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const ImageDialog = ({ enableRotate: oldEnableRotate, imageItems, imageIndex, cl

// The backend server does not support rotating HEIC images
let enableRotate = oldEnableRotate;
const suffix = mainImg.src.slice(mainImg.src.lastIndexOf('.') + 1, mainImg.src.lastIndexOf('?')).toLowerCase();
const urlParts = mainImg.src.split('?')[0].split('.');
const suffix = urlParts[urlParts.length - 1];
if (suffix === 'heic') {
enableRotate = false;
}
Expand Down
63 changes: 63 additions & 0 deletions frontend/src/tests/utils/utils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { Utils } from "../../utils/utils";

describe('getFileExtension', () => {
it('should return the file extension with dot', () => {
const fileName = 'document.pdf';
const result = Utils.getFileExtension(fileName, false);
expect(result).toBe('.pdf');
});
it('should return the file extension without dot', () => {
const fileName = 'image.jpeg';
const result = Utils.getFileExtension(fileName, true);
expect(result).toBe('jpeg');
});
it('should handle filenames with multiple dots', () => {
const fileName = 'archive.tar.gz';
const resultWithDot = Utils.getFileExtension(fileName, false);
const resultWithoutDot = Utils.getFileExtension(fileName, true);
expect(resultWithDot).toBe('.gz');
expect(resultWithoutDot).toBe('gz');
});
it('should handle filenames with upper case extensions', () => {
const fileName = 'movie.MP4';
const result = Utils.getFileExtension(fileName, true);
expect(result).toBe('mp4');
});
it('should handle file name with special characters', () => {
const fileName = '/repo/349d72de-e342-4461-a10a-45265c9cb4c2/raw/HEIC/arec4-j1qmq%20(1).heic';
const result = Utils.getFileExtension(fileName, true);
expect(result).toBe('heic');
});
});

describe('bytesToSize', () => {
it('should return empty string if bytes is undefined', () => {
const result = Utils.bytesToSize(undefined);
expect(result).toBe(' ');
});
it('should return double dash if bytes is negative', () => {
const result = Utils.bytesToSize(-1);
expect(result).toBe('--');
});
it('should return bytes with unit if bytes is 0', () => {
const result = Utils.bytesToSize(0);
expect(result).toBe('0 B');
});
it('should return bytes with unit if bytes is positive', () => {
const result = Utils.bytesToSize(1000);
expect(result).toBe('1.0 KB');
});
it('should handle different units', () => {
const result = Utils.bytesToSize(1000 * 1000);
expect(result).toBe('1.0 MB');
});
it('should handle different units', () => {
const result = Utils.bytesToSize(1000 * 1000 * 1000);
expect(result).toBe('1.0 GB');
});
it('should handle different units', () => {
const result = Utils.bytesToSize(1000 * 1000 * 1000 * 1000);
expect(result).toBe('1.0 TB');
});
});

2 changes: 1 addition & 1 deletion frontend/src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const defaultContentForSDoc = {
};

export const dirPath = '/';
export const gettext = window.gettext;
export const gettext = window.gettext || ((str) => str);

export const internalFilePath = '/_Internal/seatable-integration.json';

Expand Down

0 comments on commit a96990e

Please sign in to comment.