auto download

This commit is contained in:
Benny
2022-10-07 15:41:44 +08:00
parent 567063f6a7
commit 637dd93c78
2 changed files with 38 additions and 8 deletions

View File

@@ -88,12 +88,9 @@ yyets_offline - 人人影视离线数据
这个版本使用起来也很简单,不过页面比较朴素(又不是不能用)。无依赖。步骤如下
1. 请到 [GitHub Release](https://github.com/tgbot-collection/YYeTsBot/releases) 根据自己平台下载一键运行包
2. 请到 [database download](https://yyets.dmesg.app/database) 下载SQLite数据库然后解压缩
3. 把这两个文件放到同一个目录
4. windows双击第一步下载的文件 macos/Linuxcd到你的目录, `chmod +x yyetsweb ; ./yyetsweb`
打开浏览器 http://127.0.0.1:8888 就可以看到熟悉的搜索界面啦!
1. 请到 [GitHub Release](https://github.com/tgbot-collection/YYeTsBot/releases) 根据自己平台下载最新的一键运行包
2. windows双击第一步下载的exe文件 macos/Linuxcd到你的目录, `chmod +x yyetsweb ; ./yyetsweb`
3. 程序会自动下载数据库并启动。等到出现启动banner时 打开浏览器 http://127.0.0.1:8888 就可以看到熟悉的搜索界面啦!
# 开发

View File

@@ -1,18 +1,23 @@
package main
import (
"archive/zip"
"database/sql"
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
_ "github.com/glebarez/go-sqlite"
"io"
"log"
"net/http"
"os"
"strings"
)
const dbFile = "yyets_sqlite.db"
func main() {
downloadDB()
banner := `
▌ ▌ ▌ ▌ ▀▛▘
▝▞ ▝▞ ▞▀▖ ▌ ▞▀▘
@@ -20,6 +25,7 @@ func main() {
▘ ▘ ▝▀▘ ▘ ▀▀
Lazarus came back from the dead. By @Bennythink
http://127.0.0.1:8888/
`
r := gin.Default()
r.GET("/api/resource", entrance)
@@ -33,7 +39,6 @@ func main() {
r.GET("/", bindataStaticHandler)
fmt.Printf(banner)
_ = r.Run("localhost:8888") // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}
@@ -132,3 +137,31 @@ func entrance(c *gin.Context) {
}
}
func downloadDB() {
if _, err := os.Stat("yyets_sqlite.db"); err == nil {
log.Println("File already exists")
return
}
log.Println("Downloading database file...")
var downloadUrl = "https://yyets.dmesg.app/dump/yyets_sqlite.zip"
resp, _ := http.Get(downloadUrl)
file, _ := os.Create("yyets_sqlite.zip")
_, _ = io.Copy(file, resp.Body)
_ = resp.Body.Close()
_ = file.Close()
log.Println("Download complete, extracting...")
archive, _ := zip.OpenReader("yyets_sqlite.zip")
for _, f := range archive.File {
dstFile, _ := os.OpenFile(f.Name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
fileInArchive, _ := f.Open()
_, _ = io.Copy(dstFile, fileInArchive)
_ = dstFile.Close()
_ = fileInArchive.Close()
}
log.Println("Extraction complete, cleaning up...")
_ = os.Remove("yyets_sqlite.zip")
}