From dc4a6136846c0c041bb462ce518997b36591d91b Mon Sep 17 00:00:00 2001 From: David Abram Date: Sat, 31 Aug 2024 13:12:32 +0200 Subject: [PATCH 1/5] update css --- .../stylesheet/material/dark/base.css | 22 +++++++++---------- .../stylesheet/material/dark/bubble.css.tmpl | 15 +------------ .../stylesheet/material/dark/cta.css.tmpl | 8 +++---- .../stylesheet/material/light/base.css | 20 ++++++++--------- .../stylesheet/material/light/bubble.css.tmpl | 15 +------------ .../stylesheet/material/light/cta.css.tmpl | 8 +++---- 6 files changed, 31 insertions(+), 57 deletions(-) diff --git a/internal/template/stylesheet/material/dark/base.css b/internal/template/stylesheet/material/dark/base.css index bc7771b..579ab17 100644 --- a/internal/template/stylesheet/material/dark/base.css +++ b/internal/template/stylesheet/material/dark/base.css @@ -1,11 +1,11 @@ -:root { +.iv { --primary: #bb86fc; --primary-foreground: #000; --primary-hover: #995cff; --progress-bar: #bb86fc; } -.iv-card { +.iv .iv-card { animation: bounce-fade 0.4s; position: fixed; z-index: 10; @@ -19,7 +19,7 @@ cursor: pointer; } -.iv-close-button { +.iv .iv-close-button { position: absolute; top: -16px; right: -16px; @@ -37,7 +37,7 @@ padding-bottom: 2px; } -.iv-player { +.iv .iv-player { display: none; width: 100%; height: 100%; @@ -46,10 +46,10 @@ object-fit: cover; } -.iv-player-wrapper { +.iv .iv-player-wrapper { width: 100%; height: 100%; - position: relative; + position: rela.iv .ive; border-radius: 8px; display: flex; flex-direction: column; @@ -57,7 +57,7 @@ margin: auto; } -.iv-progressbar { +.iv .iv-progressbar { width: 100%; height: 8px; position: absolute; @@ -67,23 +67,23 @@ overflow: hidden; } -.iv-progressbar::-webkit-progress-bar { +.iv .iv-progressbar::-webkit-progress-bar { background-color: transparent; border-bottom-right-radius: 8px; border-bottom-left-radius: 8px; } -.iv-progressbar::-webkit-progress-value { +.iv .iv-progressbar::-webkit-progress-value { background-color: var(--progress-bar); } -.iv-progressbar::-moz-progress-bar { +.iv .iv-progressbar::-moz-progress-bar { background-color: transparent; border-bottom-right-radius: 8px; border-bottom-left-radius: 8px; } -.iv-progressbar::-moz-progress-value { +.iv .iv-progressbar::-moz-progress-value { background-color: var(--progress-bar); } diff --git a/internal/template/stylesheet/material/dark/bubble.css.tmpl b/internal/template/stylesheet/material/dark/bubble.css.tmpl index 030a586..c3c5fcf 100644 --- a/internal/template/stylesheet/material/dark/bubble.css.tmpl +++ b/internal/template/stylesheet/material/dark/bubble.css.tmpl @@ -1,6 +1,6 @@ {{define "bubble"}} -.iv-bubble { +.iv .iv-bubble { position: absolute; top: 30px; left: -40px; @@ -27,17 +27,4 @@ border-bottom-right-radius: 2px; } -.iv-bubble:focus { - box-shadow: 0 0 0 2px var(--primary); -} - -.iv-bubble.disabled { - pointer-events: none; - opacity: 0.5; -} - -.iv-bubble:hover { - background-color: var(--primary-hover); -} - {{end}} diff --git a/internal/template/stylesheet/material/dark/cta.css.tmpl b/internal/template/stylesheet/material/dark/cta.css.tmpl index 45df8d8..fdf3896 100644 --- a/internal/template/stylesheet/material/dark/cta.css.tmpl +++ b/internal/template/stylesheet/material/dark/cta.css.tmpl @@ -1,6 +1,6 @@ {{define "cta"}} -.iv-cta-button { +.iv .iv-cta-button { display: inline-block; position: absolute; bottom: 2rem; @@ -21,18 +21,18 @@ box-shadow 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms, border 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms; } -.iv-cta-button:hover { +.iv .iv-cta-button:hover { background-color: var(--primary-hover); box-shadow: 0px 2px 4px -1px rgba(0,0,0,0.2), 0px 4px 5px 0px rgba(0,0,0,0.14), 0px 1px 10px 0px rgba(0,0,0,0.12); } -.iv-cta-button:active { +.iv .iv-cta-button:active { box-shadow: 0px 5px 5px -3px rgba(0,0,0,0.2), 0px 8px 10px 1px rgba(0,0,0,0.14), 0px 3px 14px 2px rgba(0,0,0,0.12); } -.iv-cta-button:focus { +.iv .iv-cta-button:focus { outline: none; } diff --git a/internal/template/stylesheet/material/light/base.css b/internal/template/stylesheet/material/light/base.css index e17ff31..108ed2f 100644 --- a/internal/template/stylesheet/material/light/base.css +++ b/internal/template/stylesheet/material/light/base.css @@ -1,11 +1,11 @@ -:root { +.iv { --primary: #1976d2; --primary-foreground: #fff; --primary-hover: #1565c0; --progress-bar: #1976d2; } -.iv-card { +.iv .iv-card { animation: bounce-fade 0.4s; position: fixed; z-index: 10; @@ -19,7 +19,7 @@ cursor: pointer; } -.iv-close-button { +.iv .iv-close-button { position: absolute; top: -16px; right: -16px; @@ -37,7 +37,7 @@ padding-bottom: 2px; } -.iv-player { +.iv .iv-player { display: none; width: 100%; height: 100%; @@ -46,7 +46,7 @@ object-fit: cover; } -.iv-player-wrapper { +.iv .iv-player-wrapper { width: 100%; height: 100%; position: relative; @@ -57,7 +57,7 @@ margin: auto; } -.iv-progressbar { +.iv .iv-progressbar { width: 100%; height: 8px; position: absolute; @@ -67,23 +67,23 @@ overflow: hidden; } -.iv-progressbar::-webkit-progress-bar { +.iv .iv-progressbar::-webkit-progress-bar { background-color: transparent; border-bottom-right-radius: 8px; border-bottom-left-radius: 8px; } -.iv-progressbar::-webkit-progress-value { +.iv .iv-progressbar::-webkit-progress-value { background-color: var(--progress-bar); } -.iv-progressbar::-moz-progress-bar { +.iv .iv-progressbar::-moz-progress-bar { background-color: transparent; border-bottom-right-radius: 8px; border-bottom-left-radius: 8px; } -.iv-progressbar::-moz-progress-value { +.iv .iv-progressbar::-moz-progress-value { background-color: var(--progress-bar); } diff --git a/internal/template/stylesheet/material/light/bubble.css.tmpl b/internal/template/stylesheet/material/light/bubble.css.tmpl index 0754e78..73cc081 100644 --- a/internal/template/stylesheet/material/light/bubble.css.tmpl +++ b/internal/template/stylesheet/material/light/bubble.css.tmpl @@ -1,6 +1,6 @@ {{define "bubble"}} -.iv-bubble { +.iv .iv-bubble { position: absolute; top: 30px; @@ -32,17 +32,4 @@ border-bottom-right-radius: 2px; } -.iv-bubble:focus { - box-shadow: 0 0 0 2px var(--primary); -} - -.iv-bubble.disabled { - pointer-events: none; - opacity: 0.5; -} - -.iv-bubble:hover { - background-color: var(--primary-hover); -} - {{end}} diff --git a/internal/template/stylesheet/material/light/cta.css.tmpl b/internal/template/stylesheet/material/light/cta.css.tmpl index 45df8d8..fdf3896 100644 --- a/internal/template/stylesheet/material/light/cta.css.tmpl +++ b/internal/template/stylesheet/material/light/cta.css.tmpl @@ -1,6 +1,6 @@ {{define "cta"}} -.iv-cta-button { +.iv .iv-cta-button { display: inline-block; position: absolute; bottom: 2rem; @@ -21,18 +21,18 @@ box-shadow 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms, border 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms; } -.iv-cta-button:hover { +.iv .iv-cta-button:hover { background-color: var(--primary-hover); box-shadow: 0px 2px 4px -1px rgba(0,0,0,0.2), 0px 4px 5px 0px rgba(0,0,0,0.14), 0px 1px 10px 0px rgba(0,0,0,0.12); } -.iv-cta-button:active { +.iv .iv-cta-button:active { box-shadow: 0px 5px 5px -3px rgba(0,0,0,0.2), 0px 8px 10px 1px rgba(0,0,0,0.14), 0px 3px 14px 2px rgba(0,0,0,0.12); } -.iv-cta-button:focus { +.iv .iv-cta-button:focus { outline: none; } From b5f089c7ea2ab5c9cff68ab3514b69979919ba31 Mon Sep 17 00:00:00 2001 From: David Abram Date: Sat, 31 Aug 2024 14:31:44 +0200 Subject: [PATCH 2/5] fixed stuff --- cmd/api/main.go | 6 +- db/migrations/1715450001_video.down.sql | 1 - db/migrations/1715450001_video.up.sql | 9 - db/migrations/1715450002_instance.down.sql | 1 - db/migrations/1715450002_instance.up.sql | 6 - .../1722361838_configuration.down.sql | 27 --- db/migrations/1722361838_configuration.up.sql | 13 -- ....sql => 1725105528_configuration.down.sql} | 0 ...up.sql => 1725105528_configuration.up.sql} | 6 +- db/migrations/schema.sql | 35 ++-- .../data/{instance.go => configuration.go} | 56 ++----- ...instance_test.go => configuration_test.go} | 6 +- internal/handler/configuration.go | 154 +++++++++--------- 13 files changed, 115 insertions(+), 205 deletions(-) delete mode 100644 db/migrations/1715450001_video.down.sql delete mode 100644 db/migrations/1715450001_video.up.sql delete mode 100644 db/migrations/1715450002_instance.down.sql delete mode 100644 db/migrations/1715450002_instance.up.sql delete mode 100644 db/migrations/1722361838_configuration.down.sql delete mode 100644 db/migrations/1722361838_configuration.up.sql rename db/migrations/{1715450000_configuration.down.sql => 1725105528_configuration.down.sql} (100%) rename db/migrations/{1715450000_configuration.up.sql => 1725105528_configuration.up.sql} (70%) rename internal/data/{instance.go => configuration.go} (77%) rename internal/data/{instance_test.go => configuration_test.go} (98%) diff --git a/cmd/api/main.go b/cmd/api/main.go index d9dd1f3..aeda58e 100644 --- a/cmd/api/main.go +++ b/cmd/api/main.go @@ -18,9 +18,10 @@ func main() { e.GET("/demo/style.css", handler.Stylesheet) - e.GET("/v/:ulid", handler.Configuration) + e.GET("/v/:ulid", handler.GetConfiguration) + e.GET("/v/new", handler.GetConfiguration) + e.POST("/v/:ulid", handler.UpdateConfig) - e.GET("/v/new", handler.Configuration) e.POST("/v/new", handler.IntroVideoCode) e.POST("/v/config", handler.CreateConfig) @@ -36,4 +37,3 @@ func main() { e.Logger.Fatal(e.Start(":" + port)) } - diff --git a/db/migrations/1715450001_video.down.sql b/db/migrations/1715450001_video.down.sql deleted file mode 100644 index fe2c03a..0000000 --- a/db/migrations/1715450001_video.down.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE `videos`; diff --git a/db/migrations/1715450001_video.up.sql b/db/migrations/1715450001_video.up.sql deleted file mode 100644 index 44fdb86..0000000 --- a/db/migrations/1715450001_video.up.sql +++ /dev/null @@ -1,9 +0,0 @@ -CREATE TABLE `videos` ( - `id` INTEGER PRIMARY KEY NOT NULL, - `url` TEXT NOT NULL, - `weight` INTEGER DEFAULT 1, - `configuration_id` INTEGER NOT NULL, - `instance_id` INTEGER NOT NULL, - FOREIGN KEY(`configuration_id`) REFERENCES `configurations`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION, - FOREIGN KEY(`instance_id`) REFERENCES `instances`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION -); diff --git a/db/migrations/1715450002_instance.down.sql b/db/migrations/1715450002_instance.down.sql deleted file mode 100644 index 80ecbb1..0000000 --- a/db/migrations/1715450002_instance.down.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE `instances`; diff --git a/db/migrations/1715450002_instance.up.sql b/db/migrations/1715450002_instance.up.sql deleted file mode 100644 index 8701079..0000000 --- a/db/migrations/1715450002_instance.up.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE TABLE `instances` ( - `id` INTEGER PRIMARY KEY NOT NULL, - `external_id` BLOB UNIQUE NOT NULL -); - -CREATE INDEX instances_external_id_idx ON instances(external_id); diff --git a/db/migrations/1722361838_configuration.down.sql b/db/migrations/1722361838_configuration.down.sql deleted file mode 100644 index b1472ed..0000000 --- a/db/migrations/1722361838_configuration.down.sql +++ /dev/null @@ -1,27 +0,0 @@ -DROP TABLE IF EXISTS `videos`; -DROP TABLE IF EXISTS `instances`; -DROP TABLE IF EXISTS `configurations`; - -CREATE TABLE `configurations` ( - `id` INTEGER PRIMARY KEY NOT NULL, - `theme` TEXT DEFAULT 'default', - `bubble_enabled` BOOLEAN DEFAULT false, - `bubble_text_content` TEXT, - `cta_enabled` BOOLEAN DEFAULT false, - `cta_text_content` TEXT -); -CREATE TABLE `videos` ( - `id` INTEGER PRIMARY KEY NOT NULL, - `url` TEXT NOT NULL, - `weight` INTEGER DEFAULT 1, - `configuration_id` INTEGER NOT NULL, - `instance_id` INTEGER NOT NULL, - FOREIGN KEY(`configuration_id`) REFERENCES `configurations`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION, - FOREIGN KEY(`instance_id`) REFERENCES `instances`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION -); -CREATE TABLE `instances` ( - `id` INTEGER PRIMARY KEY NOT NULL, - `external_id` BLOB UNIQUE NOT NULL -); - -CREATE INDEX instances_external_id_idx ON instances(external_id); diff --git a/db/migrations/1722361838_configuration.up.sql b/db/migrations/1722361838_configuration.up.sql deleted file mode 100644 index d491815..0000000 --- a/db/migrations/1722361838_configuration.up.sql +++ /dev/null @@ -1,13 +0,0 @@ -DROP TABLE IF EXISTS `videos`; -DROP TABLE IF EXISTS `instances`; -DROP TABLE IF EXISTS `configurations`; - -CREATE TABLE `configurations` ( - `id` BLOB UNIQUE NOT NULL, - `theme` TEXT DEFAULT 'default', - `bubble_enabled` BOOLEAN DEFAULT false, - `bubble_text_content` TEXT, - `cta_enabled` BOOLEAN DEFAULT false, - `cta_text_content` TEXT, - `video_url` TEXT -); diff --git a/db/migrations/1715450000_configuration.down.sql b/db/migrations/1725105528_configuration.down.sql similarity index 100% rename from db/migrations/1715450000_configuration.down.sql rename to db/migrations/1725105528_configuration.down.sql diff --git a/db/migrations/1715450000_configuration.up.sql b/db/migrations/1725105528_configuration.up.sql similarity index 70% rename from db/migrations/1715450000_configuration.up.sql rename to db/migrations/1725105528_configuration.up.sql index 968e468..1dabd15 100644 --- a/db/migrations/1715450000_configuration.up.sql +++ b/db/migrations/1725105528_configuration.up.sql @@ -1,9 +1,9 @@ CREATE TABLE `configurations` ( - `id` INTEGER PRIMARY KEY NOT NULL, + `id` BLOB UNIQUE NOT NULL, `theme` TEXT DEFAULT 'default', `bubble_enabled` BOOLEAN DEFAULT false, `bubble_text_content` TEXT, `cta_enabled` BOOLEAN DEFAULT false, - `cta_text_content` TEXT + `cta_text_content` TEXT, + `video_url` TEXT ); - diff --git a/db/migrations/schema.sql b/db/migrations/schema.sql index 6b574b2..4b66018 100644 --- a/db/migrations/schema.sql +++ b/db/migrations/schema.sql @@ -1,22 +1,15 @@ -CREATE TABLE schema_migrations (id VARCHAR(255) NOT NULL PRIMARY KEY); + +-- +-- LibSQL SQL Schema dump automatic generated by geni +-- + +CREATE TABLE schema_migrations (id VARCHAR(255) NOT NULL PRIMARY KEY) CREATE TABLE `configurations` ( -\t`id` integer PRIMARY KEY NOT NULL, - `bubble_enabled` boolean DEFAULT false, - `bubble_text_content` text, - `bubble_type` text DEFAULT 'default', - `cta_enabled` boolean DEFAULT false, - `cta_text_content` text, - `cta_type` text DEFAULT 'default' -); -CREATE TABLE `videos` ( -\t`id` integer PRIMARY KEY NOT NULL, - `url` text NOT NULL, - `weight` integer DEFAULT 1, - `configuration_id` integer NOT NULL, - `instance_id` integer NOT NULL, - FOREIGN KEY(`configuration_id`) REFERENCES `configurations`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION, - FOREIGN KEY(`instance_id`) REFERENCES `instances`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION -); -CREATE TABLE `instances` ( -\t`id` integer PRIMARY KEY NOT NULL -); + `id` BLOB UNIQUE NOT NULL, + `theme` TEXT DEFAULT 'default', + `bubble_enabled` BOOLEAN DEFAULT false, + `bubble_text_content` TEXT, + `cta_enabled` BOOLEAN DEFAULT false, + `cta_text_content` TEXT, + `video_url` TEXT +) \ No newline at end of file diff --git a/internal/data/instance.go b/internal/data/configuration.go similarity index 77% rename from internal/data/instance.go rename to internal/data/configuration.go index 40ea28e..f7d3b84 100644 --- a/internal/data/instance.go +++ b/internal/data/configuration.go @@ -2,8 +2,8 @@ package data import ( "database/sql" - "os" "fmt" + "os" "github.com/crocoder-dev/intro-video/internal/config" "github.com/joho/godotenv" @@ -11,37 +11,18 @@ import ( _ "github.com/tursodatabase/libsql-client-go/libsql" ) -type Instance struct { - Id int32 - ExternalId []byte - Videos map[int32]Video - Configurations map[int32]Configuration -} - -type NewVideo struct { - Weight int32 - URL string -} - -type Video struct { - Id int32 - Weight int32 - ConfigurationId int32 - URL string -} - type NewConfiguration struct { VideoUrl string - Theme config.Theme - Bubble config.Bubble - Cta config.Cta + Theme config.Theme + Bubble config.Bubble + Cta config.Cta } type Configuration struct { - Id []byte - Theme config.Theme - Bubble config.Bubble - Cta config.Cta + Id []byte + Theme config.Theme + Bubble config.Bubble + Cta config.Cta VideoUrl string } @@ -61,7 +42,7 @@ func NewStore() (Store, error) { } -func (s *Store) LoadConfig(id []byte) (Configuration, error) { +func (s *Store) LoadConfiguration(id []byte) (Configuration, error) { db, err := sql.Open(s.DriverName, s.DatabaseUrl) if err != nil { return Configuration{}, err @@ -113,7 +94,7 @@ func (s *Store) LoadConfig(id []byte) (Configuration, error) { } return Configuration{ - Id: configId, + Id: configId, Theme: config.Theme(theme), Bubble: config.Bubble{ Enabled: bubbleEnabled, @@ -179,10 +160,10 @@ func (s *Store) CreateConfiguration(configuration NewConfiguration) (Configurati } newConfiguration := Configuration{ - Id: configurationId, - Theme: configuration.Theme, - Bubble: config.Bubble{Enabled: configuration.Bubble.Enabled, TextContent: configuration.Bubble.TextContent}, - Cta: config.Cta{Enabled: configuration.Cta.Enabled, TextContent: configuration.Cta.TextContent}, + Id: configurationId, + Theme: configuration.Theme, + Bubble: config.Bubble{Enabled: configuration.Bubble.Enabled, TextContent: configuration.Bubble.TextContent}, + Cta: config.Cta{Enabled: configuration.Cta.Enabled, TextContent: configuration.Cta.TextContent}, VideoUrl: configuration.VideoUrl, } @@ -232,13 +213,12 @@ func (s *Store) UpdateConfiguration(id []byte, configuration NewConfiguration) ( } updatedConfiguration := Configuration{ - Id: id, - Theme: configuration.Theme, - Bubble: config.Bubble{Enabled: configuration.Bubble.Enabled, TextContent: configuration.Bubble.TextContent}, - Cta: config.Cta{Enabled: configuration.Cta.Enabled, TextContent: configuration.Cta.TextContent}, + Id: id, + Theme: configuration.Theme, + Bubble: config.Bubble{Enabled: configuration.Bubble.Enabled, TextContent: configuration.Bubble.TextContent}, + Cta: config.Cta{Enabled: configuration.Cta.Enabled, TextContent: configuration.Cta.TextContent}, VideoUrl: configuration.VideoUrl, } return updatedConfiguration, nil } - diff --git a/internal/data/instance_test.go b/internal/data/configuration_test.go similarity index 98% rename from internal/data/instance_test.go rename to internal/data/configuration_test.go index 668cfbd..df683e1 100644 --- a/internal/data/instance_test.go +++ b/internal/data/configuration_test.go @@ -153,7 +153,7 @@ func TestLoadConfiguration(t *testing.T) { store := data.Store{DatabaseUrl: dbName, DriverName: "sqlite3"} - configuration, err := store.LoadConfig(binUlid) + configuration, err := store.LoadConfiguration(binUlid) if err != nil { t.Fatalf("failed to load instance: %v", err) } @@ -224,7 +224,7 @@ func TestUpdateConfiguration(t *testing.T) { Enabled: false, TextContent: "updated cta text", }, - VideoUrl: "updated url", + VideoUrl: "updated url", } expected := data.Configuration{ @@ -241,7 +241,6 @@ func TestUpdateConfiguration(t *testing.T) { VideoUrl: "updated url", } - newConfig, err := store.UpdateConfiguration(configuration.Id, updatedConfiguration) if err != nil { t.Fatalf("failed to update instance: %v", err) @@ -250,4 +249,3 @@ func TestUpdateConfiguration(t *testing.T) { t.Fatalf("Expected updated configuration %+v, got %+v", newConfig, expected) } } - diff --git a/internal/handler/configuration.go b/internal/handler/configuration.go index f47532b..bbc4bbd 100644 --- a/internal/handler/configuration.go +++ b/internal/handler/configuration.go @@ -5,9 +5,9 @@ import ( "fmt" "io" "net/http" + "net/url" "os" "strconv" - "net/url" "github.com/crocoder-dev/intro-video/internal" "github.com/crocoder-dev/intro-video/internal/config" @@ -21,82 +21,81 @@ import ( _ "github.com/tursodatabase/libsql-client-go/libsql" ) -func Configuration(c echo.Context) error { +func GetConfiguration(c echo.Context) error { defaultConfig := config.IntroVideoFormValues{ - Url: "", - Theme: config.DefaultTheme, - CtaEnabled: false, - BubbleEnabled: false, - CtaText: "", - BubbleText: "", - } - - id := c.Param("ulid") - - configuration := defaultConfig - - if id != "" && id != "new" { - err := godotenv.Load(".env") - if err != nil { - return err - } - - dbUrl := os.Getenv("DATABASE_URL") - authToken := os.Getenv("TURSO_AUTH_TOKEN") - if dbUrl == "" || authToken == "" { - return fmt.Errorf("DATABASE_URL and TURSO_AUTH_TOKEN must be set in .env file") - } - - store := data.Store{DatabaseUrl: dbUrl + "?authToken=" + authToken, DriverName: "libsql"} - - byteId, err := ulid.Parse(id) - if err != nil { + Url: "", + Theme: config.DefaultTheme, + CtaEnabled: false, + BubbleEnabled: false, + CtaText: "", + BubbleText: "", + } + + id := c.Param("ulid") + + configuration := defaultConfig + + if id != "" && id != "new" { + err := godotenv.Load(".env") + if err != nil { + return err + } + + dbUrl := os.Getenv("DATABASE_URL") + if dbUrl == "" { + return fmt.Errorf("DATABASE_URL must be set in .env file") + } + + store := data.Store{DatabaseUrl: dbUrl, DriverName: "libsql"} + + byteId, err := ulid.Parse(id) + if err != nil { return shared.ErrorToast("Failed to parse ULID: %v. Using default configuration.").Render(context.Background(), c.Response().Writer) - } else { - loadedConfig, err := store.LoadConfig(byteId.Bytes()) - if err != nil { + } else { + loadedConfig, err := store.LoadConfiguration(byteId.Bytes()) + if err != nil { return shared.ErrorToast("Failed to load configuration: %v. Using default configuration.").Render(context.Background(), c.Response().Writer) - } else { - configuration = config.IntroVideoFormValues{ - Theme: loadedConfig.Theme, - CtaEnabled: loadedConfig.Cta.Enabled, + } else { + configuration = config.IntroVideoFormValues{ + Theme: loadedConfig.Theme, + CtaEnabled: loadedConfig.Cta.Enabled, BubbleEnabled: loadedConfig.Bubble.Enabled, - BubbleText: loadedConfig.Bubble.TextContent, - CtaText: loadedConfig.Cta.TextContent, - Url: loadedConfig.VideoUrl, + BubbleText: loadedConfig.Bubble.TextContent, + CtaText: loadedConfig.Cta.TextContent, + Url: loadedConfig.VideoUrl, } - } - } - } - - themeOptions := []template.ThemeOption{ - {Caption: "Default Theme", Value: config.DefaultTheme}, - {Caption: "Shadcn Theme - Light", Value: config.ShadcnThemeLight}, - {Caption: "Shadcn Theme - Dark", Value: config.ShadcnThemeDark}, - {Caption: "MaterialUi Theme - Light", Value: config.MaterialUiThemeLight}, - {Caption: "MaterialUi Theme - Dark", Value: config.MaterialUiThemeDark}, - {Caption: "Tailwind Theme - Dark", Value: config.TailwindThemeDark}, - {Caption: "Tailwind Theme - Light", Value: config.TailwindThemeLight}, - {Caption: "CroCoder Theme", Value: config.Crocoder, Selected: true}, - {Caption: "None", Value: config.NoneTheme}, - } - - file, err := os.Open("internal/template/script/base.js") - if err != nil { + } + } + } + + themeOptions := []template.ThemeOption{ + {Caption: "Default Theme", Value: config.DefaultTheme}, + {Caption: "Shadcn Theme - Light", Value: config.ShadcnThemeLight}, + {Caption: "Shadcn Theme - Dark", Value: config.ShadcnThemeDark}, + {Caption: "MaterialUi Theme - Light", Value: config.MaterialUiThemeLight}, + {Caption: "MaterialUi Theme - Dark", Value: config.MaterialUiThemeDark}, + {Caption: "Tailwind Theme - Dark", Value: config.TailwindThemeDark}, + {Caption: "Tailwind Theme - Light", Value: config.TailwindThemeLight}, + {Caption: "CroCoder Theme", Value: config.Crocoder, Selected: true}, + {Caption: "None", Value: config.NoneTheme}, + } + + file, err := os.Open("internal/template/script/base.js") + if err != nil { return shared.ErrorToast("Something went wrong!").Render(context.Background(), c.Response().Writer) - } - defer file.Close() - base, err := io.ReadAll(file) - if err != nil { + } + defer file.Close() + base, err := io.ReadAll(file) + if err != nil { return shared.ErrorToast("Failed to read the base script file.").Render(context.Background(), c.Response().Writer) - } - basePreviewJs := "" - component := template.Configuration( - themeOptions, - basePreviewJs, - configuration, + } + basePreviewJs := "" + component := template.Configuration( + themeOptions, + basePreviewJs, + configuration, id, - ) + ) return component.Render(context.Background(), c.Response().Writer) } @@ -107,15 +106,13 @@ func initializeStore() (data.Store, error) { return data.Store{}, err } dbUrl := os.Getenv("DATABASE_URL") - authToken := os.Getenv("TURSO_AUTH_TOKEN") - if dbUrl == "" || authToken == "" { - return data.Store{}, fmt.Errorf("DATABASE_URL and TURSO_AUTH_TOKEN must be set in .env file") + if dbUrl == "" { + return data.Store{}, fmt.Errorf("DATABASE_URL must be set in .env file") } - return data.Store{DatabaseUrl: dbUrl + "?authToken=" + authToken, DriverName: "libsql"}, nil + return data.Store{DatabaseUrl: dbUrl, DriverName: "libsql"}, nil } func parseFormValues(c echo.Context) (data.NewConfiguration, error) { - newVideo := data.NewVideo{Weight: 100, URL: c.FormValue(template.URL)} newTheme := config.Theme(c.FormValue(template.THEME)) newBubbleEnabledStr := c.FormValue(template.BUBBLE_ENABLED) @@ -138,8 +135,8 @@ func parseFormValues(c echo.Context) (data.NewConfiguration, error) { } return data.NewConfiguration{ - VideoUrl: newVideo.URL, - Theme: newTheme, + VideoUrl: c.FormValue(template.URL), + Theme: newTheme, Bubble: config.Bubble{ Enabled: newBubbleEnabled, TextContent: c.FormValue(template.BUBBLE_TEXT), @@ -169,7 +166,6 @@ func validateURL(videoUrl string) error { return fmt.Errorf("Video url is invalid!") } - return nil } @@ -232,6 +228,7 @@ func UpdateConfig(c echo.Context) error { } func IntroVideoCode(c echo.Context) error { + fmt.Println( "url", c.FormValue(template.URL), "\n", "bubbleEnabled", c.FormValue(template.BUBBLE_ENABLED), "\n", @@ -278,7 +275,7 @@ func IntroVideoCode(c echo.Context) error { ctaEnabledRaw := c.FormValue(template.CTA_ENABLED) if ctaEnabledRaw == "on" || ctaEnabledRaw == "true" { ctaEnabled = true - } else if ctaEnabledRaw == "off" || ctaEnabledRaw == "" { + } else if ctaEnabledRaw == "off" || ctaEnabledRaw == "" { ctaEnabled = false } @@ -325,4 +322,3 @@ func IntroVideoCode(c echo.Context) error { component := template.IntroVideoPreview(js, css, previewScript, previewStyle) return component.Render(context.Background(), c.Response().Writer) } - From 0928b4439c320d4661ed0f66fa32d2566b75b2df Mon Sep 17 00:00:00 2001 From: David Abram Date: Sat, 31 Aug 2024 23:51:23 +0200 Subject: [PATCH 3/5] updates --- internal/handler/configuration.go | 99 ++++++++++-------------- internal/template/configuration.templ | 2 + internal/template/intro-video-form.templ | 2 +- public/components/video-input.js | 5 +- 4 files changed, 47 insertions(+), 61 deletions(-) diff --git a/internal/handler/configuration.go b/internal/handler/configuration.go index bbc4bbd..fe8a235 100644 --- a/internal/handler/configuration.go +++ b/internal/handler/configuration.go @@ -97,7 +97,6 @@ func GetConfiguration(c echo.Context) error { id, ) return component.Render(context.Background(), c.Response().Writer) - } func initializeStore() (data.Store, error) { @@ -227,79 +226,63 @@ func UpdateConfig(c echo.Context) error { return c.NoContent(http.StatusOK) } -func IntroVideoCode(c echo.Context) error { - - fmt.Println( - "url", c.FormValue(template.URL), "\n", - "bubbleEnabled", c.FormValue(template.BUBBLE_ENABLED), "\n", - "bubbleText", c.FormValue(template.BUBBLE_TEXT), "\n", - "theme", c.FormValue(template.THEME), "\n", - "ctaEnabled", c.FormValue(template.CTA_ENABLED), "\n", - "ctaText", c.FormValue(template.CTA_TEXT), - ) - - url := c.FormValue(template.URL) +type previewCode struct { + js string + css string + previewScript string + previewStyle string +} - if url == "" { - url = template.DEFAULT_URL - } +func createPreviewCode(videoUrl string, theme config.Theme, bubble config.Bubble, cta config.Cta) (previewCode, error) { - theme, err := config.NewTheme(c.FormValue(template.THEME)) - if err != nil { - fmt.Println(err) - return shared.ErrorToast("There was an issue generating the theme. Please check the theme value and try again.").Render(context.Background(), c.Response().Writer) + processableFileProps := internal.ProcessableFileProps{ + URL: videoUrl, + Theme: theme, + Bubble: bubble, + Cta: cta, } - bubbleEnabledRaw := c.FormValue(template.BUBBLE_ENABLED) + previewScript, err := internal.Script{}.Process(processableFileProps, internal.ProcessableFileOpts{Preview: true}) + previewScript = "" - var bubbleEnabled bool + previewStyle, err := internal.Stylesheet{}.Process(processableFileProps, internal.ProcessableFileOpts{Preview: true}) + previewStyle = "" - if bubbleEnabledRaw == "" || bubbleEnabledRaw == "off" { - bubbleEnabled = false - } else if bubbleEnabledRaw == "on" || bubbleEnabledRaw == "true" { - bubbleEnabled = true + js, err := internal.Script{}.Process(processableFileProps, internal.ProcessableFileOpts{Minify: true}) + if err != nil { + return previewCode{}, err } - var bubbleTextContent string - - if bubbleEnabled { - if c.FormValue(template.BUBBLE_TEXT) != "" { - bubbleTextContent = c.FormValue(template.BUBBLE_TEXT) - } else { - bubbleTextContent = template.DEFAULT_BUBBLE_TEXT - } + css, err := internal.Stylesheet{}.Process(processableFileProps, internal.ProcessableFileOpts{Minify: true}) + if err != nil { + return previewCode{}, err } + return previewCode{ + js: js, + css: css, + previewScript: previewScript, + previewStyle: previewStyle, + }, nil +} - var ctaEnabled bool +func IntroVideoCode(c echo.Context) error { - ctaEnabledRaw := c.FormValue(template.CTA_ENABLED) - if ctaEnabledRaw == "on" || ctaEnabledRaw == "true" { - ctaEnabled = true - } else if ctaEnabledRaw == "off" || ctaEnabledRaw == "" { - ctaEnabled = false - } + configuration, err := parseFormValues(c) - var ctaTextContent string + if err != nil { + return shared.ErrorToast("Something went wrong!").Render(context.Background(), c.Response().Writer) + } - if ctaEnabled { - if c.FormValue(template.CTA_TEXT) != "" { - ctaTextContent = c.FormValue(template.CTA_TEXT) - } else { - ctaTextContent = template.DEFAULT_CTA_TEXT - } + err = validateConfiguration(configuration) + if err != nil { + return shared.ErrorToast(err.Error()).Render(context.Background(), c.Response().Writer) } processableFileProps := internal.ProcessableFileProps{ - URL: url, - Theme: theme, - Bubble: config.Bubble{ - Enabled: bubbleEnabled, - TextContent: bubbleTextContent, - }, - Cta: config.Cta{ - Enabled: ctaEnabled, - TextContent: ctaTextContent, - }, + URL: configuration.VideoUrl, + Theme: configuration.Theme, + Bubble: configuration.Bubble, + Cta: configuration.Cta, } previewScript, err := internal.Script{}.Process(processableFileProps, internal.ProcessableFileOpts{Preview: true}) diff --git a/internal/template/configuration.templ b/internal/template/configuration.templ index fb8597a..1eadc7f 100644 --- a/internal/template/configuration.templ +++ b/internal/template/configuration.templ @@ -24,6 +24,8 @@ script handleErrors() { }); } +/*js string, css string, previewScript string, previewStyle string */ + templ Configuration(themeOptions []ThemeOption, basePreviewJs string, formInputValues config.IntroVideoFormValues, id string) { diff --git a/internal/template/intro-video-form.templ b/internal/template/intro-video-form.templ index a529315..aee2049 100644 --- a/internal/template/intro-video-form.templ +++ b/internal/template/intro-video-form.templ @@ -44,7 +44,7 @@ templ IntroVideoForm(themeOptions []ThemeOption, basePreviewJs string, formValue
- + +