From b723a55e129737cf9dd3fbb4d54dffc2531334b1 Mon Sep 17 00:00:00 2001 From: Fedorov Vladimir Date: Fri, 2 Oct 2026 23:36:54 +0700 Subject: [PATCH] fix --- internal/modules/scenario_archive/archive.go | 7 ++-- .../modules/scenario_archive/archive_test.go | 33 ++++++++----------- .../modules/scenario_archive/interface.go | 11 +++++-- .../services/scenarios_service/service.go | 7 +++- 4 files changed, 31 insertions(+), 27 deletions(-) diff --git a/internal/modules/scenario_archive/archive.go b/internal/modules/scenario_archive/archive.go index 104c7c0..0fd72ec 100644 --- a/internal/modules/scenario_archive/archive.go +++ b/internal/modules/scenario_archive/archive.go @@ -17,7 +17,6 @@ import ( "time" "evening_detective_server/internal/modules/storytelling" - "evening_detective_server/internal/repos" ) // Лимиты на входящие архивы (защита от zip-bomb). Суммарный объём считается @@ -63,7 +62,7 @@ func ImagePath(ref, domain string) (string, bool) { // URL остаются без изменений. Архив детерминирован (порядок записей и метки). func (a *scenarioArchive) Pack( ctx context.Context, - scenario *repos.Scenario, + scenario *Scenario, domain string, getFile func(ctx context.Context, name string) ([]byte, error), ) ([]byte, error) { @@ -72,8 +71,8 @@ func (a *scenarioArchive) Pack( } story := &storytelling.Story{} - if scenario.Scenario != "" { - if err := json.Unmarshal([]byte(scenario.Scenario), story); err != nil { + if scenario.Story != "" { + if err := json.Unmarshal([]byte(scenario.Story), story); err != nil { return nil, fmt.Errorf("не удалось разобрать историю сценария: %w", err) } } diff --git a/internal/modules/scenario_archive/archive_test.go b/internal/modules/scenario_archive/archive_test.go index 9d971fc..66662dd 100644 --- a/internal/modules/scenario_archive/archive_test.go +++ b/internal/modules/scenario_archive/archive_test.go @@ -11,22 +11,20 @@ import ( "time" "evening_detective_server/internal/modules/storytelling" - "evening_detective_server/internal/repos" ) const testDomain = "http://storage.test/api/files/" var testArchive = NewScenarioArchive() -func buildScenario() *repos.Scenario { +func buildScenario() *Scenario { description := "Детективная история" image := "cover.png" - return &repos.Scenario{ - ID: 1, + return &Scenario{ Name: "Ночной клуб", Description: &description, Image: &image, - Scenario: `{"places":[ + Story: `{"places":[ {"code":"club","name":"Клуб","text":"Тёмный зал","image":"club.png","applications":[{"name":"Билет","image":"ticket.jpg"}]}, {"code":"parking","name":"Парковка","text":"Пусто","image":"club.png"} ]}`, @@ -101,12 +99,11 @@ func TestPackUnpackRoundTrip(t *testing.T) { func TestPackUnpackIntroAudioRoundTrip(t *testing.T) { description := "desc" image := "cover.png" - scenario := &repos.Scenario{ - ID: 1, + scenario := &Scenario{ Name: "С введением", Description: &description, Image: &image, - Scenario: `{"introduction":{"text":"Введение","audio":"intro.mp3"},"places":[ + Story: `{"introduction":{"text":"Введение","audio":"intro.mp3"},"places":[ {"code":"club","name":"Клуб","text":"Тёмный зал","image":"club.png"} ]}`, } @@ -142,12 +139,11 @@ func TestPackUnpackIntroAudioRoundTrip(t *testing.T) { func TestPackExternalURLsKeptAndNotFetched(t *testing.T) { description := "desc" - scenario := &repos.Scenario{ - ID: 1, + scenario := &Scenario{ Name: "Внешний", Description: &description, Image: ptr("https://example.com/cover.png"), - Scenario: `{"places":[ + Story: `{"places":[ {"code":"p","name":"P","text":"t","image":"http://other.example/x.png"} ]}`, } @@ -182,12 +178,11 @@ func TestPackExternalURLsKeptAndNotFetched(t *testing.T) { func TestPackLegacyFullURLImage(t *testing.T) { // Устаревшие данные: полный URL хранилища срезается до базового имени файла. description := "desc" - scenario := &repos.Scenario{ - ID: 1, + scenario := &Scenario{ Name: "Legacy", Description: &description, Image: ptr(testDomain + "cover.png"), - Scenario: `{"places":[]}`, + Story: `{"places":[]}`, } data, err := testArchive.Pack(context.Background(), scenario, testDomain, newMemoryFiles().get) if err != nil { @@ -240,11 +235,10 @@ func TestPackNilScenario(t *testing.T) { func TestPackImageNameCollision(t *testing.T) { description := "desc" - scenario := &repos.Scenario{ - ID: 1, + scenario := &Scenario{ Name: "Конфликт", Description: &description, - Scenario: `{"places":[ + Story: `{"places":[ {"code":"a","name":"A","text":"t","image":"a.png"}, {"code":"b","name":"B","text":"t","image":"dir/a.png"} ]}`, @@ -471,11 +465,10 @@ func TestPackTotalSizeLimit(t *testing.T) { defer func() { maxPackSize = prev }() description := "desc" - scenario := &repos.Scenario{ - ID: 1, + scenario := &Scenario{ Name: "Большой", Description: &description, - Scenario: `{"places":[ + Story: `{"places":[ {"code":"a","name":"A","text":"t","image":"a.png"}, {"code":"b","name":"B","text":"t","image":"b.png"} ]}`, diff --git a/internal/modules/scenario_archive/interface.go b/internal/modules/scenario_archive/interface.go index 1509de6..fd04722 100644 --- a/internal/modules/scenario_archive/interface.go +++ b/internal/modules/scenario_archive/interface.go @@ -4,7 +4,6 @@ import ( "context" "evening_detective_server/internal/modules/storytelling" - "evening_detective_server/internal/repos" ) // Имя файла с описанием сценария внутри архива. @@ -23,6 +22,14 @@ type ScenarioJSON struct { Story *storytelling.Story `json:"story"` } +// Scenario — данные сценария, необходимые для сборки архива. +type Scenario struct { + Name string + Description *string + Image *string + Story string +} + type Bundle struct { Scenario *ScenarioJSON Files map[string][]byte @@ -36,7 +43,7 @@ type IScenarioArchive interface { // внешние URL остаются без изменений. Pack( ctx context.Context, - scenario *repos.Scenario, + scenario *Scenario, domain string, getFile func(ctx context.Context, name string) ([]byte, error), ) ([]byte, error) diff --git a/internal/services/scenarios_service/service.go b/internal/services/scenarios_service/service.go index 7421113..c532dec 100644 --- a/internal/services/scenarios_service/service.go +++ b/internal/services/scenarios_service/service.go @@ -424,7 +424,12 @@ func (s *ScenarioService) DownloadArchive( } data, err := s.scenarioArchive.Pack( ctx, - scenario, + &scenario_archive.Scenario{ + Name: scenario.Name, + Description: scenario.Description, + Image: scenario.Image, + Story: scenario.Scenario, + }, s.domain, func(ctx context.Context, name string) ([]byte, error) { file, err := s.fileStorage.Get(ctx, name)