diff --git a/Dockerfile b/Dockerfile index a6e8870..a93f3cd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,30 +1,27 @@ -FROM golang:1.23 as build +from golang:1.23 as build -LABEL author="Victor Lacasse-Beaudoin " -LABEL license="MIT" -LABEL licensee="AGECEM" -LABEL repo="https://git.agecem.com/agecem/babillard" +label author="Victor Lacasse-Beaudoin " +label license="MIT" +label licensee="AGECEM" +label repo="https://git.agecem.com/agecem/babillard" -WORKDIR /go/src/app +workdir /go/src/app -COPY go.mod go.sum ./ +copy go.mod go.sum LICENSE cmd.go config.go contenu.go data.go handlers.go response.go ./ -ADD cmd/ cmd/ -ADD pkg/ pkg/ -ADD ui/ ui/ +add cmd/ cmd/ +add ui/ ui/ -RUN CGO_ENABLED=0 go build -a -o babillard . +run CGO_ENABLED=0 go build -a ./cmd/babillard/ # Alpine -FROM alpine:3.21 +from alpine:3.21 -RUN apk update && apk upgrade --no-cache +workdir /app -WORKDIR /app +add contenu/ contenu/ -ADD contenu/ contenu/ +copy --from=build /go/src/app/babillard /usr/bin/babillard -COPY --from=build /go/src/app/babillard /usr/bin/babillard - -CMD ["babillard", "server"] +cmd ["babillard", "server"] diff --git a/pkg/babillard/cmd.go b/cmd.go similarity index 66% rename from pkg/babillard/cmd.go rename to cmd.go index aa745ff..ef86da6 100644 --- a/pkg/babillard/cmd.go +++ b/cmd.go @@ -2,7 +2,6 @@ package babillard import ( "flag" - "os" "codeberg.org/vlbeaudoin/couleuvre" ) @@ -10,7 +9,7 @@ import ( var app couleuvre.App[Config] func init() { - app = couleuvre.NewApp[Config]("BABILLARD_", ".", "_") + app = couleuvre.App[Config]{EnvPrefix: "babillard"} flag.StringVar(&app.Config.ServerContenuDir, ServerContenuDirName, ServerContenuDirDefault, ServerContenuDirDescription) flag.IntVar(&app.Config.ServerPort, ServerPortName, ServerPortDefault, ServerPortDescription) @@ -31,31 +30,25 @@ const ( ServerCmdDesc = "Démarrer le serveur web" ) -func ServerCmdExecuter() error { - RunServer(app.Config.ServerContenuDir, app.Config.ServerPort) +func ServerCmdExecuter(args ...string) error { + RunServer(app.Config) return nil } func Execute() error { + if err := app.AddCommands(couleuvre.Command{ + Name: ServerCmdName, + Description: ServerCmdDesc, + Executer: couleuvre.ExecuterFunc(ServerCmdExecuter), + }); err != nil { + return err + } + if err := app.Parse(); err != nil { return err } - if err := app.NewCommand(ServerCmdName, ServerCmdDesc, ServerCmdExecuter); err != nil { - return err - } - - var commandName string - if len(os.Args) > 1 { - commandName = flag.Arg(0) - } - - cmd, err := app.ParseCommand(commandName) - if err != nil { - return err - } - - if err := cmd.Execute(); err != nil { + if err := app.Execute(flag.Args()...); err != nil { return err } diff --git a/cmd/babillard/main.go b/cmd/babillard/main.go index a8195a2..879050d 100644 --- a/cmd/babillard/main.go +++ b/cmd/babillard/main.go @@ -24,7 +24,7 @@ package main import ( "log" - "git.agecem.com/agecem/babillard/v7/pkg/babillard" + "git.agecem.com/agecem/babillard/v8" ) func main() { diff --git a/compose.yaml b/compose.yaml index 2171265..fbe4ae7 100644 --- a/compose.yaml +++ b/compose.yaml @@ -8,7 +8,7 @@ services: volumes: - 'config:/app/config' - 'contenu:/app/contenu' - command: ['babillard', '--config', '/app/config/.babillard.yaml', 'server'] + command: ['babillard', '--config', '/app/config/babillard.yaml', 'server'] volumes: config: diff --git a/pkg/babillard/config.go b/config.go similarity index 100% rename from pkg/babillard/config.go rename to config.go diff --git a/pkg/babillard/contenu.go b/contenu.go similarity index 64% rename from pkg/babillard/contenu.go rename to contenu.go index e75d78d..4d54e8d 100644 --- a/pkg/babillard/contenu.go +++ b/contenu.go @@ -9,6 +9,8 @@ import ( "github.com/labstack/echo/v4" ) +// pre-v2 + type ContenuHandler struct { ContenuDir string } @@ -43,3 +45,24 @@ func (h ContenuHandler) HandleAPIContenuFile(c echo.Context) error { return c.File(fmt.Sprintf("%s/%s", contenu_dir, filename)) } + +// v2 + +func APIv2ListContenu(cfg Config) echo.HandlerFunc { + return func(c echo.Context) error { + files, err := ListContenu(cfg.ServerContenuDir) + if err != nil { + return c.JSON(http.StatusInternalServerError, ErrorResponse{Error: err.Error()}) + } + + return c.JSON(http.StatusOK, NewContenuResponse(files)) + } +} + +// ui + +func UIContenuFichier(cfg Config) echo.HandlerFunc { + return func(c echo.Context) error { + return c.File(fmt.Sprintf("%s/%s", cfg.ServerContenuDir, c.Param("fichier"))) + } +} diff --git a/data.go b/data.go new file mode 100644 index 0000000..0f19e16 --- /dev/null +++ b/data.go @@ -0,0 +1,42 @@ +package babillard + +import ( + "fmt" + "os" +) + +var forbiddenFiles = []string{".gitkeep", "messages.txt", "Thumbs.db"} + +func ListContenu(path string) (files []string, err error) { + file, err := os.Open(path) + if err != nil { + return nil, err + } + defer file.Close() + + stats, err := file.Stat() + if err != nil { + return nil, err + } + + if !stats.IsDir() { + return nil, fmt.Errorf("contenu '%s' n'est pas un répertoire", path) + } + + fileInfos, err := file.Readdir(-1) + if err != nil { + return nil, err + } + +fileLoop: + for _, fileInfo := range fileInfos { + for _, forbiddenFile := range forbiddenFiles { + if fileInfo.Name() == forbiddenFile { + continue fileLoop + } + } + files = append(files, fileInfo.Name()) + } + + return files, nil +} diff --git a/go.mod b/go.mod index 1af488a..8a2c3f6 100644 --- a/go.mod +++ b/go.mod @@ -1,27 +1,26 @@ -module git.agecem.com/agecem/babillard/v7 +module git.agecem.com/agecem/babillard/v8 -go 1.23 +go 1.23.0 + +toolchain go1.23.6 require ( - codeberg.org/vlbeaudoin/couleuvre v0.10.0 + codeberg.org/vlbeaudoin/couleuvre v0.13.0 github.com/labstack/echo/v4 v4.13.3 ) require ( github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/kr/text v0.2.0 // indirect + github.com/goccy/go-yaml v1.16.0 // indirect github.com/labstack/gommon v0.4.2 // indirect github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect - github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect - github.com/rogpeppe/go-internal v1.10.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.2.2 // indirect - golang.org/x/crypto v0.32.0 // indirect - golang.org/x/net v0.34.0 // indirect - golang.org/x/sys v0.29.0 // indirect - golang.org/x/text v0.21.0 // indirect - golang.org/x/time v0.9.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect + golang.org/x/crypto v0.36.0 // indirect + golang.org/x/net v0.38.0 // indirect + golang.org/x/sys v0.31.0 // indirect + golang.org/x/text v0.23.0 // indirect + golang.org/x/time v0.11.0 // indirect ) diff --git a/go.sum b/go.sum index 95cf8b9..2c1cb61 100644 --- a/go.sum +++ b/go.sum @@ -1,12 +1,9 @@ -codeberg.org/vlbeaudoin/couleuvre v0.10.0 h1:Uk6795M7ziZPu1Fv8KgGNEbRjc1u4NPdPU4Tip0IpHU= -codeberg.org/vlbeaudoin/couleuvre v0.10.0/go.mod h1:+M8nPA/3LknsY72RP0ZHCZycQ1SPxxRoXpnyHeSNE7U= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +codeberg.org/vlbeaudoin/couleuvre v0.13.0 h1:N2gAzpItFthQ0aPzMQjntRsrqrEXwuo0u6VHSGA/V6o= +codeberg.org/vlbeaudoin/couleuvre v0.13.0/go.mod h1:0RvzStph7J4/M+mZb903hn4GSYrTBjXYVJv72Pwpa90= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= -github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= -github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/goccy/go-yaml v1.16.0 h1:d7m1G7A0t+logajVtklHfDYJs2Et9g3gHwdBNNFou0w= +github.com/goccy/go-yaml v1.16.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA= github.com/labstack/echo/v4 v4.13.3 h1:pwhpCPrTl5qry5HRdM5FwdXnhXSLSY+WE+YQSeCaafY= github.com/labstack/echo/v4 v4.13.3/go.mod h1:o90YNEeQWjDozo584l7AwhJMHN0bOC4tAfg+Xox9q5g= github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0= @@ -15,31 +12,24 @@ github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHP github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= -github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= -github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo= github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= -golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc= -golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc= -golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0= -golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k= +golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34= +golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc= +golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8= +golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU= -golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= -golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= -golang.org/x/time v0.9.0 h1:EsRrnYcQiGH+5FfbgvV4AP7qEZstoyrHB0DzarOQ4ZY= -golang.org/x/time v0.9.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= +golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= +golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= +golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0= +golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/babillard/handlers.go b/handlers.go similarity index 75% rename from pkg/babillard/handlers.go rename to handlers.go index fc636c8..f15bf78 100644 --- a/pkg/babillard/handlers.go +++ b/handlers.go @@ -5,7 +5,7 @@ import ( "log" "net/http" - "git.agecem.com/agecem/babillard/v7/ui" + "git.agecem.com/agecem/babillard/v8/ui" "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" ) @@ -18,12 +18,16 @@ API Specifications '/api' | GET | Affiche les spécifications API '/api/contenu' | GET | Affiche le nom des fichiers dans 'contenu/' '/api/contenu/{filename}' | GET | Affiche le fichier 'contenu/{filename}' ------` +----- +v2 +-- +'/api/v2/contenu' | GET | Affiche les noms des fichiers dans 'contenu/' +` return c.String(http.StatusOK, apispec) } -func RunServer(contenuDir string, serverPort int) { +func RunServer(cfg Config) { log.Print("[I] Starting webserver") e := echo.New() @@ -45,11 +49,17 @@ func RunServer(contenuDir string, serverPort int) { groupAPI := e.Group("/api") - contenuHandler := NewContenuHandler(contenuDir) + contenuHandler := NewContenuHandler(cfg.ServerContenuDir) groupAPI.GET("/", HandleAPIShow) groupAPI.GET("/contenu/", contenuHandler.HandleAPIContenuList) groupAPI.GET("/contenu/:filename/", contenuHandler.HandleAPIContenuFile) - e.Logger.Fatal(e.Start(fmt.Sprintf(":%d", serverPort))) + groupAPI.GET("/v2/contenu/", APIv2ListContenu(cfg)) + + groupUI := e.Group("/ui") + + groupUI.GET("/contenu/:fichier/", UIContenuFichier(cfg)) + + e.Logger.Fatal(e.Start(fmt.Sprintf(":%d", cfg.ServerPort))) } diff --git a/k8s/deployment.yaml b/k8s/deployment.yaml new file mode 100644 index 0000000..83c8c0f --- /dev/null +++ b/k8s/deployment.yaml @@ -0,0 +1,31 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: babillard-deployment + labels: + app: babillard +spec: + replicas: 1 + selector: + matchLabels: + app: babillard + template: + metadata: + labels: + app: babillard + spec: + containers: + - name: babillard + image: git.agecem.com/agecem/babillard:latest + imagePullPolicy: Always + ports: + - containerPort: 8080 + volumeMounts: + - name: babillard-nfs + mountPath: "/app/contenu" + volumes: + - name: babillard-nfs + nfs: + server: fs.agecem.com + path: /mnt/Pool1/babillard + readOnly: true diff --git a/k8s/service.yaml b/k8s/service.yaml new file mode 100644 index 0000000..fe1ece0 --- /dev/null +++ b/k8s/service.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: babillard-service +spec: + type: NodePort + selector: + app: babillard + ports: + - protocol: TCP + port: 8080 + targetPort: 8080 + nodePort: 30001 diff --git a/pkg/babillard/data.go b/pkg/babillard/data.go deleted file mode 100644 index e126748..0000000 --- a/pkg/babillard/data.go +++ /dev/null @@ -1,24 +0,0 @@ -package babillard - -import "os" - -func ListContenu(path string) ([]string, error) { - var files []string - f, err_open := os.Open(path) - defer f.Close() - - if err_open != nil { - return nil, err_open - } - fileInfo, err_read := f.Readdir(-1) - if err_read != nil { - return nil, err_read - } - - for _, file := range fileInfo { - if file.Name() != ".gitkeep" && file.Name() != "messages.txt" { - files = append(files, file.Name()) - } - } - return files, nil -} diff --git a/response.go b/response.go new file mode 100644 index 0000000..01b2638 --- /dev/null +++ b/response.go @@ -0,0 +1,20 @@ +package babillard + +type ErrorResponse struct { + Error string +} + +type MessageResponse struct { + Message string +} + +type ContenuResponse struct { + Data struct { + Contenu []string + } +} + +func NewContenuResponse(fichiers []string) (response ContenuResponse) { + response.Data.Contenu = fichiers + return +} diff --git a/ui/css/style.css b/ui/css/style.css index 8c8549e..36cc922 100644 --- a/ui/css/style.css +++ b/ui/css/style.css @@ -20,60 +20,3 @@ embed { flex: 1; min-height: 0; } - -#bar { - width: 100%; - background-image: linear-gradient(to right, #033ead, #3093d1); - color: white; - font-family: 'Roboto', sans-serif; - font-weight: bold; - display: flex; - align-items: center; - min-height: 75px; -} - -img#bar-bg { - position: absolute; - width: 100%; - height: 100%; - z-index: -1; -} - -#time { - font-size: 300%; - height: 53px; -} - -#text-content { - white-space: nowrap; - z-index: 1; - display: block; - height: 100%; - padding-top: 55px; - position: relative; -} - -#text-container { - height: 100%; - background-image: linear-gradient(to right, #033ead, #3093d1); - display: flex; - align-items: center; - font-size: 20px; - flex-grow: 1; -} - -#text-content div { - display: block; - position: fixed; - height: 100%; -} - -#date-time { - display: flex; - flex-flow: column; - align-items: center; - height: 100%; - background-color: #033ead; - z-index: 1; - width: 225px; -} \ No newline at end of file diff --git a/ui/embed.go b/ui/embed.go index 3b63250..f67189c 100644 --- a/ui/embed.go +++ b/ui/embed.go @@ -2,17 +2,17 @@ package ui import "embed" -//go:embed html/* +//go:embed html/*.html var htmlFS embed.FS func HTMLFS() embed.FS { return htmlFS } -//go:embed css/* +//go:embed css/*.css var cssFS embed.FS func CSSFS() embed.FS { return cssFS } -//go:embed js/* +//go:embed js/*.js var jsFS embed.FS func JSFS() embed.FS { return jsFS } diff --git a/ui/html/index.html b/ui/html/index.html index d9b81a5..b564060 100644 --- a/ui/html/index.html +++ b/ui/html/index.html @@ -1,43 +1,17 @@ - AGECEM | slider - + AGECEM | babillard - - - - - + + -

-
- - - diff --git a/ui/js/carousel.js b/ui/js/carousel.js new file mode 100644 index 0000000..ed61f17 --- /dev/null +++ b/ui/js/carousel.js @@ -0,0 +1,32 @@ +// 2025-02 Victor Lacasse-Beaudoin, AGECEM +// +// Carousel d'images à afficher sur https://babillard.agecem.com/ ainsi que +// sur la télévision du Centre-Multi Services de l'AGECEM. +// +// WIP +async function getContenu() { + const url = "/api/v2/contenu/"; + try { + const response = await fetch(url); + if (!response.ok) { + //TODO start interval then refresh page to try again + throw new Error(`Response status: ${response.status}`); + } + json = await response.json(); + console.log("[i] got contenu"); + console.log(json); + + //startCarousel(json); + } + catch (error) { + console.error(error.message); + } +} + +function run(){ + console.log("[i] run"); + + getContenu(); +} + +run(); diff --git a/ui/js/slider.js b/ui/js/slider.js index e30a9c6..827aa6d 100644 --- a/ui/js/slider.js +++ b/ui/js/slider.js @@ -10,15 +10,14 @@ function afficherImage() { } function augmenterIndex() { - if (indexImages >= images.length - 1) { - indexImages = 0; - } else { indexImages ++; - } } function executionLoop(){ - //afficherIndex(); + if (indexImages >= images.length) { + location.reload(); + } + afficherImage(); augmenterIndex(); } @@ -41,5 +40,6 @@ function obtenirContenu(){ $(function(){ obtenirContenu(); - var executionInterval = setInterval(executionLoop, 10000); + executionLoop(); + var executionInterval = setInterval(executionLoop, (Math.floor(Math.random() * 6)+15)*1000); }); diff --git a/ui/js/text.js b/ui/js/text.js deleted file mode 100644 index 88675c8..0000000 --- a/ui/js/text.js +++ /dev/null @@ -1,65 +0,0 @@ -// VARS -// Vitesses -var vitesseTexte = 4000; // En millisecondes - -// Coordonnées -var pointInitial = '100%'; -var pointDestination = '-=2000px'; - -// Messages -var messageDiv = '#text-content div' -var messages = []; -var indexMessages = 0; - -var fontSize; -var fontSizeLength; - -// FUNCS -function animerTexte(){ - // Diriger le texte vers la droite jusqu'à `pointDestination'. - // Récursivement reset la position du texte. - $(messageDiv).animate({left: pointDestination}, vitesseTexte, 'linear', resetTexte); -} - -function resetTexte(){ - // Remettre le texte au point initial - $(messageDiv).css('left', pointInitial); - - // Récursivement animer le texte - animerTexte(); -} - -function updateTexte(){ - var message = messages[indexMessages]; - - $(messageDiv).text(message); - - augmenterIndex(); -} - -function augmenterIndex() { - if (indexMessages >= messages.length - 1) { - indexMessages = 0; - } else { - indexMessages ++; - } -} - -function initialiserMessages(){ - fontSize = $(messageDiv).css('fontSize'); - fontSizeLength = fontSize.length; - - // TODO Importer messages - messages = ['hello, world!']; - - - // TODO pointDestination = -1 * longueurMessage - //pointDestination = messages[0].width * fontSize.substring(fontSize.length-2); - pointDestination = messages[indexMessages].width; -} - -// EXEC -$(function(){ - //initialiserMessages(); - resetTexte(); -});