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

Update the draft Downloader implementation to actually download discovered new files #10

Merged
merged 1 commit into from
Nov 26, 2023

Conversation

andreiled
Copy link
Owner

@andreiled andreiled commented Nov 24, 2023

  1. Add a new FileCopier class with a copy method encapsulating the logic to:
    • automatically create necessary directories at the destination
    • actually attempt copying the file
    • identify and handle the edge case when the specified target file already exists
      using a provided FileCopyEventsHandler implementation
  2. Update the Downloader class to:
    1. Create and configure a FileCopier instance with a simple FileCopyEventsHandler implementation
      to automatically skip copying over existing files.
    2. Update the downloadNewFilesFromDir method to call the FileCopier.copy method
      from the newFiles loop.

Manual Test

in addition to running unit tests added by this PR

  1. Manually create %USER_DR%\AppData\Local\auto-download\config.json with the following content.

    {
        "DCIM": {
            "target": {
                "root": "%MY_PHOTOS%"
            }
        }
    }
  2. Create a cursor file: X:\DCIM\.auto-download\cursor.json:

    {"sequential":{"lastProcessedFile":"101MSDCF/%LAST_FILE_I_COPIED_MANUALLY%"}}
  3. Manually copy one of the newer files from my memory card to an appropriately named new directory.

  4. Temporarily put the following code into the index.ts:

    import { Downloader } from "./downloader";
    
    (async function () {
        new Downloader().downloadAllNewFiles("X:");
    })();
  5. Build and run the main script:

    npm run build && node dist/index.js
    • AR == ER: the script is executed successfully.
    • AR == ER: the script found and copied new files from my memory card.
    • AR == ER: the script automatically skipped the file I already copied manually.
    [X:] Found 1 supported directory: X:/DCIM
    [X:/DCIM] Skip previously processed sub-directories and/or files: 100MSDCF
    [X:/DCIM] 101MSDCF is the latest previously processed sub-directory and could have new files: will process all sub-directories and files starting from it: 101MSDCF
    [X:/DCIM/101MSDCF] Skip previously processed sub-directories and/or files: --redacted--
    [X:/DCIM/101MSDCF] New sub-directories and/or files found: --redacted--
    [X:/DCIM] Found 20 new files in total (in this source directory)
    [X:/DCIM] Copy 101MSDCF/--redacted-- to %MY_PHOTOS%/2023-10-27/--redacted--
    ...
    --redacted-- already exists in %MY_PHOTOS%/2023-11-12: skip copying X:/DCIM/101MSDCF/--redacted--
    ...
    [X:/DCIM] Save final cursor position: 101MSDCF/--redacted--
    

…covered new files

1. Add a new `FileCopier` class with a `copy` method encapsulating the logic to:
    - automatically create necessary directories at the destination
    - actually attempt copying the file
    - identify and handle the edge case when the specified target file already exists
      using a provided `FileCopyEventsHandler` implementation
2. Update the `Downloader` class to:
    1. Create and configure a `FileCopier` instance with a simple `FileCopyEventsHandler` implementation
       to automatically skip copying over existing files.
    2. Update the `downloadNewFilesFromDir` method to call the `FileCopier.copy` method
       from the `newFiles` loop.
@andreiled andreiled merged commit 8fb5e79 into main Nov 26, 2023
2 checks passed
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.

1 participant