Commit 6c660a49 authored by chenhan wang's avatar chenhan wang
Browse files

本地调试2.4

parent b2b68a75
...@@ -19,8 +19,8 @@ type File struct { ...@@ -19,8 +19,8 @@ type File struct {
User string `json:"user" form:"user" query:"user"` User string `json:"user" form:"user" query:"user"`
Passwd string `json:"passwd" form:"passwd" query:"passwd"` Passwd string `json:"passwd" form:"passwd" query:"passwd"`
Url string `json:"url" form:"url" query:"url"` Url string `json:"url" form:"url" query:"url"`
Time time.Time `json:"time" form:"time" query:"time"` // 用户指定的时间期限 Time time.Time `json:"time" form:"time" query:"time"` // 用户指定的时间期限
MaxAccess uint `json:"maxaccess form:"maxaccess" query:"maxaccess"` // 文件最大可访问次数 MaxAccess uint `json:"maxaccess" form:"maxaccess" query:"maxaccess"` // 文件最大可访问次数
//Expiry time.Time `json:"expiry"` // 有效期 //Expiry time.Time `json:"expiry"` // 有效期
//Content string `json:"content"` //Content string `json:"content"`
} }
......
...@@ -9,15 +9,27 @@ import ( ...@@ -9,15 +9,27 @@ import (
func addRoutes() { func addRoutes() {
api := e.Group("api") api := e.Group("api")
api.Use(middleware.Auth) api.Use(middleware.Auth)
api.GET("/ping", controller.Ping) api.GET("/ping", controller.Ping) // 测试用
// 前端向后端申请一个包含sessionId的cookie,暂不不支持自定义cookie有效时间,默认半小时
api.GET("/ask/sid", controller.AskUid) api.GET("/ask/sid", controller.AskUid)
//api.POST("/passwd",controller.AskPasswd) // 密码,返回cookie
/* 前端用于上传文件的接口,
* 使用时需要带上文件后缀名,如fileType:.md, 不设置仍能运行,只是会影响文件在服务端存放位置
* 使用时最好带cookie,没有就用申请api申请。
* 其余参数可以不设置,有效期默认半小时后, 最大可访问次数默认30(config文件)
*/
api.POST("/file/recv", controller.RecvFile) // 接收文件 api.POST("/file/recv", controller.RecvFile) // 接收文件
api.POST("/file/send", controller.SendFile)
//api.POST("/text/recv",controller.RecvText) /*
//api.POST("/text/send",controller.RecvText) * 前端用于下载文件的接口
//files.Post("/download/*",controller.Download) * 需要cookie,url,passwd
* 使用时带cookie。如果cookie有权限,则直接返回有文件内容的response。没有则返回一个需要密码的状态码
* 前端跳转密码输入界面获取密码后带上密码再次使用此接口,密码正确则给接口权限,返回内容
* 若文件没设密码则不带密码也可访问
* 状态码: 403:密码错误; 410:内容过期; 200:访问成功; 401:请进行身份验证(输密码)
*/
api.POST("/file/send", controller.SendFile)
} }
func ApiAssign() { func ApiAssign() {
......
...@@ -64,11 +64,7 @@ func Findlink(_url string) string { ...@@ -64,11 +64,7 @@ func Findlink(_url string) string {
// save text information // save text information
// 保存文本和文件信息 // 保存文本和文件信息
func Savetext(_Route string, _Time uint, _Passwd string, _Time1 time.Time, _url string) { func Savetext(_Route string, _Time uint, _Passwd string, _Time1 time.Time, _url string) {
var id1 int64
DB.Model(&Content{}).Count(&id1)
id1++
p := Content{ p := Content{
ID: id1,
Route: _Route, Route: _Route,
Time: _Time, Time: _Time,
Passwd: _Passwd, Passwd: _Passwd,
...@@ -192,11 +188,3 @@ func CreatelinkFirstTime(sid string, _url string, _Time1 time.Time) { ...@@ -192,11 +188,3 @@ func CreatelinkFirstTime(sid string, _url string, _Time1 time.Time) {
} }
DB.Create(&sid1) DB.Create(&sid1)
} }
/*
func Test() {
var p Content
var Url2 string = "1234"
DB.First(&p, "url1 = ?", Url2)
fmt.Println(Checkt(p))
}*/
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
) )
type Content struct { type Content struct {
ID int64 `gorm:"primarykey"` gorm.Model
Route string Route string
Time uint Time uint
Passwd string Passwd string
......
This diff is collapsed.
...@@ -24,6 +24,9 @@ DROP TABLE IF EXISTS `contents`; ...@@ -24,6 +24,9 @@ DROP TABLE IF EXISTS `contents`;
/*!50503 SET character_set_client = utf8mb4 */; /*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `contents` ( CREATE TABLE `contents` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT, `id` bigint unsigned NOT NULL AUTO_INCREMENT,
`created_at` datetime(3) DEFAULT NULL,
`updated_at` datetime(3) DEFAULT NULL,
`deleted_at` datetime(3) DEFAULT NULL,
`route` longtext, `route` longtext,
`time` bigint unsigned DEFAULT NULL, `time` bigint unsigned DEFAULT NULL,
`passwd` longtext, `passwd` longtext,
...@@ -32,7 +35,8 @@ CREATE TABLE `contents` ( ...@@ -32,7 +35,8 @@ CREATE TABLE `contents` (
`time1` datetime(3) DEFAULT NULL, `time1` datetime(3) DEFAULT NULL,
`time2` bigint unsigned DEFAULT NULL, `time2` bigint unsigned DEFAULT NULL,
`url1` longtext, `url1` longtext,
PRIMARY KEY (`id`) PRIMARY KEY (`id`),
KEY `idx_contents_deleted_at` (`deleted_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;
...@@ -83,6 +87,7 @@ CREATE TABLE `sids` ( ...@@ -83,6 +87,7 @@ CREATE TABLE `sids` (
`created_at` datetime(3) DEFAULT NULL, `created_at` datetime(3) DEFAULT NULL,
`updated_at` datetime(3) DEFAULT NULL, `updated_at` datetime(3) DEFAULT NULL,
`deleted_at` datetime(3) DEFAULT NULL, `deleted_at` datetime(3) DEFAULT NULL,
`time` datetime(3) DEFAULT NULL,
`s` longtext, `s` longtext,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `idx_sids_deleted_at` (`deleted_at`) KEY `idx_sids_deleted_at` (`deleted_at`)
...@@ -160,4 +165,4 @@ UNLOCK TABLES; ...@@ -160,4 +165,4 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2023-01-17 22:07:33 -- Dump completed on 2023-01-19 11:51:11
文件结构:
app:
controller:
init:route对应的handle函数
foo: handle函数需要调用的函数
middleware:
login:登录中间件,添加uid,增加日志
response:
response:自定义reseponse,都采用json返回信息
init: 网络初始化,域名在config.yaml获取。
日志自定义格式
routes: 路由分配
model:
init: 数据库相关函数,包含着有关和数据库交互的各种操作,比如连接数据库,通过数据库反查内容,保存文本和文件信息等操作的函数
model: 存储着各表的结构,一共有五个结构体
mysql:
pastebinDatabase: 建立数据库脚本
pastebinTable: 建立数据库的数据表脚本
files:
.txt/.csv/tex/.md: 本地存放前端上传的文件
sys.log: 日志文件
config.yaml: 修改设置
go.mod
go.sum
main.go
readme
api:
见route.go
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment