farmOS / farmOS.js

A JavaScript library for working with farmOS data structures and interacting with farmOS servers.
MIT License
15 stars 13 forks source link

Add support for files #47

Closed jgaehring closed 1 year ago

jgaehring commented 2 years ago

I'm just noticing that the docs for the farmOS Data Model now include both data streams and files. At least, the navigation menu for Record Types now includes them, though they don't appear in the Introduction. Is that intentional, @mstenta?

This also seems like a good time for deciding if I want to parameterize all record types in the model, so if a consumer knows they'll never use data streams or files (eg, perhaps for certain SurveyStack applications), they can be omitted when instantiating the model. Of course, we could include some defaults if the entities are not provided, so essentially the parameter would be an override.

mstenta commented 2 years ago

At least, the navigation menu for Record Types now includes them, though they don't appear in the Introduction. Is that intentional, @mstenta?

Nope! Just forgot to add it to the intro. I'll do that...

jgaehring commented 2 years ago

I think I'm going to restrict the scope of this issue to only files, since Field Kit does not use data streams in any way so far, but I am planning to overhaul images (farmOS/farmOS-client#45) prior to the FK beta release.

This also seems like a good time for deciding if I want to parameterize all record types in the model

I still really like this idea, and I feel I've gone a long ways to making this possible in the future with how I've encapsulated most of the details about specific entities in src/entities.js. But it's probably premature to do so now, when I don't have a concrete use case for it. That can be a separate issue when it arises.

jgaehring commented 2 years ago

I'm doing some preliminary investigation into how JSON:API file uploads will work in 2.x, and it looks promising, but will take some experimentation to figure out how best to fit this into farmOS.js itself. It may be instructive to hold off on this until I've resolved farmOS/farmOS-client#45, using the plain request method in farmOS.js instead of adding another independent method or including the process in the existing methods somehow. Otherwise it's a rather premature abstraction.

So I am moving this to the general release milestone, but will probably circle back to it first thing, once I resume on Field Kit.

jgaehring commented 2 years ago

@paul121 just pointed out a related issue, farmOS/farmOS.py#49, which should prove helpful, particularly this example of "Flow 1" as mentioned in the JSON:API change record:

# Flow 1: update existing log
data = open('data.csv', 'rb').read()
response = client.file.create('log', 'observation', 'file', data, 'observation_data.csv', '{log_id}')