jordan-dalby / ByteStash

A code snippet storage solution written in React & node.js
GNU General Public License v3.0
390 stars 11 forks source link

[FEATURE] api for pushing code. #60

Open gomeology opened 1 week ago

gomeology commented 1 week ago

Api to push code. Not sure how the formatting would work for this one though.

jordan-dalby commented 1 week ago

@gomeology Pushing code to where? Into ByteStash?

gomeology commented 1 week ago

Yes. Im basically requesting a way to push code from the command line. With an API it wouldn't matter if it's windows/nix. You could also implement a way to pull code with an API search of sorts. Maybe using tags.

scheibling commented 1 week ago

I'd love to see something like this as well! There are a couple of examples (paste-C), basically you'd wanna pipe a file or some text via curl to the service and get the link in return. Settings can be set via query parameters, and the entire body becomes the content

jordan-dalby commented 1 week ago

@scheibling I hadn't considered a use-case like that, good idea! From your perspective, what's the best way this should be implemented? As someone who hasn't used paste-c, I'm not sure of it's intricacies. Is it feasible for you to write out json every time you want to submit a snippet, e.g.:

{
    "title": "My Title",
    "description": "Some description",
    "categories": ["1", "2"],
    "fragments": [
        {
            "file_name": "name.py",
            "code": "My code",
            "language": "python"
        }
    ]
}

Thoughts? Is there an easier way you can come up with?

scheibling commented 1 week ago

I think two or three options might be nice in the long run - post, multipart and json. This could be the same endpoint, but the content type header differentiates between the three (application/octet-stream, multipart/form-data or application/json)

Post would be /upload?filename=abc124&description=Test&tags=taga,tagb

With the file as body

Multipart would include the file, filename in the multipart data and title/description/tags in form fields

And then json, basically like you describe it! That would cover most all of the use cases I can think of (upload via CLI tool, plain curl for quick uploads, from postman or integrated in a piece of software)

I'd be happy to put together an initial PR if you'd like, I have my own CLI toolbox that currently uses paste-C but I've been looking for a good self-hosted alternative and this looks awesome

jordan-dalby commented 1 week ago

@scheibling Great ideas, that sounds perfect.

Go ahead! Contributions are always welcome.

jordan-dalby commented 2 days ago

With the addition of user accounts this is more complex- we should allow users to create API keys that they can use to push this code to their account. The general idea stays the same, i.e.: /upload?filename=somefile&description=mydescription&tags=tag1,tag2 Just include authentication: /upload?filename=somefile&description=mydescription&tags=tag1,tag2&api_key=my-api-key

Maybe also public=true|false, might also need to consider fragments