add images

This commit is contained in:
2026-03-14 17:01:11 +07:00
parent ae82f8e0d9
commit 3a30123096
10 changed files with 65 additions and 32 deletions
+13
View File
@@ -8,6 +8,7 @@ import (
const (
ClientPort = ":8100"
FilePort = ":8120"
)
func GetStoryFilepath() string {
@@ -30,6 +31,18 @@ func GetHost() string {
return "http://" + ips[0] + ClientPort
}
func GetFileHost() string {
host := os.Getenv("FILE_HOST")
if host != "" {
return host
}
ips, err := getLocalIPs()
if err != nil || len(ips) == 0 {
return "http://127.0.0.1" + FilePort
}
return "http://" + ips[0] + FilePort
}
func getFilepath(env string, defaultFilepath string) string {
filepath := selectFilepath(env, defaultFilepath)
ensureDirExists(filepath)
+2 -1
View File
@@ -1,5 +1,6 @@
package link
type ILinkService interface {
GetTeamClientLink(host string, name string, password string) string
GetTeamClientLink(name string, password string) string
GetImageLink(name string) string
}
+14 -6
View File
@@ -5,12 +5,20 @@ import (
"net/url"
)
type service struct{}
func NewLinkService() ILinkService {
return &service{}
type service struct {
host string
}
func (s *service) GetTeamClientLink(host string, name string, password string) string {
return fmt.Sprintf("%s?name=%s&password=%s", host, url.PathEscape(name), password)
func NewLinkService(host string) ILinkService {
return &service{
host: host,
}
}
func (s *service) GetTeamClientLink(name string, password string) string {
return fmt.Sprintf("%s?name=%s&password=%s", s.host, url.PathEscape(name), password)
}
func (s *service) GetImageLink(name string) string {
return fmt.Sprintf("%s/%s", s.host, name)
}
+4 -6
View File
@@ -25,7 +25,6 @@ type Services struct {
linkService link.ILinkService
passwordGenerator password.IPasswordGenerator
pdfGenerator pdf.IPDFGenerator
clientHost string
}
func NewServices(
@@ -34,7 +33,6 @@ func NewServices(
linkService link.ILinkService,
passwordGenerator password.IPasswordGenerator,
pdfGenerator pdf.IPDFGenerator,
clientHost string,
) *Services {
return &Services{
dbService: dbService,
@@ -42,7 +40,6 @@ func NewServices(
linkService: linkService,
passwordGenerator: passwordGenerator,
pdfGenerator: pdfGenerator,
clientHost: clientHost,
}
}
@@ -141,8 +138,9 @@ func (s *Services) GetTeam(ctx context.Context, req *proto.GetTeamReq) (*proto.G
res := make([]*proto.Action, 0, len(actions))
for _, place := range s.storyService.GetPlaces(actionsCodes) {
newAction := mapPlaceToProtoAction(place)
newAction.Text = place.Text
newAction.Name = place.Name
newAction.Text = place.Text
newAction.Image = place.Image
newAction.Applications = make([]*proto.Application, 0, len(place.Applications))
for _, application := range place.Applications {
newAction.Applications = append(newAction.Applications, mapStoryApplicationToProtoApplication(application))
@@ -176,7 +174,7 @@ func (s *Services) GetTeams(ctx context.Context, _ *proto.GetTeamsReq) (*proto.G
if err != nil {
return nil, err
}
newTeam.Url = s.linkService.GetTeamClientLink(s.clientHost, team.Name, team.Password)
newTeam.Url = s.linkService.GetTeamClientLink(team.Name, team.Password)
newTeam.SpendTime = int64(len(actions))
currentApplications, err := s.dbService.GetApplicationsByState(ctx, team.ID, "NEW")
if err != nil {
@@ -214,7 +212,7 @@ func (s *Services) DownloadTeamsQrCodesFile(ctx context.Context, req *proto.Down
return nil, err
}
for _, team := range teams {
team.Link = s.linkService.GetTeamClientLink(s.clientHost, team.Name, team.Password)
team.Link = s.linkService.GetTeamClientLink(team.Name, team.Password)
}
b, err := s.pdfGenerator.CreateTeamsPDF(teams)
if err != nil {
+5 -1
View File
@@ -4,6 +4,7 @@ import (
"context"
"evening_detective/internal/modules/cleaner"
"evening_detective/internal/modules/formatter"
"evening_detective/internal/services/link"
"evening_detective/internal/services/story_service/models"
"regexp"
"strings"
@@ -14,17 +15,20 @@ type StoryService struct {
formatter formatter.IFormatter
story *models.Story
storyStorage IStoryStorage
linkService link.ILinkService
}
func NewStoryService(
cleaner cleaner.ICleaner,
formatter formatter.IFormatter,
storyStorage IStoryStorage,
linkService link.ILinkService,
) (*StoryService, error) {
s := &StoryService{
cleaner: cleaner,
formatter: formatter,
storyStorage: storyStorage,
linkService: linkService,
}
story, err := s.storyStorage.Load(context.Background())
if err != nil {
@@ -77,7 +81,7 @@ func (s *StoryService) GetPlace(code string) *models.Place {
place.Code,
place.Name,
s.cleaner.ClearText(place.Text),
models.WithPlaceImage(place.Image),
models.WithPlaceImage(s.linkService.GetImageLink(place.Image)),
models.WithPlaceApplication(applications...),
models.WithPlaceHidden(place.Hidden),
models.WithPlaceDoors(doors...),
@@ -3,6 +3,7 @@ package story_service_test
import (
"evening_detective/internal/modules/cleaner"
"evening_detective/internal/modules/formatter"
"evening_detective/internal/services/link"
"evening_detective/internal/services/story_service"
"evening_detective/internal/services/story_service/models"
"evening_detective/internal/services/story_storage"
@@ -147,6 +148,7 @@ func TestStoryService_GetPlace(t *testing.T) {
cleaner.NewCleaner(),
formatter.NewFormatter(),
story_storage.NewVarStoryStorage(tt.story),
link.NewLinkService("http://localhost:8120"),
)
if err != nil {
t.Fatalf("could not construct receiver type: %v", err)
@@ -461,6 +463,7 @@ func TestStoryService_GetPlaces(t *testing.T) {
cleaner.NewCleaner(),
formatter.NewFormatter(),
story_storage.NewVarStoryStorage(tt.story),
link.NewLinkService("http://localhost:8120"),
)
assert.Nil(t, err)