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

Updates to the @actual-budget/api package #464

Merged
merged 17 commits into from
Feb 24, 2023
Merged

Conversation

j-f1
Copy link
Contributor

@j-f1 j-f1 commented Jan 14, 2023

While working on actualbudget/docs#76, I made some improvements to make the API easier to use.

@jlongster if possible I would love a review of these changes, especially around handling keys (in packages/loot-core/src/server/api.js). I want to make sure I’m guiding people down a correct and stable path here.

@netlify
Copy link

netlify bot commented Jan 14, 2023

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit 92f3672
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/63e95fc5096f5b00086b44b8
😎 Deploy Preview https://deploy-preview-464--actualbudget.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Copy link
Contributor

@jlongster jlongster left a comment

Choose a reason for hiding this comment

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

This is great! Definitely along the lines I was thinking. let me know when this is ready for a final review and I'll approve if it looks good. (see my main question about downloadBudget)

packages/api/index.js Show resolved Hide resolved
packages/api/methods.js Show resolved Hide resolved
packages/loot-core/src/server/main.js Show resolved Hide resolved
@@ -160,6 +161,35 @@ handlers['api/load-budget'] = async function ({ id }) {
}
};

handlers['api/download-budget'] = async function ({ syncId, password }) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think in this function we want to check if the file is already downloaded, and if so do nothing right?

Or change the API the be api.loadBudget and it would magically automatically download it if it's not already downloaded. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think in this function we want to check if the file is already downloaded, and if so do nothing right?

I assumed cloudStorage.download already did that because download-budget checks for the file-exists error, but it seems like it doesn’t. I’ll add that!

Or change the API the be api.loadBudget and it would magically automatically download it if it's not already downloaded. What do you think?

Currently you have to use the sync id to download, and the budget id to open. (The budget id is helpfully returned from the handlers['download-budget'] API, once the download completes).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(Fortunately, get-budgets returns sync file IDs for local budgets, so I’m able to fetch them that way).

Updated the code to look for a local budget and trigger a full sync on it instead of re-downloading if possible. I think this is ready for another review!

@j-f1
Copy link
Contributor Author

j-f1 commented Jan 14, 2023

@j-f1
Copy link
Contributor Author

j-f1 commented Feb 7, 2023

@jlongster Would you be able to take a look at this?

@BrunoPansani
Copy link

Hi @j-f1,
It looks like there's a mismatch between actualbudget/docs#76 and this PR. This should've been merged before the docs, but now the docs are updated without the new functions you implemented.

@j-f1 j-f1 merged commit 93a1f8a into actualbudget:master Feb 24, 2023
@trafico-bot trafico-bot bot added the ✨ Merged Pull Request has been merged successfully label Feb 24, 2023
@j-f1 j-f1 deleted the api-v5 branch February 24, 2023 04:01
FlorianLang06 pushed a commit to FlorianLang06/actual that referenced this pull request Mar 7, 2024
* Make it easier to build the bundle.api.js for the API

* Remove budgetId parameter, move config to top level of API

* that’s a breaking change

* Add support for signing into the server in init()

* Add api.downloadBudget(syncId, { password }) method

* Fix lint errors

* Refactor: extract out getSyncError

* api/download-budget: sync if possible instead of downloading

* Don’t bother with fetching remote files and installing key if the file is local

* *groupId

* FIx lint issues

* Remove extra close+reopen

* Refactor out duplicate load-budget logic

* Trailing commas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ Merged Pull Request has been merged successfully
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants