Skip to content

Commit

Permalink
fix: 🔥 abort nt chrome
Browse files Browse the repository at this point in the history
  • Loading branch information
Aimerny committed Jul 9, 2024
1 parent 68b833b commit 385924b
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 255 deletions.
2 changes: 1 addition & 1 deletion app/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func kook(wg *sync.WaitGroup) {
return
}
initService(config)
go server.StartApiServer(config.ApiServerPort)
// go server.StartApiServer(config.ApiServerPort)
go server.StartWsProxyServer(config.WsProxyServerPort)
kookSession.RegisterEventHandler(&kook_event.ElixEventHandler{})
kookSession.Start()
Expand Down
44 changes: 0 additions & 44 deletions app/internal/render/chrome_test.go

This file was deleted.

81 changes: 81 additions & 0 deletions app/internal/render/img_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package render

import (
"fmt"
"github.com/nfnt/resize"
"image"
"image/draw"
"image/jpeg"
"os"
"testing"
)

func TestImg(t *testing.T) {
// 打开背景图片
backgroundFile, err := os.Open("plain.jpg")
if err != nil {
fmt.Println("Error: Unable to open background image.")
return
}
defer backgroundFile.Close()

// 解码背景图片
backgroundImg, err := jpeg.Decode(backgroundFile)
if err != nil {
fmt.Println("Error: Unable to decode background image.")
return
}

// 打开素材图片
overlayFile, err := os.Open("cat.jpg")
if err != nil {
fmt.Println("Error: Unable to open overlay image.")
return
}
defer overlayFile.Close()

// 解码素材图片
overlayImg, err := jpeg.Decode(overlayFile)
if err != nil {
fmt.Println("Error: Unable to decode overlay image.")
return
}

// 获取背景图的大小
bgBounds := backgroundImg.Bounds()

// 创建一个新的 RGBA 图像用于合成
resultImg := image.NewRGBA(bgBounds)

// 将背景图绘制到新图像上
draw.Draw(resultImg, bgBounds, backgroundImg, image.Point{0, 0}, draw.Src)

// 素材图的位置
offset := image.Pt(100, 100) // 可以根据需要调整位置

// 获取素材图的大小
scaledWidth := 1000
scaledHeight := 1000

// 缩放
m := resize.Resize(uint(scaledWidth), uint(scaledHeight), overlayImg, resize.Bilinear)

// 将素材图绘制到新图像的指定位置上
draw.Draw(resultImg, image.Rect(offset.X, offset.Y, offset.X+scaledWidth, offset.Y+scaledHeight), m, image.Point{0, 0}, draw.Over)

// 保存结果图像到文件
outputFile, err := os.Create("result.jpg")
if err != nil {
fmt.Println("Error: Unable to create result image.")
return
}
defer outputFile.Close()

// 将合成的图像编码为 JPEG 并写入文件
if err := jpeg.Encode(outputFile, resultImg, nil); err != nil {
fmt.Println("Error: Unable to encode result image.")
return
}

fmt.Println("Image composition complete.")
}
26 changes: 1 addition & 25 deletions app/internal/server/api_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import (
"github/aimerny/elix/app/internal/service"
"io"
"net/http"
"os"
"path/filepath"
"strconv"
"strings"
)

func StartApiServer(port int) {
Expand All @@ -24,15 +21,8 @@ func StartApiServer(port int) {
router.POST("/message/send", messageSend)
router.GET("/channel/bot-channels", getAllBotChannelsMeta)

templateFiles, err := getHTMLFiles("templates")
if err != nil {
logrus.WithError(err).Panic("start api server failed!")
}
router.LoadHTMLFiles(templateFiles...)
router.Static("/assets", "./templates/assets")
router.GET("/onge/mai/b50", renderMaiB50)
logrus.Info("start api server")
err = router.Run(":" + strconv.Itoa(port))
err := router.Run(":" + strconv.Itoa(port))
if err != nil {
logrus.WithError(err).Error("api server listen stop")
return
Expand Down Expand Up @@ -63,17 +53,3 @@ func getAllBotChannelsMeta(ctx *gin.Context) {
channels := service.FindChannels(searchKey)
ctx.JSON(http.StatusOK, channels)
}

func getHTMLFiles(dir string) ([]string, error) {
var files []string
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() && strings.HasSuffix(path, ".html") {
files = append(files, path)
}
return nil
})
return files, err
}
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/image v0.18.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
Expand Down Expand Up @@ -117,6 +119,8 @@ golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/image v0.18.0 h1:jGzIakQa/ZXI1I0Fxvaa9W7yP25TqT6cHIHn+6CqvSQ=
golang.org/x/image v0.18.0/go.mod h1:4yyo5vMFQjVjUcVk4jEQcU9MGy/rulF5WvUILseCM2E=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
Expand All @@ -136,6 +140,8 @@ golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
64 changes: 0 additions & 64 deletions templates/assets/css/b50-old.css

This file was deleted.

12 changes: 0 additions & 12 deletions templates/assets/css/b50.css

This file was deleted.

15 changes: 0 additions & 15 deletions templates/assets/css/global.css

This file was deleted.

Binary file removed templates/assets/img/icon.png
Binary file not shown.
Empty file removed templates/assets/js/b50.js
Empty file.
Loading

0 comments on commit 385924b

Please sign in to comment.