Closed mabugaj closed 2 years ago
Provider post-string
and post-file
both accept a meta
argument right now, but it's filled automatically with just the file details (path, extension, etc). Not all providers actually use this though, (ixio.fnl
does).
The main API doesn't expose any meta-var except when calling post-string
directly (this was actually omitted from the docs), It's probably reasonable to add a meta var to the tail of the others functions but then its out of sync with post-string
, so I would want to shuffle that around. Which would be a breaking change.
The fact that the docs were wrong and no one raised an issue and the plugin is pretty niche probably means its unlikely actually break anything, probably....
I think I would wonder what the user interface should look like. I think you would want to set a default & probably need a way to set per-post settings.
The the :PP
command might accept x=y
arguments maybe.
I thought about specifying such default arguments in setup method. For example:
-- options shown with default values
require("paperplanes").setup({
register = "+",
provider = "dpaste.org",
expire_time = 3600,
-- default file format (it should be set based on vim filetype if not explicitly specified)
-- which sets filename and lexer in case of dpaste.org
file_format = "python"
})
Though Your idea to specify arguments with :PP
command is also nice. Never the less I'd like to set some defaults that are different then provider's defaults.
You also need to specify a token for paste.sr.ht, I think it would be better to have something like
require("paperplanes").setup({
provider = "srht",
provider_opts = { token = "xxx" }
})
and then the make
function can get these opts using something like
local token = require("paperplanes").get_config().provider_opts.token
I will admit this totally slipped my mind.
You can sample this branch https://github.com/rktjmp/paperplanes.nvim/tree/provider-opts you should be able to just pass a provider_options
table to setup.
dpaste.org
is the only provider updated to handle options right now as a test, patches welcome until I get around to the other providers or adding sr.ht (you only need post-string
really), build instructions at the bottom of the readme.
Should I make a PR against that branch?
ah the token is supplied using an iAuthorization: token xxxxxxxx
header
Yes against that branch is preferred.
I know you striked it, but right now everything is send as form data because that's just how the original providers accepted options. Not against refactoring to support both and returning a richer curl-args datastructure. There's actually a number of bits to clean up in the code tbh.
What's wrong here? I added a print statement here and post-args seem to be fine: https://github.com/p00f/paperplanes.nvim/blob/696ddcb2487245b6715bb07620fff02b705ca527/fnl/paperplanes.fnl#L34
Passing the same thing to curl works:
It's something to do with how uv.spawn (and curl?) handle arguments with quotes.
# See added quote marks
curl --silent --show-error --write-out "\n%{response_code}" --header "Authorization:'token <TOKEN>'" \
--header Content-Type:'application/json' https://paste.sr.ht/api/pastes \
--data '{"files":[{"filename":"README.md","contents":"contentttt"}],"visibility":"unlisted"}'
{"errors": [{"reason": "No authorization supplied (expected an OAuth token)"}]}
401%
Spawn may wrap them (or whatever handles the args eventually) with quotes to curl sends the header literally as "Auth..:"
instead of Auth: ..
?
Wrapping the header with escaped quotes in the provider itself.
Running curl with -vvv
shows:
Without quotes (creates paste) --header Authorization:'token TOKEN'
> authorization:token TOKEN
> content-type:application/json
With quotes (fails) --header "Authorization:'token TOKEN'"
> authorization:'token TOKEN'
> content-type:application/json
Note the single quotes in the second request. That'll be it probably.
I don't have those extra quotes in my request either though - see the output of (print (table.concat post-args))
in the first screenshot
uv.spawn
is "adding" them with how args are passed to exec.
See PR review, should fix it.
Fixed (?) in #5, currently only sr.ht
and dpaste.org
support provider_options
, PR's welcome. Thank you all for your contributions.
Great plugin and works like a charm.
It would be nice to have some additional options for specific providers. For example to set
expire time
,file format
(file format cold be a mapping of vim filetypes).Not all of them provide such API but as I can see dpaste has pretty nice features:
https://dpaste.readthedocs.io/en/latest/api.html#third-party-api-integration-into-editors