mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
CLI support! You can use curl (only curl at the moment) to
PUT files into the database.
This commit is contained in:
parent
f6c287ba24
commit
bd59a69f28
19
README.md
19
README.md
@ -2,7 +2,7 @@
|
||||
|
||||
# [cowyo.com](http://cowyo.com/)
|
||||
|
||||
[![Version 0.94](https://img.shields.io/badge/version-0.94-brightgreen.svg)]() [![Go Report Card](https://goreportcard.com/badge/github.com/schollz/cowyo)](https://goreportcard.com/report/github.com/schollz/cowyo) [![Join the chat at https://gitter.im/schollz/cowyo](https://badges.gitter.im/schollz/cowyo.svg)](https://gitter.im/schollz/cowyo?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
[![Version 0.95](https://img.shields.io/badge/version-0.94-brightgreen.svg)]() [![Go Report Card](https://goreportcard.com/badge/github.com/schollz/cowyo)](https://goreportcard.com/report/github.com/schollz/cowyo) [![Join the chat at https://gitter.im/schollz/cowyo](https://badges.gitter.im/schollz/cowyo.svg)](https://gitter.im/schollz/cowyo?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
|
||||
This is a self-contained notepad webserver that makes sharing easy and _fast_. The most important feature here is *simplicity*. There are many other features as well including versioning, page locking, self-destructing messages, encryption, math support, and listifying. Read on to learn more about the features.
|
||||
|
||||
@ -44,6 +44,23 @@ This is a self-contained notepad webserver that makes sharing easy and _fast_. T
|
||||
|
||||
<br>
|
||||
|
||||
**CLI support**. Want to upload/download from a server? Its super easy. Upload/download files like this:
|
||||
```bash
|
||||
$ echo "Hello, world!" > hi.txt
|
||||
$ curl --upload-file hi.txt cowyo.com
|
||||
File uploaded to http://cowyo.com/hi.txt
|
||||
$ curl cowyo.com/test.txt
|
||||
Hello, world!
|
||||
```
|
||||
or just skip the file-creation step,
|
||||
```bash
|
||||
$ echo "Wow, so easy" | curl --upload-file "-" cowyo.com
|
||||
File uploaded to http://cowyo.com/CautiousCommonLoon
|
||||
$ curl cowyo.com/CautiousCommonLoon
|
||||
Wow, so easy
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
**Keyboard Shortcuts**. Quickly transition between Edit/View/List by using `Ctl+Shift+E` to Edit, `Ctl+Shift+Z` to View, and `Ctl+Shift+L` to Listify.
|
||||
|
||||
|
5
main.go
5
main.go
@ -35,10 +35,8 @@ var RuntimeArgs struct {
|
||||
}
|
||||
var VersionNum string
|
||||
|
||||
const _24K = (1 << 20) * 24
|
||||
|
||||
func main() {
|
||||
VersionNum = "0.94"
|
||||
VersionNum = "0.95"
|
||||
// _, executableFile, _, _ := runtime.Caller(0) // get full path of this file
|
||||
cwd, _ := os.Getwd()
|
||||
databaseFile := path.Join(cwd, "data.db")
|
||||
@ -105,6 +103,7 @@ Options:`)
|
||||
r.HEAD("/", func(c *gin.Context) { c.Status(200) })
|
||||
r.GET("/:title", editNote)
|
||||
r.PUT("/:title", putFile)
|
||||
r.PUT("/", putFile)
|
||||
r.GET("/:title/*option", everythingElse)
|
||||
r.POST("/:title/*option", encryptionRoute)
|
||||
r.DELETE("/listitem", deleteListItem)
|
||||
|
29
ratelimiter.go
Executable file
29
ratelimiter.go
Executable file
@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
var bannedIPs []string
|
||||
|
||||
func init() {
|
||||
go clearBannedIPs()
|
||||
}
|
||||
|
||||
func clearBannedIPs() {
|
||||
for {
|
||||
fmt.Println("CLEARING IPS!!")
|
||||
bannedIPs = []string{}
|
||||
time.Sleep(3 * time.Minute)
|
||||
}
|
||||
}
|
||||
|
||||
func isIPBanned(ip string) bool {
|
||||
if stringInSlice(ip, bannedIPs) {
|
||||
return true
|
||||
} else {
|
||||
bannedIPs = append(bannedIPs, ip)
|
||||
return false
|
||||
}
|
||||
}
|
10
routes.go
10
routes.go
@ -21,8 +21,17 @@ import (
|
||||
"github.com/russross/blackfriday"
|
||||
)
|
||||
|
||||
const _24K = (1 << 20) * 24
|
||||
|
||||
func putFile(c *gin.Context) {
|
||||
if isIPBanned(c.ClientIP()) {
|
||||
c.Data(200, "text/plain", []byte("You are rate limited to 20 requests/hour."))
|
||||
return
|
||||
}
|
||||
filename := c.Param("title")
|
||||
if len(filename) == 0 {
|
||||
filename = randomAlliterateCombo()
|
||||
}
|
||||
contentLength := c.Request.ContentLength
|
||||
var reader io.Reader
|
||||
reader = c.Request.Body
|
||||
@ -68,7 +77,6 @@ func putFile(c *gin.Context) {
|
||||
var p WikiData
|
||||
p.load(strings.ToLower(filename))
|
||||
p.save(buf.String())
|
||||
fmt.Println(c.ClientIP())
|
||||
c.Data(200, "text/plain", []byte("File uploaded to http://"+RuntimeArgs.ExternalIP+"/"+filename))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user