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

refactor(server): download assets #3032

Merged
merged 9 commits into from
Jun 30, 2023
Merged

Conversation

jrasm91
Copy link
Contributor

@jrasm91 jrasm91 commented Jun 29, 2023

Tested scenarios:

  • Download a single file from the timeline
  • Download multiple files from the timeline
  • Download a live photo from the timeline
  • Download a single file from an album
  • Download multiple files from an album
  • Download an entire album
  • Download a live photo from an album
  • Download an entire shared link (album)
  • Download a single file from a shared link (album)
  • Download multiple files from a shared link (album)
  • Download a live photo from a shared link (album)
  • Download an entire shared link (individual)
  • Download a single file from a shared link (individual)
  • Download multiple files from a shared link (individual)
  • Download a live photo from a shared link (individual)
  • Download a single file from search
  • Download multiple files from search
  • Download a single file from a shared partner
  • Download multiple files from a shared partner
  • Download a live photo from a shared partner
  • Download a file from the asset viewer from a shared partner
  • Download a file from the asset viewer from an album
  • Download a file from the asset viewer from a shared link (album)
  • Download a file from the asset viewer from a shared link (individual)
  • Download a single file from favorites
  • Download multiple files from favorites
  • Download a file from the asset viewer from the favorites page
  • Download a live photo from the asset viewer
  • Download a live photo from the asset view on the archive page
  • Download a single from from the archive page
  • Download multiple files from the archive page

@vercel
Copy link

vercel bot commented Jun 29, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
immich ⬜️ Ignored (Inspect) Jun 30, 2023 1:08pm

@jrasm91 jrasm91 marked this pull request as ready for review June 30, 2023 02:41
server/src/infra/repositories/asset.repository.ts Outdated Show resolved Hide resolved
web/src/lib/utils/asset-utils.ts Outdated Show resolved Hide resolved
@alextran1502 alextran1502 merged commit ad343b7 into main Jun 30, 2023
19 checks passed
@alextran1502 alextran1502 deleted the refactor/download-assets branch June 30, 2023 16:24
Comment on lines +99 to +113
const paths: Record<string, boolean> = {};

for (const { originalPath, originalFileName } of assets) {
const ext = extname(originalPath);
let filename = `${originalFileName}${ext}`;
for (let i = 0; i < 10_000; i++) {
if (!paths[filename]) {
break;
}
filename = `${originalFileName}+${i + 1}${ext}`;
}

paths[filename] = true;
zip.addFile(originalPath, filename);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am late with my review, but it seems if we change the type of the Record to Record<string, number> the code looks cleaner:

  const paths: Record<string, number> = {};

  for (const { originalPath, originalFileName } of assets) {
    const ext = extname(originalPath);

    const baseName = `${originalFileName}${ext}`;
    let filename = baseName;

    let index = paths[baseName];
    if (index === undefined) {
      index = 0;
    } else {
      index++;
      filename = `${originalFileName}+${index}${ext}`;
    }
    paths[baseName] = index;
    
    zip.addFile(originalPath, filename);
  }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a shame as Array.prototype.group would make this quite nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just because it was merged doesn't mean it can't be fixed anymore lol 😛

Do you have an example of how array.group would look? I've never used it before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

group is still experimental, so I can implement the suggestion from @brighteyed instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants