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.
Former-commit-id: 9c6d499403675cb28eb76676a73304e3acd2cc48 [formerly b30cad27b172756fdfcbf55d1e4c7542d90ca710] [formerly f2d936c586cb11525e36421c235bd1eb8909af3a [formerly bd59a69f28
]]
Former-commit-id: c8f9d721fe83366a7545df693bbec7cdf376bf1b [formerly c97362f33772b2fc391d4705cc3d6eaf0f78f26b]
Former-commit-id: 31366a03506e761af053625496c662f675dfeb8d
This commit is contained in:
parent
360ad6773b
commit
920ba22309
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