This commit is contained in:
Nite07 2024-12-26 21:09:00 +08:00
parent 45f7eff8b1
commit 2553a35a4a
74 changed files with 189 additions and 199 deletions

View File

@ -17,7 +17,7 @@ jobs:
uses: docker/metadata-action@v5 uses: docker/metadata-action@v5
with: with:
images: | images: |
nite07/pcgamedb nite07/game-crawler
tags: | tags: |
type=semver,pattern={{version}} type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}} type=semver,pattern={{major}}.{{minor}}

View File

@ -1,4 +1,4 @@
project_name: pcgamedb project_name: game-crawler
before: before:
hooks: hooks:
- go install github.com/swaggo/swag/cmd/swag@latest - go install github.com/swaggo/swag/cmd/swag@latest
@ -16,7 +16,7 @@ builds:
- arm - arm
- "386" - "386"
ldflags: ldflags:
- -s -w -X pcgamedb/constant.Version={{ .Version }} - -s -w -X game-crawler/constant.Version={{ .Version }}
flags: flags:
- -trimpath - -trimpath
archives: archives:

View File

@ -14,10 +14,10 @@ ARG version=dev
RUN if [ "$version" = "dev" ]; then \ RUN if [ "$version" = "dev" ]; then \
version=$(git describe --tags --always); \ version=$(git describe --tags --always); \
fi && \ fi && \
CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w -X pcgamedb/constant.Version=${version}" -o pcgamedb . CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w -X game-crawler/constant.Version=${version}" -o game-crawler .
FROM alpine:latest FROM alpine:latest
WORKDIR /app WORKDIR /app
COPY --from=builder /app/pcgamedb /app/pcgamedb COPY --from=builder /app/game-crawler /app/game-crawler
ENTRYPOINT ["/app/pcgamedb", "server"] ENTRYPOINT ["/app/game-crawler", "server"]

View File

@ -1,6 +1,6 @@
# pcgamedb # game-crawler
pcgamedb is a powerful command-line tool designed to scrape and manage repack game data from various online sources. With support for multiple data sources and the ability to provide a RESTful API. game-crawler is a powerful command-line tool designed to scrape and manage repack game data from various online sources. With support for multiple data sources and the ability to provide a RESTful API.
## Features ## Features

View File

@ -1,4 +1,4 @@
go install github.com/swaggo/swag/cmd/swag@latest go install github.com/swaggo/swag/cmd/swag@latest
swag init swag init
CGO_ENABLED=0 CGO_ENABLED=0
go build -o pcgamedb -ldflags "-s -w -X pcgamedb/constant.Version=$(git describe --tags --always)" . go build -o game-crawler -ldflags "-s -w -X game-crawler/constant.Version=$(git describe --tags --always)" .

4
cache/redis.go vendored
View File

@ -6,8 +6,8 @@ import (
"sync" "sync"
"time" "time"
"pcgamedb/config" "game-crawler/config"
"pcgamedb/log" "game-crawler/log"
"github.com/redis/go-redis/v9" "github.com/redis/go-redis/v9"
) )

View File

@ -1,8 +1,8 @@
package cmd package cmd
import ( import (
"pcgamedb/log" "game-crawler/log"
"pcgamedb/task" "game-crawler/task"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )

View File

@ -6,9 +6,9 @@ import (
"strconv" "strconv"
"strings" "strings"
"pcgamedb/crawler" "game-crawler/crawler"
"pcgamedb/log" "game-crawler/log"
"pcgamedb/utils" "game-crawler/utils"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"go.uber.org/zap" "go.uber.org/zap"

View File

@ -4,9 +4,9 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"game-crawler/db"
"game-crawler/log"
"go.uber.org/zap" "go.uber.org/zap"
"pcgamedb/db"
"pcgamedb/log"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )

View File

@ -1,10 +1,10 @@
package cmd package cmd
import ( import (
"game-crawler/db"
"game-crawler/log"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"go.uber.org/zap" "go.uber.org/zap"
"pcgamedb/db"
"pcgamedb/log"
) )
type importCommandConfig struct { type importCommandConfig struct {

View File

@ -1,8 +1,8 @@
package cmd package cmd
import ( import (
"pcgamedb/db" "game-crawler/db"
"pcgamedb/log" "game-crawler/log"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"go.uber.org/zap" "go.uber.org/zap"

View File

@ -1,9 +1,9 @@
package cmd package cmd
import ( import (
"pcgamedb/crawler" "game-crawler/crawler"
"pcgamedb/db" "game-crawler/db"
"pcgamedb/log" "game-crawler/log"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"go.uber.org/zap" "go.uber.org/zap"

View File

@ -4,9 +4,9 @@ import (
"encoding/json" "encoding/json"
"os" "os"
"pcgamedb/crawler" "game-crawler/crawler"
"pcgamedb/db" "game-crawler/db"
"pcgamedb/log" "game-crawler/log"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/bson/primitive"

View File

@ -1,8 +1,8 @@
package cmd package cmd
import ( import (
"pcgamedb/config" "game-crawler/config"
"pcgamedb/server" "game-crawler/server"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )

View File

@ -1,9 +1,9 @@
package cmd package cmd
import ( import (
"game-crawler/crawler"
"game-crawler/log"
"go.uber.org/zap" "go.uber.org/zap"
"pcgamedb/crawler"
"pcgamedb/log"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )

View File

@ -1,8 +1,8 @@
package cmd package cmd
import ( import (
"pcgamedb/log" "game-crawler/log"
"pcgamedb/task" "game-crawler/task"
"github.com/robfig/cron/v3" "github.com/robfig/cron/v3"
"github.com/spf13/cobra" "github.com/spf13/cobra"

View File

@ -4,15 +4,15 @@ import (
"fmt" "fmt"
"runtime" "runtime"
"pcgamedb/constant" "game-crawler/constant"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var versionCmd = &cobra.Command{ var versionCmd = &cobra.Command{
Use: "version", Use: "version",
Long: "Get version of pcgamedb", Long: "Get version of game-crawler",
Short: "Get version of pcgamedb", Short: "Get version of game-crawler",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Version: %s\n", constant.Version) fmt.Printf("Version: %s\n", constant.Version)
fmt.Printf("Go: %s\n", runtime.Version()) fmt.Printf("Go: %s\n", runtime.Version())

View File

@ -8,10 +8,10 @@ import (
"strconv" "strconv"
"strings" "strings"
"pcgamedb/constant" "game-crawler/constant"
"pcgamedb/db" "game-crawler/db"
"pcgamedb/model" "game-crawler/model"
"pcgamedb/utils" "game-crawler/utils"
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
"go.uber.org/zap" "go.uber.org/zap"

View File

@ -2,15 +2,16 @@ package crawler
import ( import (
"bytes" "bytes"
"encoding/base64"
"errors" "errors"
"fmt" "fmt"
"strconv" "strconv"
"strings" "strings"
"pcgamedb/constant" "game-crawler/constant"
"pcgamedb/db" "game-crawler/db"
"pcgamedb/model" "game-crawler/model"
"pcgamedb/utils" "game-crawler/utils"
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
"go.uber.org/zap" "go.uber.org/zap"
@ -47,7 +48,6 @@ func (c *ChovkaCrawler) CrawlByUrl(URL string) (*model.GameItem, error) {
item.RawName = doc.Find(".inner-entry__title").First().Text() item.RawName = doc.Find(".inner-entry__title").First().Text()
item.Name = ChovkaFormatter(item.RawName) item.Name = ChovkaFormatter(item.RawName)
item.Author = "Chovka" item.Author = "Chovka"
item.UpdateFlag = item.RawName
item.Platform = "windows" item.Platform = "windows"
downloadURL := doc.Find(".download-torrent").AttrOr("href", "") downloadURL := doc.Find(".download-torrent").AttrOr("href", "")
if downloadURL == "" { if downloadURL == "" {
@ -83,7 +83,7 @@ func (c *ChovkaCrawler) Crawl(page int) ([]*model.GameItem, error) {
return return
} }
urls = append(urls, u) urls = append(urls, u)
updateFlags = append(updateFlags, s.Find(".entry__title.h2 a").Text()) updateFlags = append(updateFlags, base64.StdEncoding.EncodeToString([]byte(s.Find(".entry__title.h2 a").Text())))
}) })
var res []*model.GameItem var res []*model.GameItem
for i, u := range urls { for i, u := range urls {
@ -96,6 +96,7 @@ func (c *ChovkaCrawler) Crawl(page int) ([]*model.GameItem, error) {
c.logger.Warn("Failed to crawl", zap.Error(err), zap.String("URL", u)) c.logger.Warn("Failed to crawl", zap.Error(err), zap.String("URL", u))
continue continue
} }
item.UpdateFlag = updateFlags[i]
if err := db.SaveGameItem(item); err != nil { if err := db.SaveGameItem(item); err != nil {
c.logger.Warn("Failed to save", zap.Error(err), zap.String("URL", u)) c.logger.Warn("Failed to save", zap.Error(err), zap.String("URL", u))
continue continue

View File

@ -1,7 +1,7 @@
package crawler package crawler
import ( import (
"pcgamedb/model" "game-crawler/model"
"go.uber.org/zap" "go.uber.org/zap"
) )

View File

@ -4,8 +4,8 @@ import (
"regexp" "regexp"
"strings" "strings"
"pcgamedb/model" "game-crawler/model"
"pcgamedb/utils" "game-crawler/utils"
"go.uber.org/zap" "go.uber.org/zap"
) )

View File

@ -2,16 +2,17 @@ package crawler
import ( import (
"bytes" "bytes"
"encoding/base64"
"errors" "errors"
"fmt" "fmt"
"regexp" "regexp"
"strconv" "strconv"
"strings" "strings"
"pcgamedb/constant" "game-crawler/constant"
"pcgamedb/db" "game-crawler/db"
"pcgamedb/model" "game-crawler/model"
"pcgamedb/utils" "game-crawler/utils"
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
"go.uber.org/zap" "go.uber.org/zap"
@ -91,7 +92,7 @@ func (c *FitGirlCrawler) Crawl(page int) ([]*model.GameItem, error) {
d, exist2 := s.Find("time").First().Attr("datetime") d, exist2 := s.Find("time").First().Attr("datetime")
if exist1 && exist2 { if exist1 && exist2 {
urls = append(urls, u) urls = append(urls, u)
updateFlags = append(updateFlags, fmt.Sprintf("%s%s", u, d)) updateFlags = append(updateFlags, base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s%s", u, d))))
} }
}) })
var res []*model.GameItem var res []*model.GameItem

View File

@ -11,11 +11,11 @@ import (
"strings" "strings"
"time" "time"
"pcgamedb/cache" "game-crawler/cache"
"pcgamedb/config" "game-crawler/config"
"pcgamedb/constant" "game-crawler/constant"
"pcgamedb/db" "game-crawler/db"
"pcgamedb/model" "game-crawler/model"
"git.nite07.com/nite/ccs" "git.nite07.com/nite/ccs"
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
@ -79,7 +79,7 @@ func (c *FreeGOGCrawler) Crawl(num int) ([]*model.GameItem, error) {
var updateFlags []string //rawName+link var updateFlags []string //rawName+link
doc.Find(".items-outer li a").Each(func(i int, s *goquery.Selection) { doc.Find(".items-outer li a").Each(func(i int, s *goquery.Selection) {
urls = append(urls, s.AttrOr("href", "")) urls = append(urls, s.AttrOr("href", ""))
updateFlags = append(updateFlags, s.Text()+s.AttrOr("href", "")) updateFlags = append(updateFlags, base64.StdEncoding.EncodeToString([]byte(s.Text()+s.AttrOr("href", ""))))
}) })
var res []*model.GameItem var res []*model.GameItem

View File

@ -6,9 +6,9 @@ import (
"strings" "strings"
"time" "time"
"pcgamedb/db" "game-crawler/db"
"pcgamedb/model" "game-crawler/model"
"pcgamedb/utils" "game-crawler/utils"
"go.uber.org/zap" "go.uber.org/zap"

View File

@ -1,17 +1,18 @@
package crawler package crawler
import ( import (
"encoding/base64"
"encoding/json" "encoding/json"
"fmt" "fmt"
"path" "path"
"strings" "strings"
"time" "time"
"pcgamedb/config" "game-crawler/config"
"pcgamedb/constant" "game-crawler/constant"
"pcgamedb/db" "game-crawler/db"
"pcgamedb/model" "game-crawler/model"
"pcgamedb/utils" "game-crawler/utils"
"git.nite07.com/nite/ccs" "git.nite07.com/nite/ccs"
"go.uber.org/zap" "go.uber.org/zap"
@ -116,7 +117,7 @@ func (c *GOGGamesCrawler) Crawl(page int) ([]*model.GameItem, error) {
var updateFlags []string //link+date var updateFlags []string //link+date
for _, item := range data.Data { for _, item := range data.Data {
urls = append(urls, fmt.Sprintf(constant.GOGGamesPageURL, item.Slug)) urls = append(urls, fmt.Sprintf(constant.GOGGamesPageURL, item.Slug))
updateFlags = append(updateFlags, fmt.Sprintf("%s%s", item.GogURL, item.LastUpdate)) updateFlags = append(updateFlags, base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s%s", item.GogURL, item.LastUpdate))))
} }
res := make([]*model.GameItem, 0) res := make([]*model.GameItem, 0)
for i, u := range urls { for i, u := range urls {
@ -130,12 +131,6 @@ func (c *GOGGamesCrawler) Crawl(page int) ([]*model.GameItem, error) {
continue continue
} }
item.UpdateFlag = updateFlags[i] item.UpdateFlag = updateFlags[i]
oldItem, err := db.GetGameItemByUrl(u)
if err == nil {
db.MergeGameItem(oldItem, item)
}
if err := db.SaveGameItem(item); err != nil { if err := db.SaveGameItem(item); err != nil {
c.logger.Warn("Failed to save", zap.Error(err), zap.String("URL", u)) c.logger.Warn("Failed to save", zap.Error(err), zap.String("URL", u))
continue continue

View File

@ -11,12 +11,12 @@ import (
"strings" "strings"
"time" "time"
"pcgamedb/cache" "game-crawler/cache"
"pcgamedb/config" "game-crawler/config"
"pcgamedb/constant" "game-crawler/constant"
"pcgamedb/db" "game-crawler/db"
"pcgamedb/model" "game-crawler/model"
"pcgamedb/utils" "game-crawler/utils"
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"

View File

@ -4,7 +4,7 @@ import (
"regexp" "regexp"
"strings" "strings"
"pcgamedb/model" "game-crawler/model"
"go.uber.org/zap" "go.uber.org/zap"
) )

View File

@ -4,7 +4,7 @@ import (
"regexp" "regexp"
"strings" "strings"
"pcgamedb/model" "game-crawler/model"
"go.uber.org/zap" "go.uber.org/zap"
) )

View File

@ -2,6 +2,7 @@ package crawler
import ( import (
"bytes" "bytes"
"encoding/base64"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
@ -13,12 +14,12 @@ import (
"strings" "strings"
"time" "time"
"pcgamedb/cache" "game-crawler/cache"
"pcgamedb/config" "game-crawler/config"
"pcgamedb/constant" "game-crawler/constant"
"pcgamedb/db" "game-crawler/db"
"pcgamedb/model" "game-crawler/model"
"pcgamedb/utils" "game-crawler/utils"
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
"go.uber.org/zap" "go.uber.org/zap"
@ -61,8 +62,7 @@ func (c *OnlineFixCrawler) Crawl(page int) ([]*model.GameItem, error) {
urls = append(urls, s.Find(".big-link").First().AttrOr("href", "")) urls = append(urls, s.Find(".big-link").First().AttrOr("href", ""))
updateFlags = append( updateFlags = append(
updateFlags, updateFlags,
s.Find(".big-link").First().AttrOr("href", "")+ base64.StdEncoding.EncodeToString([]byte(s.Find(".big-link").First().AttrOr("href", "")+s.Find("time").Text())),
s.Find("time").Text(),
) )
}) })

View File

@ -9,10 +9,10 @@ import (
"strconv" "strconv"
"strings" "strings"
"pcgamedb/cache" "game-crawler/cache"
"pcgamedb/constant" "game-crawler/constant"
"pcgamedb/model" "game-crawler/model"
"pcgamedb/utils" "game-crawler/utils"
) )
func GetSteamAppDetail(id int) (*model.SteamAppDetail, error) { func GetSteamAppDetail(id int) (*model.SteamAppDetail, error) {

View File

@ -4,16 +4,16 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"game-crawler/cache"
"game-crawler/db"
"net/url" "net/url"
"pcgamedb/cache"
"pcgamedb/db"
"regexp" "regexp"
"strconv" "strconv"
"time" "time"
"pcgamedb/constant" "game-crawler/constant"
"pcgamedb/model" "game-crawler/model"
"pcgamedb/utils" "game-crawler/utils"
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
) )

View File

@ -2,15 +2,16 @@ package crawler
import ( import (
"bytes" "bytes"
"encoding/base64"
"errors" "errors"
"fmt" "fmt"
"regexp" "regexp"
"strings" "strings"
"pcgamedb/constant" "game-crawler/constant"
"pcgamedb/db" "game-crawler/db"
"pcgamedb/model" "game-crawler/model"
"pcgamedb/utils" "game-crawler/utils"
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
"go.uber.org/zap" "go.uber.org/zap"
@ -98,7 +99,7 @@ func (c *SteamRIPCrawler) Crawl(num int) ([]*model.GameItem, error) {
return return
} }
urls = append(urls, fmt.Sprintf("%s%s", constant.SteamRIPBaseURL, u)) urls = append(urls, fmt.Sprintf("%s%s", constant.SteamRIPBaseURL, u))
updateFlags = append(updateFlags, s.Text()) updateFlags = append(updateFlags, base64.StdEncoding.EncodeToString([]byte(s.Text())))
}) })
for i, u := range urls { for i, u := range urls {
if count == num { if count == num {
@ -114,12 +115,6 @@ func (c *SteamRIPCrawler) Crawl(num int) ([]*model.GameItem, error) {
continue continue
} }
item.UpdateFlag = updateFlags[i] item.UpdateFlag = updateFlags[i]
oldItem, err := db.GetGameItemByUrl(u)
if err == nil {
db.MergeGameItem(oldItem, item)
}
if err := db.SaveGameItem(item); err != nil { if err := db.SaveGameItem(item); err != nil {
c.logger.Warn("Failed to save item", zap.Error(err)) c.logger.Warn("Failed to save item", zap.Error(err))
continue continue

View File

@ -2,16 +2,17 @@ package crawler
import ( import (
"bytes" "bytes"
"encoding/base64"
"errors" "errors"
"fmt" "fmt"
"regexp" "regexp"
"strconv" "strconv"
"strings" "strings"
"pcgamedb/constant" "game-crawler/constant"
"pcgamedb/db" "game-crawler/db"
"pcgamedb/model" "game-crawler/model"
"pcgamedb/utils" "game-crawler/utils"
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
"go.uber.org/zap" "go.uber.org/zap"
@ -51,7 +52,7 @@ func (c *XatabCrawler) Crawl(page int) ([]*model.GameItem, error) {
return return
} }
urls = append(urls, u) urls = append(urls, u)
updateFlags = append(updateFlags, s.Find(".entry__title.h2 a").Text()) updateFlags = append(updateFlags, base64.StdEncoding.EncodeToString([]byte(s.Find(".entry__title.h2 a").Text())))
}) })
var res []*model.GameItem var res []*model.GameItem
for i, u := range urls { for i, u := range urls {
@ -64,6 +65,7 @@ func (c *XatabCrawler) Crawl(page int) ([]*model.GameItem, error) {
c.logger.Warn("Failed to crawl", zap.Error(err), zap.String("URL", u)) c.logger.Warn("Failed to crawl", zap.Error(err), zap.String("URL", u))
continue continue
} }
item.UpdateFlag = updateFlags[i]
err = db.SaveGameItem(item) err = db.SaveGameItem(item)
if err != nil { if err != nil {
c.logger.Warn("Failed to save", zap.Error(err)) c.logger.Warn("Failed to save", zap.Error(err))
@ -95,7 +97,6 @@ func (c *XatabCrawler) CrawlByUrl(URL string) (*model.GameItem, error) {
item.RawName = doc.Find(".inner-entry__title").First().Text() item.RawName = doc.Find(".inner-entry__title").First().Text()
item.Name = XatabFormatter(item.RawName) item.Name = XatabFormatter(item.RawName)
item.Author = "Xatab" item.Author = "Xatab"
item.UpdateFlag = item.RawName
item.Platform = "windows" item.Platform = "windows"
downloadURL := doc.Find("#download>a").First().AttrOr("href", "") downloadURL := doc.Find("#download>a").First().AttrOr("href", "")
if downloadURL == "" { if downloadURL == "" {

View File

@ -1,7 +1,7 @@
package db package db
import ( import (
"pcgamedb/model" "game-crawler/model"
) )
func GetDODIGameItems() ([]*model.GameItem, error) { func GetDODIGameItems() ([]*model.GameItem, error) {

View File

@ -1,6 +1,6 @@
package db package db
import "pcgamedb/model" import "game-crawler/model"
func IsARMGDDNCrawled(flag string) bool { func IsARMGDDNCrawled(flag string) bool {
return IsGameCrawled(flag, "armgddn") return IsGameCrawled(flag, "armgddn")

View File

@ -3,7 +3,7 @@ package db
import ( import (
"context" "context"
"pcgamedb/config" "game-crawler/config"
"go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options" "go.mongodb.org/mongo-driver/mongo/options"

View File

@ -6,8 +6,8 @@ import (
"sync" "sync"
"time" "time"
"pcgamedb/config" "game-crawler/config"
"pcgamedb/log" "game-crawler/log"
"go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo"

View File

@ -5,8 +5,8 @@ import (
"encoding/json" "encoding/json"
"time" "time"
"game-crawler/model"
"go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson"
"pcgamedb/model"
) )
func Export() ([]byte, []byte, error) { func Export() ([]byte, []byte, error) {

View File

@ -1,6 +1,6 @@
package db package db
import "pcgamedb/model" import "game-crawler/model"
func GetFitgirlAllGameItems() ([]*model.GameItem, error) { func GetFitgirlAllGameItems() ([]*model.GameItem, error) {
return GetGameItemsByAuthor("fitgirl") return GetGameItemsByAuthor("fitgirl")

View File

@ -1,7 +1,7 @@
package db package db
import ( import (
"pcgamedb/model" "game-crawler/model"
) )
func GetFreeGOGGameItems() ([]*model.GameItem, error) { func GetFreeGOGGameItems() ([]*model.GameItem, error) {

View File

@ -5,13 +5,13 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"pcgamedb/utils" "game-crawler/utils"
"regexp" "regexp"
"strings" "strings"
"time" "time"
"pcgamedb/cache" "game-crawler/cache"
"pcgamedb/model" "game-crawler/model"
"go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/bson/primitive"

View File

@ -5,7 +5,7 @@ import (
"encoding/json" "encoding/json"
"os" "os"
"pcgamedb/model" "game-crawler/model"
) )
func ImportGameInfo(filePath string) error { func ImportGameInfo(filePath string) error {

View File

@ -1,7 +1,7 @@
package db package db
import ( import (
"pcgamedb/model" "game-crawler/model"
) )
func GetOnlineFixGameItems() ([]*model.GameItem, error) { func GetOnlineFixGameItems() ([]*model.GameItem, error) {

View File

@ -1,7 +1,7 @@
package db package db
import ( import (
"pcgamedb/model" "game-crawler/model"
) )
func GetXatabGameItems() ([]*model.GameItem, error) { func GetXatabGameItems() ([]*model.GameItem, error) {

View File

@ -1,22 +1,22 @@
services: services:
pcgamedb: game-crawler:
image: nite07/pcgamedb image: nite07/game-crawler
restart: unless-stopped restart: unless-stopped
ports: ports:
- "8080:8080" - "8080:8080"
environment: environment:
- LOG_LEVEL=info - LOG_LEVEL=info
- SERVER_PORT=8080 - SERVER_PORT=8080
- DATABASE_HOST=pcgamedb-mongodb - DATABASE_HOST=game-crawler-mongodb
- DATABASE_PORT=27017 - DATABASE_PORT=27017
- DATABASE_USER=root - DATABASE_USER=root
- DATABASE_PASSWORD=password - DATABASE_PASSWORD=password
- DATABASE_NAME=pcgamedb - DATABASE_NAME=game-crawler
- REDIS_HOST=pcgamedb-redis - REDIS_HOST=game-crawler-redis
- REDIS_PORT=6379 - REDIS_PORT=6379
- REDIS_DB=0 - REDIS_DB=0
# Read more about environment variables: config/config.go # Read more about environment variables: config/config.go
pcgamedb-mongodb: game-crawler-mongodb:
image: mongo:latest image: mongo:latest
restart: unless-stopped restart: unless-stopped
environment: environment:
@ -24,7 +24,7 @@ services:
MONGO_INITDB_ROOT_PASSWORD: password MONGO_INITDB_ROOT_PASSWORD: password
volumes: volumes:
- ./mongodb:/data/db - ./mongodb:/data/db
pcgamedb-redis: game-crawler-redis:
image: redis:latest image: redis:latest
volumes: volumes:
- ./redis:/data - ./redis:/data

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
go.mod
View File

@ -1,4 +1,4 @@
module pcgamedb module game-crawler
go 1.23.3 go 1.23.3

View File

@ -4,7 +4,7 @@ import (
"os" "os"
"strings" "strings"
"pcgamedb/config" "game-crawler/config"
"go.uber.org/zap" "go.uber.org/zap"
"go.uber.org/zap/zapcore" "go.uber.org/zap/zapcore"

View File

@ -3,8 +3,8 @@ package main
import ( import (
"strings" "strings"
"pcgamedb/cmd" "game-crawler/cmd"
"pcgamedb/log" "game-crawler/log"
"go.uber.org/zap" "go.uber.org/zap"
) )

View File

@ -50,7 +50,7 @@ type GameItem struct {
Password string `json:"password,omitempty" bson:"password"` Password string `json:"password,omitempty" bson:"password"`
Author string `json:"author,omitempty" bson:"author"` Author string `json:"author,omitempty" bson:"author"`
Platform string `json:"platform,omitempty" bson:"platform"` Platform string `json:"platform,omitempty" bson:"platform"`
UpdateFlag string `json:"-" bson:"update_flag,omitempty"` UpdateFlag string `json:"update_flag,omitempty" bson:"update_flag"`
CreatedAt time.Time `json:"created_at" bson:"created_at"` CreatedAt time.Time `json:"created_at" bson:"created_at"`
UpdatedAt time.Time `json:"updated_at" bson:"updated_at"` UpdatedAt time.Time `json:"updated_at" bson:"updated_at"`
} }

View File

@ -3,8 +3,8 @@ package handler
import ( import (
"net/http" "net/http"
"pcgamedb/log" "game-crawler/log"
"pcgamedb/task" "game-crawler/task"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

View File

@ -3,7 +3,7 @@ package handler
import ( import (
"net/http" "net/http"
"pcgamedb/db" "game-crawler/db"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/bson/primitive"

View File

@ -3,7 +3,7 @@ package handler
import ( import (
"net/http" "net/http"
"pcgamedb/db" "game-crawler/db"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

View File

@ -3,8 +3,8 @@ package handler
import ( import (
"net/http" "net/http"
"pcgamedb/db" "game-crawler/db"
"pcgamedb/model" "game-crawler/model"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

View File

@ -3,8 +3,8 @@ package handler
import ( import (
"net/http" "net/http"
"pcgamedb/db" "game-crawler/db"
"pcgamedb/model" "game-crawler/model"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/bson/primitive"

View File

@ -3,8 +3,8 @@ package handler
import ( import (
"net/http" "net/http"
"pcgamedb/db" "game-crawler/db"
"pcgamedb/model" "game-crawler/model"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo"

View File

@ -3,8 +3,8 @@ package handler
import ( import (
"net/http" "net/http"
"pcgamedb/db" "game-crawler/db"
"pcgamedb/model" "game-crawler/model"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/bson/primitive"

View File

@ -3,8 +3,8 @@ package handler
import ( import (
"net/http" "net/http"
"pcgamedb/db" "game-crawler/db"
"pcgamedb/model" "game-crawler/model"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo"

View File

@ -3,8 +3,8 @@ package handler
import ( import (
"net/http" "net/http"
"pcgamedb/db" "game-crawler/db"
"pcgamedb/model" "game-crawler/model"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

View File

@ -1,10 +1,10 @@
package handler package handler
import ( import (
"game-crawler/crawler"
"game-crawler/db"
"game-crawler/model"
"net/http" "net/http"
"pcgamedb/crawler"
"pcgamedb/db"
"pcgamedb/model"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

View File

@ -3,8 +3,8 @@ package handler
import ( import (
"net/http" "net/http"
"pcgamedb/db" "game-crawler/db"
"pcgamedb/model" "game-crawler/model"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

View File

@ -6,9 +6,9 @@ import (
"runtime" "runtime"
"time" "time"
"pcgamedb/config" "game-crawler/config"
"pcgamedb/constant" "game-crawler/constant"
"pcgamedb/db" "game-crawler/db"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

View File

@ -3,8 +3,8 @@ package handler
import ( import (
"net/http" "net/http"
"pcgamedb/crawler" "game-crawler/crawler"
"pcgamedb/model" "game-crawler/model"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/bson/primitive"

View File

@ -3,8 +3,8 @@ package handler
import ( import (
"net/http" "net/http"
"pcgamedb/db" "game-crawler/db"
"pcgamedb/model" "game-crawler/model"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

View File

@ -4,7 +4,7 @@ import (
"net/http" "net/http"
"strings" "strings"
"pcgamedb/config" "game-crawler/config"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

View File

@ -2,7 +2,7 @@ package middleware
import ( import (
"fmt" "fmt"
"pcgamedb/log" "game-crawler/log"
"strings" "strings"
"time" "time"

View File

@ -3,7 +3,7 @@ package middleware
import ( import (
"net/http" "net/http"
"pcgamedb/log" "game-crawler/log"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go.uber.org/zap" "go.uber.org/zap"

View File

@ -3,14 +3,14 @@ package server
import ( import (
"embed" "embed"
"errors" "errors"
"game-crawler/crawler"
"game-crawler/db"
"game-crawler/log"
"game-crawler/server/handler"
"game-crawler/server/middleware"
"io/fs" "io/fs"
"net/http" "net/http"
"path/filepath" "path/filepath"
"pcgamedb/crawler"
"pcgamedb/db"
"pcgamedb/log"
"pcgamedb/server/handler"
"pcgamedb/server/middleware"
"strconv" "strconv"
"strings" "strings"
@ -20,7 +20,7 @@ import (
"go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/bson/primitive"
"go.uber.org/zap" "go.uber.org/zap"
"pcgamedb/docs" "game-crawler/docs"
swaggerfiles "github.com/swaggo/files" swaggerfiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger" ginSwagger "github.com/swaggo/gin-swagger"
@ -133,7 +133,7 @@ func initFrontend(app *gin.Engine) {
page := ctx.Query("page") page := ctx.Query("page")
key = strings.TrimSpace(key) key = strings.TrimSpace(key)
if len(key) < 2 { if len(key) < 2 {
ctx.HTML(400, "400.html", errors.New("Search key should be at least 2 characters long")) ctx.HTML(400, "400.html", errors.New("search key should be at least 2 characters long"))
return return
} }
if page == "" { if page == "" {

View File

@ -4,12 +4,12 @@ import (
"io" "io"
"time" "time"
"pcgamedb/cache" "game-crawler/cache"
"pcgamedb/config" "game-crawler/config"
"pcgamedb/db" "game-crawler/db"
"pcgamedb/log" "game-crawler/log"
"pcgamedb/server/middleware" "game-crawler/server/middleware"
"pcgamedb/task" "game-crawler/task"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/robfig/cron/v3" "github.com/robfig/cron/v3"

View File

@ -3,8 +3,7 @@
<footer class="text-light py-4 mt-5"> <footer class="text-light py-4 mt-5">
<div class="container"> <div class="container">
<div class="col text-center"> <div class="col text-center">
<div><a href="https://git.nite07.com/nite/pcgamedb" target="_blank">Open Source</a> | <a <div><a href="/api/swagger/index.html">API Doc</a></div>
href="/api/swagger/index.html">API Doc</a></div>
<div>Made by <a href="https://www.nite07.com" target="_blank">Nite</a></div> <div>Made by <a href="https://www.nite07.com" target="_blank">Nite</a></div>
</div> </div>
</div> </div>

View File

@ -1,7 +1,7 @@
package task package task
import ( import (
"pcgamedb/db" "game-crawler/db"
"go.uber.org/zap" "go.uber.org/zap"
) )

View File

@ -3,11 +3,11 @@ package task
import ( import (
"net/url" "net/url"
"pcgamedb/config" "game-crawler/config"
"pcgamedb/crawler" "game-crawler/crawler"
"pcgamedb/db" "game-crawler/db"
"pcgamedb/model" "game-crawler/model"
"pcgamedb/utils" "game-crawler/utils"
"go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/bson/primitive"
"go.uber.org/zap" "go.uber.org/zap"

View File

@ -1,7 +1,7 @@
package task package task
import ( import (
"pcgamedb/crawler" "game-crawler/crawler"
"go.uber.org/zap" "go.uber.org/zap"
) )