Browse Source

Add write.as command line / curl tool

master
Matt Baer 9 years ago
parent
commit
83bde1364b
2 changed files with 78 additions and 0 deletions
  1. +24
    -0
      static/cmd.txt
  2. +54
    -0
      write-curl.go

+ 24
- 0
static/cmd.txt View File

@@ -0,0 +1,24 @@
Welcome to cmd.write.as!

████████████████████████████████████████████████████
█ █
█ <command> | curl -F 'w=<-' http://cmd.write.as █
█ █
████████████████████████████████████████████████████

Simple text pasting / publishing. Run then share the link you get.

No funny stuff — all posts show up on write.as once the command finishes. No
sign up, no publicized URLs, no analytics. Publish what you like.

This is the pre-pre-alpha of write.as, showcasing some of what you'll see later.
We have many plans, all based in text/plain. Keep up to date with us @writeas__
on Twitter or get notified when we launch at https://write.as.


You can also use telnet: nerds.write.as


BUGS/ISSUES/YOU HACKED THE GIBSON
—————————————————————————————————
Report bugs and flaws to hello@write.as.

+ 54
- 0
write-curl.go View File

@@ -0,0 +1,54 @@
package main

import (
"fmt"
"flag"
"io/ioutil"
"net/http"
"github.com/writeas/writeas-telnet/store"
)

var (
outDir string
indexPage []byte
)

func poster(w http.ResponseWriter, r *http.Request) {
post := r.FormValue("w")

if post == "" {
fmt.Fprintf(w, "%s", indexPage)
return
}

filename, err := store.SavePost(outDir, []byte(post))
if err != nil {
fmt.Println(err)
fmt.Fprint(w, "Couldn't save :(\n")
return
}
fmt.Fprintf(w, "https://write.as/%s\n", filename)
}

func main() {
outDirPtr := flag.String("o", "/home/matt", "Directory where text files will be stored.")
staticDirPtr := flag.String("s", "./static", "Directory where required static files exist.")
portPtr := flag.Int("p", 8080, "Port to listen on.")
flag.Parse()

outDir = *outDirPtr

fmt.Print("Initializing...")
var err error
indexPage, err = ioutil.ReadFile(*staticDirPtr + "/cmd.txt")
if err != nil {
fmt.Println(err)
}
fmt.Println("DONE")

fmt.Printf("Serving on http://localhost:%d\n", *portPtr)

http.HandleFunc("/", poster)
http.ListenAndServe(fmt.Sprintf(":%d", *portPtr), nil)
}

Loading…
Cancel
Save