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

Master #85

Closed
wants to merge 1 commit into from
Closed

Master #85

wants to merge 1 commit into from

Conversation

MJVerhulst
Copy link

Tried to fix problem with environment variables not begin processed

Copy link
Author

@MJVerhulst MJVerhulst left a comment

Choose a reason for hiding this comment

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

Minor correction

Copy link
Contributor

@cbundy cbundy left a comment

Choose a reason for hiding this comment

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

I'm a little new to Github so not sure the best way I can collaborate on your PR unfortunately.

I think you were right thought about skipping the properties that are false from the form.

Your code was almost right and would have worked but there was a . between the syncOptions and the [configVariable], removing that I think would work.

Since the linting/quality settings are high for this project, you'd also need to change your use of let and var to be const, which is generally preferred because it's safer (you can't reassign something else to it by accident). let would be fine, but only if the linter sees that you actually reassign a different value to it.

If you'd like to check out neat way of doing it in JavaScript/TS, this is what I came up with

private generateForm(): typeof FormData.prototype {
    const form = new FormData();
    form.append('token', this.token);

    (Object.keys(Config.syncOptions) as (keyof SyncOptions)[])
      .filter(key => Config.syncOptions[key])
      .forEach(key => form.append(key, 'true'))

    return form;
}

Of the 3 main lines it's essentially

  1. Get all of the property names of the SyncOptions object as strings in an array (easier to do in JS, I had to learn the keyof operator here for TS, which I am still learning)
  2. For each of the keys that we get back, check the value the user has set and if it is false then filter it out (since the result of syncOptions[key] is a boolean, we don't need to check for equality with something using == or ===)
  3. For each remaining key that wasn't filtered out, then execute the form.append function

There is also one more step to do, which is to fix some of the failing tests (because previously they expected to see the false values in the request payload.

@cbundy
Copy link
Contributor

cbundy commented Nov 24, 2022

Also, I don't have a good environment to fully test this in right now. Are you using this in docker?

If you clone your branch, and do a docker build after the . fix I mentioned above, then I think that's all you'd need to be able to run it against your actual pihole setup if you want to beta test it 🤞

@mattwebbio
Copy link
Owner

Closed in favor of #87

@mattwebbio mattwebbio closed this Nov 30, 2022
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.

3 participants