added profiles properly

This commit is contained in:
Hazel Noack 2025-07-11 16:02:46 +02:00
parent 560d37abd4
commit 2cea019aca
5 changed files with 70 additions and 54 deletions

View File

@ -8,14 +8,19 @@ https://diyhrt.market/api/
2. Run air 2. Run air
```sh ```sh
air air dev
``` ```
## Config and Profiles
This tool works with profiles. The default profile is `startpage`. If you want to load another profile just write it as command line arg after the command. To write a config File you can create the files here:
- `{profile}.toml`
- `.{profile}.toml`
- `~/.config/startpage/{profile}.toml`
## TODO ## TODO
- implement regular fetching
- implement starting it on a certain port depending on command line arg
- implement config file
- implement ctl - implement ctl
- implement fetching in intervals - implement fetching in intervals
- actually building and figuring out how I should do that - actually building and figuring out how I should do that

2
dev.toml Normal file
View File

@ -0,0 +1,2 @@
[Server]
Port = 1234

View File

@ -13,7 +13,11 @@ import (
"github.com/pelletier/go-toml" "github.com/pelletier/go-toml"
) )
type RenderingConfig struct { type ServerConfig struct {
Port int
}
type TemplateConfig struct {
HeaderPhrases []string HeaderPhrases []string
BackgroundScrollX string BackgroundScrollX string
BackgroundScrollY string BackgroundScrollY string
@ -29,8 +33,17 @@ type RenderingConfig struct {
Stores []diyhrt.Store Stores []diyhrt.Store
} }
func DefaultRenderingConfig() RenderingConfig { type Config struct{
return RenderingConfig{ Server ServerConfig
Template TemplateConfig
}
func NewConfig() Config{
return Config{
Server: ServerConfig{
Port: 5500,
},
Template: TemplateConfig{
HeaderPhrases: []string{ HeaderPhrases: []string{
"GirlJuice.Inject();", "GirlJuice.Inject();",
"Child.CrowdKill();", "Child.CrowdKill();",
@ -55,10 +68,11 @@ func DefaultRenderingConfig() RenderingConfig {
ListingFilter: diyhrt.ListingFilter{ ListingFilter: diyhrt.ListingFilter{
FromStores: []int{7}, FromStores: []int{7},
}, },
},
} }
} }
func (rc *RenderingConfig) LoadDiyHrt(listings []diyhrt.Listing) { func (rc *TemplateConfig) LoadDiyHrt(listings []diyhrt.Listing) {
existingStores := make(map[int]diyhrt.Store) existingStores := make(map[int]diyhrt.Store)
for _, listing := range listings { for _, listing := range listings {
@ -70,7 +84,7 @@ func (rc *RenderingConfig) LoadDiyHrt(listings []diyhrt.Listing) {
} }
func (rc *RenderingConfig) ScanForConfigFile(profile string) error { func (rc *Config) ScanForConfigFile(profile string) error {
profileFile := profile + ".toml" profileFile := profile + ".toml"
configPath := configdir.LocalConfig("startpage") configPath := configdir.LocalConfig("startpage")
@ -91,7 +105,7 @@ func (rc *RenderingConfig) ScanForConfigFile(profile string) error {
return errors.New("No config file found") return errors.New("No config file found")
} }
func (rc *RenderingConfig) LoadConfigFile(file string) error { func (rc *Config) LoadConfigFile(file string) error {
if _, err := os.Stat(file); err != nil { if _, err := os.Stat(file); err != nil {
return err return err
} }

37
main.go
View File

@ -4,13 +4,17 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"net/http" "net/http"
"os"
"strconv"
"gitea.elara.ws/Hazel/transfem-startpage/internal/diyhrt" "gitea.elara.ws/Hazel/transfem-startpage/internal/diyhrt"
"gitea.elara.ws/Hazel/transfem-startpage/internal/rendering" "gitea.elara.ws/Hazel/transfem-startpage/internal/rendering"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
) )
var CurrentRenderingConfig = rendering.DefaultRenderingConfig()
var CurrentConfig = rendering.NewConfig()
func FetchDiyHrt() error { func FetchDiyHrt() error {
fmt.Println("Fetch DiyHrt Marketplaces...") fmt.Println("Fetch DiyHrt Marketplaces...")
@ -19,22 +23,13 @@ func FetchDiyHrt() error {
if err != nil { if err != nil {
return err return err
} }
CurrentRenderingConfig.LoadDiyHrt(l) CurrentConfig.Template.LoadDiyHrt(l)
return nil return nil
} }
func setConfig(c echo.Context) error {
err := c.Bind(&CurrentRenderingConfig)
if err != nil {
return c.String(http.StatusBadRequest, err.Error())
}
return c.String(http.StatusOK, "OK")
}
func getIndex(c echo.Context) error { func getIndex(c echo.Context) error {
var tpl bytes.Buffer var tpl bytes.Buffer
rendering.IndexTemplate.Execute(&tpl, CurrentRenderingConfig) rendering.IndexTemplate.Execute(&tpl, CurrentConfig.Template)
return c.HTML(http.StatusOK, tpl.String()) return c.HTML(http.StatusOK, tpl.String())
} }
@ -42,9 +37,18 @@ func getIndex(c echo.Context) error {
func main() { func main() {
fmt.Println("running transfem startpage") fmt.Println("running transfem startpage")
CurrentRenderingConfig.ScanForConfigFile("startpage") profile := "startpage"
if len(os.Args) > 1 {
profile = os.Args[1]
}
fmt.Println("loading profile " + profile + "...")
err := FetchDiyHrt() err := CurrentConfig.ScanForConfigFile(profile)
if err != nil {
fmt.Println(err)
}
err = FetchDiyHrt()
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
@ -54,8 +58,5 @@ func main() {
e.Static("/scripts", "frontend/scripts") e.Static("/scripts", "frontend/scripts")
e.GET("/", getIndex) e.GET("/", getIndex)
// this is for me to later setup the ctl such that I can config the running program on the command line e.Logger.Fatal(e.Start(":" + strconv.Itoa(CurrentConfig.Server.Port)))
e.POST("/api/config", setConfig)
e.Logger.Fatal(e.Start(":5500"))
} }

View File

@ -1,6 +0,0 @@
HeaderPhrases = [
"NewTab.SFW = true;",
"You.Cute = true;",
"You.Gay = true;",
"Dolls.Headpat();",
]