stchang / pasterack

The Racket pastebin.
30 stars 7 forks source link

Accessing raw code? #63

Closed Metaxal closed 4 years ago

Metaxal commented 4 years ago

Hi,

Is there a way to access the raw code, like gists (with the '/raw' suffix)?

stchang commented 4 years ago

There's no way at the moment but it should be straightforward to add I think.

Are you trying to programmatically retrieve pastes?

Metaxal commented 4 years ago

Yes, for selected pastes only, no batching. It's so that people can post scripts for DrRacket's Quickscript without having a github (gists) or gitlab account (snippets).

stchang commented 4 years ago

I think I have something working. Is something like this sufficient? http://pasterack.org/pastes/8953/raw

Metaxal commented 4 years ago

It's perfect, thanks!

stchang commented 4 years ago

Hmm, actually the raw pastes are still serving html. is that ok? The raw gists seem to be serving a plain txt file?

Metaxal commented 4 years ago

oh, I assumed it was raw text. I'd rather have plain txt (since gists and snippets serve raw text). If it takes you more than 30min, don't bother, I'm not even sure how useful this would be in general.

stchang commented 4 years ago

It's been a while since I used the webserver and there doesnt seem to be a convenient response/text. Do you know off the top of your head how to do it with the more general response forms?

stchang commented 4 years ago

More specifically, I can return the raw text, but it doesnt render properly like the gists, eg: http://pasterack.org/pastes/8953/raw

Is that ok?

Metaxal commented 4 years ago

Yes, that looks good, apart from the \r\n in the source, but I can easily strip these off. Currently, I'm fetching the raw texts with this:

#lang racket
(require net/url)
(displayln
 (port->string (get-pure-port (string->url "http://pasterack.org/pastes/8953/raw")
                              #:redirections 10)))

Thanks!

stchang commented 4 years ago

Ok i figured it out. just had to change the mime-type to text/plain.

The line breaks are preserved from what the user submitted I think. But yes, should be easy to remove.

Let me know if there are any other problems.

Metaxal commented 4 years ago

That's perfect, thank you!