add file prefix

This commit is contained in:
2026-07-19 21:18:16 +07:00
parent ed59b558ea
commit 2522a928de
6 changed files with 33 additions and 9 deletions
+2
View File
@@ -11,3 +11,5 @@ S3_HOST=http://0.0.0.0:9000
S3_USER=rustfs
S3_PASSWORD=your_password
S3_BUCKET=evening-detective
FILE_PREFIX_DOMAIN=http://0.0.0.0:8090/api/files/
+4 -1
View File
@@ -72,7 +72,10 @@ func main() {
}
fileService := file_service.NewFileService(fileStorage)
scenariosRepo := scenarios_repo.NewScenariosRepo(dbpool)
scenarioService := scenarios_service.NewScenarioService(scenariosRepo)
scenarioService := scenarios_service.NewScenarioService(
scenariosRepo,
os.Getenv("FILE_PREFIX_DOMAIN"),
)
// Create a listener on TCP port
lis, err := net.Listen("tcp", ":8080")
+1
View File
@@ -22,6 +22,7 @@ services:
S3_USER: rustfs
S3_PASSWORD: your_password
S3_BUCKET: evening-detective
FILE_PREFIX_DOMAIN: http://0.0.0.0:8090/api/files/
depends_on:
- postgres
restart: unless-stopped
@@ -6,10 +6,13 @@ import (
"evening_detective_server/internal/repos"
)
func mapScenarios(o []*repos.Scenario) ([]*Scenario, error) {
func mapScenarios(
o []*repos.Scenario,
domain string,
) ([]*Scenario, error) {
res := make([]*Scenario, 0, len(o))
for _, item := range o {
scenario, err := mapScenario(item)
scenario, err := mapScenario(item, domain)
if err != nil {
return nil, err
}
@@ -18,7 +21,10 @@ func mapScenarios(o []*repos.Scenario) ([]*Scenario, error) {
return res, nil
}
func mapScenario(o *repos.Scenario) (*Scenario, error) {
func mapScenario(
o *repos.Scenario,
domain string,
) (*Scenario, error) {
story, err := mapStory(o.Scenario)
if err != nil {
return nil, err
@@ -27,7 +33,7 @@ func mapScenario(o *repos.Scenario) (*Scenario, error) {
ID: o.ID,
Name: o.Name,
Description: o.Description,
Image: o.Image,
Image: mapImage(o.Image, domain),
Story: story,
Author: o.Author,
Status: o.Status,
@@ -53,3 +59,12 @@ func convertStory(o *storytelling.Story) (string, error) {
}
return string(b), nil
}
func mapImage(image *string, domain string) *string {
if image == nil {
u := domain + "question.png"
return &u
}
u := domain + *image
return &u
}
@@ -9,13 +9,16 @@ import (
type ScenarioService struct {
scenariosRepo *scenarios_repo.ScenariosRepo
domain string
}
func NewScenarioService(
scenariosRepo *scenarios_repo.ScenariosRepo,
domain string,
) *ScenarioService {
return &ScenarioService{
scenariosRepo: scenariosRepo,
domain: domain,
}
}
@@ -39,7 +42,7 @@ func (s *ScenarioService) GetScenariosByAuthorID(
if err != nil {
return nil, err
}
return mapScenarios(scenarios)
return mapScenarios(scenarios, s.domain)
}
func (s *ScenarioService) GetScenarioByID(
@@ -50,7 +53,7 @@ func (s *ScenarioService) GetScenarioByID(
if err != nil {
return nil, err
}
return mapScenario(scenario)
return mapScenario(scenario, s.domain)
}
func (s *ScenarioService) UpdateScenarioByID(
@@ -2,7 +2,7 @@
CREATE TABLE
IF NOT EXISTS scenarios (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL UNIQUE,
name VARCHAR(255) NOT NULL,
description TEXT,
image TEXT,
scenario JSONB NOT NULL DEFAULT '{}'::jsonb,
@@ -17,4 +17,4 @@ CREATE TABLE
);
-- +goose Down
DROP TABLE IF EXISTS scenarios;
DROP TABLE IF EXISTS scenarios;