add images

This commit is contained in:
Владимир Фёдоров 2026-03-14 16:02:33 +07:00
parent 4ae2715ab0
commit ae82f8e0d9
6 changed files with 58 additions and 11 deletions

View File

@ -165,9 +165,10 @@ message Action {
string place = 2;
string name = 3;
string text = 4;
repeated Application applications = 5;
bool hidden = 6;
repeated Door doors = 7;
string image = 5;
repeated Application applications = 6;
bool hidden = 7;
repeated Door doors = 8;
}
message GetGameReq {}

View File

@ -19,6 +19,7 @@ import (
"log"
"net"
"net/http"
"time"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"google.golang.org/grpc"
@ -139,6 +140,19 @@ func main() {
log.Fatalln(http.ListenAndServe(config.ClientPort, muxUser))
}()
go func() {
dir := "./data/story/images"
// Создаем файловый сервер
fs := http.FileServer(http.Dir(dir))
// Добавляем middleware для логирования
http.Handle("/", loggingMiddleware(fs))
log.Println("Файловый сервер запущен на http://localhost:8120")
log.Println("Обслуживается директория: " + dir)
log.Fatal(http.ListenAndServe(":8120", nil))
}()
muxAdmin := http.NewServeMux()
subAdminFS, err := fs.Sub(adminFS, "static/admin")
if err != nil {
@ -163,3 +177,14 @@ func cors(h http.Handler) http.Handler {
h.ServeHTTP(w, r)
})
}
func loggingMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
// Логируем запрос
log.Printf("[%s] %s %s", r.Method, r.URL.Path, time.Since(start))
next.ServeHTTP(w, r)
})
}

View File

@ -4,6 +4,7 @@ type Place struct {
Code string `json:"code"`
Name string `json:"name"`
Text string `json:"text"`
Image string `json:"image"`
Applications []*Application `json:"applications,omitempty"`
Hidden bool `json:"hidden"`
Doors []*Door `json:"doors"`
@ -36,6 +37,13 @@ func NewClientErrorPlace(code string) *Place {
type PlaceOpt func(place *Place) error
func WithPlaceImage(image string) PlaceOpt {
return func(place *Place) error {
place.Image = image
return nil
}
}
func WithPlaceApplication(applications ...*Application) PlaceOpt {
return func(place *Place) error {
for _, application := range applications {

View File

@ -77,6 +77,7 @@ func (s *StoryService) GetPlace(code string) *models.Place {
place.Code,
place.Name,
s.cleaner.ClearText(place.Text),
models.WithPlaceImage(place.Image),
models.WithPlaceApplication(applications...),
models.WithPlaceHidden(place.Hidden),
models.WithPlaceDoors(doors...),

View File

@ -824,9 +824,10 @@ type Action struct {
Place string `protobuf:"bytes,2,opt,name=place,proto3" json:"place,omitempty"`
Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"`
Text string `protobuf:"bytes,4,opt,name=text,proto3" json:"text,omitempty"`
Applications []*Application `protobuf:"bytes,5,rep,name=applications,proto3" json:"applications,omitempty"`
Hidden bool `protobuf:"varint,6,opt,name=hidden,proto3" json:"hidden,omitempty"`
Doors []*Door `protobuf:"bytes,7,rep,name=doors,proto3" json:"doors,omitempty"`
Image string `protobuf:"bytes,5,opt,name=image,proto3" json:"image,omitempty"`
Applications []*Application `protobuf:"bytes,6,rep,name=applications,proto3" json:"applications,omitempty"`
Hidden bool `protobuf:"varint,7,opt,name=hidden,proto3" json:"hidden,omitempty"`
Doors []*Door `protobuf:"bytes,8,rep,name=doors,proto3" json:"doors,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
@ -889,6 +890,13 @@ func (x *Action) GetText() string {
return ""
}
func (x *Action) GetImage() string {
if x != nil {
return x.Image
}
return ""
}
func (x *Action) GetApplications() []*Application {
if x != nil {
return x.Applications
@ -1745,15 +1753,16 @@ const file_main_proto_rawDesc = "" +
"\aactions\x18\x02 \x03(\v2\x1f.crabs.evening_detective.ActionR\aactions\"$\n" +
"\fAddActionReq\x12\x14\n" +
"\x05place\x18\x01 \x01(\tR\x05place\"\x0e\n" +
"\fAddActionRsp\"\xed\x01\n" +
"\fAddActionRsp\"\x83\x02\n" +
"\x06Action\x12\x0e\n" +
"\x02id\x18\x01 \x01(\x03R\x02id\x12\x14\n" +
"\x05place\x18\x02 \x01(\tR\x05place\x12\x12\n" +
"\x04name\x18\x03 \x01(\tR\x04name\x12\x12\n" +
"\x04text\x18\x04 \x01(\tR\x04text\x12H\n" +
"\fapplications\x18\x05 \x03(\v2$.crabs.evening_detective.ApplicationR\fapplications\x12\x16\n" +
"\x06hidden\x18\x06 \x01(\bR\x06hidden\x123\n" +
"\x05doors\x18\a \x03(\v2\x1d.crabs.evening_detective.DoorR\x05doors\"\f\n" +
"\x04text\x18\x04 \x01(\tR\x04text\x12\x14\n" +
"\x05image\x18\x05 \x01(\tR\x05image\x12H\n" +
"\fapplications\x18\x06 \x03(\v2$.crabs.evening_detective.ApplicationR\fapplications\x12\x16\n" +
"\x06hidden\x18\a \x01(\bR\x06hidden\x123\n" +
"\x05doors\x18\b \x03(\v2\x1d.crabs.evening_detective.DoorR\x05doors\"\f\n" +
"\n" +
"GetGameReq\"R\n" +
"\n" +

View File

@ -397,6 +397,9 @@
"text": {
"type": "string"
},
"image": {
"type": "string"
},
"applications": {
"type": "array",
"items": {