package pages

import (
  "gitler.moe/suwako/gitlin/utils"
  "github.com/gofiber/fiber/v2"
  "os"
  "runtime"
)

type PrivacyInfo struct {
  ProxyEnabled  string
  IPAddr        string
  ReqURL        string
  UserAgent     string
  Diagnostics   string
  Country       string
  Provider      string
  Cloudflare    string
  PrivacyPolicy string
  Ver           string
  Ves           string
  GoVersion     string
  FiberVersion  string
}

func HandleAbout(c *fiber.Ctx) error {
  var privacyInfoArray []PrivacyInfo
  privacyInfoArray = append(privacyInfoArray, PrivacyInfo{
    ProxyEnabled:  os.Getenv("GITLIN_PROXYING_ENABLED"),
    IPAddr:        os.Getenv("GITLIN_IP_LOGGED"),
    ReqURL:        os.Getenv("GITLIN_REQUEST_URL_LOGGED"),
    UserAgent:     os.Getenv("GITLIN_USER_AGENT_LOGGED"),
    Diagnostics:   os.Getenv("GITLIN_DIAGNOSTIC_INFO_LOGGED"),
    Country:       os.Getenv("GITLIN_INSTANCE_COUNTRY"),
    Provider:      os.Getenv("GITLIN_INSTANCE_PROVIDER"),
    Cloudflare:    os.Getenv("GITLIN_INSTANCE_CLOUDFLARE"),
    PrivacyPolicy: os.Getenv("GITLIN_INSTANCE_PRIVACY_POLICY"),
    Ver:           utils.Ver,
    Ves:           utils.Ves,
    FiberVersion:  fiber.Version,
    GoVersion:     runtime.Version(),
  })

  return c.Render("about", fiber.Map{
    "title":              "Gitlinインスタンスについて",
    "ver":                utils.Ver,
    "ves":                utils.Ves,
    "privacyInformation": privacyInfoArray,
  })
}
