添加上传md文件的接口

master
zcy 2024-01-14 02:54:32 +08:00
parent 702f023cb5
commit 19da5c532c
5 changed files with 239 additions and 23 deletions

View File

@ -25,6 +25,43 @@ import (
type FileController struct { type FileController struct {
} }
func (this *FileController) OnUploadDoc(c *gin.Context) {
// uid, e := uuid.NewV1()
// if nil != e {
// log.Print(e.Error())
// return
// }
// imgtype := c.Query("type")
// log.Print(imgtype)
// file, _, err := c.Request.FormFile("doc")
// if nil != err || nil == file {
// log.Print(err.Error())
// return
// }
// img, name, err := image.Decode(file)
// if nil != err {
// log.Print(err.Error())
// return
// }
// dx := img.Bounds().Dx()
// // resize to width 1000 using Lanczos resampling
// // and preserve aspect ratio
// if dx > 800 {
// dx = dx / 2
// }
// m := resize.Resize(uint(dx), 0, img, resize.Lanczos3)
// datout, err := os.Create("image/" + uid.String() + "." + name)
// defer datout.Close()
// if err != nil {
// log.Fatal(err)
// }
// jpeg.Encode(datout, m, nil)
// c.JSON(200, map[string]interface{}{"url": uid.String() + "." + name})
}
func (this *FileController) OnUpload(c *gin.Context) { func (this *FileController) OnUpload(c *gin.Context) {
uid, e := uuid.NewV1() uid, e := uuid.NewV1()
if nil != e { if nil != e {

View File

@ -38,6 +38,8 @@ func CORSMiddleware(c *gin.Context) {
if config.ApiConfig().RunMode == "release" { if config.ApiConfig().RunMode == "release" {
c.Writer.Header().Set("Access-Control-Allow-Origin", "https://testingcloud.club") c.Writer.Header().Set("Access-Control-Allow-Origin", "https://testingcloud.club")
} else { } else {
c.Writer.Header().Set("Access-Control-Allow-Origin", "https://testingcloud.club")
c.Writer.Header().Set("Access-Control-Allow-Origin", "http://127.0.0.1:8080") c.Writer.Header().Set("Access-Control-Allow-Origin", "http://127.0.0.1:8080")
} }
c.Writer.Header().Set("Access-Control-Max-Age", "86400") c.Writer.Header().Set("Access-Control-Max-Age", "86400")
@ -162,7 +164,9 @@ func main() {
api.POST("/articles", controller.GetArticles) // 获取所有文章 api.POST("/articles", controller.GetArticles) // 获取所有文章
api.GET("/articles_tree", controller.GetArticlesTree) // 获取所有文章 api.GET("/articles_tree", controller.GetArticlesTree) // 获取所有文章
api.PUT("/article", controller.AddArticle) // 添加文章 api.PUT("/article", controller.AddArticle) // 添加文章
api.PUT("/article_file", controller.AddArticle) // 添加文章
api.PUT("/article_tree", controller.AddArticleTree) // 添加文章 api.PUT("/article_tree", controller.AddArticleTree) // 添加文章
api.PUT("/article_tree_history", controller.AddArticleHistory) // 添加文章 api.PUT("/article_tree_history", controller.AddArticleHistory) // 添加文章
@ -190,6 +194,8 @@ func main() {
api.GET("/hardware", controller.ReadHardWare) // 读取硬件 api.GET("/hardware", controller.ReadHardWare) // 读取硬件
api.DELETE("/hardware", controller.DeleteHardWare) // 读取硬件 api.DELETE("/hardware", controller.DeleteHardWare) // 读取硬件
api.POST("/file", fileController.OnFileUploadFile) // 上传文件
api.PUT("/file", fileController.OnFileUploadFile) // 上传文件 api.PUT("/file", fileController.OnFileUploadFile) // 上传文件
api.GET("/file", fileController.DownloadFile) // 下载 文件 api.GET("/file", fileController.DownloadFile) // 下载 文件
api.GET("/filelist", fileController.FileList) // 文件列表 api.GET("/filelist", fileController.FileList) // 文件列表

View File

@ -29,44 +29,44 @@ func TestDDL2ORM(t *testing.T) {
` `
tbname, fields := utils.DDL2Field(ddl) tbname, fields := utils.DDL2Field(ddl)
log.Print(tbname, fields) log.Print(tbname, fields)
gocode := utils.CreateGoStruct(tbname,fields) gocode := utils.CreateGoStruct(tbname, fields)
log.Print(gocode) log.Print(gocode)
} }
func TestVariableNameChange(t *testing.T){ func TestVariableNameChange(t *testing.T) {
t.Log(utils.ToSnakeString("CaTest")) t.Log(utils.ToSnakeString("CaTest"))
} }
func TestSpeed(t *testing.T){ func TestSpeed(t *testing.T) {
var tcpAddr *net.TCPAddr var tcpAddr *net.TCPAddr
tcpAddr,_ = net.ResolveTCPAddr("tcp","192.168.6.103:6500") tcpAddr, _ = net.ResolveTCPAddr("tcp", "192.168.6.103:6500")
conn,err := net.DialTCP("tcp",nil,tcpAddr) conn, err := net.DialTCP("tcp", nil, tcpAddr)
if err!=nil { if err != nil {
fmt.Println("Client connect error ! " + err.Error()) fmt.Println("Client connect error ! " + err.Error())
return return
}
defer conn.Close()
recv := make([]byte,128)
i := int32(0)
for ;i < 128;i++ {
recv[i] = byte(i&0xff)
} }
fmt.Println(conn.LocalAddr().String() + " : Client connected!")
defer conn.Close()
recv := make([]byte, 128)
i := int32(0)
for ; i < 128; i++ {
recv[i] = byte(i & 0xff)
}
fmt.Println(conn.LocalAddr().String() + " : Client connected!")
reportTime := time.Now() reportTime := time.Now()
speed := 0; speed := 0
for { for {
cnt,_ := conn.Write(recv) cnt, _ := conn.Write(recv)
speed += cnt speed += cnt
// cnt,e = conn.Read(recv) // cnt,e = conn.Read(recv)
// if nil != e{ // if nil != e{
// log.Print(e.Error()) // log.Print(e.Error())
// } // }
// speed += cnt // speed += cnt
if(reportTime.Add(time.Second).Before(time.Now())){ if reportTime.Add(time.Second).Before(time.Now()) {
reportTime = time.Now() reportTime = time.Now()
t.Log("speed ",speed," B/S") t.Log("speed ", speed, " B/S")
speed = 0 speed = 0
} }
} }

85
漂移动画.html Normal file
View File

@ -0,0 +1,85 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<canvas id="webgl" width="500" height="500"></canvas>
<script>
const gl = document.getElementById('webgl').getContext('webgl');
const vertexShaderSource = "" +
"attribute vec4 apos;" +
"uniform mat4 mat;" +
"void main(){" +
" gl_Position = mat * apos;" +
"}";
const fragmentShaderSource = "" +
"void main(){" +
" gl_FragColor = vec4(1.0,0.0,0.0,1.0);" +
"}";
const program = initShader(gl,vertexShaderSource,fragmentShaderSource);
const aposlocation = gl.getAttribLocation(program,'apos');
const matlocation = gl.getUniformLocation(program,'mat');
const data = new Float32Array([
0.0,0.0,
-.3,-.3,
.3,-.3
]);
const buffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER,buffer);
gl.bufferData(gl.ARRAY_BUFFER,data,gl.STATIC_DRAW);
gl.vertexAttribPointer(aposlocation,2,gl.FLOAT,false,0,0);
gl.enableVertexAttribArray(aposlocation);
let Tx = 0.1; //x坐标的位置
let Ty = 0.1; //y坐标的位置
let Tz = 0.0; //z坐标的位置
let Tw = 1.0; //差值
function run () {
Tx += 0.01
Ty += 0.01
const mat = new Float32Array([
1.0,0.0,0.0,0.0,
0.0,1.0,0.0,0.0,
0.0,0.0,1.0,0.0,
Tx,Ty,Tz,Tw,
]);
if(Tx > 0.8){
Tx = -0.8
}
if(Ty > 0.8){
Ty = -0.8
}
gl.uniformMatrix4fv(matlocation,false,mat);
gl.drawArrays(gl.TRIANGLES,0,3);
// 使用此方法实现一个动画
requestAnimationFrame(run)
}
run()
function initShader(gl,vertexShaderSource,fragmentShaderSource){
const vertexShader = gl.createShader(gl.VERTEX_SHADER);
const fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
gl.shaderSource(vertexShader,vertexShaderSource);
gl.shaderSource(fragmentShader,fragmentShaderSource);
gl.compileShader(vertexShader);
gl.compileShader(fragmentShader);
const program = gl.createProgram();
gl.attachShader(program,vertexShader);
gl.attachShader(program,fragmentShader)
gl.linkProgram(program);
gl.useProgram(program);
return program;
}
</script>
</body>
</html>

88
画线矩形.html Normal file
View File

@ -0,0 +1,88 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>使用WebGL绘制一个点</title>
</head>
<body>
<!--canvas标签创建一个宽高均为500像素背景为蓝色的矩形画布-->
<canvas id="webgl" width="500" height="500" style="background-color: blue"></canvas>
<script id="vertexShader" type="x-shader/x-vertex">
//attribute声明vec4类型变量apos
attribute vec4 apos;
void main() {
//顶点坐标apos赋值给内置变量gl_Position
//逐顶点处理数据
gl_Position = apos;
}
</script>
<!-- 片元着色器源码 -->
<script id="fragmentShader" type="x-shader/x-fragment">
void main() {
// 逐片元处理数据,所有片元(像素)设置为红色
gl_FragColor = vec4(1.0,0.0,0.0,1.0);
}
</script>
<script>
//通过getElementById()方法获取canvas画布
var canvas=document.getElementById('webgl');
//通过方法getContext()获取WebGL上下文
var gl=canvas.getContext('webgl');
//初始化着色器
var vertexShaderSource = document.getElementById('vertexShader').innerText;
//片元着色器源码
var fragShaderSource = document.getElementById('fragmentShader').innerText;
//初始化着色器
var program = initShader(gl,vertexShaderSource,fragShaderSource);
//开始绘制,显示器显示结果
//获取顶点着色器的位置变量apos即aposLocation指向apos变量。
var aposLocation = gl.getAttribLocation(program,'apos');
var data=new Float32Array([0.5,0.5,-0.5,0.5,-0.5,-0.5,0.5,-0.5]);
//创建缓冲区对象
var buffer=gl.createBuffer();
//绑定缓冲区对象,激活buffer
gl.bindBuffer(gl.ARRAY_BUFFER,buffer);
//顶点数组data数据传入缓冲区
gl.bufferData(gl.ARRAY_BUFFER,data,gl.STATIC_DRAW);
//缓冲区中的数据按照一定的规律传递给位置变量apos
gl.vertexAttribPointer(aposLocation,2,gl.FLOAT,false,0,0);
//允许数据传递
gl.enableVertexAttribArray(aposLocation);
gl.drawArrays(gl.TRIANGLES,0,4);
//声明初始化着色器函数
function initShader(gl,vertexShaderSource,fragmentShaderSource){
//创建顶点着色器对象
var vertexShader = gl.createShader(gl.VERTEX_SHADER);
//创建片元着色器对象
var fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
//引入顶点、片元着色器源代码
gl.shaderSource(vertexShader,vertexShaderSource);
gl.shaderSource(fragmentShader,fragmentShaderSource);
//编译顶点、片元着色器
gl.compileShader(vertexShader);
gl.compileShader(fragmentShader);
//创建程序对象program
var program = gl.createProgram();
//附着顶点着色器和片元着色器到program
gl.attachShader(program,vertexShader);
gl.attachShader(program,fragmentShader);
//链接program
gl.linkProgram(program);
//使用program
gl.useProgram(program);
//返回程序program对象
return program;
}
</script>
</body>
</html>