added profiles properly
This commit is contained in:
parent
560d37abd4
commit
2cea019aca
13
README.md
13
README.md
@ -8,14 +8,19 @@ https://diyhrt.market/api/
|
||||
2. Run air
|
||||
|
||||
```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
|
||||
|
||||
- implement regular fetching
|
||||
- implement starting it on a certain port depending on command line arg
|
||||
- implement config file
|
||||
- implement ctl
|
||||
- implement fetching in intervals
|
||||
- actually building and figuring out how I should do that
|
||||
|
@ -13,7 +13,11 @@ import (
|
||||
"github.com/pelletier/go-toml"
|
||||
)
|
||||
|
||||
type RenderingConfig struct {
|
||||
type ServerConfig struct {
|
||||
Port int
|
||||
}
|
||||
|
||||
type TemplateConfig struct {
|
||||
HeaderPhrases []string
|
||||
BackgroundScrollX string
|
||||
BackgroundScrollY string
|
||||
@ -29,8 +33,17 @@ type RenderingConfig struct {
|
||||
Stores []diyhrt.Store
|
||||
}
|
||||
|
||||
func DefaultRenderingConfig() RenderingConfig {
|
||||
return RenderingConfig{
|
||||
type Config struct{
|
||||
Server ServerConfig
|
||||
Template TemplateConfig
|
||||
}
|
||||
|
||||
func NewConfig() Config{
|
||||
return Config{
|
||||
Server: ServerConfig{
|
||||
Port: 5500,
|
||||
},
|
||||
Template: TemplateConfig{
|
||||
HeaderPhrases: []string{
|
||||
"GirlJuice.Inject();",
|
||||
"Child.CrowdKill();",
|
||||
@ -55,10 +68,11 @@ func DefaultRenderingConfig() RenderingConfig {
|
||||
ListingFilter: diyhrt.ListingFilter{
|
||||
FromStores: []int{7},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (rc *RenderingConfig) LoadDiyHrt(listings []diyhrt.Listing) {
|
||||
func (rc *TemplateConfig) LoadDiyHrt(listings []diyhrt.Listing) {
|
||||
existingStores := make(map[int]diyhrt.Store)
|
||||
|
||||
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"
|
||||
|
||||
configPath := configdir.LocalConfig("startpage")
|
||||
@ -91,7 +105,7 @@ func (rc *RenderingConfig) ScanForConfigFile(profile string) error {
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
37
main.go
37
main.go
@ -4,13 +4,17 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"gitea.elara.ws/Hazel/transfem-startpage/internal/diyhrt"
|
||||
"gitea.elara.ws/Hazel/transfem-startpage/internal/rendering"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
var CurrentRenderingConfig = rendering.DefaultRenderingConfig()
|
||||
|
||||
var CurrentConfig = rendering.NewConfig()
|
||||
|
||||
|
||||
func FetchDiyHrt() error {
|
||||
fmt.Println("Fetch DiyHrt Marketplaces...")
|
||||
@ -19,22 +23,13 @@ func FetchDiyHrt() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
CurrentRenderingConfig.LoadDiyHrt(l)
|
||||
CurrentConfig.Template.LoadDiyHrt(l)
|
||||
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 {
|
||||
var tpl bytes.Buffer
|
||||
rendering.IndexTemplate.Execute(&tpl, CurrentRenderingConfig)
|
||||
rendering.IndexTemplate.Execute(&tpl, CurrentConfig.Template)
|
||||
|
||||
return c.HTML(http.StatusOK, tpl.String())
|
||||
}
|
||||
@ -42,9 +37,18 @@ func getIndex(c echo.Context) error {
|
||||
func main() {
|
||||
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 {
|
||||
fmt.Println(err)
|
||||
}
|
||||
@ -54,8 +58,5 @@ func main() {
|
||||
e.Static("/scripts", "frontend/scripts")
|
||||
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.POST("/api/config", setConfig)
|
||||
|
||||
e.Logger.Fatal(e.Start(":5500"))
|
||||
e.Logger.Fatal(e.Start(":" + strconv.Itoa(CurrentConfig.Server.Port)))
|
||||
}
|
||||
|
@ -1,6 +0,0 @@
|
||||
HeaderPhrases = [
|
||||
"NewTab.SFW = true;",
|
||||
"You.Cute = true;",
|
||||
"You.Gay = true;",
|
||||
"Dolls.Headpat();",
|
||||
]
|
Loading…
x
Reference in New Issue
Block a user