Skip to content
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

clean image preview cache after rotate #7460

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 6 additions & 5 deletions frontend/src/components/dir-view-mode/dir-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class DirFiles extends React.Component {
this.isNodeMenuShow = true;
this.imageItemsSnapshot = [];
this.imageIndexSnapshot = 0;
this.rotateImageCacheBuster = new Date().getTime();
}

componentDidUpdate(prevProps) {
Expand Down Expand Up @@ -252,9 +253,9 @@ class DirFiles extends React.Component {
const src = `${siteRoot}repo/${repoID}/raw${path}`;
let thumbnail = '';
if (repoEncrypted || isGIF) {
thumbnail = src;
thumbnail = `${src}?t=${this.rotateImageCacheBuster}`;
} else {
thumbnail = `${siteRoot}thumbnail/${repoID}/${thumbnailSizeForOriginal}${path}`;
thumbnail = `${siteRoot}thumbnail/${repoID}/${thumbnailSizeForOriginal}${path}?t=${this.rotateImageCacheBuster}`;
}
return {
name,
Expand Down Expand Up @@ -325,11 +326,11 @@ class DirFiles extends React.Component {
imageAPI.rotateImage(repoID, path, 360 - angle).then((res) => {
seafileAPI.createThumbnail(repoID, path, thumbnailDefaultSize).then((res) => {
// Generate a unique query parameter to bust the cache
const cacheBuster = new Date().getTime();
const newThumbnailSrc = `${res.data.encoded_thumbnail_src}?t=${cacheBuster}`;
this.rotateImageCacheBuster = new Date().getTime();
const newThumbnailSrc = `${res.data.encoded_thumbnail_src}?t=${this.rotateImageCacheBuster}`;
this.setState((prevState) => {
const updatedImageItems = [...prevState.imageNodeItems];
updatedImageItems[imageIndex].src = newThumbnailSrc;
updatedImageItems[imageIndex].thumbnail = newThumbnailSrc;
return { imageNodeItems: updatedImageItems };
});
// Update the thumbnail URL with the cache-busting query parameter
Expand Down
11 changes: 6 additions & 5 deletions frontend/src/components/dirent-grid-view/dirent-grid-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class DirentGridView extends React.Component {
};
this.containerRef = React.createRef();
this.isRepoOwner = props.currentRepoInfo.owner_email === username;
this.rotateImageCacheBuster = new Date().getTime();
}

componentDidMount() {
Expand Down Expand Up @@ -604,9 +605,9 @@ class DirentGridView extends React.Component {
let thumbnail = '';
const isGIF = fileExt === 'gif';
if (repoEncrypted || isGIF) {
thumbnail = `${siteRoot}repo/${repoID}/raw${path}?t=${cacheBuster}`;
thumbnail = `${siteRoot}repo/${repoID}/raw${path}?t=${cacheBuster}?t=${this.rotateImageCacheBuster}`;
} else {
thumbnail = `${siteRoot}thumbnail/${repoID}/${thumbnailSizeForOriginal}${path}`;
thumbnail = `${siteRoot}thumbnail/${repoID}/${thumbnailSizeForOriginal}${path}?t=${this.rotateImageCacheBuster}`;
}

let src = '';
Expand Down Expand Up @@ -684,11 +685,11 @@ class DirentGridView extends React.Component {
imageAPI.rotateImage(repoID, path, 360 - angle).then((res) => {
seafileAPI.createThumbnail(repoID, path, thumbnailDefaultSize).then((res) => {
// Generate a unique query parameter to bust the cache
const cacheBuster = new Date().getTime();
const newThumbnailSrc = `${res.data.encoded_thumbnail_src}?t=${cacheBuster}`;
this.rotateImageCacheBuster = new Date().getTime();
const newThumbnailSrc = `${res.data.encoded_thumbnail_src}?t=${this.rotateImageCacheBuster}`;
this.setState((prevState) => {
const updatedImageItems = [...prevState.imageItems];
updatedImageItems[imageIndex].src = newThumbnailSrc;
updatedImageItems[imageIndex].thumbnail = newThumbnailSrc;
return { imageItems: updatedImageItems };
});
// Update the thumbnail URL with the cache-busting query parameter
Expand Down
11 changes: 6 additions & 5 deletions frontend/src/components/dirent-list-view/dirent-list-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class DirentListView extends React.Component {
const { modify } = customPermission.permission;
this.canDrop = modify;
}
this.rotateImageCacheBuster = new Date().getTime();
}

componentDidMount() {
Expand Down Expand Up @@ -191,9 +192,9 @@ class DirentListView extends React.Component {
let thumbnail = '';
const isGIF = fileExt === 'gif';
if (repoEncrypted || isGIF) {
thumbnail = `${siteRoot}repo/${repoID}/raw${path}`;
thumbnail = `${siteRoot}repo/${repoID}/raw${path}?t=${this.rotateImageCacheBuster}`;
} else {
thumbnail = `${siteRoot}thumbnail/${repoID}/${thumbnailSizeForOriginal}${path}`;
thumbnail = `${siteRoot}thumbnail/${repoID}/${thumbnailSizeForOriginal}${path}?t=${this.rotateImageCacheBuster}`;
}

let src = '';
Expand Down Expand Up @@ -271,11 +272,11 @@ class DirentListView extends React.Component {
imageAPI.rotateImage(repoID, path, 360 - angle).then((res) => {
seafileAPI.createThumbnail(repoID, path, thumbnailDefaultSize).then((res) => {
// Generate a unique query parameter to bust the cache
const cacheBuster = new Date().getTime();
const newThumbnailSrc = `${res.data.encoded_thumbnail_src}?t=${cacheBuster}`;
this.rotateImageCacheBuster = new Date().getTime();
const newThumbnailSrc = `${res.data.encoded_thumbnail_src}?t=${this.rotateImageCacheBuster}`;
this.setState((prevState) => {
const updatedImageItems = [...prevState.imageItems];
updatedImageItems[imageIndex].src = newThumbnailSrc;
updatedImageItems[imageIndex].thumbnail = newThumbnailSrc;
return { imageItems: updatedImageItems };
});
// Update the thumbnail URL with the cache-busting query parameter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from 'react';
import React, { useEffect, useState, useRef } from 'react';
import PropTypes from 'prop-types';
import { ModalPortal } from '@seafile/sf-metadata-ui-component';
import ModalPortal from '../../../components/modal-portal';
import toaster from '../../../components/toast';
import ImageDialog from '../../../components/dialog/image-dialog';
import imageAPI from '../../../utils/image-api';
Expand All @@ -12,6 +12,7 @@ import { getFileNameFromRecord, getParentDirFromRecord, getRecordIdFromRecord }
const ImagePreviewer = ({ record, table, repoID, repoInfo, closeImagePopup }) => {
const [imageIndex, setImageIndex] = useState(0);
const [imageItems, setImageItems] = useState([]);
let rotateImageCacheBuster = useRef(new Date().getTime());

useEffect(() => {
const newImageItems = table.rows
Expand All @@ -30,7 +31,7 @@ const ImagePreviewer = ({ record, table, repoID, repoInfo, closeImagePopup }) =>
id,
name: fileName,
url: `${siteRoot}lib/${repoID}/file${path}`,
thumbnail: `${siteRoot}thumbnail/${repoID}/${thumbnailSizeForOriginal}${path}`,
thumbnail: `${siteRoot}thumbnail/${repoID}/${thumbnailSizeForOriginal}${path}?t=${rotateImageCacheBuster.current}`,
src: src,
parentDir,
downloadURL: `${fileServerRoot}repos/${repoID}/files${path}/?op=download`,
Expand Down Expand Up @@ -66,9 +67,9 @@ const ImagePreviewer = ({ record, table, repoID, repoInfo, closeImagePopup }) =>
if (res.data?.success) {
seafileAPI.createThumbnail(repoID, path, thumbnailDefaultSize).then((res) => {
if (res.data?.encoded_thumbnail_src) {
const cacheBuster = new Date().getTime();
const newThumbnailSrc = `${res.data.encoded_thumbnail_src}?t=${cacheBuster}`;
imageItems[imageIndex].src = newThumbnailSrc;
rotateImageCacheBuster.current = new Date().getTime();
const newThumbnailSrc = `${res.data.encoded_thumbnail_src}?t=${rotateImageCacheBuster.current}`;
imageItems[imageIndex].thumbnail = newThumbnailSrc;
setImageItems(imageItems);
}
}).catch(error => {
Expand Down