mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-26 15:26:19 +00:00
Merge pull request #3752 from haiwen/image_thumb_react
image preview thumb react
This commit is contained in:
@@ -9,7 +9,7 @@ import './css/image-file-view.css';
|
||||
|
||||
const {
|
||||
repoID, filePath, err,
|
||||
fileName, previousImage, nextImage, rawPath
|
||||
fileName, previousImage, nextImage, rawPath, thumbnailSizeForOriginal,
|
||||
} = window.app.pageOptions;
|
||||
|
||||
let previousImageUrl, nextImageUrl;
|
||||
@@ -30,6 +30,14 @@ class ViewFileImage extends React.Component {
|
||||
|
||||
class FileContent extends React.Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
thumbnailError: false,
|
||||
};
|
||||
this.thumbnailSuffixList = ['tiff', 'eps', 'psd'];
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if (previousImage && e.keyCode == 37) { // press '<-'
|
||||
@@ -41,10 +49,20 @@ class FileContent extends React.Component {
|
||||
});
|
||||
}
|
||||
|
||||
handleError = () => {
|
||||
this.setState({
|
||||
thumbnailError: true
|
||||
});
|
||||
};
|
||||
|
||||
render() {
|
||||
if (err) {
|
||||
if (err || this.state.thumbnailError) {
|
||||
return <FileViewTip />;
|
||||
}
|
||||
let thumbnailUrl = `${siteRoot}thumbnail/${repoID}/${thumbnailSizeForOriginal}${Utils.encodePath(filePath)}`;
|
||||
let imageSuffix = fileName.split('.').pop();
|
||||
let isPreviewThumbnail = this.thumbnailSuffixList.includes(imageSuffix);
|
||||
|
||||
return (
|
||||
<div className="file-view-content flex-1 image-file-view">
|
||||
{previousImage && (
|
||||
@@ -53,7 +71,10 @@ class FileContent extends React.Component {
|
||||
{nextImage && (
|
||||
<a href={nextImageUrl} id="img-next" title={gettext('you can also press →')}><span className="fas fa-chevron-right"></span></a>
|
||||
)}
|
||||
{isPreviewThumbnail ?
|
||||
<img src={thumbnailUrl} alt={fileName} id="image-view" onError={this.handleError}/> :
|
||||
<img src={rawPath} alt={fileName} id="image-view"/>
|
||||
}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
@@ -16,6 +16,7 @@ window.app.pageOptions = {
|
||||
shareLinkExpireDaysDefault: {{ share_link_expire_days_default }},
|
||||
shareLinkExpireDaysMin: {{ share_link_expire_days_min }},
|
||||
shareLinkExpireDaysMax: {{ share_link_expire_days_max }},
|
||||
thumbnailSizeForOriginal: {{ thumbnail_size_for_original }},
|
||||
|
||||
// for all types of files
|
||||
fileName: '{{ filename|escapejs }}',
|
||||
|
@@ -531,6 +531,7 @@ def view_lib_file(request, repo_id, path):
|
||||
'share_link_expire_days_max': SHARE_LINK_EXPIRE_DAYS_MAX,
|
||||
'can_download_file': parse_repo_perm(permission).can_download,
|
||||
'seafile_collab_server': SEAFILE_COLLAB_SERVER,
|
||||
'thumbnail_size_for_original': settings.THUMBNAIL_SIZE_FOR_ORIGINAL,
|
||||
}
|
||||
|
||||
# check whether file is starred
|
||||
|
Reference in New Issue
Block a user