Skip to content

Gif image not support rotate #300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/ImagePreviewerLightbox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import Lightbox from '@seafile/react-image-lightbox';
import { checkSVGImage, generateCurrentBaseImageUrl, getImageThumbnailUrl, isCustomAssetUrl, isDigitalSignsUrl, isInternalImg, needUseThumbnailImage } from '../utils/url';
import { getFileSuffix, generateCurrentBaseImageUrl, getImageThumbnailUrl, isCustomAssetUrl, isDigitalSignsUrl, isInternalImg, needUseThumbnailImage } from '../utils/url';
import { getLocale } from '../lang';

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

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

let mainSrc = URL;
if (needUseThumbnailImage(URL)) {
Expand Down
9 changes: 6 additions & 3 deletions src/utils/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ export const checkImgExists = (url) => {
});
};

export const getFileSuffix = (filename) => {
if (!filename || typeof filename !== 'string') return '';
return filename.substring(filename.lastIndexOf('.') + 1).toLowerCase();
};

export const checkSVGImage = (url) => {
if (!url || typeof url !== 'string') return false;
const isSVGImage = url.substring(url.lastIndexOf('.')).toLowerCase() === '.svg';
return isSVGImage;
return getFileSuffix(url) === 'svg';
};

export const isAIUrl = (url) => {
Expand Down
14 changes: 14 additions & 0 deletions tests/utils/url.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { getFileSuffix } from '../../src/utils/url';

describe('getFileSuffix', () => {
it('should return the suffix of the filename in lowercase', () => {
expect(getFileSuffix('example.TXT')).toBe('txt');
expect(getFileSuffix('example.jpeg')).toBe('jpeg');
expect(getFileSuffix('example.heic')).toBe('heic');
});
it('should return an empty string if input is not a valid string', () => {
expect(getFileSuffix(null)).toBe('');
expect(getFileSuffix(123)).toBe('');
expect(getFileSuffix(undefined)).toBe('');
});
});