Added API endpoint for file manifest #76
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I saw the issue at https://github.com/eepMoody/open5e-api/issues/57 and decided to take a stab at it. I'm open to any feedback or suggestions for improvements.
I've added a function that calculates the sha256 hash of a given file. The hash function is called inside the populatedb management command whenever a new data file is opened. The resulting hash is stored with the corresponding file path in the database in its own model, Manifest.
Let me know if there's a better place to calculate the file hashes, or if you have better suggestions for the model name or anything else.
I've also added a DRF read-only ViewSet (and registered it with the router) for the Manifest model. This allows anybody to grab a list of all the data files and their file hashes and use it to check if any data files have changed since the last time they checked the manifest endpoint.
Also, the populatedb.py is a bit verbose with quite a bit of unnecessary duplication, especially with my additions. My next step would be to reduce all of that as much as possible, assuming you're okay with it.