1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-21 11:27:18 +00:00

Fix create thumbnail error (#6798)

* fix create thumbnail in dirent grid item

* fix create thumbnail in dirent list item

* optimise codes

* change thumbnail start

* change 2 thumbnail centers
This commit is contained in:
Michael An
2024-09-20 14:29:37 +08:00
committed by GitHub
parent 6746e5ab1d
commit f1a180b23d
8 changed files with 346 additions and 174 deletions

View File

@@ -0,0 +1,52 @@
import { seafileAPI } from '../utils/seafile-api';
import { thumbnailDefaultSize } from '../utils/constants';
class ThumbnailCenter {
constructor() {
this.waitingQuery = [];
this.isStartQuery = false;
}
createThumbnail = ({ repoID, path, callback }) => {
this.waitingQuery.push({ repoID, path, callback });
if (!this.isStartQuery) {
this.startQuery();
}
};
cancelThumbnail = ({ repoID, path }) => {
const index = this.waitingQuery.findIndex(q => (q.repoID === repoID && q.path === path));
if (index > -1) {
this.waitingQuery.splice(index, 1);
}
if (this.waitingQuery.length === 0) {
this.isStartQuery = false;
}
};
startQuery = () => {
if (this.waitingQuery.length === 0) {
this.isStartQuery = false;
return;
}
this.isStartQuery = true;
let { repoID, path, callback } = this.waitingQuery[0];
seafileAPI.createThumbnail(repoID, path, thumbnailDefaultSize).then((res) => {
callback && callback(res.data.encoded_thumbnail_src);
}).catch((error) => {
// eslint-disable-next-line no-console
console.log(error);
}).then(() => {
this.waitingQuery.shift();
this.startQuery();
});
};
}
// server generates image and PDF thumbnails quickly, but generates video thumbnails slowly, so use two queues
const imageThumbnailCenter = new ThumbnailCenter();
const videoThumbnailCenter = new ThumbnailCenter();
export { imageThumbnailCenter, videoThumbnailCenter };