mirror of
https://github.com/haiwen/seahub.git
synced 2025-06-22 13:18:42 +00:00
show video thumbnail (#7639)
* show video thumbnail * check preview permission --------- Co-authored-by: zhouwenxuan <aries@Mac.local>
This commit is contained in:
parent
618e25d1ab
commit
abf09b4593
@ -7,6 +7,7 @@ import {
|
|||||||
import LocalStorage from './utils/local-storage';
|
import LocalStorage from './utils/local-storage';
|
||||||
import EventBus from '../components/common/event-bus';
|
import EventBus from '../components/common/event-bus';
|
||||||
import { username, lang } from '../utils/constants';
|
import { username, lang } from '../utils/constants';
|
||||||
|
import { Utils } from '../utils/utils';
|
||||||
|
|
||||||
class Context {
|
class Context {
|
||||||
|
|
||||||
@ -41,6 +42,8 @@ class Context {
|
|||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
|
|
||||||
this.permission = repoInfo.permission !== 'admin' && repoInfo.permission !== 'rw' ? 'r' : 'rw';
|
this.permission = repoInfo.permission !== 'admin' && repoInfo.permission !== 'rw' ? 'r' : 'rw';
|
||||||
|
const { isCustomPermission, customPermission } = Utils.getUserPermission(repoInfo.permission);
|
||||||
|
this.customPermission = isCustomPermission ? customPermission : null;
|
||||||
|
|
||||||
this.hasInit = true;
|
this.hasInit = true;
|
||||||
}
|
}
|
||||||
@ -187,6 +190,14 @@ class Context {
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
canPreview = () => {
|
||||||
|
if (this.customPermission) {
|
||||||
|
const { preview, modify } = this.customPermission.permission;
|
||||||
|
return preview || modify;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
restoreRows = () => {
|
restoreRows = () => {
|
||||||
// todo
|
// todo
|
||||||
};
|
};
|
||||||
|
@ -101,7 +101,6 @@ export const openFile = (repoID, record, _openImage = () => {}) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const openInNewTab = (repoID, record) => {
|
export const openInNewTab = (repoID, record) => {
|
||||||
if (!record) return;
|
|
||||||
const isDir = checkIsDir(record);
|
const isDir = checkIsDir(record);
|
||||||
const fileName = getFileNameFromRecord(record);
|
const fileName = getFileNameFromRecord(record);
|
||||||
const parentDir = _getParentDir(record);
|
const parentDir = _getParentDir(record);
|
||||||
|
@ -8,12 +8,13 @@ import GalleryContextmenu from './context-menu';
|
|||||||
import { useMetadataView } from '../../hooks/metadata-view';
|
import { useMetadataView } from '../../hooks/metadata-view';
|
||||||
import { Utils } from '../../../utils/utils';
|
import { Utils } from '../../../utils/utils';
|
||||||
import { getDateDisplayString, getFileMTimeFromRecord, getFileNameFromRecord, getParentDirFromRecord, getRecordIdFromRecord } from '../../utils/cell';
|
import { getDateDisplayString, getFileMTimeFromRecord, getFileNameFromRecord, getParentDirFromRecord, getRecordIdFromRecord } from '../../utils/cell';
|
||||||
import { siteRoot, fileServerRoot, thumbnailSizeForGrid, thumbnailSizeForOriginal, thumbnailDefaultSize } from '../../../utils/constants';
|
import { siteRoot, fileServerRoot, thumbnailSizeForGrid, thumbnailSizeForOriginal, thumbnailDefaultSize, enableVideoThumbnail } from '../../../utils/constants';
|
||||||
import { EVENT_BUS_TYPE, GALLERY_DATE_MODE, DATE_TAG_HEIGHT, STORAGE_GALLERY_DATE_MODE_KEY, STORAGE_GALLERY_ZOOM_GEAR_KEY, VIEW_TYPE_DEFAULT_SORTS, VIEW_TYPE } from '../../constants';
|
import { EVENT_BUS_TYPE, GALLERY_DATE_MODE, DATE_TAG_HEIGHT, STORAGE_GALLERY_DATE_MODE_KEY, STORAGE_GALLERY_ZOOM_GEAR_KEY, VIEW_TYPE_DEFAULT_SORTS, VIEW_TYPE } from '../../constants';
|
||||||
import { getRowById } from '../../../components/sf-table/utils/table';
|
import { getRowById } from '../../../components/sf-table/utils/table';
|
||||||
import { getEventClassName } from '../../../utils/dom';
|
import { getEventClassName } from '../../../utils/dom';
|
||||||
import { getColumns, getImageSize, getRowHeight } from './utils';
|
import { getColumns, getImageSize, getRowHeight } from './utils';
|
||||||
import ObjectUtils from '../../../utils/object';
|
import ObjectUtils from '../../../utils/object';
|
||||||
|
import { openFile } from '../../utils/file';
|
||||||
|
|
||||||
import './index.css';
|
import './index.css';
|
||||||
|
|
||||||
@ -36,13 +37,17 @@ const Main = ({ isLoadingMore, metadata, onDelete, onLoadMore, duplicateRecord,
|
|||||||
|
|
||||||
const { repoID, updateCurrentDirent } = useMetadataView();
|
const { repoID, updateCurrentDirent } = useMetadataView();
|
||||||
const repoInfo = window.sfMetadataContext.getSetting('repoInfo');
|
const repoInfo = window.sfMetadataContext.getSetting('repoInfo');
|
||||||
|
const canPreview = window.sfMetadataContext.canPreview();
|
||||||
|
|
||||||
const images = useMemo(() => {
|
const images = useMemo(() => {
|
||||||
if (isFirstLoading) return [];
|
if (isFirstLoading) return [];
|
||||||
if (!Array.isArray(metadata.rows) || metadata.rows.length === 0) return [];
|
if (!Array.isArray(metadata.rows) || metadata.rows.length === 0) return [];
|
||||||
const firstSort = metadata.view.sorts[0] || VIEW_TYPE_DEFAULT_SORTS[VIEW_TYPE.GALLERY];
|
const firstSort = metadata.view.sorts[0] || VIEW_TYPE_DEFAULT_SORTS[VIEW_TYPE.GALLERY];
|
||||||
return metadata.rows
|
return metadata.rows
|
||||||
.filter(record => Utils.imageCheck(getFileNameFromRecord(record)))
|
.filter(record => {
|
||||||
|
const fileName = getFileNameFromRecord(record);
|
||||||
|
return Utils.imageCheck(fileName) || Utils.videoCheck(fileName);
|
||||||
|
})
|
||||||
.map(record => {
|
.map(record => {
|
||||||
const id = getRecordIdFromRecord(record);
|
const id = getRecordIdFromRecord(record);
|
||||||
const fileName = getFileNameFromRecord(record);
|
const fileName = getFileNameFromRecord(record);
|
||||||
@ -59,13 +64,32 @@ const Main = ({ isLoadingMore, metadata, onDelete, onLoadMore, duplicateRecord,
|
|||||||
const year = date.slice(0, 4);
|
const year = date.slice(0, 4);
|
||||||
const month = date.slice(0, -3);
|
const month = date.slice(0, -3);
|
||||||
const day = date.slice(-2,);
|
const day = date.slice(-2,);
|
||||||
|
|
||||||
|
const isVideo = Utils.videoCheck(fileName);
|
||||||
|
const useFallbackIcon = isVideo && !enableVideoThumbnail;
|
||||||
|
|
||||||
|
const baseThumbnailPath = `${siteRoot}thumbnail/${repoID}`;
|
||||||
|
let src = useFallbackIcon
|
||||||
|
? Utils.getFileIconUrl(fileName)
|
||||||
|
: `${baseThumbnailPath}/${size}${path}`;
|
||||||
|
|
||||||
|
let thumbnail = useFallbackIcon
|
||||||
|
? Utils.getFileIconUrl(fileName)
|
||||||
|
: `${baseThumbnailPath}/${thumbnailSizeForOriginal}${path}?mtime=${mtime}`;
|
||||||
|
|
||||||
|
if (!canPreview) {
|
||||||
|
const fileIcon = Utils.getFileIconUrl(fileName);
|
||||||
|
src = fileIcon;
|
||||||
|
thumbnail = fileIcon;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id,
|
id,
|
||||||
name: fileName,
|
name: fileName,
|
||||||
parentDir,
|
parentDir,
|
||||||
url: `${siteRoot}lib/${repoID}/file${path}`,
|
url: `${siteRoot}lib/${repoID}/file${path}`,
|
||||||
src: `${siteRoot}thumbnail/${repoID}/${size}${path}`,
|
src,
|
||||||
thumbnail: `${siteRoot}thumbnail/${repoID}/${thumbnailSizeForOriginal}${path}?mtime=${mtime}`,
|
thumbnail,
|
||||||
downloadURL: `${fileServerRoot}repos/${repoID}/files${path}?op=download`,
|
downloadURL: `${fileServerRoot}repos/${repoID}/files${path}?op=download`,
|
||||||
year,
|
year,
|
||||||
month,
|
month,
|
||||||
@ -192,10 +216,14 @@ const Main = ({ isLoadingMore, metadata, onDelete, onLoadMore, duplicateRecord,
|
|||||||
|
|
||||||
const handleDoubleClick = useCallback((event, image) => {
|
const handleDoubleClick = useCallback((event, image) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
const record = getRowById(metadata, image.id);
|
||||||
|
if (!canPreview) return;
|
||||||
|
openFile(repoID, record, () => {
|
||||||
const index = images.findIndex(item => item.id === image.id);
|
const index = images.findIndex(item => item.id === image.id);
|
||||||
setImageIndex(index);
|
setImageIndex(index);
|
||||||
setIsImagePopupOpen(true);
|
setIsImagePopupOpen(true);
|
||||||
}, [images]);
|
});
|
||||||
|
}, [repoID, metadata, images]);
|
||||||
|
|
||||||
const handleContextMenu = useCallback((event, image) => {
|
const handleContextMenu = useCallback((event, image) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
@ -31,6 +31,8 @@ const Card = ({
|
|||||||
if (titleColumn?.type !== CellType.FILE_NAME) return;
|
if (titleColumn?.type !== CellType.FILE_NAME) return;
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.nativeEvent.stopImmediatePropagation();
|
event.nativeEvent.stopImmediatePropagation();
|
||||||
|
const canPreview = window.sfMetadataContext.canPreview();
|
||||||
|
if (!canPreview) return;
|
||||||
onOpenFile(record);
|
onOpenFile(record);
|
||||||
}, [titleColumn, record, onOpenFile]);
|
}, [titleColumn, record, onOpenFile]);
|
||||||
|
|
||||||
|
@ -182,6 +182,8 @@ const Boards = ({ modifyRecord, deleteRecords, modifyColumnData, onCloseSettings
|
|||||||
|
|
||||||
const onOpenFile = useCallback((record) => {
|
const onOpenFile = useCallback((record) => {
|
||||||
const repoID = window.sfMetadataContext.getSetting('repoID');
|
const repoID = window.sfMetadataContext.getSetting('repoID');
|
||||||
|
const canPreview = window.sfMetadataContext.canPreview();
|
||||||
|
if (!canPreview) return;
|
||||||
openFile(repoID, record, () => {
|
openFile(repoID, record, () => {
|
||||||
currentImageRef.current = record;
|
currentImageRef.current = record;
|
||||||
setImagePreviewerVisible(true);
|
setImagePreviewerVisible(true);
|
||||||
|
@ -451,6 +451,7 @@ class InteractionMasks extends React.Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
handleSpaceKeyDown = (e) => {
|
handleSpaceKeyDown = (e) => {
|
||||||
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.nativeEvent.stopImmediatePropagation();
|
e.nativeEvent.stopImmediatePropagation();
|
||||||
const repoID = window.sfMetadataContext.getSetting('repoID');
|
const repoID = window.sfMetadataContext.getSetting('repoID');
|
||||||
|
@ -154,6 +154,8 @@ const Cell = React.memo(({
|
|||||||
event.nativeEvent.stopImmediatePropagation();
|
event.nativeEvent.stopImmediatePropagation();
|
||||||
if (!isCellSelected) return;
|
if (!isCellSelected) return;
|
||||||
const repoID = window.sfMetadataContext.getSetting('repoID');
|
const repoID = window.sfMetadataContext.getSetting('repoID');
|
||||||
|
const canPreview = window.sfMetadataContext.canPreview();
|
||||||
|
if (!canPreview) return;
|
||||||
openFile(repoID, record, () => {
|
openFile(repoID, record, () => {
|
||||||
window.sfMetadataContext.eventBus.dispatch(EVENT_BUS_TYPE.OPEN_EDITOR, EDITOR_TYPE.PREVIEWER);
|
window.sfMetadataContext.eventBus.dispatch(EVENT_BUS_TYPE.OPEN_EDITOR, EDITOR_TYPE.PREVIEWER);
|
||||||
});
|
});
|
||||||
|
@ -22,6 +22,8 @@ const FileNameOperationBtn = ({ column, record, ...props }) => {
|
|||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.nativeEvent.stopImmediatePropagation();
|
event.nativeEvent.stopImmediatePropagation();
|
||||||
const repoID = window.sfMetadataContext.getSetting('repoID');
|
const repoID = window.sfMetadataContext.getSetting('repoID');
|
||||||
|
const canPreview = window.sfMetadataContext.canPreview();
|
||||||
|
if (!canPreview) return;
|
||||||
openFile(repoID, record, () => {
|
openFile(repoID, record, () => {
|
||||||
window.sfMetadataContext.eventBus.dispatch(METADATA_EVENT_BUS_TYPE.OPEN_EDITOR, EDITOR_TYPE.PREVIEWER);
|
window.sfMetadataContext.eventBus.dispatch(METADATA_EVENT_BUS_TYPE.OPEN_EDITOR, EDITOR_TYPE.PREVIEWER);
|
||||||
});
|
});
|
||||||
|
@ -2,6 +2,7 @@ import tagsAPI from './api';
|
|||||||
import LocalStorage from '../metadata/utils/local-storage';
|
import LocalStorage from '../metadata/utils/local-storage';
|
||||||
import EventBus from '../components/common/event-bus';
|
import EventBus from '../components/common/event-bus';
|
||||||
import { username, lang } from '../utils/constants';
|
import { username, lang } from '../utils/constants';
|
||||||
|
import { Utils } from '../utils/utils';
|
||||||
|
|
||||||
class Context {
|
class Context {
|
||||||
|
|
||||||
@ -36,6 +37,8 @@ class Context {
|
|||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
|
|
||||||
this.permission = repoInfo.permission !== 'admin' && repoInfo.permission !== 'rw' ? 'r' : 'rw';
|
this.permission = repoInfo.permission !== 'admin' && repoInfo.permission !== 'rw' ? 'r' : 'rw';
|
||||||
|
const { isCustomPermission, customPermission } = Utils.getUserPermission(repoInfo.permission);
|
||||||
|
this.customPermission = isCustomPermission ? customPermission : null;
|
||||||
|
|
||||||
this.hasInit = true;
|
this.hasInit = true;
|
||||||
}
|
}
|
||||||
@ -72,6 +75,14 @@ class Context {
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
canPreview = () => {
|
||||||
|
if (this.customPermission) {
|
||||||
|
const { preview, modify } = this.customPermission.permission;
|
||||||
|
return preview || modify;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
canAddTag = () => {
|
canAddTag = () => {
|
||||||
if (this.permission === 'r') return false;
|
if (this.permission === 'r') return false;
|
||||||
return true;
|
return true;
|
||||||
|
@ -76,7 +76,8 @@ const TagFile = ({ isSelected, repoID, file, tagsData, onSelectFile, openImagePr
|
|||||||
|
|
||||||
const handelClickFileName = useCallback((event) => {
|
const handelClickFileName = useCallback((event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (isRenameing) return;
|
const canPreview = window.sfTagsDataContext.canPreview();
|
||||||
|
if (isRenameing || !canPreview) return;
|
||||||
openFile(repoID, file, () => {
|
openFile(repoID, file, () => {
|
||||||
openImagePreview(file);
|
openImagePreview(file);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user