~sircmpwn/sr.ht-discuss

3 3

piping from terminal to paste.sr.ht (echo foo | curl .... )

Details
Message ID
<a19e4595-81ee-483b-a176-19042f595d62@www.fastmail.com>
DKIM signature
missing
Download raw message
I can access my list of pastes via:

$ curl -vXGET https://paste.sr.ht/api/pastes  -Hauthorization:token\ ....

but I don't see an easy way to POST a new paste. Is this possible without
constructing the JSON blob separately?

{
  "visibility": "access level",
  "files": [
    {
      "filename": "filename" or null, (optional)
      "contents": "contents of this file"
    }
  ]
}

Ideally, this would be possible:

foo | curl -vXPOST \
    -Hauthorization:token\ ... \
    https://paste.sr.ht/api/pastes/filename.ext

With visibility provided either as HTTP query parameter, or as X-...header.

A+
Dave
Details
Message ID
<HIVkKm4MmfMfA5NuiK5EuQu7yljxOsYhkcrbb-b9Xnk5nilQUw-sOIhIrYcVoDwirckEwWpzHn9lC1E33kyZ7zrCFeNVQLyCHktxJ3q_xOE=@emersion.fr>
In-Reply-To
<a19e4595-81ee-483b-a176-19042f595d62@www.fastmail.com> (view parent)
DKIM signature
missing
Download raw message
On Saturday, July 20, 2019 3:19 PM, Dave Cottlehuber <dch@skunkwerks.at> wrote:

> I can access my list of pastes via:
>
> $ curl -vXGET https://paste.sr.ht/api/pastes -Hauthorization:token\ ....
>
> but I don't see an easy way to POST a new paste. Is this possible without
> constructing the JSON blob separately?
>
> {
> "visibility": "access level",
> "files": [
> {
> "filename": "filename" or null, (optional)
> "contents": "contents of this file"
> }
> ]
> }
>
> Ideally, this would be possible:
>
> foo | curl -vXPOST \
> -Hauthorization:token\ ... \
> https://paste.sr.ht/api/pastes/filename.ext
>
> With visibility provided either as HTTP query parameter, or as X-...header.

I believe the right way to do this would be to accept multipart request
bodies on the POST endpoint.
Details
Message ID
<BVOITGKLOMZA.KFT4TPTKP78P@homura>
In-Reply-To
<a19e4595-81ee-483b-a176-19042f595d62@www.fastmail.com> (view parent)
DKIM signature
missing
Download raw message
A simple script will help you out, with the aid of jq. Something like
this (untested):

	#!/bin/sh
	jq '{"files":[{"filename": "'$1'", "contents": .}]}' < "$1" | \
		curl -X POST \
			-H Authorization:"token ..." \
			-H Content-Type:application/json \
			-d @- https:///paste.sr.ht/api/pastes
Details
Message ID
<7f43c66020cb98647b73cb5e17cf616c@packetlost.dev>
In-Reply-To
<a19e4595-81ee-483b-a176-19042f595d62@www.fastmail.com> (view parent)
DKIM signature
missing
Download raw message
July 20, 2019 7:19 AM, "Dave Cottlehuber" <dch@skunkwerks.at> wrote:
> Ideally, this would be possible:
> 
> foo | curl -vXPOST \
> -Hauthorization:token\ ... \
> https://paste.sr.ht/api/pastes/filename.ext
> 
> With visibility provided either as HTTP query parameter, or as X-...header.


How about a cli utility for interfacing with paste.sr.ht?

https://git.sr.ht/~chiefnoah/psi

It's a little rough, and the docs are lacking. But I don't think it's too bad for 1 day's worth of work.
That allow the simple piping syntax you're going for, and allows for specifying file names using the -n option.

Patches/suggestions welcome!
Export thread (mbox)