Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions cmd/main/main.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
package main

import (
"github.com/alexflint/go-arg"
"log"
"os"
"path/filepath"
"torrsru/db"
"torrsru/global"
"torrsru/tgbot"
"torrsru/web"

"github.com/alexflint/go-arg"
)

func main() {
var args struct {
Port string `default:"8094" arg:"-p" help:"port for http"`
RebuildIndex bool `default:"false" arg:"-r" help:"rebuild index and exit"`
TMDBProxy bool `default:"false" arg:"--tmdb" help:"proxy for TMDB"`
TGBotToken string `default:"" arg:"--token" help:"telegram bot token"`
TGHost string `default:"http://127.0.0.1:8081" arg:"--tgapi" help:"telegram api host"`
TSHost string `default:"http://127.0.0.1:8090" arg:"--ts" help:"TorrServer host"`
TMDBProxy bool `default:"false" arg:"--tmdb,env:TMDB_PROXY" help:"proxy for TMDB"`
Port string `default:"8094" arg:"-p,env:PORT" help:"port for http"`
TGBotToken string `default:"" arg:"--token,env:TG_TOKEN" help:"telegram bot token"`
TGHost string `default:"http://127.0.0.1:8081" arg:"--tgapi,env:TG_HOST" help:"telegram api host"`
TSHost string `default:"http://127.0.0.1:8090" arg:"--ts,env:TS_HOST" help:"TorrServer host"`
DBHost string `default:"http://62.112.8.193:9117" arg:"--db,env:DB_HOST" help:"External sync database host"`
DBSync int `default:"20" arg:"--db-sync,env:DB_SYNC" help:"External database sync delay"`
DBSyncRetry int `default:"10" arg:"--db-sync-retry,env:DB_SYNC_RETRY" help:"External database sync retry"`
}
arg.MustParse(&args)

Expand All @@ -30,6 +34,10 @@ func main() {
global.TMDBProxy = args.TMDBProxy
global.TSHost = args.TSHost

global.DBHost = args.DBHost
global.DBSync = args.DBSync
global.DBSyncRetry = args.DBSyncRetry

db.Init()

if args.RebuildIndex {
Expand Down
12 changes: 7 additions & 5 deletions db/dbsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ var (
func StartSync() {
for !global.Stopped {
syncDB()
time.Sleep(time.Minute * 20)
time.Sleep(time.Minute * time.Duration(global.DBSync))
}
}

func syncDB() {
log.Println("Starting datbase sync from:", global.DBHost)

mu.Lock()
if isSync {
mu.Unlock()
Expand All @@ -44,11 +46,11 @@ func syncDB() {
ftstr := strconv.FormatInt(filetime, 10)
t := time.Unix(ft2sec(filetime), 0)
log.Println("Fetch:", t.Format("2006-01-02 15:04:05"))
resp, err := http.Get("http://62.112.8.193:9117/sync/fdb/torrents?time=" + ftstr)
resp, err := http.Get(global.DBHost + "/sync/fdb/torrents?time=" + ftstr)
if err != nil {
log.Println("Error connect to fdb:", err)
log.Println("Waiting 10 minutes before retrying...")
time.Sleep(time.Minute * 10)
log.Printf("Error connect to fdb(%s): %s\n", global.DBHost, err)
log.Printf("Waiting %d minutes before retrying...\n", global.DBSyncRetry)
time.Sleep(time.Minute * time.Duration(global.DBSync))
continue
}

Expand Down
4 changes: 4 additions & 0 deletions global/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ var (
TMDBProxy = false
TSHost = ""

DBHost = ""
DBSync = 20
DBSyncRetry = 10

SendFromWeb func(initData, msg string) error
)
2 changes: 1 addition & 1 deletion web/static/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func RouteStaticFiles(route *gin.Engine) {
etag := fmt.Sprintf("%x", md5.Sum(Filesimgbrowserconfigxml))
c.Header("Cache-Control", "public, max-age=31536000")
c.Header("ETag", etag)
c.Data(200, "application/xml; charset=utf-8", Filesimgbrowserconfigxml)
c.Data(200, "text/xml; charset=utf-8", Filesimgbrowserconfigxml)
})

route.GET("/img/copy.svg", func(c *gin.Context) {
Expand Down