mirror of
https://github.com/tgbot-collection/YYeTsBot.git
synced 2025-11-25 19:37:34 +08:00
new binary - new UI
This commit is contained in:
6
.github/workflows/onekey.yaml
vendored
6
.github/workflows/onekey.yaml
vendored
@@ -18,11 +18,17 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
go-version: 1.19
|
go-version: 1.19
|
||||||
|
|
||||||
|
- name: Install nodejs
|
||||||
|
uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 16
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v1
|
uses: docker/setup-buildx-action@v1
|
||||||
|
|
||||||
- name: Build binaries
|
- name: Build binaries
|
||||||
run: |
|
run: |
|
||||||
|
npm install -g yarn
|
||||||
make all
|
make all
|
||||||
ls yyetsweb/builds/
|
ls yyetsweb/builds/
|
||||||
|
|
||||||
|
|||||||
13
Makefile
13
Makefile
@@ -1,7 +1,7 @@
|
|||||||
OS = darwin linux windows
|
OS = darwin linux windows
|
||||||
ARCH = amd64 arm64
|
ARCH = amd64 arm64
|
||||||
WEB := $(shell cd yyetsweb;pwd)
|
WEB := $(shell cd yyetsweb;pwd)
|
||||||
|
DATE:=$(shell date +"%Y-%m-%d %H:%M:%S")
|
||||||
update:
|
update:
|
||||||
git pull
|
git pull
|
||||||
git submodule update --remote
|
git submodule update --remote
|
||||||
@@ -36,20 +36,25 @@ current:
|
|||||||
|
|
||||||
asset:
|
asset:
|
||||||
cd $(WEB);go get -u github.com/go-bindata/go-bindata/... ;go install github.com/go-bindata/go-bindata/...
|
cd $(WEB);go get -u github.com/go-bindata/go-bindata/... ;go install github.com/go-bindata/go-bindata/...
|
||||||
cd yyetsweb/templates;~/go/bin/go-bindata -o assets.go resource.html index.html search.html js/... css/... fonts/... img/...
|
cd $(WEB)/templates;~/go/bin/go-bindata -o assets.go ./...
|
||||||
mv yyetsweb/templates/assets.go yyetsweb/assets.go
|
mv yyetsweb/templates/assets.go yyetsweb/assets.go
|
||||||
|
|
||||||
|
frontend:
|
||||||
|
cd YYeTsFE; yarn && yarn run release
|
||||||
|
cp -R YYeTsFE/build/* yyetsweb/templates/
|
||||||
|
|
||||||
all:
|
all:
|
||||||
make clean
|
make clean
|
||||||
|
make frontend
|
||||||
make asset
|
make asset
|
||||||
@echo "Build all platform executables..."
|
@echo "Build all platform executables..."
|
||||||
@for o in $(OS) ; do \
|
@for o in $(OS) ; do \
|
||||||
for a in $(ARCH) ; do \
|
for a in $(ARCH) ; do \
|
||||||
echo "Building $$o-$$a..."; \
|
echo "Building $$o-$$a..."; \
|
||||||
if [ "$$o" = "windows" ]; then \
|
if [ "$$o" = "windows" ]; then \
|
||||||
cd $(WEB);CGO_ENABLED=0 GOOS=$$o GOARCH=$$a go build -ldflags="-s -w" -o builds/yyetsweb-$$o-$$a.exe .; \
|
cd $(WEB);CGO_ENABLED=0 GOOS=$$o GOARCH=$$a go build -ldflags="-s -w -X 'main.buildTime=$(DATE)'" -o builds/yyetsweb-$$o-$$a.exe .; \
|
||||||
else \
|
else \
|
||||||
cd $(WEB);CGO_ENABLED=0 GOOS=$$o GOARCH=$$a go build -ldflags="-s -w" -o builds/yyetsweb-$$o-$$a .; \
|
cd $(WEB);CGO_ENABLED=0 GOOS=$$o GOARCH=$$a go build -ldflags="-s -w -X 'main.buildTime=$(DATE)'" -o builds/yyetsweb-$$o-$$a .; \
|
||||||
fi; \
|
fi; \
|
||||||
done \
|
done \
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ yyets_offline - 人人影视离线数据
|
|||||||
|
|
||||||
## 一键运行包
|
## 一键运行包
|
||||||
|
|
||||||
这个版本使用起来也很简单,不过页面比较朴素(又不是不能用)。无依赖。步骤如下
|
这个版本使用起来也很简单,也同样是最新的UI,只不过只有最基础的搜索功能。步骤如下
|
||||||
|
|
||||||
1. 请到 [GitHub Release](https://github.com/tgbot-collection/YYeTsBot/releases) 根据自己平台下载最新的一键运行包
|
1. 请到 [GitHub Release](https://github.com/tgbot-collection/YYeTsBot/releases) 根据自己平台下载最新的一键运行包
|
||||||
2. windows:双击第一步下载的exe文件; macos/Linux,cd到你的目录, `chmod +x yyetsweb ; ./yyetsweb`
|
2. windows:双击第一步下载的exe文件; macos/Linux,cd到你的目录, `chmod +x yyetsweb ; ./yyetsweb`
|
||||||
|
|||||||
@@ -68,7 +68,11 @@ def prepare_mysql():
|
|||||||
cnname varchar(256) null,
|
cnname varchar(256) null,
|
||||||
enname varchar(256) null,
|
enname varchar(256) null,
|
||||||
aliasname varchar(256) null,
|
aliasname varchar(256) null,
|
||||||
data longtext null
|
area varchar(32),
|
||||||
|
views int null,
|
||||||
|
data longtext null,
|
||||||
|
douban longtext null,
|
||||||
|
image blob null
|
||||||
) charset utf8mb4;
|
) charset utf8mb4;
|
||||||
"""
|
"""
|
||||||
comment_sql = """
|
comment_sql = """
|
||||||
@@ -103,7 +107,11 @@ def prepare_sqlite():
|
|||||||
cnname varchar(256) null,
|
cnname varchar(256) null,
|
||||||
enname varchar(256) null,
|
enname varchar(256) null,
|
||||||
aliasname varchar(256) null,
|
aliasname varchar(256) null,
|
||||||
data longtext null
|
area varchar(32),
|
||||||
|
views int null,
|
||||||
|
data longtext null,
|
||||||
|
douban longtext null,
|
||||||
|
image blob null
|
||||||
);
|
);
|
||||||
"""
|
"""
|
||||||
comment_sql = """
|
comment_sql = """
|
||||||
@@ -137,13 +145,15 @@ def dump_resource():
|
|||||||
cnname = data["cnname"]
|
cnname = data["cnname"]
|
||||||
enname = data["enname"]
|
enname = data["enname"]
|
||||||
aliasname = data["aliasname"]
|
aliasname = data["aliasname"]
|
||||||
|
views = data["views"]
|
||||||
|
area = data["area"]
|
||||||
data = json.dumps(each, ensure_ascii=False)
|
data = json.dumps(each, ensure_ascii=False)
|
||||||
|
|
||||||
batch_data.append((resource_id, cnname, enname, aliasname, data))
|
batch_data.append((resource_id, cnname, enname, aliasname, area, views, data, "", ""))
|
||||||
mb.append(each)
|
mb.append(each)
|
||||||
if len(batch_data) == CHUNK_SIZE:
|
if len(batch_data) == CHUNK_SIZE:
|
||||||
sql1 = "insert into yyets values (%s, %s, %s, %s, %s)"
|
sql1 = "insert into yyets values (%s, %s, %s, %s, %s, %s, %s, %s,%s)"
|
||||||
sql2 = "insert into yyets values (?, ?, ?, ?, ?)"
|
sql2 = "insert into yyets values (?, ?, ?, ?, ?,?,?,?,?)"
|
||||||
insert_func(batch_data, mb, sql1, sql2, "yyets")
|
insert_func(batch_data, mb, sql1, sql2, "yyets")
|
||||||
batch_data = []
|
batch_data = []
|
||||||
mb = []
|
mb = []
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ go 1.19
|
|||||||
require (
|
require (
|
||||||
github.com/gin-gonic/gin v1.8.1
|
github.com/gin-gonic/gin v1.8.1
|
||||||
github.com/glebarez/go-sqlite v1.19.1
|
github.com/glebarez/go-sqlite v1.19.1
|
||||||
|
github.com/sirupsen/logrus v1.9.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
|||||||
@@ -59,6 +59,8 @@ github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qq
|
|||||||
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
|
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
|
||||||
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
|
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
|
||||||
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
|
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
|
||||||
|
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
|
||||||
|
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
@@ -90,6 +92,7 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec h1:BkDtF2Ih9xZ7le9ndzTA7KJow28VbQW3odyk/8drmuI=
|
golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec h1:BkDtF2Ih9xZ7le9ndzTA7KJow28VbQW3odyk/8drmuI=
|
||||||
golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
|||||||
@@ -7,47 +7,41 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
_ "github.com/glebarez/go-sqlite"
|
_ "github.com/glebarez/go-sqlite"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const dbFile = "yyets_sqlite.db"
|
const dbFile = "yyets_sqlite.db"
|
||||||
|
|
||||||
func main() {
|
var (
|
||||||
downloadDB()
|
buildTime string
|
||||||
banner := `
|
db, _ = sql.Open("sqlite", dbFile)
|
||||||
▌ ▌ ▌ ▌ ▀▛▘
|
)
|
||||||
▝▞ ▝▞ ▞▀▖ ▌ ▞▀▘
|
|
||||||
▌ ▌ ▛▀ ▌ ▝▀▖
|
|
||||||
▘ ▘ ▝▀▘ ▘ ▀▀
|
|
||||||
|
|
||||||
Lazarus came back from the dead. By @Bennythink
|
type basicInfo struct {
|
||||||
http://127.0.0.1:8888/
|
Id int `json:"id"`
|
||||||
`
|
Cnname string `json:"cnname"`
|
||||||
r := gin.Default()
|
Enname string `json:"enname"`
|
||||||
r.GET("/api/resource", entrance)
|
Aliasname string `json:"aliasname"`
|
||||||
r.GET("/js/*f", bindataStaticHandler)
|
}
|
||||||
r.GET("/css/*f", bindataStaticHandler)
|
|
||||||
r.GET("/fonts/*f", bindataStaticHandler)
|
|
||||||
r.GET("/img/*f", bindataStaticHandler)
|
|
||||||
r.GET("/index.html", bindataStaticHandler)
|
|
||||||
r.GET("/search.html", bindataStaticHandler)
|
|
||||||
r.GET("/resource.html", bindataStaticHandler)
|
|
||||||
r.GET("/", bindataStaticHandler)
|
|
||||||
|
|
||||||
fmt.Printf(banner)
|
type Announcement struct {
|
||||||
_ = r.Run("localhost:8888") // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
|
Username string `json:"username"`
|
||||||
|
Date string `json:"date"`
|
||||||
|
Content string `json:"content"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func bindataStaticHandler(c *gin.Context) {
|
func bindataStaticHandler(c *gin.Context) {
|
||||||
|
c.Status(http.StatusOK)
|
||||||
path := c.Request.RequestURI[1:]
|
path := c.Request.RequestURI[1:]
|
||||||
if strings.Contains(path, "search.html") || strings.Contains(path, "resource.html") {
|
if strings.Contains(path, "search.html") || strings.Contains(path, "resource.html") {
|
||||||
path = strings.Split(path, "?")[0]
|
path = strings.Split(path, "?")[0]
|
||||||
}
|
}
|
||||||
|
fmt.Println(path)
|
||||||
data, err := Asset(path)
|
data, err := Asset(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Asset was not found.
|
// Asset was not found.
|
||||||
@@ -58,15 +52,20 @@ func bindataStaticHandler(c *gin.Context) {
|
|||||||
|
|
||||||
if strings.Contains(path, ".css") {
|
if strings.Contains(path, ".css") {
|
||||||
c.Writer.Header().Add("content-type", "text/css")
|
c.Writer.Header().Add("content-type", "text/css")
|
||||||
|
|
||||||
} else if strings.Contains(path, ".js") {
|
} else if strings.Contains(path, ".js") {
|
||||||
c.Writer.Header().Add("content-type", "text/javascript")
|
c.Writer.Header().Add("content-type", "text/javascript")
|
||||||
|
|
||||||
} else if strings.Contains(path, ".html") {
|
} else if strings.Contains(path, ".html") {
|
||||||
c.Writer.Header().Add("content-type", "text/html")
|
c.Writer.Header().Add("content-type", "text/html")
|
||||||
|
|
||||||
} else if strings.Contains(path, ".png") {
|
} else if strings.Contains(path, ".png") {
|
||||||
c.Writer.Header().Add("content-type", "image/png")
|
c.Writer.Header().Add("content-type", "image/png")
|
||||||
|
} else if strings.Contains(path, ".svg") {
|
||||||
|
c.Writer.Header().Add("content-type", "image/svg+xml")
|
||||||
|
} else if strings.Contains(path, ".jpg") {
|
||||||
|
c.Writer.Header().Add("content-type", "image/jpeg")
|
||||||
|
} else if strings.Contains(path, ".ico") {
|
||||||
|
c.Writer.Header().Add("content-type", "image/x-icon")
|
||||||
|
} else if strings.Contains(path, ".gif") {
|
||||||
|
c.Writer.Header().Add("content-type", "image/gif")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _ = c.Writer.Write(data)
|
_, _ = c.Writer.Write(data)
|
||||||
@@ -74,42 +73,27 @@ func bindataStaticHandler(c *gin.Context) {
|
|||||||
// Handle errors here too and cache headers
|
// Handle errors here too and cache headers
|
||||||
}
|
}
|
||||||
|
|
||||||
type basicInfo struct {
|
|
||||||
Id int `json:"id"`
|
|
||||||
Cnname string `json:"cnname"`
|
|
||||||
Enname string `json:"enname"`
|
|
||||||
Aliasname string `json:"aliasname"`
|
|
||||||
}
|
|
||||||
type InnerInfo struct {
|
|
||||||
Info basicInfo `json:"info"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ItemData struct {
|
|
||||||
Data InnerInfo `json:"data"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func search(c *gin.Context) {
|
func search(c *gin.Context) {
|
||||||
keyword, _ := c.GetQuery("keyword")
|
keyword, _ := c.GetQuery("keyword")
|
||||||
keyword = "%" + keyword + "%"
|
keyword = "%" + keyword + "%"
|
||||||
db, _ := sql.Open("sqlite", dbFile)
|
|
||||||
|
|
||||||
rows, _ := db.Query("SELECT resource_id, cnname, enname, aliasname FROM yyets "+
|
rows, _ := db.Query("SELECT resource_id, cnname, enname, aliasname FROM yyets "+
|
||||||
"WHERE cnname LIKE ? or enname LIKE ? or aliasname LIKE ?", keyword, keyword, keyword)
|
"WHERE cnname LIKE ? or enname LIKE ? or aliasname LIKE ?", keyword, keyword, keyword)
|
||||||
var finaldata []ItemData
|
var searchResult []basicInfo
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var t ItemData
|
var t basicInfo
|
||||||
_ = rows.Scan(&t.Data.Info.Id, &t.Data.Info.Cnname, &t.Data.Info.Enname, &t.Data.Info.Aliasname)
|
_ = rows.Scan(&t.Id, &t.Cnname, &t.Enname, &t.Aliasname)
|
||||||
finaldata = append(finaldata, t)
|
searchResult = append(searchResult, t)
|
||||||
}
|
}
|
||||||
c.JSON(200, gin.H{
|
c.JSON(200, gin.H{
|
||||||
"data": finaldata,
|
"data": searchResult,
|
||||||
|
"extra": []string{},
|
||||||
|
"comment": []string{},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func resource(c *gin.Context) {
|
func resource(c *gin.Context) {
|
||||||
id, _ := c.GetQuery("id")
|
id, _ := c.GetQuery("id")
|
||||||
db, _ := sql.Open("sqlite", dbFile)
|
|
||||||
|
|
||||||
rows, _ := db.Query("SELECT data FROM yyets WHERE resource_id=?", id)
|
rows, _ := db.Query("SELECT data FROM yyets WHERE resource_id=?", id)
|
||||||
var result string
|
var result string
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
@@ -119,10 +103,10 @@ func resource(c *gin.Context) {
|
|||||||
json.Unmarshal([]byte(result), &data)
|
json.Unmarshal([]byte(result), &data)
|
||||||
|
|
||||||
c.JSON(200, data)
|
c.JSON(200, data)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func entrance(c *gin.Context) {
|
func entrance(c *gin.Context) {
|
||||||
|
|
||||||
var _, keyword = c.GetQuery("keyword")
|
var _, keyword = c.GetQuery("keyword")
|
||||||
var _, id = c.GetQuery("id")
|
var _, id = c.GetQuery("id")
|
||||||
|
|
||||||
@@ -138,13 +122,98 @@ func entrance(c *gin.Context) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func announcement(c *gin.Context) {
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"data": []Announcement{{
|
||||||
|
Username: "Benny",
|
||||||
|
Date: buildTime,
|
||||||
|
Content: "YYeTs一键运行包 https://yyets.dmesg.app/。",
|
||||||
|
}},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func newest(c *gin.Context) {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"data": []string{},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func douban(c *gin.Context) {
|
||||||
|
var resourceId, _ = c.GetQuery("resource_id")
|
||||||
|
var requestType, _ = c.GetQuery("type")
|
||||||
|
|
||||||
|
type Image struct {
|
||||||
|
PosterLink string `json:"posterLink"`
|
||||||
|
}
|
||||||
|
rows, _ := db.Query("SELECT douban,image FROM yyets WHERE resource_id=?", resourceId)
|
||||||
|
var doubanInfo string
|
||||||
|
var doubanPoster []byte
|
||||||
|
for rows.Next() {
|
||||||
|
_ = rows.Scan(&doubanInfo, &doubanPoster)
|
||||||
|
}
|
||||||
|
if doubanInfo == "" {
|
||||||
|
var image Image
|
||||||
|
log.Warnf("Douban resource not found, requesting to main site %s...", resourceId)
|
||||||
|
resp, _ := http.Get("https://yyets.dmesg.app" + c.Request.URL.String())
|
||||||
|
body, _ := io.ReadAll(resp.Body)
|
||||||
|
doubanInfo = string(body)
|
||||||
|
json.Unmarshal(body, &image)
|
||||||
|
resp, _ = http.Get(image.PosterLink)
|
||||||
|
body, _ = io.ReadAll(resp.Body)
|
||||||
|
_, _ = db.Exec("UPDATE yyets SET douban=?,image=? WHERE resource_id=?", doubanInfo, body, resourceId)
|
||||||
|
}
|
||||||
|
|
||||||
|
if requestType == "image" {
|
||||||
|
c.Writer.Header().Add("content-type", "image/jpeg")
|
||||||
|
_, _ = c.Writer.Write(doubanPoster)
|
||||||
|
} else {
|
||||||
|
c.String(http.StatusOK, doubanInfo)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func queryTop(area string) []gin.H {
|
||||||
|
var sqlQuery string
|
||||||
|
if area == "ALL" {
|
||||||
|
sqlQuery = "SELECT resource_id, cnname, enname, aliasname FROM yyets order by views desc limit 15"
|
||||||
|
} else {
|
||||||
|
sqlQuery = "SELECT resource_id, cnname, enname, aliasname FROM yyets where area=? order by views desc limit 15"
|
||||||
|
}
|
||||||
|
rows, _ := db.Query(sqlQuery, area)
|
||||||
|
var finaldata []gin.H
|
||||||
|
for rows.Next() {
|
||||||
|
var t basicInfo
|
||||||
|
_ = rows.Scan(&t.Id, &t.Cnname, &t.Enname, &t.Aliasname)
|
||||||
|
finaldata = append(finaldata, gin.H{"data": gin.H{"info": t}})
|
||||||
|
}
|
||||||
|
return finaldata
|
||||||
|
}
|
||||||
|
|
||||||
|
func top(c *gin.Context) {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"ALL": queryTop("ALL"),
|
||||||
|
"US": queryTop("美国"),
|
||||||
|
"JP": queryTop("日本"),
|
||||||
|
"KR": queryTop("韩国"),
|
||||||
|
"UK": queryTop("英国"),
|
||||||
|
"class": gin.H{
|
||||||
|
"ALL": gin.H{"$regex": ".*"},
|
||||||
|
"US": "美国",
|
||||||
|
"JP": "日本",
|
||||||
|
"KR": "韩国",
|
||||||
|
"UK": "英国",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func downloadDB() {
|
func downloadDB() {
|
||||||
if _, err := os.Stat("yyets_sqlite.db"); err == nil {
|
if _, err := os.Stat(dbFile); err == nil {
|
||||||
log.Println("File already exists")
|
log.Warningln("Database file already exists")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("Downloading database file...")
|
log.Infoln("Downloading database file...")
|
||||||
var downloadUrl = "https://yyets.dmesg.app/dump/yyets_sqlite.zip"
|
var downloadUrl = "https://yyets.dmesg.app/dump/yyets_sqlite.zip"
|
||||||
resp, _ := http.Get(downloadUrl)
|
resp, _ := http.Get(downloadUrl)
|
||||||
file, _ := os.Create("yyets_sqlite.zip")
|
file, _ := os.Create("yyets_sqlite.zip")
|
||||||
@@ -152,16 +221,54 @@ func downloadDB() {
|
|||||||
_ = resp.Body.Close()
|
_ = resp.Body.Close()
|
||||||
_ = file.Close()
|
_ = file.Close()
|
||||||
|
|
||||||
log.Println("Download complete, extracting...")
|
log.Infoln("Download complete, extracting...")
|
||||||
archive, _ := zip.OpenReader("yyets_sqlite.zip")
|
archive, _ := zip.OpenReader("yyets_sqlite.zip")
|
||||||
for _, f := range archive.File {
|
for _, f := range archive.File {
|
||||||
dstFile, _ := os.OpenFile(f.Name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
|
var targetPath = path.Clean(f.Name)
|
||||||
|
dstFile, _ := os.OpenFile(targetPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
|
||||||
fileInArchive, _ := f.Open()
|
fileInArchive, _ := f.Open()
|
||||||
_, _ = io.Copy(dstFile, fileInArchive)
|
_, _ = io.Copy(dstFile, fileInArchive)
|
||||||
_ = dstFile.Close()
|
_ = dstFile.Close()
|
||||||
_ = fileInArchive.Close()
|
_ = fileInArchive.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("Extraction complete, cleaning up...")
|
log.Infoln("Extraction complete, cleaning up...")
|
||||||
_ = os.Remove("yyets_sqlite.zip")
|
_ = os.Remove("yyets_sqlite.zip")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
downloadDB()
|
||||||
|
banner := `
|
||||||
|
▌ ▌ ▌ ▌ ▀▛▘
|
||||||
|
▝▞ ▝▞ ▞▀▖ ▌ ▞▀▘
|
||||||
|
▌ ▌ ▛▀ ▌ ▝▀▖
|
||||||
|
▘ ▘ ▝▀▘ ▘ ▀▀
|
||||||
|
|
||||||
|
Lazarus came back from the dead. By @Bennythink
|
||||||
|
http://127.0.0.1:8888/
|
||||||
|
`
|
||||||
|
r := gin.Default()
|
||||||
|
r.GET("/api/resource", entrance)
|
||||||
|
r.GET("/api/announcement", announcement)
|
||||||
|
r.GET("/api/comment/newest", newest)
|
||||||
|
r.GET("/api/resource/latest", newest)
|
||||||
|
r.GET("/api/captcha", newest)
|
||||||
|
r.GET("/api/comment", newest)
|
||||||
|
r.GET("/api/douban", douban)
|
||||||
|
r.GET("/api/top", top)
|
||||||
|
r.GET("/js/*f", bindataStaticHandler)
|
||||||
|
r.GET("/css/*f", bindataStaticHandler)
|
||||||
|
r.GET("/fonts/*f", bindataStaticHandler)
|
||||||
|
r.GET("/img/*f", bindataStaticHandler)
|
||||||
|
//r.GET("/index.html", bindataStaticHandler)
|
||||||
|
//r.GET("/search.html", bindataStaticHandler)
|
||||||
|
r.GET("/resource.html", bindataStaticHandler)
|
||||||
|
r.GET("/", bindataStaticHandler)
|
||||||
|
r.GET("/index.css", bindataStaticHandler)
|
||||||
|
r.GET("/svg/*f", bindataStaticHandler)
|
||||||
|
|
||||||
|
r.NoRoute(bindataStaticHandler)
|
||||||
|
|
||||||
|
fmt.Printf(banner)
|
||||||
|
_ = r.Run("localhost:8888") // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user