bvanelli / actualpy

Python API implementation for Actual server - reference https://actualbudget.org/
20 stars 4 forks source link

Allow BudgetID instead of fileID #45

Closed bobokun closed 1 month ago

bobokun commented 1 month ago

Description

When passing file="My budget" does seem to work while using the name, however it's not easy for a user to find the file_id. budget_id makes more sense and is easier to find for the user, could we modify to use budget ID in addition to the current options?

bvanelli commented 1 month ago

Hi,

thanks for the suggestion, but I think there is no good way to implement this. See how this budget_id is generated:

https://github.com/actualbudget/actual/blob/9a85a7208990d4636cd8a574d04145b9e3318c98/packages/loot-core/src/server/util/budget-name.ts#L21-L41

...
export async function idFromFileName(name) {
  let id = name.replace(/( |[^A-Za-z0-9])/g, '-') + '-' + uuidv4().slice(0, 7);

On creation, the budget id is set to a random value. That is also not stored on the budget, existing only on the metadata. Here is the server table storing the file names as reference:

-- auto-generated definition
CREATE TABLE files
(
    id            TEXT
        PRIMARY KEY,
    group_id      TEXT,
    sync_version  SMALLINT,
    encrypt_meta  TEXT,
    encrypt_keyid TEXT,
    encrypt_salt  TEXT,
    encrypt_test  TEXT,
    deleted       BOOLEAN DEFAULT FALSE,
    name          TEXT
);
image

so, while we could use the sync id (sync_id == group_id) to locate the file, we can only find the budget id after downloading the file.

Would that be enough to implement the search also for the sync id?

bobokun commented 1 month ago

Yup that makes sense. I only opened this issue because I thought it was a bug after trying to enter both Budget ID and Sync ID. Also updating the details in the Basic Usage section that the README will help people understand Sync ID can be used too