GithubHelp home page GithubHelp logo

Comments (14)

rktjmp avatar rktjmp commented on June 7, 2024

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.

from paperplanes.nvim.

mabugaj avatar mabugaj commented on June 7, 2024

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.

from paperplanes.nvim.

p00f avatar p00f commented on June 7, 2024

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

from paperplanes.nvim.

rktjmp avatar rktjmp commented on June 7, 2024

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.

(local options {:register :+
:provider "0x0.st"
:provider_options {}})

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.

(fn make [content-arg meta opts]
(local args (doto (opts-to-fields opts)
(set-field :format :default)
(set-field :content content-arg)
(set-field :filename meta.filename)
(table.insert "https://dpaste.org/api/")))

from paperplanes.nvim.

p00f avatar p00f commented on June 7, 2024

Should I make a PR against that branch?

from paperplanes.nvim.

p00f avatar p00f commented on June 7, 2024

ah the token is supplied using an Authorization: token xxxxxxxx header i

from paperplanes.nvim.

rktjmp avatar rktjmp commented on June 7, 2024

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.

from paperplanes.nvim.

p00f avatar p00f commented on June 7, 2024

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
image

Passing the same thing to curl works:
image

from paperplanes.nvim.

rktjmp avatar rktjmp commented on June 7, 2024

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.

from paperplanes.nvim.

rktjmp avatar rktjmp commented on June 7, 2024

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.

from paperplanes.nvim.

p00f avatar p00f commented on June 7, 2024

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

from paperplanes.nvim.

rktjmp avatar rktjmp commented on June 7, 2024

uv.spawn is "adding" them with how args are passed to exec.

from paperplanes.nvim.

rktjmp avatar rktjmp commented on June 7, 2024

See PR review, should fix it.

from paperplanes.nvim.

rktjmp avatar rktjmp commented on June 7, 2024

Fixed (?) in #5, currently only sr.ht and dpaste.org support provider_options, PR's welcome. Thank you all for your contributions.

from paperplanes.nvim.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.