Skip to content

Commit b2e7386

Browse files
change rotate image type
1 parent dc8e9d6 commit b2e7386

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

src/ImagePreviewerLightbox/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import classnames from 'classnames';
44
import Lightbox from '@seafile/react-image-lightbox';
5-
import { checkSVGImage, generateCurrentBaseImageUrl, getImageThumbnailUrl, isCustomAssetUrl, isDigitalSignsUrl, isInternalImg, needUseThumbnailImage } from '../utils/url';
5+
import { getFileSuffix, generateCurrentBaseImageUrl, getImageThumbnailUrl, isCustomAssetUrl, isDigitalSignsUrl, isInternalImg, needUseThumbnailImage } from '../utils/url';
66
import { getLocale } from '../lang';
77

88
import '@seafile/react-image-lightbox/style.css';
@@ -39,8 +39,7 @@ function ImagePreviewerLightbox(props) {
3939
console.log(error);
4040
}
4141

42-
// svg image is vectorgraph and can't rotate, external image can't rotate
43-
const canRotateImage = onRotateImage && !readOnly && !checkSVGImage(URL) && isInternalImg(URL, server);
42+
const canRotateImage = onRotateImage && !readOnly && ['gif', 'heic', 'heif'].includes(getFileSuffix(URL)) && isInternalImg(URL, server);
4443

4544
let mainSrc = URL;
4645
if (needUseThumbnailImage(URL)) {

src/utils/url.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,13 @@ export const checkImgExists = (url) => {
3434
});
3535
};
3636

37+
export const getFileSuffix = (filename) => {
38+
if (!filename || typeof filename !== 'string') return '';
39+
return filename.substring(filename.lastIndexOf('.') + 1).toLowerCase();
40+
};
41+
3742
export const checkSVGImage = (url) => {
38-
if (!url || typeof url !== 'string') return false;
39-
const isSVGImage = url.substring(url.lastIndexOf('.')).toLowerCase() === '.svg';
40-
return isSVGImage;
43+
return getFileSuffix(url) === 'svg';
4144
};
4245

4346
export const isAIUrl = (url) => {

tests/utils/url.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { getFileSuffix } from '../../src/utils/url';
2+
3+
describe('getFileSuffix', () => {
4+
it('should return the suffix of the filename in lowercase', () => {
5+
expect(getFileSuffix('example.TXT')).toBe('txt');
6+
expect(getFileSuffix('example.jpeg')).toBe('jpeg');
7+
expect(getFileSuffix('example.heic')).toBe('heic');
8+
});
9+
it('should return an empty string if input is not a valid string', () => {
10+
expect(getFileSuffix(null)).toBe('');
11+
expect(getFileSuffix(123)).toBe('');
12+
expect(getFileSuffix(undefined)).toBe('');
13+
});
14+
});

0 commit comments

Comments
 (0)