-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Public API for Sketch management #1076
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
Public API for Sketch management #1076
Conversation
f998530
to
ba22552
Compare
Overall I like this! Some thoughts/questions/etc..:
{
name: "dog.jpg",
content: <file_content>
} and returns {
name: "dog.jpg",
url: <new_s3_url>
} This could also accept a query parameter that's Another solution would be to only allow media uploads after a sketch has been created, and then use a new file route to upload the media file to the sketch itself.
|
Yeah, there should be. Something like |
Yep, that's part of it. Both The way the current import scripts work, they delete all sketches and then re-upload them, creating new sketch IDs. This means all existing sketch links are broken. Maybe that's desired, but it might be nice for the author to choose which behaviour they want. Another use case, is being able to change sketch metadata without having to delete the sketch. Right now, this is just the sketch name.
I think the slug URL is a great feature and would remove the need for supporting sketch ID stability above. For v1 of the public API, shall we just support specifying a slug, and not support I think |
For file uploads, I think having files' belong to sketches makes things easier as it means we can be certain when a sketch is deleted then all the associated files can be safely removed from S3. And also, when a file is deleted from a sketch, it won't be in use by other sketches so can again be deleted from S3. I'll prototype this out in code so we can see how it works with the upload scripts. |
I agree that a user managing timestamps seems a bit much. I'll do some more research in how different APIs handle this. For the bulk-import use case, we can assume that a user creating or modifying a resource within the sketch—either files or the sketch itself—updates an |
Thanks for the comments! We can keep this open for more discussion and I'll start writing some code to implement a basic version of these endpoints. |
great! i'll make sure there's an index in the db for the slug key.
do you mean if folks want to use the API in the context of another web application/GUI? like maybe we don't even want to suggest that could be possible right now, as it adds a huge layer of complication. i think we want to focus on moving sketches to/from the web editor, rather than adding a new UI for editing sketches. |
I was thinking that ultimately we might just have one API for the editor and public uses. But you're right, that overcomplicating things for now. |
I've realised that the API needs to support referencing files hosted elsewhere on the internet. For example, the ml5 examples reference models hosted in GitHub via jsdelivr. I've split the file into two to support this. What do you think @catarak? |
I've just split this into two documents, Will merge this into the |
This is a proposal for a public-facing API that would allow users to automate the upload of sketches into the editor, replacing the scripts that talk to mongodb directly. (See #542)
Supported actions
The key actions for this API are:
The scripts deleting existing sketches, but I've also proposed a way to replace the contents of a sketch too.
I've added the proposed API documentation as a markdown file so that we can comment on the file directly.
Files instead of IDs
The key change (as discussed in #1073) is representing trees hierarchically and referencing files/directories via their path. This seems more intuitive for API users, but some investigation is needed figure out if we still need to reference files by ID. And if so, perhaps the filename approach is only used as a convenience for sketch creation.
Further work
files
returned by the API might need to be redirects to S3 or other hosting. And this would impact how the files are specified also.updatedAt
timestamp to protect against overwriting stale projects. These should probably be added everywhere.