Add html output type

This commit is contained in:
Eliot Whalan 2016-06-23 13:45:00 +10:00
parent 424ebb7915
commit 11e59f31b6
2 changed files with 16 additions and 14 deletions

View File

@ -29,7 +29,7 @@
<div class="page-header"> <div class="page-header">
<h1>Pantsu Paste</h1> <h1>Pantsu Paste</h1>
</div> </div>
<form action="/save" method="post" class="form-horizontal"> <form action="/save/html" method="post" class="form-horizontal">
<fieldset> <fieldset>
<div class="well"> <div class="well">
<div class="form-group is-empty"> <div class="form-group is-empty">
@ -451,7 +451,7 @@
</form> </form>
<div class="well"> <div class="well">
<code>$ &lt;command&gt; | curl -F 'p=&lt;-' https://p.pantsu.cat/save</code><br/> <code>$ &lt;command&gt; | curl -F 'p=&lt;-' https://p.pantsu.cat/save</code><br/>
<code>https://p.pantsu.cat/save/(XML|JSON)</code><br/> <code>https://p.pantsu.cat/save/(XML|JSON|HTML)</code><br/>
<code>https://p.pantsu.cat/p/(PASTE)/(lang)</code><br/> <code>https://p.pantsu.cat/p/(PASTE)/(lang)</code><br/>
<code>https://p.pantsu.cat/del/(PASTE)/(DELKEY)</code<br/> <code>https://p.pantsu.cat/del/(PASTE)/(DELKEY)</code<br/>
<p>Source: <a href="https://github.com/ewhal/Pastebin">Pastebin</a></p> <p>Source: <a href="https://github.com/ewhal/Pastebin">Pastebin</a></p>

26
main.go
View File

@ -19,18 +19,13 @@ import (
) )
const ( const (
ADDRESS = "http://localhost:9900" ADDRESS = "http://localhost:9900"
LENGTH = 6 LENGTH = 6
DELETE = ADDRESS + "/del/{PASTE}/{DELKEY}\n" PORT = ":9900"
PASTEARGS = ADDRESS + "/p/{PASTE}/(python|language)\n" USERNAME = ""
URLARGS = ADDRESS + "/save/XML|JSON\n" PASS = ""
SOURCE = "Source: https://github.com/ewhal/Pastebin\n" NAME = ""
TEXT = "$ <command> | curl -F 'p=<-' " + ADDRESS + "/save" + "\n" + PASTEARGS + URLARGS + DELETE + SOURCE DATABASE = USERNAME + ":" + PASS + "@/" + NAME + "?charset=utf8"
PORT = ":9900"
USERNAME = ""
PASS = ""
NAME = ""
DATABASE = USERNAME + ":" + PASS + "@/" + NAME + "?charset=utf8"
) )
type Response struct { type Response struct {
@ -169,6 +164,13 @@ func saveHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/xml") w.Header().Set("Content-Type", "application/xml")
w.Write(x) w.Write(x)
case "html":
w.Header().Set("Content-Type", "text/html")
io.WriteString(w, "<p>ID</p><p>"+b.ID+"</p><br/>")
io.WriteString(w, "<p>hash</p><p>"+b.HASH+"</p><br/>")
io.WriteString(w, "<p>URL</p><a href='"+b.URL+"'>"+b.URL+"</a><br/>")
io.WriteString(w, "<p>hash</p><p>"+b.SIZE+"</p><br/>")
io.WriteString(w, "<a href='"+b.URL+"/p/"+b.DELKEY+"'>"+b.DELKEY+"</a>")
default: default:
io.WriteString(w, b.URL+"\n") io.WriteString(w, b.URL+"\n")