commit
90e5cb45e9
|
@ -244,18 +244,15 @@ const PhotoFrame = ({
|
||||||
}, [open]);
|
}, [open]);
|
||||||
|
|
||||||
const updateURL = (index: number) => (url: string) => {
|
const updateURL = (index: number) => (url: string) => {
|
||||||
files[index] = {
|
const updateFile = (file: EnteFile) => {
|
||||||
...files[index],
|
file = {
|
||||||
|
...file,
|
||||||
msrc: url,
|
msrc: url,
|
||||||
src: files[index].src ? files[index].src : url,
|
|
||||||
w: window.innerWidth,
|
w: window.innerWidth,
|
||||||
h: window.innerHeight,
|
h: window.innerHeight,
|
||||||
};
|
};
|
||||||
if (
|
if (file.metadata.fileType === FILE_TYPE.VIDEO && !file.html) {
|
||||||
files[index].metadata.fileType === FILE_TYPE.VIDEO &&
|
file.html = `
|
||||||
!files[index].html
|
|
||||||
) {
|
|
||||||
files[index].html = `
|
|
||||||
<div class="video-loading">
|
<div class="video-loading">
|
||||||
<img src="${url}" />
|
<img src="${url}" />
|
||||||
<div class="spinner-border text-light" role="status">
|
<div class="spinner-border text-light" role="status">
|
||||||
|
@ -263,46 +260,59 @@ const PhotoFrame = ({
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
delete files[index].src;
|
} else if (
|
||||||
}
|
(file.metadata.fileType === FILE_TYPE.IMAGE ||
|
||||||
if (
|
file.metadata.fileType === FILE_TYPE.LIVE_PHOTO) &&
|
||||||
files[index].metadata.fileType === FILE_TYPE.IMAGE &&
|
!file.src
|
||||||
!files[index].src
|
|
||||||
) {
|
) {
|
||||||
files[index].src = url;
|
file.src = url;
|
||||||
}
|
}
|
||||||
setFiles(files);
|
return file;
|
||||||
|
};
|
||||||
|
setFiles((files) => {
|
||||||
|
files[index] = updateFile(files[index]);
|
||||||
|
return [...files];
|
||||||
|
});
|
||||||
|
return updateFile(files[index]);
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateSrcURL = async (index: number, url: string) => {
|
const updateSrcURL = async (index: number, url: string) => {
|
||||||
files[index] = {
|
const isPlayable = await isPlaybackPossible(url);
|
||||||
...files[index],
|
const updateFile = (file: EnteFile) => {
|
||||||
|
file = {
|
||||||
|
...file,
|
||||||
w: window.innerWidth,
|
w: window.innerWidth,
|
||||||
h: window.innerHeight,
|
h: window.innerHeight,
|
||||||
};
|
};
|
||||||
if (files[index].metadata.fileType === FILE_TYPE.VIDEO) {
|
if (file.metadata.fileType === FILE_TYPE.VIDEO) {
|
||||||
if (await isPlaybackPossible(url)) {
|
if (isPlayable) {
|
||||||
files[index].html = `
|
file.html = `
|
||||||
<video controls>
|
<video controls>
|
||||||
<source src="${url}" />
|
<source src="${url}" />
|
||||||
Your browser does not support the video tag.
|
Your browser does not support the video tag.
|
||||||
</video>
|
</video>
|
||||||
`;
|
`;
|
||||||
} else {
|
} else {
|
||||||
files[index].html = `
|
file.html = `
|
||||||
<div class="video-loading">
|
<div class="video-loading">
|
||||||
<img src="${files[index].msrc}" />
|
<img src="${file.msrc}" />
|
||||||
<div class="download-message" >
|
<div class="download-message" >
|
||||||
${constants.VIDEO_PLAYBACK_FAILED_DOWNLOAD_INSTEAD}
|
${constants.VIDEO_PLAYBACK_FAILED_DOWNLOAD_INSTEAD}
|
||||||
<a class="btn btn-outline-success" href=${url} download="${files[index].metadata.title}"">Download</button>
|
<a class="btn btn-outline-success" href=${url} download="${file.metadata.title}"">Download</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
files[index].src = url;
|
file.src = url;
|
||||||
}
|
}
|
||||||
setFiles(files);
|
return file;
|
||||||
|
};
|
||||||
|
setFiles((files) => {
|
||||||
|
files[index] = updateFile(files[index]);
|
||||||
|
return [...files];
|
||||||
|
});
|
||||||
|
return updateFile(files[index]);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleClose = (needUpdate) => {
|
const handleClose = (needUpdate) => {
|
||||||
|
@ -418,13 +428,13 @@ const PhotoFrame = ({
|
||||||
}
|
}
|
||||||
galleryContext.thumbs.set(item.id, url);
|
galleryContext.thumbs.set(item.id, url);
|
||||||
}
|
}
|
||||||
updateURL(item.dataIndex)(url);
|
const newFile = updateURL(item.dataIndex)(url);
|
||||||
item.msrc = url;
|
item.msrc = newFile.msrc;
|
||||||
if (!item.src) {
|
item.html = newFile.html;
|
||||||
item.src = url;
|
item.src = newFile.src;
|
||||||
}
|
item.w = newFile.w;
|
||||||
item.w = window.innerWidth;
|
item.h = newFile.h;
|
||||||
item.h = window.innerHeight;
|
|
||||||
try {
|
try {
|
||||||
instance.invalidateCurrItems();
|
instance.invalidateCurrItems();
|
||||||
instance.updateSize(true);
|
instance.updateSize(true);
|
||||||
|
@ -442,6 +452,7 @@ const PhotoFrame = ({
|
||||||
if (galleryContext.files.has(item.id)) {
|
if (galleryContext.files.has(item.id)) {
|
||||||
url = galleryContext.files.get(item.id);
|
url = galleryContext.files.get(item.id);
|
||||||
} else {
|
} else {
|
||||||
|
galleryContext.startLoading();
|
||||||
if (
|
if (
|
||||||
publicCollectionGalleryContext.accessedThroughSharedURL
|
publicCollectionGalleryContext.accessedThroughSharedURL
|
||||||
) {
|
) {
|
||||||
|
@ -454,13 +465,15 @@ const PhotoFrame = ({
|
||||||
} else {
|
} else {
|
||||||
url = await DownloadManager.getFile(item, true);
|
url = await DownloadManager.getFile(item, true);
|
||||||
}
|
}
|
||||||
|
galleryContext.finishLoading();
|
||||||
galleryContext.files.set(item.id, url);
|
galleryContext.files.set(item.id, url);
|
||||||
}
|
}
|
||||||
await updateSrcURL(item.dataIndex, url);
|
const newFile = await updateSrcURL(item.dataIndex, url);
|
||||||
item.html = files[item.dataIndex].html;
|
item.msrc = newFile.msrc;
|
||||||
item.src = files[item.dataIndex].src;
|
item.html = newFile.html;
|
||||||
item.w = files[item.dataIndex].w;
|
item.src = newFile.src;
|
||||||
item.h = files[item.dataIndex].h;
|
item.w = newFile.w;
|
||||||
|
item.h = newFile.h;
|
||||||
try {
|
try {
|
||||||
instance.invalidateCurrItems();
|
instance.invalidateCurrItems();
|
||||||
instance.updateSize(true);
|
instance.updateSize(true);
|
||||||
|
|
|
@ -490,7 +490,8 @@ function InfoModal({
|
||||||
|
|
||||||
function PhotoSwipe(props: Iprops) {
|
function PhotoSwipe(props: Iprops) {
|
||||||
const pswpElement = useRef<HTMLDivElement>();
|
const pswpElement = useRef<HTMLDivElement>();
|
||||||
const [photoSwipe, setPhotoSwipe] = useState<Photoswipe<any>>();
|
const [photoSwipe, setPhotoSwipe] =
|
||||||
|
useState<Photoswipe<Photoswipe.Options>>();
|
||||||
|
|
||||||
const { isOpen, items } = props;
|
const { isOpen, items } = props;
|
||||||
const [isFav, setIsFav] = useState(false);
|
const [isFav, setIsFav] = useState(false);
|
||||||
|
|
|
@ -164,7 +164,7 @@ const Cont = styled.div<{ disabled: boolean; selected: boolean }>`
|
||||||
|
|
||||||
export default function PreviewCard(props: IProps) {
|
export default function PreviewCard(props: IProps) {
|
||||||
const [imgSrc, setImgSrc] = useState<string>();
|
const [imgSrc, setImgSrc] = useState<string>();
|
||||||
const { thumbs, files } = useContext(GalleryContext);
|
const { thumbs } = useContext(GalleryContext);
|
||||||
const {
|
const {
|
||||||
file,
|
file,
|
||||||
onClick,
|
onClick,
|
||||||
|
@ -203,10 +203,6 @@ export default function PreviewCard(props: IProps) {
|
||||||
if (isMounted.current) {
|
if (isMounted.current) {
|
||||||
setImgSrc(url);
|
setImgSrc(url);
|
||||||
thumbs.set(file.id, url);
|
thumbs.set(file.id, url);
|
||||||
file.msrc = url;
|
|
||||||
if (!file.src) {
|
|
||||||
file.src = url;
|
|
||||||
}
|
|
||||||
updateURL(url);
|
updateURL(url);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -218,13 +214,6 @@ export default function PreviewCard(props: IProps) {
|
||||||
const thumbImgSrc = thumbs.get(file.id);
|
const thumbImgSrc = thumbs.get(file.id);
|
||||||
setImgSrc(thumbImgSrc);
|
setImgSrc(thumbImgSrc);
|
||||||
file.msrc = thumbImgSrc;
|
file.msrc = thumbImgSrc;
|
||||||
if (!file.src) {
|
|
||||||
if (files.has(file.id)) {
|
|
||||||
file.src = files.get(file.id);
|
|
||||||
} else {
|
|
||||||
file.src = thumbImgSrc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
main();
|
main();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,15 @@ import { EncryptionResult } from 'types/upload';
|
||||||
import { Collection } from 'types/collection';
|
import { Collection } from 'types/collection';
|
||||||
import HTTPService from './HTTPService';
|
import HTTPService from './HTTPService';
|
||||||
import { logError } from 'utils/sentry';
|
import { logError } from 'utils/sentry';
|
||||||
import { decryptFile, mergeMetadata, sortFiles } from 'utils/file';
|
import {
|
||||||
|
decryptFile,
|
||||||
|
mergeMetadata,
|
||||||
|
preservePhotoswipeProps,
|
||||||
|
sortFiles,
|
||||||
|
} from 'utils/file';
|
||||||
import CryptoWorker from 'utils/crypto';
|
import CryptoWorker from 'utils/crypto';
|
||||||
import { EnteFile, TrashRequest, UpdateMagicMetadataRequest } from 'types/file';
|
import { EnteFile, TrashRequest, UpdateMagicMetadataRequest } from 'types/file';
|
||||||
|
import { SetFiles } from 'types/gallery';
|
||||||
|
|
||||||
const ENDPOINT = getEndpoint();
|
const ENDPOINT = getEndpoint();
|
||||||
const FILES_TABLE = 'files';
|
const FILES_TABLE = 'files';
|
||||||
|
@ -28,13 +34,13 @@ const getCollectionLastSyncTime = async (collection: Collection) =>
|
||||||
|
|
||||||
export const syncFiles = async (
|
export const syncFiles = async (
|
||||||
collections: Collection[],
|
collections: Collection[],
|
||||||
setFiles: (files: EnteFile[]) => void
|
setFiles: SetFiles
|
||||||
) => {
|
) => {
|
||||||
const localFiles = await getLocalFiles();
|
const localFiles = await getLocalFiles();
|
||||||
let files = await removeDeletedCollectionFiles(collections, localFiles);
|
let files = await removeDeletedCollectionFiles(collections, localFiles);
|
||||||
if (files.length !== localFiles.length) {
|
if (files.length !== localFiles.length) {
|
||||||
await setLocalFiles(files);
|
await setLocalFiles(files);
|
||||||
setFiles([...sortFiles(mergeMetadata(files))]);
|
setFiles(preservePhotoswipeProps([...sortFiles(mergeMetadata(files))]));
|
||||||
}
|
}
|
||||||
for (const collection of collections) {
|
for (const collection of collections) {
|
||||||
if (!getToken()) {
|
if (!getToken()) {
|
||||||
|
@ -70,7 +76,7 @@ export const syncFiles = async (
|
||||||
`${collection.id}-time`,
|
`${collection.id}-time`,
|
||||||
collection.updationTime
|
collection.updationTime
|
||||||
);
|
);
|
||||||
setFiles([...sortFiles(mergeMetadata(files))]);
|
setFiles(preservePhotoswipeProps([...sortFiles(mergeMetadata(files))]));
|
||||||
}
|
}
|
||||||
return sortFiles(mergeMetadata(files));
|
return sortFiles(mergeMetadata(files));
|
||||||
};
|
};
|
||||||
|
@ -79,7 +85,7 @@ export const getFiles = async (
|
||||||
collection: Collection,
|
collection: Collection,
|
||||||
sinceTime: number,
|
sinceTime: number,
|
||||||
files: EnteFile[],
|
files: EnteFile[],
|
||||||
setFiles: (files: EnteFile[]) => void
|
setFiles: SetFiles
|
||||||
): Promise<EnteFile[]> => {
|
): Promise<EnteFile[]> => {
|
||||||
try {
|
try {
|
||||||
const decryptedFiles: EnteFile[] = [];
|
const decryptedFiles: EnteFile[] = [];
|
||||||
|
@ -116,6 +122,7 @@ export const getFiles = async (
|
||||||
time = resp.data.diff.slice(-1)[0].updationTime;
|
time = resp.data.diff.slice(-1)[0].updationTime;
|
||||||
}
|
}
|
||||||
setFiles(
|
setFiles(
|
||||||
|
preservePhotoswipeProps(
|
||||||
sortFiles(
|
sortFiles(
|
||||||
mergeMetadata(
|
mergeMetadata(
|
||||||
[...(files || []), ...decryptedFiles].filter(
|
[...(files || []), ...decryptedFiles].filter(
|
||||||
|
@ -123,6 +130,7 @@ export const getFiles = async (
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
} while (resp.data.hasMore);
|
} while (resp.data.hasMore);
|
||||||
return decryptedFiles;
|
return decryptedFiles;
|
||||||
|
|
|
@ -2,7 +2,12 @@ import { SetFiles } from 'types/gallery';
|
||||||
import { Collection } from 'types/collection';
|
import { Collection } from 'types/collection';
|
||||||
import { getEndpoint } from 'utils/common/apiUtil';
|
import { getEndpoint } from 'utils/common/apiUtil';
|
||||||
import { getToken } from 'utils/common/key';
|
import { getToken } from 'utils/common/key';
|
||||||
import { decryptFile, mergeMetadata, sortFiles } from 'utils/file';
|
import {
|
||||||
|
decryptFile,
|
||||||
|
mergeMetadata,
|
||||||
|
preservePhotoswipeProps,
|
||||||
|
sortFiles,
|
||||||
|
} from 'utils/file';
|
||||||
import { logError } from 'utils/sentry';
|
import { logError } from 'utils/sentry';
|
||||||
import localForage from 'utils/storage/localForage';
|
import localForage from 'utils/storage/localForage';
|
||||||
import { getCollection } from './collectionService';
|
import { getCollection } from './collectionService';
|
||||||
|
@ -120,7 +125,12 @@ export const updateTrash = async (
|
||||||
updatedTrash = removeRestoredOrDeletedTrashItems(updatedTrash);
|
updatedTrash = removeRestoredOrDeletedTrashItems(updatedTrash);
|
||||||
|
|
||||||
setFiles(
|
setFiles(
|
||||||
sortFiles([...(files ?? []), ...getTrashedFiles(updatedTrash)])
|
preservePhotoswipeProps(
|
||||||
|
sortFiles([
|
||||||
|
...(files ?? []),
|
||||||
|
...getTrashedFiles(updatedTrash),
|
||||||
|
])
|
||||||
|
)
|
||||||
);
|
);
|
||||||
await localForage.setItem(TRASH, updatedTrash);
|
await localForage.setItem(TRASH, updatedTrash);
|
||||||
await localForage.setItem(TRASH_TIME, time);
|
await localForage.setItem(TRASH_TIME, time);
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { getDedicatedCryptoWorker } from 'utils/crypto';
|
||||||
import {
|
import {
|
||||||
sortFilesIntoCollections,
|
sortFilesIntoCollections,
|
||||||
sortFiles,
|
sortFiles,
|
||||||
removeUnnecessaryFileProps,
|
preservePhotoswipeProps,
|
||||||
} from 'utils/file';
|
} from 'utils/file';
|
||||||
import { logError } from 'utils/sentry';
|
import { logError } from 'utils/sentry';
|
||||||
import { getMetadataJSONMapKey, parseMetadataJSON } from './metadataService';
|
import { getMetadataJSONMapKey, parseMetadataJSON } from './metadataService';
|
||||||
|
@ -239,10 +239,8 @@ class UploadManager {
|
||||||
if (fileUploadResult === FileUploadResults.UPLOADED) {
|
if (fileUploadResult === FileUploadResults.UPLOADED) {
|
||||||
this.existingFiles.push(file);
|
this.existingFiles.push(file);
|
||||||
this.existingFiles = sortFiles(this.existingFiles);
|
this.existingFiles = sortFiles(this.existingFiles);
|
||||||
await setLocalFiles(
|
await setLocalFiles(this.existingFiles);
|
||||||
removeUnnecessaryFileProps(this.existingFiles)
|
this.setFiles(preservePhotoswipeProps(this.existingFiles));
|
||||||
);
|
|
||||||
this.setFiles(this.existingFiles);
|
|
||||||
if (!this.existingFilesCollectionWise.has(file.collectionID)) {
|
if (!this.existingFilesCollectionWise.has(file.collectionID)) {
|
||||||
this.existingFilesCollectionWise.set(file.collectionID, []);
|
this.existingFilesCollectionWise.set(file.collectionID, []);
|
||||||
}
|
}
|
||||||
|
|
|
@ -281,20 +281,18 @@ export async function decryptFile(file: EnteFile, collectionKey: string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function removeUnnecessaryFileProps(files: EnteFile[]): EnteFile[] {
|
export const preservePhotoswipeProps =
|
||||||
const stripedFiles = files.map((file) => {
|
(newFiles: EnteFile[]) =>
|
||||||
delete file.src;
|
(currentFiles: EnteFile[]): EnteFile[] => {
|
||||||
delete file.msrc;
|
const currentFilesMap = Object.fromEntries(
|
||||||
delete file.file.objectKey;
|
currentFiles.map((file) => [file.id, file])
|
||||||
delete file.thumbnail.objectKey;
|
);
|
||||||
delete file.h;
|
const fileWithPreservedProperty = newFiles.map((file) => {
|
||||||
delete file.html;
|
const currentFile = currentFilesMap[file.id];
|
||||||
delete file.w;
|
return { ...currentFile, ...file };
|
||||||
|
|
||||||
return file;
|
|
||||||
});
|
});
|
||||||
return stripedFiles;
|
return fileWithPreservedProperty;
|
||||||
}
|
};
|
||||||
|
|
||||||
export function fileNameWithoutExtension(filename) {
|
export function fileNameWithoutExtension(filename) {
|
||||||
const lastDotPosition = filename.lastIndexOf('.');
|
const lastDotPosition = filename.lastIndexOf('.');
|
||||||
|
|
Loading…
Reference in a new issue