├── photos └── .gitignore ├── web ├── src │ ├── api │ │ └── common.js │ ├── assets │ │ └── logo.png │ ├── main.js │ └── App.vue ├── public │ ├── favicon.ico │ └── index.html ├── babel.config.js ├── vue.config.js ├── .gitignore ├── README.md └── package.json ├── 1.build_web.sh ├── 1.build_web.bat ├── 2.build_go.bat ├── 2.build_go.sh ├── conf.json ├── 3.build_go2linux.bat ├── docker-compose-build-1web.yml ├── docker-compose-build-2go.yml ├── .gitignore ├── main_router.go ├── docker-compose-run-2single.yml ├── main_model.go ├── docker-compose-run-1nginx.yml ├── default.conf ├── go.mod ├── main_utils.go ├── README.md ├── main.go ├── go.sum └── main_handles.go /photos/.gitignore: -------------------------------------------------------------------------------- 1 | *.jpg -------------------------------------------------------------------------------- /web/src/api/common.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios' 2 | 3 | -------------------------------------------------------------------------------- /web/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william10240/fanhao/HEAD/web/public/favicon.ico -------------------------------------------------------------------------------- /web/src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william10240/fanhao/HEAD/web/src/assets/logo.png -------------------------------------------------------------------------------- /web/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/cli-plugin-babel/preset' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /1.build_web.sh: -------------------------------------------------------------------------------- 1 | cd web 2 | npm i --registry=http://registry.npm.taobao.org && npm run build && cd ../ && echo build done -------------------------------------------------------------------------------- /1.build_web.bat: -------------------------------------------------------------------------------- 1 | cd web 2 | npm i --registry=http://registry.npm.taobao.org && npm run build && cd ../ && echo build done -------------------------------------------------------------------------------- /2.build_go.bat: -------------------------------------------------------------------------------- 1 | set GO111MODULE=on 2 | set GOPROXY=https://goproxy.cn,https://goproxy.io,direct 3 | go build 4 | echo build done -------------------------------------------------------------------------------- /2.build_go.sh: -------------------------------------------------------------------------------- 1 | export GO111MODULE=on 2 | export GOPROXY=https://goproxy.cn,https://goproxy.io,direct 3 | go build 4 | echo build done -------------------------------------------------------------------------------- /conf.json: -------------------------------------------------------------------------------- 1 | { 2 | "port": "8888", 3 | "path": "photos", 4 | "dbName": "fanhao.db", 5 | "proxy": "", 6 | "busUrl": "https://www.javsee.club/" 7 | } 8 | -------------------------------------------------------------------------------- /web/vue.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | publicPath: process.env.NODE_ENV === 'production' 3 | ? '/static/' 4 | : '/', 5 | productionSourceMap: false, 6 | } -------------------------------------------------------------------------------- /3.build_go2linux.bat: -------------------------------------------------------------------------------- 1 | 2 | SET GOOS=linux 3 | SET GOARCH=amd64 4 | go env 5 | 6 | go env -w GO111MODULE=on 7 | go env -w GOPROXY=https://goproxy.cn,https://goproxy.io,direct 8 | go build 9 | echo build done -------------------------------------------------------------------------------- /web/src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import App from './App.vue' 3 | 4 | 5 | 6 | import ElementUI from 'element-ui'; 7 | import 'element-ui/lib/theme-chalk/index.css'; 8 | Vue.use(ElementUI); 9 | 10 | Vue.config.productionTip = false 11 | new Vue({ 12 | render: h => h(App), 13 | }).$mount('#app') 14 | -------------------------------------------------------------------------------- /web/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | package-lock.json 6 | 7 | # local env files 8 | .env.local 9 | .env.*.local 10 | 11 | # Log files 12 | npm-debug.log* 13 | yarn-debug.log* 14 | yarn-error.log* 15 | pnpm-debug.log* 16 | 17 | # Editor directories and files 18 | .idea 19 | .vscode 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /docker-compose-build-1web.yml: -------------------------------------------------------------------------------- 1 | 2 | version: '3' 3 | 4 | services: 5 | 6 | buildweb: 7 | image: node:14.15.3-alpine 8 | volumes: 9 | - ./web:/web 10 | network_mode: "host" 11 | working_dir: /web 12 | user: "1000:1000" 13 | command: /bin/sh -c "/usr/local/bin/npm i --registry=http://registry.npm.taobao.org; /usr/local/bin/npm run build; echo 'build done'" 14 | -------------------------------------------------------------------------------- /docker-compose-build-2go.yml: -------------------------------------------------------------------------------- 1 | 2 | version: '3' 3 | 4 | services: 5 | 6 | buildgo: 7 | image: golang:1.17 8 | volumes: 9 | - ./:/app 10 | network_mode: "host" 11 | working_dir: /app 12 | environment: 13 | - GO111MODULE=on 14 | - GOPROXY=https://goproxy.cn,https://proxy.golang.org,direct 15 | command: /bin/sh -c "go build;chmod +x fanhao;echo 'build done'" 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /static 3 | fanhao 4 | fanhao.exe 5 | fanhao.db 6 | fanhao1.db 7 | foo.db 8 | foo1.db 9 | 10 | 11 | # local env files 12 | .env.local 13 | .env.*.local 14 | 15 | # Log files 16 | npm-debug.log* 17 | yarn-debug.log* 18 | yarn-error.log* 19 | pnpm-debug.log* 20 | 21 | # Editor directories and files 22 | .idea 23 | .vscode 24 | *.suo 25 | *.ntvs* 26 | *.njsproj 27 | *.sln 28 | *.sw? 29 | /package-lock.json 30 | -------------------------------------------------------------------------------- /web/README.md: -------------------------------------------------------------------------------- 1 | # fanhao 2 | 3 | ## Project setup 4 | ``` 5 | npm install 6 | ``` 7 | 8 | ### Compiles and hot-reloads for development 9 | ``` 10 | npm run serve 11 | ``` 12 | 13 | ### Compiles and minifies for production 14 | ``` 15 | npm run build 16 | ``` 17 | 18 | ### Lints and fixes files 19 | ``` 20 | npm run lint 21 | ``` 22 | 23 | ### Customize configuration 24 | See [Configuration Reference](https://cli.vuejs.org/config/). 25 | -------------------------------------------------------------------------------- /main_router.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "embed" 5 | "io/fs" 6 | "path" 7 | ) 8 | 9 | // StaticResource 嵌入普通静态资源 10 | type StaticResource struct { 11 | // 静态资源 12 | staticFS embed.FS 13 | // 设置embed文件到静态资源的相对路径,也就是embed注释里的路径 14 | path string 15 | } 16 | 17 | // Open 静态资源被访问逻辑 18 | func (_this_ *StaticResource) Open(name string) (fs.File, error) { 19 | return _this_.staticFS.Open(path.Join("web/dist", name)) 20 | } 21 | 22 | //go:embed web/dist 23 | var WebUI embed.FS -------------------------------------------------------------------------------- /docker-compose-run-2single.yml: -------------------------------------------------------------------------------- 1 | 2 | version: '3' 3 | 4 | services: 5 | 6 | go: 7 | image: golang:1.17 8 | volumes: 9 | - ./:/app 10 | # 以下两行 数据放在自定义目录 11 | # - /data/dcdb/fanhao/photos:/app/photos 12 | # - /data/dcdb/fanhao/fanhao.db:/app/fanhao.db 13 | ports: 14 | - 8888:8888 15 | working_dir: /app 16 | environment: 17 | - GO111MODULE=on 18 | - GOPROXY=https://goproxy.cn,https://proxy.golang.org,direct 19 | command: "/app/fanhao" 20 | restart: always -------------------------------------------------------------------------------- /web/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | <%= htmlWebpackPlugin.options.title %> 9 | 10 | 11 | 14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /main_model.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | type fanhao struct { 4 | ID int `gorm:"primaryKey"` 5 | Code string `gorm:"type:string;size:64;not null;index:code_idx"` 6 | Title string `gorm:"type:string;size:128"` 7 | Star string `gorm:"type:string;size:64"` 8 | StarCode string `gorm:"type:string;size:64"` 9 | Img string `gorm:"type:string;size:128"` 10 | Fname string `gorm:"type:string;size:128"` 11 | Ima int `gorm:"type:int;default:0"` 12 | Iface int `gorm:"type:int;default:0"` 13 | Starnum int `gorm:"type:int;default:0"` 14 | Downed int `gorm:"type:int;default:0"` 15 | CreatedAt int64 `gorm:"autoCreateTime"` 16 | UpdatedAt int64 `gorm:"autoUpdateTime"` 17 | } 18 | func (f *fanhao) TableName() string{ 19 | return "fanhao" 20 | } -------------------------------------------------------------------------------- /docker-compose-run-1nginx.yml: -------------------------------------------------------------------------------- 1 | 2 | version: '3' 3 | 4 | services: 5 | 6 | web: 7 | image: nginx:alpine 8 | volumes: 9 | - ./default.conf:/etc/nginx/conf.d/default.conf 10 | - ./:/app 11 | # 以下一行 数据放在自定义目录 12 | # - /data/dcdb/fanhao/photos:/app/photos 13 | ports: 14 | - 8888:80 15 | restart: always 16 | 17 | go: 18 | image: golang:1.17 19 | volumes: 20 | - ./:/app 21 | # 以下一行 数据放在自定义目录 22 | # - /data/dcdb/fanhao/fanhao.db:/app/fanhao.db 23 | # - /data/dcdb/fanhao/photos:/app/photos 24 | working_dir: /app 25 | environment: 26 | - GO111MODULE=on 27 | - GOPROXY=https://goproxy.cn,https://proxy.golang.org,direct 28 | command: "/app/fanhao" 29 | restart: always 30 | 31 | -------------------------------------------------------------------------------- /default.conf: -------------------------------------------------------------------------------- 1 | 2 | charset utf-8; 3 | index index.html index.php; 4 | 5 | 6 | 7 | server { 8 | listen 80; 9 | 10 | root /app/web/dist; 11 | 12 | location /static/ { 13 | alias /app/web/dist/; 14 | } 15 | location /photos/ { 16 | alias /app/photos/; 17 | } 18 | 19 | location ~ /api/ { 20 | proxy_pass http://go:8888; 21 | proxy_send_timeout 1800; 22 | proxy_read_timeout 1800; 23 | proxy_connect_timeout 1800; 24 | client_max_body_size 2048m; 25 | proxy_http_version 1.1; 26 | proxy_set_header Upgrade $http_upgrade; 27 | proxy_set_header Connection "Upgrade"; 28 | proxy_set_header Host $http_host; # required for docker client's sake 29 | proxy_set_header X-Real-IP $remote_addr; # pass on real client's IP 30 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 31 | proxy_set_header X-Forwarded-Proto $scheme; 32 | add_header Access-Control-Allow-Origin * always; 33 | add_header Access-Control-Allow-Methods PUT,OPTIONS; 34 | add_header Access-Control-Allow-Headers Content-Type; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /web/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fanhao", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "serve": "vue-cli-service serve", 7 | "build": "vue-cli-service build", 8 | "lint": "vue-cli-service lint" 9 | }, 10 | "dependencies": { 11 | "axios": "^0.22.0", 12 | "core-js": "^3.6.5", 13 | "element-ui": "^2.15.6", 14 | "vue": "^2.6.11" 15 | }, 16 | "devDependencies": { 17 | "@vue/cli-plugin-babel": "~4.5.0", 18 | "@vue/cli-plugin-eslint": "~4.5.0", 19 | "@vue/cli-service": "~4.5.0", 20 | "babel-eslint": "^10.1.0", 21 | "eslint": "^6.7.2", 22 | "eslint-plugin-vue": "^6.2.2", 23 | "vue-template-compiler": "^2.6.11" 24 | }, 25 | "eslintConfig": { 26 | "root": true, 27 | "env": { 28 | "node": true 29 | }, 30 | "extends": [ 31 | "plugin:vue/essential", 32 | "eslint:recommended" 33 | ], 34 | "parserOptions": { 35 | "parser": "babel-eslint" 36 | }, 37 | "rules": {} 38 | }, 39 | "browserslist": [ 40 | "> 1%", 41 | "last 2 versions", 42 | "not dead" 43 | ] 44 | } 45 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module fanhao 2 | 3 | go 1.17 4 | 5 | require ( 6 | github.com/gin-gonic/gin v1.7.4 7 | gorm.io/driver/sqlite v1.1.6 8 | gorm.io/gorm v1.21.16 9 | ) 10 | 11 | require ( 12 | github.com/gin-contrib/sse v0.1.0 // indirect 13 | github.com/go-playground/locales v0.13.0 // indirect 14 | github.com/go-playground/universal-translator v0.17.0 // indirect 15 | github.com/go-playground/validator/v10 v10.4.1 // indirect 16 | github.com/golang/protobuf v1.3.3 // indirect 17 | github.com/jinzhu/inflection v1.0.0 // indirect 18 | github.com/jinzhu/now v1.1.2 // indirect 19 | github.com/json-iterator/go v1.1.9 // indirect 20 | github.com/leodido/go-urn v1.2.0 // indirect 21 | github.com/mattn/go-isatty v0.0.12 // indirect 22 | github.com/mattn/go-sqlite3 v1.14.8 // indirect 23 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect 24 | github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 // indirect 25 | github.com/ugorji/go/codec v1.1.7 // indirect 26 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect 27 | golang.org/x/sys v0.0.0-20200116001909-b77594299b42 // indirect 28 | gopkg.in/yaml.v2 v2.2.8 // indirect 29 | ) 30 | -------------------------------------------------------------------------------- /main_utils.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "crypto/tls" 5 | "github.com/gin-gonic/gin" 6 | "log" 7 | "net/http" 8 | "net/url" 9 | ) 10 | 11 | 12 | func checkErr(err error) { 13 | if err != nil { 14 | log.Fatal("err:", err) 15 | //panic(err) 16 | } 17 | } 18 | func Cors() gin.HandlerFunc { 19 | return func(c *gin.Context) { 20 | method := c.Request.Method 21 | origin := c.Request.RequestURI 22 | if origin != "" { 23 | c.Header("Access-Control-Allow-Origin", "*") // 可将将 * 替换为指定的域名 24 | c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE") 25 | c.Header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization") 26 | c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Cache-Control, Content-Language, Content-Type") 27 | c.Header("Access-Control-Allow-Credentials", "true") 28 | } 29 | if method == "OPTIONS" { 30 | c.AbortWithStatus(http.StatusNoContent) 31 | } 32 | c.Next() 33 | } 34 | } 35 | 36 | // 请求二进制 37 | func _request(u string) (*http.Response, error) { 38 | 39 | tr:=&http.Transport{TLSClientConfig: &tls.Config{ 40 | InsecureSkipVerify: true, 41 | }} 42 | 43 | if len(CONF.Proxy) > 0{ 44 | proxyUrl, err := url.Parse(CONF.Proxy) 45 | checkErr(err) 46 | tr.Proxy = http.ProxyURL(proxyUrl) 47 | } 48 | 49 | client := &http.Client{ 50 | Transport: tr, 51 | } 52 | //提交请求 53 | reqest, err := http.NewRequest("GET", u, nil) 54 | //增加header选项 55 | reqest.Header.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36") 56 | 57 | if err != nil { 58 | return nil, err 59 | } 60 | //处理返回结果 61 | response, err := client.Do(reqest) 62 | 63 | if err != nil { 64 | return response, err 65 | } 66 | if response.StatusCode != 200 { 67 | return response, http.ErrMissingFile 68 | } 69 | return response, err 70 | } 71 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 |

番械库

3 |

私人番号收藏

4 |

5 | 6 | ## 简介 7 | 每个人都有自己喜欢的番号,每个人都想有自己记录番号的小本本。。 8 | 9 | 当小本本记录了太多之后我们想找到今日想要的哪一部时,究竟哪行神秘代码对应哪部电影,想选择却无从下手 10 | 11 | 现在有个番号收藏,管理番号,so easy ! 12 | 13 | 添加番号收藏后会自动添加番号对应的封面图片,演员,还可手动标记骑兵步兵 14 | 15 | ## 注意事项 16 | 根目录下"fanhao.db"文件为数据库文件,请注意存档备份;如使用docker部署可存放在其他目录更安全,操作方式下面有 17 | 18 | ## 部署方式1:docker(推荐!推荐!推荐!) 19 | ### 1. 编译前端 必须先编译前端 20 | ``` 21 | docker-compose -f docker-compose-build-1web.yml up 22 | 23 | 直到看到"build done"容器自动退出则编译成功 24 | ``` 25 | 26 | ### 2. 编译后端 27 | ``` 28 | docker-compose -f docker-compose-build-2go.yml up 29 | 直到看到"build done"容器自动退出则编译成功 30 | ``` 31 | 32 | ### 3. 运行 使用nginx代理静态资源 33 | ``` 34 | docker-compose -f docker-compose-run-1nginx.yml up 35 | 36 | 启动成功后访问 http://ip:8888 37 | 38 | 端口在 docker-compose-run-1nginx.yml 中修改 39 | 40 | ``` 41 | 42 | ### 4. 运行 不使用nginx代理静态资源 43 | ``` 44 | docker-compose -f docker-compose-run-2single.yml up 45 | 46 | 启动成功后访问 http://ip:8888 47 | 48 | 端口在 docker-compose-run-2single.yml 中修改 49 | 50 | ``` 51 | 52 | 此部署模式下 数据库文件"fanhao.db"和图片目录"photos" 都可以在yml文件中指定和修改 53 | 54 | ### 5. 修改数据存储位置 55 | 56 | ``` 57 | 在"docker-compose-run-1nginx.yml"和"docker-compose-run-2single.yml"里均有被注释的 58 | " 59 | # - /data/dcdb/fanhao/photos:/app/photos 60 | # - /data/dcdb/fanhao/fanhao.db:/app/fanhao.db 61 | " 62 | 以上两行,注释掉就是使用项目目录存放数据,解开注释就是使用自定义目录 63 | 在使用自定义目录前,需要先启动一次生成数据库文件,然后自己建好目录,将fanhao.db和photos移动到新目录,再修改路径,后面的"/app/photos"和"/app/fanhao.db"与"conf.json"配置文件挂钩不建议修改 64 | ``` 65 | 66 | 67 | ## 部署方法2:手动 68 | ### 1. 编译前端 必须先编译前端 69 | ``` 70 | cd web # 进入前端目录 71 | npm i # 安装相关组件,速度和网速,代理等有关 72 | npm run build # 开始编译 73 | ``` 74 | 75 | ### 2. 编译后端 76 | ``` 77 | go build # 开始编译,速度和网速,代理等有关 78 | ``` 79 | ### 3. 运行 80 | 81 | ``` 82 | 运行当前目录下生成的"fanhao"或"番fahao.exe"文件即可 83 | ``` 84 | 85 | ### 4. 配置nginx反向代理 86 | 87 | ``` 88 | 既然选择手动部署,我相信你动手能力一定很强,加油鸭 89 | ``` 90 | 91 | ## 问题处理 92 | ### 获取番号信息时报错, 93 | ``` 94 | 1.请检查 busUrl 地址是否被墙,busUrl地址可能会更换,使用浏览器打开busUrl网址看是否能访问,如果还不能访问请发issue,题主会定期更换 95 | 96 | 2.程序所在环境是否能正常访问到小飞机的代理, 97 | 98 | 3.如果代理没有问题,则可能是代理环境无法访问配置文件中配置的"busUrl"网址,则把小飞机更换为全局代理模式实施 99 | ``` 100 | 101 | ## 技术参考 102 | > golang v1.17+ , node v16.10+ 103 | > docker 需要 配套 docker-compose 104 | > 数据库使用sqlite,默认保存在根目录 "fanhao.db" 中,注意备份!!!注意备份!!!注意备份!!! 105 | 106 | 107 | ## 关于代理 108 | 在 "conf.json" 中配置 proxy,默认为"",配置如"socks5://127.0.0.1:1080" 或 "http://127.0.0.1:1081" 109 | 110 | 确保本地小飞机软件已打开,如代理不在本机则确保设置"允许其他设备接入"已勾选, 111 | 112 | socks代理端口默认为1080 , http代理端口默认为1081,请根据实际情况填写 (具体方法请绅士自查) 113 | 114 | 修改配置需要重启程序 115 | 116 | ## license 117 | > 本作品仅供学习交流使用,对使用后产生的任何后果不承担任何责任; 前方净空,允许进入,祝君武运昌隆 118 | 119 | ## todo: 120 | > ~~配置项集中到配置文件~~ 121 | > 122 | > ~~换用sqlite存储方式~~ 123 | > 124 | > ~~自动化初始脚本~~ -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "github.com/gin-gonic/gin" 7 | "gorm.io/driver/sqlite" 8 | "gorm.io/gorm" 9 | "gorm.io/gorm/logger" 10 | "net/http" 11 | "os" 12 | "path" 13 | ) 14 | 15 | type configuration struct { 16 | Port string 17 | Path string 18 | DbName string 19 | Proxy string 20 | BusUrl string 21 | } 22 | 23 | var CONF = configuration{} 24 | 25 | // 定义 图片目录 26 | var imgPath string 27 | 28 | func init() { 29 | // 读取配置文件 30 | file, _ := os.Open("conf.json") 31 | defer file.Close() 32 | decoder := json.NewDecoder(file) 33 | err := decoder.Decode(&CONF) 34 | checkErr(err) 35 | fmt.Println(CONF) 36 | 37 | appPath, _ := os.Getwd() 38 | imgPath = path.Join(appPath, CONF.Path) 39 | 40 | // 判断目录是否存在 41 | _, err = os.Stat(imgPath) 42 | if err != nil { 43 | err := os.MkdirAll(imgPath, os.ModePerm) 44 | checkErr(err) 45 | } 46 | 47 | // connection 48 | db, err := gorm.Open(sqlite.Open(CONF.DbName), &gorm.Config{}) 49 | checkErr(err) 50 | db.AutoMigrate(&fanhao{}) 51 | sqlDB, err := db.DB() 52 | if err == nil { 53 | defer sqlDB.Close() 54 | } 55 | 56 | fmt.Println("photoPath:", imgPath) 57 | fmt.Println("dataBases:",CONF.DbName) 58 | } 59 | func main() { 60 | 61 | // 设置静态资源 62 | static := &StaticResource{staticFS: WebUI, path: "static"} 63 | gin.SetMode(gin.ReleaseMode) 64 | r := gin.Default() 65 | r.Use(Cors()) 66 | 67 | r.StaticFS("/static/", http.FS(static)) 68 | r.Static("/photos/", CONF.Path) 69 | r.GET("/", handleIndex) 70 | 71 | r.GET("/api/getList", handleApiGetList) 72 | r.GET("/api/set", handleApiSet) 73 | r.GET("/api/search", handleApiSearch) 74 | r.GET("/api/del", handleApiDel) 75 | r.GET("/api/test", handleApiTest) 76 | 77 | r.GET("/ping", func(c *gin.Context) { c.JSON(200, gin.H{"message": "pong"}) }) 78 | err := r.Run(":" + CONF.Port) 79 | checkErr(err) 80 | } 81 | 82 | func main1() { 83 | //tmi := time.Unix(1492442108,0).Format("2006-01-02 15:04:05") 84 | //fmt.Println(tmi) 85 | //tmi1,_ := time.Parse("2006-01-02 15:04:05",tmi) 86 | //fmt.Println(tmi1) 87 | //fmt.Println(tmi1.Unix()) 88 | //fmt.Println(time.Now().Unix()) 89 | 90 | //db,err := gorm.Open(sqlite.Open(CONF.DbName),&gorm.Config{ 91 | // Logger: logger.Default.LogMode(logger.Info), 92 | //}) 93 | //checkErr(err) 94 | 95 | //err = db.AutoMigrate(&fanhao{}) 96 | //checkErr(err) 97 | 98 | //var fan fanhao 99 | //db.First(&fan) 100 | //fmt.Println(fan.UpdatedAt) 101 | //fan.Starnum=2 102 | //db.Save(fan) 103 | 104 | // all code 105 | //type onlyCode struct { Code string } 106 | //var codes []onlyCode 107 | //db.Model(&fanhao{}).Find(&codes) 108 | //fmt.Println(codes) 109 | 110 | //var fans []fanhao 111 | //db.Find(&fans) 112 | //fmt.Println(fans) 113 | 114 | // connection 115 | db, err := gorm.Open(sqlite.Open(CONF.DbName), &gorm.Config{ 116 | Logger: logger.Default.LogMode(logger.Info), 117 | }) 118 | checkErr(err) 119 | 120 | var fans fanhao 121 | db.First(&fans) 122 | fmt.Print(fans) 123 | } 124 | 125 | func main2() { 126 | 127 | // 关闭文件 128 | file, _ := os.Open("conf.json") 129 | defer file.Close() 130 | decoder := json.NewDecoder(file) 131 | err := decoder.Decode(&CONF) 132 | checkErr(err) 133 | fmt.Println(CONF) 134 | 135 | } 136 | 137 | func main3() { 138 | fmt.Println("123") 139 | } -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 2 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 3 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 4 | github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= 5 | github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= 6 | github.com/gin-gonic/gin v1.7.4 h1:QmUZXrvJ9qZ3GfWvQ+2wnW/1ePrTEJqPKMYEU3lD/DM= 7 | github.com/gin-gonic/gin v1.7.4/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY= 8 | github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= 9 | github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= 10 | github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= 11 | github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= 12 | github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= 13 | github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= 14 | github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE= 15 | github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4= 16 | github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I= 17 | github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= 18 | github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 19 | github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= 20 | github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= 21 | github.com/jinzhu/now v1.1.2 h1:eVKgfIdy9b6zbWBMgFpfDPoAMifwSZagU9HmEU6zgiI= 22 | github.com/jinzhu/now v1.1.2/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= 23 | github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns= 24 | github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= 25 | github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= 26 | github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= 27 | github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= 28 | github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= 29 | github.com/mattn/go-sqlite3 v1.14.8 h1:gDp86IdQsN/xWjIEmr9MF6o9mpksUgh0fu+9ByFxzIU= 30 | github.com/mattn/go-sqlite3 v1.14.8/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= 31 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= 32 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 33 | github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg= 34 | github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 35 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 36 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 37 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 38 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 39 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 40 | github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= 41 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 42 | github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= 43 | github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= 44 | github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs= 45 | github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= 46 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 47 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= 48 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 49 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 50 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 51 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 52 | golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg= 53 | golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 54 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 55 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 56 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 57 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 58 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 59 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 60 | gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= 61 | gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 62 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= 63 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 64 | gorm.io/driver/sqlite v1.1.6 h1:p3U8WXkVFTOLPED4JjrZExfndjOtya3db8w9/vEMNyI= 65 | gorm.io/driver/sqlite v1.1.6/go.mod h1:W8LmC/6UvVbHKah0+QOC7Ja66EaZXHwUTjgXY8YNWX8= 66 | gorm.io/gorm v1.21.15/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0= 67 | gorm.io/gorm v1.21.16 h1:YBIQLtP5PLfZQz59qfrq7xbrK7KWQ+JsXXCH/THlMqs= 68 | gorm.io/gorm v1.21.16/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0= 69 | -------------------------------------------------------------------------------- /main_handles.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "github.com/gin-gonic/gin" 6 | "gorm.io/driver/sqlite" 7 | "gorm.io/gorm" 8 | "io" 9 | "io/ioutil" 10 | "net/http" 11 | "os" 12 | "path" 13 | "regexp" 14 | "strconv" 15 | "strings" 16 | ) 17 | 18 | func handleIndex(c *gin.Context) { 19 | indexHTML, _ := WebUI.ReadFile("web/dist/index.html") 20 | _, err := c.Writer.Write(indexHTML) 21 | if err != nil { 22 | c.Writer.WriteHeader(http.StatusInternalServerError) 23 | } else { 24 | c.Writer.WriteHeader(http.StatusOK) 25 | } 26 | c.Writer.Header().Add("Accept", "text/html") 27 | c.Writer.Flush() 28 | } 29 | func handleApiGetList(c *gin.Context) { 30 | // connection 31 | db, err := gorm.Open(sqlite.Open(CONF.DbName), &gorm.Config{ 32 | //Logger: logger.Default.LogMode(logger.Info), 33 | }) 34 | if err != nil { 35 | c.String(http.StatusBadRequest, "failed open db") 36 | return 37 | } 38 | sqlDB, err := db.DB() 39 | if err == nil { 40 | defer sqlDB.Close() 41 | } 42 | 43 | var querys = make(map[string]interface{}) 44 | 45 | if star, ex := c.GetQuery("star"); ex { 46 | if len(star) > 0 { 47 | querys["star"] = star 48 | } 49 | } 50 | if code, ex := c.GetQuery("code"); ex { 51 | if len(code) > 0 { 52 | querys["code"] = code 53 | } 54 | } 55 | if ma, ex := c.GetQuery("ma"); ex { 56 | if len(ma) > 0 { 57 | querys["ma"] = ma 58 | } 59 | } 60 | if dn, ex := c.GetQuery("downed"); ex { 61 | if len(dn) > 0 { 62 | querys["downed"] = dn 63 | } 64 | } 65 | //fmt.Println(querys) 66 | 67 | size := 48 68 | if re, ex := c.GetQuery("size"); ex { 69 | if ai, err := strconv.Atoi(re); err == nil { 70 | size = ai 71 | } 72 | } 73 | index := 1 74 | if re, ex := c.GetQuery("index"); ex { 75 | if ai, err := strconv.Atoi(re); err == nil { 76 | index = ai 77 | } 78 | } 79 | 80 | var fans []fanhao 81 | db.Limit(size).Offset((index - 1) * size).Where(querys).Order("id desc").Find(&fans) 82 | //fmt.Print(fans) 83 | 84 | var count int64 85 | db.Model(&fanhao{}).Where(querys).Count(&count) 86 | 87 | //// all code 88 | type onlyCode struct{ Code string } 89 | var codes []onlyCode 90 | db.Model(&fanhao{}).Order("Code").Find(&codes) 91 | //fmt.Println(codes) 92 | //// all star 93 | type onlyStar struct{ Star string } 94 | var stars []onlyStar 95 | db.Model(&fanhao{}).Group("Star").Order("Star").Find(&stars) 96 | //fmt.Println(stars) 97 | 98 | c.JSON(200, gin.H{ 99 | "codes": codes, 100 | "stars": stars, 101 | "fans": fans, 102 | "size": size, 103 | "index": index, 104 | "count": count, 105 | "busurl": CONF.BusUrl, 106 | }) 107 | } 108 | func handleApiSet(c *gin.Context) { 109 | tp, has := c.GetQuery("t") 110 | if has != true { 111 | c.String(http.StatusBadRequest, "null: t") 112 | return 113 | } 114 | 115 | id, has := c.GetQuery("id") 116 | if has != true { 117 | c.String(http.StatusBadRequest, "null: id") 118 | return 119 | } 120 | iId, err := strconv.Atoi(id) 121 | if err != nil { 122 | c.String(http.StatusBadRequest, "must be number: id") 123 | return 124 | } 125 | 126 | flag, has := c.GetQuery("flag") 127 | if has != true { 128 | c.String(http.StatusBadRequest, "null: flag") 129 | return 130 | } 131 | iFlag, err := strconv.Atoi(flag) 132 | if err != nil { 133 | c.String(http.StatusBadRequest, "must be number: flag") 134 | return 135 | } 136 | 137 | // connection 138 | db, err := gorm.Open(sqlite.Open(CONF.DbName), &gorm.Config{ 139 | //Logger: logger.Default.LogMode(logger.Info), 140 | }) 141 | if err != nil { 142 | c.String(http.StatusBadRequest, "failed open db") 143 | return 144 | } 145 | sqlDB, err := db.DB() 146 | if err == nil { 147 | defer sqlDB.Close() 148 | } 149 | 150 | var fan fanhao 151 | res := db.Where("id", iId).First(&fan) 152 | if res.RowsAffected != 1 { 153 | c.String(http.StatusBadRequest, "arg err: id") 154 | return 155 | } 156 | switch tp { 157 | case "st": 158 | fan.Starnum = iFlag 159 | break 160 | case "ma": 161 | fan.Ima = iFlag 162 | case "fa": 163 | fan.Iface = iFlag 164 | case "dn": 165 | fan.Downed = iFlag 166 | } 167 | res = db.Save(&fan) 168 | 169 | //fmt.Println(res) 170 | if res.RowsAffected != 1 { 171 | c.String(http.StatusBadRequest, "update err") 172 | return 173 | } else { 174 | c.String(http.StatusOK, "ok") 175 | } 176 | 177 | } 178 | func handleApiSearch(c *gin.Context) { 179 | //-- 校验参数 180 | code, has := c.GetQuery("c") 181 | if has != true { 182 | c.String(http.StatusBadRequest, "null: c") 183 | return 184 | } 185 | code = strings.ToUpper(strings.Trim(code, " ")) 186 | url := CONF.BusUrl + code 187 | 188 | _, justUp := c.GetQuery("u") 189 | 190 | //-- 请求页面数据 191 | res, err := _request(url) 192 | if err != nil { 193 | c.String(http.StatusBadRequest, "request err") 194 | return 195 | } 196 | defer res.Body.Close() 197 | 198 | body, err := ioutil.ReadAll(res.Body) 199 | if err != nil { 200 | c.String(http.StatusBadRequest, "request read body err") 201 | return 202 | } 203 | 204 | html := string(body) 205 | 206 | //-- 解析页面数据 207 | regCode, err := regexp.Compile("識別碼:.*?(.*?)") 208 | if err != nil { 209 | c.String(http.StatusBadRequest, "failed match code") 210 | return 211 | } 212 | matchCode := regCode.FindStringSubmatch(html) 213 | 214 | regTitle, err := regexp.Compile("

(.*?)

") 215 | if err != nil { 216 | c.String(http.StatusBadRequest, "failed match title") 217 | return 218 | } 219 | matchTitle := regTitle.FindStringSubmatch(html) 220 | 221 | regStar, err := regexp.Compile("
(.*?)
") 222 | if err != nil { 223 | c.String(http.StatusBadRequest, "failed match star") 224 | return 225 | } 226 | matchStar := regStar.FindStringSubmatch(html) 227 | 228 | regStarCode, err := regexp.Compile("
.*?
") 229 | if err != nil { 230 | c.String(http.StatusBadRequest, "failed match starcode") 231 | return 232 | } 233 | matchStarCode := regStarCode.FindStringSubmatch(html) 234 | 235 | regImg, err := regexp.Compile("") 236 | if err != nil { 237 | c.String(http.StatusBadRequest, "failed match img") 238 | return 239 | } 240 | matchImg := regImg.FindStringSubmatch(html) 241 | 242 | // connection 243 | db, err := gorm.Open(sqlite.Open(CONF.DbName), &gorm.Config{ 244 | //Logger: logger.Default.LogMode(logger.Info), 245 | }) 246 | if err != nil { 247 | c.String(http.StatusBadRequest, "failed open db") 248 | return 249 | } 250 | sqlDB, err := db.DB() 251 | if err == nil { 252 | defer sqlDB.Close() 253 | } 254 | 255 | //-- 查询数据 256 | var fan fanhao 257 | dbGetRes := db.Where("Code", code).First(&fan) 258 | 259 | if !justUp && dbGetRes.RowsAffected == 1 { 260 | c.String(http.StatusOK, "has") 261 | return 262 | } 263 | 264 | if len(matchCode) > 1 { 265 | fan.Code = matchCode[1] 266 | } 267 | if len(matchTitle) > 1 { 268 | fan.Title = matchTitle[1] 269 | } 270 | if len(matchStar) > 1 { 271 | fan.Star = matchStar[1] 272 | } else { 273 | fan.Star = "-暂无-" 274 | } 275 | if len(matchStarCode) > 1 { 276 | fan.StarCode = matchStarCode[1] 277 | } 278 | if len(matchImg) > 1 { 279 | fan.Img = matchImg[1] 280 | } 281 | fan.Fname = fan.Code + ".jpg" 282 | 283 | dbSaveRes := db.Save(&fan) 284 | 285 | if dbSaveRes.RowsAffected != 1 { 286 | c.String(http.StatusBadRequest, "update err") 287 | return 288 | } 289 | 290 | // 开始保存图片 291 | imgUrl := CONF.BusUrl + fan.Img 292 | resImg, err := _request(imgUrl) 293 | if err != nil { 294 | c.String(http.StatusBadRequest, "request img err") 295 | return 296 | } 297 | defer resImg.Body.Close() 298 | imgBody, err := ioutil.ReadAll(resImg.Body) 299 | checkErr(err) 300 | if err != nil { 301 | c.String(http.StatusBadRequest, "request img read err") 302 | return 303 | } 304 | 305 | fPath := path.Join(CONF.Path, fan.Fname) 306 | file, err := os.Create(fPath) 307 | defer file.Close() 308 | if err != nil { 309 | c.String(http.StatusBadRequest, "request img create err") 310 | return 311 | } 312 | _, err = io.Copy(file, bytes.NewReader(imgBody)) 313 | if err != nil { 314 | c.String(http.StatusBadRequest, "request img save err") 315 | return 316 | } 317 | 318 | c.String(http.StatusOK, "ok") 319 | 320 | } 321 | func handleApiDel(c *gin.Context) { 322 | 323 | id, has := c.GetQuery("qazxsw") 324 | if has != true { 325 | c.String(http.StatusBadRequest, "null: id") 326 | return 327 | } 328 | iId, err := strconv.Atoi(id) 329 | if err != nil { 330 | c.String(http.StatusBadRequest, "must be number: id") 331 | return 332 | } 333 | 334 | // connection 335 | db, err := gorm.Open(sqlite.Open(CONF.DbName), &gorm.Config{ 336 | //Logger: logger.Default.LogMode(logger.Info), 337 | }) 338 | if err != nil { 339 | c.String(http.StatusBadRequest, "failed open db") 340 | return 341 | } 342 | sqlDB, err := db.DB() 343 | if err == nil { 344 | defer sqlDB.Close() 345 | } 346 | 347 | dbDelRes := db.Delete(&fanhao{}, iId) 348 | 349 | c.String(http.StatusOK, string(dbDelRes.RowsAffected)) 350 | 351 | } 352 | func handleApiTest(c *gin.Context) { 353 | // connection 354 | db, err := gorm.Open(sqlite.Open(CONF.DbName), &gorm.Config{ 355 | //Logger: logger.Default.LogMode(logger.Info), 356 | }) 357 | if err != nil { 358 | c.String(http.StatusBadRequest, "failed open db") 359 | return 360 | } 361 | sqlDB, err := db.DB() 362 | if err == nil { 363 | defer sqlDB.Close() 364 | } 365 | 366 | var fans fanhao 367 | db.First(&fans) 368 | //fmt.Print(fans) 369 | 370 | c.JSON(200, gin.H{ 371 | "fans": fans, 372 | }) 373 | } 374 | -------------------------------------------------------------------------------- /web/src/App.vue: -------------------------------------------------------------------------------- 1 | 97 | 98 | 272 | 273 | 354 | --------------------------------------------------------------------------------