Skip to content

Commit

Permalink
[web] Refactoring of downloader - Part x/x (#4155)
Browse files Browse the repository at this point in the history
  • Loading branch information
mnvr authored Nov 23, 2024
2 parents 3c47e86 + 01cc72a commit 07ba083
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 158 deletions.
3 changes: 1 addition & 2 deletions web/apps/photos/src/components/FixCreationTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,7 @@ const updateEnteFileDate = async (
timestamp: customDate!.timestamp,
};
} else if (enteFile.metadata.fileType == FileType.image) {
const stream = await downloadManager.getFile(enteFile);
const blob = await new Response(stream).blob();
const blob = await downloadManager.fileBlob(enteFile);
const file = new File([blob], enteFile.metadata.title);
const { DateTimeOriginal, DateTimeDigitized, MetadataDate, DateTime } =
await extractExifDates(file);
Expand Down
4 changes: 3 additions & 1 deletion web/apps/photos/src/components/PhotoFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,9 @@ const PhotoFrame = ({
}
log.info(`[${item.id}] doesn't have thumbnail`);
thumbFetching[item.id] = true;
const url = await DownloadManager.getThumbnailForPreview(item);
// URL will always be defined (unless an error is thrown) since
// we are not passing the `cachedOnly` option.
const url = await DownloadManager.renderableThumbnailURL(item)!;
updateThumb(instance, index, item, url, false);
} catch (e) {
log.error("getSlideData failed get msrc url failed", e);
Expand Down
4 changes: 0 additions & 4 deletions web/apps/photos/src/components/PhotoList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -631,10 +631,6 @@ export function PhotoList({

/**
* Checks and merge multiple dates into a single row.
*
* @param items
* @param columns
* @returns
*/
const mergeTimeStampList = (
items: TimeStampListItem[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export default function PreviewCard(props: IProps) {
return;
}
const url: string =
await DownloadManager.getThumbnailForPreview(
await DownloadManager.renderableThumbnailURL(
file,
props.showPlaceholder,
);
Expand Down
2 changes: 1 addition & 1 deletion web/apps/photos/src/services/export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ class ExportService {
const electron = ensureElectron();
try {
const fileUID = getExportRecordFileUID(file);
const originalFileStream = await downloadManager.getFile(file);
const originalFileStream = await downloadManager.fileStream(file);
if (file.metadata.fileType === FileType.livePhoto) {
await this.exportLivePhoto(
exportDir,
Expand Down
3 changes: 1 addition & 2 deletions web/apps/photos/src/services/export/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,7 @@ async function getFileExportNamesFromExportedFiles(
For Live Photos we need to download the file to get the image and video name
*/
if (file.metadata.fileType === FileType.livePhoto) {
const fileStream = await downloadManager.getFile(file);
const fileBlob = await new Response(fileStream).blob();
const fileBlob = await downloadManager.fileBlob(file);
const { imageFileName, videoFileName } = await decodeLivePhoto(
file.metadata.title,
fileBlob,
Expand Down
6 changes: 2 additions & 4 deletions web/apps/photos/src/utils/file/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ export enum FILE_OPS_TYPE {

export async function downloadFile(file: EnteFile) {
try {
let fileBlob = await new Response(
await DownloadManager.getFile(file),
).blob();
let fileBlob = await DownloadManager.fileBlob(file);
if (file.metadata.fileType === FileType.livePhoto) {
const { imageFileName, imageData, videoFileName, videoData } =
await decodeLivePhoto(file.metadata.title, fileBlob);
Expand Down Expand Up @@ -392,7 +390,7 @@ async function downloadFileDesktop(
) {
const fs = electron.fs;

const stream = await DownloadManager.getFile(file);
const stream = await DownloadManager.fileStream(file);

if (file.metadata.fileType === FileType.livePhoto) {
const fileBlob = await new Response(stream).blob();
Expand Down
2 changes: 1 addition & 1 deletion web/packages/new/photos/components/Tiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const ItemCard: React.FC<React.PropsWithChildren<ItemCardProps>> = ({
);
} else {
void downloadManager
.getThumbnailForPreview(coverFile, isScrolling)
.renderableThumbnailURL(coverFile, isScrolling)
.then((url) => !didCancel && setCoverImageURL(url));
}

Expand Down
Loading

0 comments on commit 07ba083

Please sign in to comment.