Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenhan wang
pastebin
Commits
6c660a49
Commit
6c660a49
authored
Jan 19, 2023
by
chenhan wang
Browse files
本地调试2.4
parent
b2b68a75
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
backend/app/controller/interface.go
View file @
6c660a49
...
...
@@ -19,8 +19,8 @@ type File struct {
User
string
`json:"user" form:"user" query:"user"`
Passwd
string
`json:"passwd" form:"passwd" query:"passwd"`
Url
string
`json:"url" form:"url" query:"url"`
Time
time
.
Time
`json:"time" form:"time" query:"time"`
// 用户指定的时间期限
MaxAccess
uint
`json:"maxaccess form:"maxaccess" query:"maxaccess"`
// 文件最大可访问次数
Time
time
.
Time
`json:"time" form:"time" query:"time"`
// 用户指定的时间期限
MaxAccess
uint
`json:"maxaccess
"
form:"maxaccess" query:"maxaccess"`
// 文件最大可访问次数
//Expiry time.Time `json:"expiry"` // 有效期
//Content string `json:"content"`
}
...
...
backend/app/routes.go
View file @
6c660a49
...
...
@@ -9,15 +9,27 @@ import (
func
addRoutes
()
{
api
:=
e
.
Group
(
"api"
)
api
.
Use
(
middleware
.
Auth
)
api
.
GET
(
"/ping"
,
controller
.
Ping
)
api
.
GET
(
"/ping"
,
controller
.
Ping
)
// 测试用
// 前端向后端申请一个包含sessionId的cookie,暂不不支持自定义cookie有效时间,默认半小时
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/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
()
{
...
...
backend/model/init.go
View file @
6c660a49
...
...
@@ -64,11 +64,7 @@ func Findlink(_url string) string {
// save text information
// 保存文本和文件信息
func
Savetext
(
_Route
string
,
_Time
uint
,
_Passwd
string
,
_Time1
time
.
Time
,
_url
string
)
{
var
id1
int64
DB
.
Model
(
&
Content
{})
.
Count
(
&
id1
)
id1
++
p
:=
Content
{
ID
:
id1
,
Route
:
_Route
,
Time
:
_Time
,
Passwd
:
_Passwd
,
...
...
@@ -192,11 +188,3 @@ func CreatelinkFirstTime(sid string, _url string, _Time1 time.Time) {
}
DB
.
Create
(
&
sid1
)
}
/*
func Test() {
var p Content
var Url2 string = "1234"
DB.First(&p, "url1 = ?", Url2)
fmt.Println(Checkt(p))
}*/
backend/model/model.go
View file @
6c660a49
...
...
@@ -6,7 +6,7 @@ import (
)
type
Content
struct
{
ID
int64
`gorm:"primarykey"`
gorm
.
Model
Route
string
Time
uint
Passwd
string
...
...
backend/model/test.sql
deleted
100644 → 0
View file @
b2b68a75
This diff is collapsed.
Click to expand it.
backend/mysql/mysql.ibd
deleted
100644 → 0
View file @
b2b68a75
File deleted
backend/mysql/pastebin.sql
→
backend/mysql/pastebin
Database
.sql
View file @
6c660a49
File moved
backend/mysql/
test1
.sql
→
backend/mysql/
pastebinTable
.sql
View file @
6c660a49
...
...
@@ -24,6 +24,9 @@ DROP TABLE IF EXISTS `contents`;
/*!50503 SET character_set_client = utf8mb4 */
;
CREATE
TABLE
`contents`
(
`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
,
`time`
bigint
unsigned
DEFAULT
NULL
,
`passwd`
longtext
,
...
...
@@ -32,7 +35,8 @@ CREATE TABLE `contents` (
`time1`
datetime
(
3
)
DEFAULT
NULL
,
`time2`
bigint
unsigned
DEFAULT
NULL
,
`url1`
longtext
,
PRIMARY
KEY
(
`id`
)
PRIMARY
KEY
(
`id`
),
KEY
`idx_contents_deleted_at`
(
`deleted_at`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8mb3
;
/*!40101 SET character_set_client = @saved_cs_client */
;
...
...
@@ -83,6 +87,7 @@ CREATE TABLE `sids` (
`created_at`
datetime
(
3
)
DEFAULT
NULL
,
`updated_at`
datetime
(
3
)
DEFAULT
NULL
,
`deleted_at`
datetime
(
3
)
DEFAULT
NULL
,
`time`
datetime
(
3
)
DEFAULT
NULL
,
`s`
longtext
,
PRIMARY
KEY
(
`id`
),
KEY
`idx_sids_deleted_at`
(
`deleted_at`
)
...
...
@@ -160,4 +165,4 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */
;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */
;
-- Dump completed on 2023-01-1
7 22:07:33
-- Dump completed on 2023-01-1
9 11:51:11
backend/readme.txt
View file @
6c660a49
文件结构:
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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment