ptpb / pb

pb is a formerly-lightweight pastebin and url shortener
Other
553 stars 52 forks source link

Some handlers don't seem to work #158

Closed jetpacktuxedo closed 8 years ago

jetpacktuxedo commented 8 years ago

Specifically /f for the html form always returns status: not found

I sort of suspect that this might be an artifact of my configuration (and might just be something that needs more documentation)

local/pb/paste/views.py has routes defined for /s, /l, /lf, and /ls, but nothing for /f, so maybe it is being tested as though it is a paste, seeing that it isn't a valid paste, and then dumping me out there?

I'm not sure why my local install is having this issue while https://ptpb.pw/ handles it fine.

jetpacktuxedo commented 8 years ago

Solution for the html form handler (where $PBROOT is the root directory of your pb clone):

git clone https://github.com/sudokode/pbwww.git
cd pbwww
python deploy.py index.html js/index.js css/index.css > $PBROOT/pb/templates/f.html
echo '@paste.route('/f')
def html_form():
    content = render_template("f.html")
    return content' >> $PBROOT/pb/paste/views.py

Edit: Better solution that is a bit more faithful to the official implementation (thanks @sudokode):

git clone https://github.com/sudokode/pbwww.git
cd pbwww
python deploy.py index.html js/index.js css/index.css | curl -F c=@- http://pb.whatever/~f

This won't have the normal /f link work, though. Instead you will need /~f.html. You can then edit pb/templates/index.rst to change the /f link to /~f.html. Then you will have similar functionality to the official implementation.

sudokode commented 8 years ago

@jetpacktuxedo pbwww is managed separately of pb and, yes, it is a paste. The /f handler is now (somehow, I don't know the internals of pb) pointed at that paste: https://ptpb.pw/f/html

Edit: If /f isn't working, it could be a caching issue. Try Ctrl+F5 to reload all of the assets.

jetpacktuxedo commented 8 years ago

Oh interesting, the way that I fixed it didn't use it as a paste, and I was sort of confused by what the page meant when it said it was just a paste. So the actual solution doesn't copy it into the project itself, but instead curls it to a novelty paste.

Does anyone have any insight as to how the /f handler works internally? It looks like it used to be built in, but was removed in commit 6128ee23e766360082bb51d4c648b43378c6b277

buhman commented 8 years ago

Sorry for taking so long to respond; someone mentioned this issue to me awhile ago, but I forgot about it until I happened to see it again now.

It looks like it used to be built in, but was removed in commit 6128ee2

Correct. I never really wanted to include UI like that in pb (which is supposed to just be an API), but I caved to demand and created the old /f. So, I really enjoyed removing the route in 6128ee2 after pbwww appeared and started calling itself /~index.html.

Does anyone have any insight as to how the /f handler works internally?

Internally, /f works exactly how it was created/enabled in 6128ee2--that is, /f is a regular paste with label=f. Creating this isn't allowed via the API, so you need to do a mongodb query to make it yourself. The way it works on ptpb is I did this for a paste that sudokode created, and sudokode can update via the API it because he knows the uuid of that paste.

The docs don't have parity with this information--related: #151.

jetpacktuxedo commented 8 years ago

Ah, that makes sense. I was trying to set it up on my local copy and couldn't write to the single character label. I didn't even think about writing it directly to the db. I ended up doing a vanity paste to /~f and changing the index to point there instead. I'll switch mine out to closer match the official implementation and maybe put some work into improving the docs for single character labels like was mentioned in #151.

jetpacktuxedo commented 8 years ago

Just to add onto this in case someone runs into the same issue and stumbles across this post, here is the solution I settled on to get my configuration to mirror the official one:

$ git clone https://github.com/sudokode/pbwww
$ cd pbwww
$ python deploy.py index.html js/index.js css/index.css | \
  curl -F 'c=@-;filename=_.html' http://pb.west.isilon.com:8000/~htmlform
$ mongo pb
> db.pastes.update({label: "~htmlform"}, {$set: {"label": "f"}})

Note the filename= -F parameter, which sets the filename that curl passes to pb, which is used to set the default mimetype.

Thanks @sudokode and @buhman for the pointers. Feel free to close this issue if you'd like.

buhman commented 8 years ago

I modified your thing trivially, for clarity. Github is now stackoverflow.