├── .gitattributes ├── LICENSE ├── Minimalist-Web-Notepad-PY.zip ├── README.md ├── go.mod ├── go.sum ├── index.html ├── main.go └── static ├── favicon.svg ├── script.js └── styles.css /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 2 | Version 2, December 2004 3 | 4 | Copyright (C) 2004 Sam Hocevar 5 | 6 | Everyone is permitted to copy and distribute verbatim or modified 7 | copies of this license document, and changing it is allowed as long 8 | as the name is changed. 9 | 10 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 11 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 12 | 13 | 0. You just DO WHAT THE FUCK YOU WANT TO. -------------------------------------------------------------------------------- /Minimalist-Web-Notepad-PY.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/114514-24/Minimalist-Web-Notepad-Go/76ce4d32e73ac4220d9c501d2826fa4c7aa766e1/Minimalist-Web-Notepad-PY.zip -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Minimalist Web Notepad Golang 2 | 3 | Minimalist Web Notepad Golang重置版 4 | 5 | 最近我在github发现了一个不错的PHP项目[Minimalist Web Notepad](https://github.com/pereorga/minimalist-web-notepad) 6 | 7 | 用于临时记录与传输纯文本非常方便,简直是像我这种极简主义的最爱 8 | 9 | 于是我就用go重置了一下 10 | 11 | ## 运行教程 12 | ``` 13 | Minimalist-Web-Notepad-Go -l 随机字符长度 -p :端口号 14 | ``` 15 | #### 举个例子 16 | ``` 17 | Minimalist-Web-Notepad-Go -l 8 -p :8080 18 | 19 | 此时就会生成8位的随机字符,并监听8080端口 例如 https://example.com:8080/12345678 20 | ``` 21 | ## 使用方法 22 | 23 | 1. 访问网页 24 | 2. 它会随机分配指定字符组成的地址,如果想指定地址,只需要访问时手动修改 25 | 3. 在上面编辑文本 26 | 4. 等待一会(几秒,取决于延迟),服务端就会存储网页内容到名为 114514 的文件里。 27 | 5. 关闭网页,如果关闭太快,会来不及保存,丢失编辑。 28 | 6. 在其他平台再访问同样的网址,就能剪切内容了 ٩۹(๑•̀ω•́ ๑)۶ 29 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module Minimalist-Web-Notepad-Go 2 | 3 | go 1.23.0 4 | 5 | toolchain go1.24.7 6 | 7 | require github.com/gin-gonic/gin v1.11.0 8 | 9 | require ( 10 | github.com/bytedance/sonic v1.14.0 // indirect 11 | github.com/bytedance/sonic/loader v0.3.0 // indirect 12 | github.com/cloudwego/base64x v0.1.6 // indirect 13 | github.com/gabriel-vasile/mimetype v1.4.8 // indirect 14 | github.com/gin-contrib/sse v1.1.0 // indirect 15 | github.com/go-playground/locales v0.14.1 // indirect 16 | github.com/go-playground/universal-translator v0.18.1 // indirect 17 | github.com/go-playground/validator/v10 v10.27.0 // indirect 18 | github.com/goccy/go-json v0.10.2 // indirect 19 | github.com/goccy/go-yaml v1.18.0 // indirect 20 | github.com/json-iterator/go v1.1.12 // indirect 21 | github.com/klauspost/cpuid/v2 v2.3.0 // indirect 22 | github.com/leodido/go-urn v1.4.0 // indirect 23 | github.com/mattn/go-isatty v0.0.20 // indirect 24 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect 25 | github.com/modern-go/reflect2 v1.0.2 // indirect 26 | github.com/pelletier/go-toml/v2 v2.2.4 // indirect 27 | github.com/quic-go/qpack v0.5.1 // indirect 28 | github.com/quic-go/quic-go v0.54.0 // indirect 29 | github.com/twitchyliquid64/golang-asm v0.15.1 // indirect 30 | github.com/ugorji/go/codec v1.3.0 // indirect 31 | go.uber.org/mock v0.5.0 // indirect 32 | golang.org/x/arch v0.20.0 // indirect 33 | golang.org/x/crypto v0.40.0 // indirect 34 | golang.org/x/mod v0.25.0 // indirect 35 | golang.org/x/net v0.42.0 // indirect 36 | golang.org/x/sync v0.16.0 // indirect 37 | golang.org/x/sys v0.35.0 // indirect 38 | golang.org/x/text v0.27.0 // indirect 39 | golang.org/x/tools v0.34.0 // indirect 40 | google.golang.org/protobuf v1.36.9 // indirect 41 | ) 42 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/bytedance/sonic v1.14.0 h1:/OfKt8HFw0kh2rj8N0F6C/qPGRESq0BbaNZgcNXXzQQ= 2 | github.com/bytedance/sonic v1.14.0/go.mod h1:WoEbx8WTcFJfzCe0hbmyTGrfjt8PzNEBdxlNUO24NhA= 3 | github.com/bytedance/sonic/loader v0.3.0 h1:dskwH8edlzNMctoruo8FPTJDF3vLtDT0sXZwvZJyqeA= 4 | github.com/bytedance/sonic/loader v0.3.0/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI= 5 | github.com/cloudwego/base64x v0.1.6 h1:t11wG9AECkCDk5fMSoxmufanudBtJ+/HemLstXDLI2M= 6 | github.com/cloudwego/base64x v0.1.6/go.mod h1:OFcloc187FXDaYHvrNIjxSe8ncn0OOM8gEHfghB2IPU= 7 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 8 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 9 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 10 | github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM= 11 | github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8= 12 | github.com/gin-contrib/sse v1.1.0 h1:n0w2GMuUpWDVp7qSpvze6fAu9iRxJY4Hmj6AmBOU05w= 13 | github.com/gin-contrib/sse v1.1.0/go.mod h1:hxRZ5gVpWMT7Z0B0gSNYqqsSCNIJMjzvm6fqCz9vjwM= 14 | github.com/gin-gonic/gin v1.11.0 h1:OW/6PLjyusp2PPXtyxKHU0RbX6I/l28FTdDlae5ueWk= 15 | github.com/gin-gonic/gin v1.11.0/go.mod h1:+iq/FyxlGzII0KHiBGjuNn4UNENUlKbGlNmc+W50Dls= 16 | github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= 17 | github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= 18 | github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= 19 | github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= 20 | github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= 21 | github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= 22 | github.com/go-playground/validator/v10 v10.27.0 h1:w8+XrWVMhGkxOaaowyKH35gFydVHOvC0/uWoy2Fzwn4= 23 | github.com/go-playground/validator/v10 v10.27.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo= 24 | github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= 25 | github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= 26 | github.com/goccy/go-yaml v1.18.0 h1:8W7wMFS12Pcas7KU+VVkaiCng+kG8QiFeFwzFb+rwuw= 27 | github.com/goccy/go-yaml v1.18.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA= 28 | github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= 29 | github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= 30 | github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 31 | github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= 32 | github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= 33 | github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y= 34 | github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0= 35 | github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= 36 | github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= 37 | github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= 38 | github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= 39 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= 40 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 41 | github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= 42 | github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= 43 | github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= 44 | github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= 45 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 46 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 47 | github.com/quic-go/qpack v0.5.1 h1:giqksBPnT/HDtZ6VhtFKgoLOWmlyo9Ei6u9PqzIMbhI= 48 | github.com/quic-go/qpack v0.5.1/go.mod h1:+PC4XFrEskIVkcLzpEkbLqq1uCoxPhQuvK5rH1ZgaEg= 49 | github.com/quic-go/quic-go v0.54.0 h1:6s1YB9QotYI6Ospeiguknbp2Znb/jZYjZLRXn9kMQBg= 50 | github.com/quic-go/quic-go v0.54.0/go.mod h1:e68ZEaCdyviluZmy44P6Iey98v/Wfz6HCjQEm+l8zTY= 51 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 52 | github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= 53 | github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= 54 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 55 | github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 56 | github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= 57 | github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= 58 | github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= 59 | github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= 60 | github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= 61 | github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= 62 | github.com/ugorji/go/codec v1.3.0 h1:Qd2W2sQawAfG8XSvzwhBeoGq71zXOC/Q1E9y/wUcsUA= 63 | github.com/ugorji/go/codec v1.3.0/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4= 64 | go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU= 65 | go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM= 66 | golang.org/x/arch v0.20.0 h1:dx1zTU0MAE98U+TQ8BLl7XsJbgze2WnNKF/8tGp/Q6c= 67 | golang.org/x/arch v0.20.0/go.mod h1:bdwinDaKcfZUGpH09BB7ZmOfhalA8lQdzl62l8gGWsk= 68 | golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM= 69 | golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY= 70 | golang.org/x/mod v0.25.0 h1:n7a+ZbQKQA/Ysbyb0/6IbB1H/X41mKgbhfv7AfG/44w= 71 | golang.org/x/mod v0.25.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww= 72 | golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs= 73 | golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8= 74 | golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw= 75 | golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= 76 | golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 77 | golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI= 78 | golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= 79 | golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4= 80 | golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU= 81 | golang.org/x/tools v0.34.0 h1:qIpSLOxeCYGg9TrcJokLBG4KFA6d795g0xkBkiESGlo= 82 | golang.org/x/tools v0.34.0/go.mod h1:pAP9OwEaY1CAW3HOmg3hLZC5Z0CCmzjAF2UQMSqNARg= 83 | google.golang.org/protobuf v1.36.9 h1:w2gp2mA27hUeUzj9Ex9FBjsBm40zfaDtEWow293U7Iw= 84 | google.golang.org/protobuf v1.36.9/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU= 85 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 86 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 87 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 88 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 89 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | {{.title}} 7 | 8 | 9 | 10 | 11 |
12 | 13 |
14 |

15 |     
16 | 
17 | 
18 | 


--------------------------------------------------------------------------------
/main.go:
--------------------------------------------------------------------------------
  1 | package main
  2 | 
  3 | import (
  4 | 	"flag"
  5 | 	"io"
  6 | 	"math/rand"
  7 | 	"net/http"
  8 | 	"os"
  9 | 	"path/filepath"
 10 | 
 11 | 	"github.com/gin-gonic/gin"
 12 | )
 13 | 
 14 | func main() {
 15 | 	// 设置为开发模式
 16 | 	// gin.SetMode(gin.DebugMode)
 17 | 	// 设置为生产模式
 18 | 	gin.SetMode(gin.ReleaseMode)
 19 | 	// 设置为测试模式
 20 | 	// gin.SetMode(gin.TestMode)
 21 | 
 22 | 	// 创建一个默认的路由引擎
 23 | 	r := gin.Default()
 24 | 	r.Static("/static", "./static")
 25 | 	r.LoadHTMLGlob("index.html")
 26 | 
 27 | 	var random_int int
 28 | 
 29 | 	flag.IntVar(&random_int, "l", 10, "random int long")
 30 | 
 31 | 	// 当访问根目录时,生成一个随机字符串,并重定向到"/random"路径
 32 | 	r.GET("/", func(c *gin.Context) {
 33 | 		randomString := randomString(random_int)
 34 | 		c.Redirect(http.StatusFound, "/"+randomString)
 35 | 	})
 36 | 
 37 | 	r.GET("/:path", func(c *gin.Context) {
 38 | 		path := c.Param("path")
 39 | 		filePath := "./_tmp_/" + path
 40 | 
 41 | 		// 检查文件是否存在,如果不存在则创建
 42 | 		if _, err := os.Stat(filePath); os.IsNotExist(err) {
 43 | 			// 创建目录
 44 | 			if err := os.MkdirAll(filepath.Dir(filePath), 0755); err != nil {
 45 | 				c.JSON(http.StatusInternalServerError, gin.H{
 46 | 					"error": err.Error(),
 47 | 				})
 48 | 				return
 49 | 			}
 50 | 
 51 | 			// 创建文件
 52 | 			if _, err := os.Create(filePath); err != nil {
 53 | 				c.JSON(http.StatusInternalServerError, gin.H{
 54 | 					"error": err.Error(),
 55 | 				})
 56 | 				return
 57 | 			}
 58 | 		}
 59 | 
 60 | 		fileContent, err := os.ReadFile(filePath)
 61 | 		if err != nil {
 62 | 			c.JSON(http.StatusInternalServerError, gin.H{
 63 | 				"error": err.Error(),
 64 | 			})
 65 | 			return
 66 | 		}
 67 | 
 68 | 		body := string(fileContent)
 69 | 		c.HTML(http.StatusOK, "index.html", gin.H{
 70 | 			"title": path,
 71 | 			"body":  body,
 72 | 		})
 73 | 	})
 74 | 
 75 | 	r.POST("/:path", func(c *gin.Context) {
 76 | 		// 读取POST请求的内容
 77 | 		body, err := io.ReadAll(c.Request.Body)
 78 | 		if err != nil {
 79 | 			c.JSON(http.StatusInternalServerError, gin.H{"error": "Error reading request body"})
 80 | 			return
 81 | 		}
 82 | 
 83 | 		// 获取文件路径
 84 | 		path := c.Param("path")
 85 | 
 86 | 		// 定义文件路径
 87 | 		filePath := "./_tmp_/" + path
 88 | 
 89 | 		// 创建文件夹,如果不存在的话
 90 | 		dir := "./_tmp_/"
 91 | 		if _, err := os.Stat(dir); os.IsNotExist(err) {
 92 | 			os.Mkdir(dir, 0755)
 93 | 		}
 94 | 
 95 | 		// 写入文件
 96 | 		err = os.WriteFile(filePath, body, 0644)
 97 | 		if err != nil {
 98 | 			c.JSON(http.StatusInternalServerError, gin.H{"error": "Error writing to file"})
 99 | 			return
100 | 		}
101 | 		// 删除空白内容
102 | 
103 | 		fileContent, err := os.ReadFile(filePath)
104 | 		if err != nil {
105 | 			c.JSON(http.StatusInternalServerError, gin.H{
106 | 				"error": err.Error(),
107 | 			})
108 | 			return
109 | 		}
110 | 		if len(fileContent) == 0 {
111 | 			os.Remove(filePath)
112 | 		}
113 | 
114 | 		if len(body) == 0 {
115 | 			os.Remove(filePath)
116 | 			c.JSON(http.StatusOK, gin.H{"status": "Success"})
117 | 			return
118 | 		}
119 | 
120 | 		// 返回成功的响应
121 | 		c.JSON(http.StatusOK, gin.H{"status": "Success"})
122 | 
123 | 	})
124 | 
125 | 	var port string
126 | 
127 | 	flag.StringVar(&port, "p", ":80", "port to listen on")
128 | 
129 | 	flag.Parse()
130 | 
131 | 	r.Run(port)
132 | }
133 | 
134 | // randomString 生成指定长度的随机字符串
135 | func randomString(length int) string {
136 | 	const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
137 | 	b := make([]byte, length)
138 | 	for i := range b {
139 | 		b[i] = charset[rand.Intn(len(charset))]
140 | 	}
141 | 	return string(b)
142 | }
143 | 


--------------------------------------------------------------------------------
/static/favicon.svg:
--------------------------------------------------------------------------------
1 | 


--------------------------------------------------------------------------------
/static/script.js:
--------------------------------------------------------------------------------
 1 | // 获取元素引用
 2 | var textarea = document.getElementById('content');
 3 | var printable = document.getElementById('printable');
 4 | 
 5 | // 初始化内容
 6 | var content = textarea.value;
 7 | 
 8 | // 创建一个函数来定期检查和上传内容
 9 | function checkAndUploadContent() {
10 |     var currentContent = textarea.value;
11 |     if (currentContent !== content) {
12 |         // 内容已更改,发送POST请求
13 |         var request = new XMLHttpRequest();
14 |         request.open('POST', window.location.href, true);
15 |         request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
16 |         request.send(currentContent);
17 | 
18 |         // 更新printable的内容
19 |         while (printable.firstChild) {
20 |             printable.removeChild(printable.firstChild);
21 |         }
22 |         printable.appendChild(document.createTextNode(currentContent));
23 | 
24 |         // 更新存储的内容
25 |         content = currentContent;
26 |     }
27 | 
28 |     // 1秒后再次检查
29 |     setTimeout(checkAndUploadContent, 1000);
30 | }
31 | 
32 | // 开始定期检查和上传内容
33 | checkAndUploadContent();


--------------------------------------------------------------------------------
/static/styles.css:
--------------------------------------------------------------------------------
 1 | /*! Minimalist Web Notepad | https://github.com/pereorga/minimalist-web-notepad */
 2 | 
 3 | body {
 4 |     margin: 0;
 5 |     background: #ebeef1;
 6 | }
 7 | .container {
 8 |     position: absolute;
 9 |     top: 20px;
10 |     right: 20px;
11 |     bottom: 20px;
12 |     left: 20px;
13 | }
14 | #content {
15 |     font-size: 100%;
16 |     margin: 0;
17 |     padding: 20px;
18 |     overflow-y: auto;
19 |     resize: none;
20 |     width: 100%;
21 |     height: 100%;
22 |     min-height: 100%;
23 |     box-sizing: border-box;
24 |     border: 1px #ddd solid;
25 |     outline: none;
26 | }
27 | #printable {
28 |     display: none;
29 | }
30 | 
31 | @media (prefers-color-scheme: dark) {
32 |     body {
33 |         background: #383934;
34 |     }
35 |     #content {
36 |         background: #282923;
37 |         color: #f8f8f2;
38 |         border: 0;
39 |     }
40 | }
41 | 
42 | @media print {
43 |     .container {
44 |         display: none;
45 |     }
46 |     #printable {
47 |         display: block;
48 |         white-space: pre-wrap;
49 |         word-break: break-word;
50 |     }
51 | }
52 | 


--------------------------------------------------------------------------------