1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-10-23 04:01:25 +00:00

fix heic image preview in external link page (#7459)

This commit is contained in:
Michael An
2025-02-13 14:18:01 +08:00
committed by GitHub
parent 3ff13909cd
commit 49dd313899
2 changed files with 13 additions and 3 deletions

View File

@@ -2,11 +2,13 @@ import React from 'react';
import ReactDom from 'react-dom';
import SharedFileView from './components/shared-file-view/shared-file-view';
import SharedFileViewTip from './components/shared-file-view/shared-file-view-tip';
import { gettext } from './utils/constants';
import { Utils } from './utils/utils';
import { gettext, siteRoot } from './utils/constants';
import './css/image-file-view.css';
const { fileName, rawPath, err, prevImgPath, nextImgPath } = window.shared.pageOptions;
const { fileName, rawPath, err, prevImgPath, nextImgPath, repoEncrypted, fileExt, filePath, sharedToken } = window.shared.pageOptions;
const { thumbnailSizeForOriginal } = window.app.pageOptions;
const prevImgURL = `?p=${encodeURIComponent(prevImgPath)}`;
const nextImgURL = `?p=${encodeURIComponent(nextImgPath)}`;
@@ -35,6 +37,13 @@ class FileContent extends React.Component {
return <SharedFileViewTip />;
}
// some types of images, the browser can't preview them directly, so we need to get thumbnails for them
let thumbnailURL = '';
const fileExtList = ['tif', 'tiff', 'psd', 'heic'];
if (!repoEncrypted && fileExtList.includes(fileExt)) {
thumbnailURL = `${siteRoot}thumbnail/${sharedToken}/${thumbnailSizeForOriginal}${Utils.encodePath(filePath)}`;
}
return (
<div className="shared-file-view-body d-flex text-center">
<div className="image-file-view flex-1">
@@ -44,7 +53,7 @@ class FileContent extends React.Component {
{nextImgPath && (
<a href={nextImgURL} id="img-next" title={gettext('you can also press →')}><span className="sf3-font sf3-font-down rotate-270 d-inline-block"></span></a>
)}
<img src={rawPath} alt={fileName} id="image-view" />
<img src={thumbnailURL || rawPath} alt={fileName} id="image-view" />
</div>
</div>
);