Skip to content

Commit a96990e

Browse files
fix heic format rotate image (#7430)
1 parent fef0d63 commit a96990e

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

frontend/src/components/dialog/image-dialog.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ const ImageDialog = ({ enableRotate: oldEnableRotate, imageItems, imageIndex, cl
2727

2828
// The backend server does not support rotating HEIC images
2929
let enableRotate = oldEnableRotate;
30-
const suffix = mainImg.src.slice(mainImg.src.lastIndexOf('.') + 1, mainImg.src.lastIndexOf('?')).toLowerCase();
30+
const urlParts = mainImg.src.split('?')[0].split('.');
31+
const suffix = urlParts[urlParts.length - 1];
3132
if (suffix === 'heic') {
3233
enableRotate = false;
3334
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { Utils } from "../../utils/utils";
2+
3+
describe('getFileExtension', () => {
4+
it('should return the file extension with dot', () => {
5+
const fileName = 'document.pdf';
6+
const result = Utils.getFileExtension(fileName, false);
7+
expect(result).toBe('.pdf');
8+
});
9+
it('should return the file extension without dot', () => {
10+
const fileName = 'image.jpeg';
11+
const result = Utils.getFileExtension(fileName, true);
12+
expect(result).toBe('jpeg');
13+
});
14+
it('should handle filenames with multiple dots', () => {
15+
const fileName = 'archive.tar.gz';
16+
const resultWithDot = Utils.getFileExtension(fileName, false);
17+
const resultWithoutDot = Utils.getFileExtension(fileName, true);
18+
expect(resultWithDot).toBe('.gz');
19+
expect(resultWithoutDot).toBe('gz');
20+
});
21+
it('should handle filenames with upper case extensions', () => {
22+
const fileName = 'movie.MP4';
23+
const result = Utils.getFileExtension(fileName, true);
24+
expect(result).toBe('mp4');
25+
});
26+
it('should handle file name with special characters', () => {
27+
const fileName = '/repo/349d72de-e342-4461-a10a-45265c9cb4c2/raw/HEIC/arec4-j1qmq%20(1).heic';
28+
const result = Utils.getFileExtension(fileName, true);
29+
expect(result).toBe('heic');
30+
});
31+
});
32+
33+
describe('bytesToSize', () => {
34+
it('should return empty string if bytes is undefined', () => {
35+
const result = Utils.bytesToSize(undefined);
36+
expect(result).toBe(' ');
37+
});
38+
it('should return double dash if bytes is negative', () => {
39+
const result = Utils.bytesToSize(-1);
40+
expect(result).toBe('--');
41+
});
42+
it('should return bytes with unit if bytes is 0', () => {
43+
const result = Utils.bytesToSize(0);
44+
expect(result).toBe('0 B');
45+
});
46+
it('should return bytes with unit if bytes is positive', () => {
47+
const result = Utils.bytesToSize(1000);
48+
expect(result).toBe('1.0 KB');
49+
});
50+
it('should handle different units', () => {
51+
const result = Utils.bytesToSize(1000 * 1000);
52+
expect(result).toBe('1.0 MB');
53+
});
54+
it('should handle different units', () => {
55+
const result = Utils.bytesToSize(1000 * 1000 * 1000);
56+
expect(result).toBe('1.0 GB');
57+
});
58+
it('should handle different units', () => {
59+
const result = Utils.bytesToSize(1000 * 1000 * 1000 * 1000);
60+
expect(result).toBe('1.0 TB');
61+
});
62+
});
63+

frontend/src/utils/constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const defaultContentForSDoc = {
44
};
55

66
export const dirPath = '/';
7-
export const gettext = window.gettext;
7+
export const gettext = window.gettext || ((str) => str);
88

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

0 commit comments

Comments
 (0)