add full data erasure + reformat the entire thing cause vsc sucks
This commit is contained in:
@@ -26,40 +26,13 @@ type DiscordUserResult struct {
|
|||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var rdb *redis.Client
|
||||||
|
|
||||||
func hash(s string) string {
|
func hash(s string) string {
|
||||||
return fmt.Sprintf("%x", sha1.Sum([]byte(s)))
|
return fmt.Sprintf("%x", sha1.Sum([]byte(s)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func requireAuth(c *fiber.Ctx) error {
|
||||||
// environment
|
|
||||||
HOST := os.Getenv("HOST")
|
|
||||||
PORT := os.Getenv("PORT")
|
|
||||||
REDIS_URI := os.Getenv("REDIS_URI")
|
|
||||||
ROOT_REDIRECT := os.Getenv("ROOT_REDIRECT")
|
|
||||||
|
|
||||||
DISCORD_CLIENT_ID := os.Getenv("DISCORD_CLIENT_ID")
|
|
||||||
DISCORD_CLIENT_SECRET := os.Getenv("DISCORD_CLIENT_SECRET")
|
|
||||||
DISCORD_REDIRECT_URI := os.Getenv("DISCORD_REDIRECT_URI")
|
|
||||||
|
|
||||||
PEPPER_SECRETS := os.Getenv("PEPPER_SECRETS")
|
|
||||||
PEPPER_SETTINGS := os.Getenv("PEPPER_SETTINGS")
|
|
||||||
|
|
||||||
slRaw, _ := strconv.ParseInt(os.Getenv("SIZE_LIMIT"), 10, 0)
|
|
||||||
SIZE_LIMIT := int(slRaw)
|
|
||||||
|
|
||||||
app := fiber.New()
|
|
||||||
rdb := redis.NewClient(&redis.Options{
|
|
||||||
Addr: REDIS_URI,
|
|
||||||
})
|
|
||||||
req := reqHttp.C()
|
|
||||||
|
|
||||||
app.Use(cors.New(cors.Config{
|
|
||||||
ExposeHeaders: "ETag",
|
|
||||||
}))
|
|
||||||
app.Use(logger.New())
|
|
||||||
|
|
||||||
// #region settings
|
|
||||||
app.All("/settings", func(c *fiber.Ctx) error {
|
|
||||||
authToken := c.Get("Authorization")
|
authToken := c.Get("Authorization")
|
||||||
|
|
||||||
if authToken == "" {
|
if authToken == "" {
|
||||||
@@ -91,7 +64,7 @@ func main() {
|
|||||||
userId := tokenSplit[0]
|
userId := tokenSplit[0]
|
||||||
secret := tokenSplit[1]
|
secret := tokenSplit[1]
|
||||||
|
|
||||||
storedSecret, err := rdb.Get(c.Context(), "secrets:" + hash(PEPPER_SECRETS + userId)).Result()
|
storedSecret, err := rdb.Get(c.Context(), "secrets:"+hash(os.Getenv("PEPPER_SECRETS")+userId)).Result()
|
||||||
|
|
||||||
if err == redis.Nil {
|
if err == redis.Nil {
|
||||||
return c.Status(401).JSON(&fiber.Map{
|
return c.Status(401).JSON(&fiber.Map{
|
||||||
@@ -110,7 +83,38 @@ func main() {
|
|||||||
c.Context().SetUserValue("userId", userId)
|
c.Context().SetUserValue("userId", userId)
|
||||||
|
|
||||||
return c.Next()
|
return c.Next()
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// environment
|
||||||
|
HOST := os.Getenv("HOST")
|
||||||
|
PORT := os.Getenv("PORT")
|
||||||
|
REDIS_URI := os.Getenv("REDIS_URI")
|
||||||
|
ROOT_REDIRECT := os.Getenv("ROOT_REDIRECT")
|
||||||
|
|
||||||
|
DISCORD_CLIENT_ID := os.Getenv("DISCORD_CLIENT_ID")
|
||||||
|
DISCORD_CLIENT_SECRET := os.Getenv("DISCORD_CLIENT_SECRET")
|
||||||
|
DISCORD_REDIRECT_URI := os.Getenv("DISCORD_REDIRECT_URI")
|
||||||
|
|
||||||
|
PEPPER_SECRETS := os.Getenv("PEPPER_SECRETS")
|
||||||
|
PEPPER_SETTINGS := os.Getenv("PEPPER_SETTINGS")
|
||||||
|
|
||||||
|
slRaw, _ := strconv.ParseInt(os.Getenv("SIZE_LIMIT"), 10, 0)
|
||||||
|
SIZE_LIMIT := int(slRaw)
|
||||||
|
|
||||||
|
app := fiber.New()
|
||||||
|
rdb = redis.NewClient(&redis.Options{
|
||||||
|
Addr: REDIS_URI,
|
||||||
})
|
})
|
||||||
|
req := reqHttp.C()
|
||||||
|
|
||||||
|
app.Use(cors.New(cors.Config{
|
||||||
|
ExposeHeaders: "ETag",
|
||||||
|
}))
|
||||||
|
app.Use(logger.New())
|
||||||
|
|
||||||
|
// #region settings
|
||||||
|
app.All("/settings", requireAuth)
|
||||||
|
|
||||||
app.Head("/settings", func(c *fiber.Ctx) error {
|
app.Head("/settings", func(c *fiber.Ctx) error {
|
||||||
userId := c.Context().UserValue("userId").(string)
|
userId := c.Context().UserValue("userId").(string)
|
||||||
@@ -154,13 +158,13 @@ func main() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
app.Put("/settings", func(c *fiber.Ctx) error {
|
app.Put("/settings", func(c *fiber.Ctx) error {
|
||||||
if (c.Get("Content-Type") != "application/octet-stream") {
|
if c.Get("Content-Type") != "application/octet-stream" {
|
||||||
return c.Status(415).JSON(&fiber.Map{
|
return c.Status(415).JSON(&fiber.Map{
|
||||||
"error": "Content type must be application/octet-stream",
|
"error": "Content type must be application/octet-stream",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len(c.Body()) > SIZE_LIMIT) {
|
if len(c.Body()) > SIZE_LIMIT {
|
||||||
return c.Status(413).JSON(&fiber.Map{
|
return c.Status(413).JSON(&fiber.Map{
|
||||||
"error": "Settings are too large",
|
"error": "Settings are too large",
|
||||||
})
|
})
|
||||||
@@ -277,6 +281,17 @@ func main() {
|
|||||||
})
|
})
|
||||||
// #endregion
|
// #endregion
|
||||||
|
|
||||||
|
// #region erase all
|
||||||
|
app.Delete("/", requireAuth, func(c *fiber.Ctx) error {
|
||||||
|
userId := c.Context().UserValue("userId").(string)
|
||||||
|
|
||||||
|
rdb.Del(c.Context(), "settings:"+hash(PEPPER_SETTINGS+userId))
|
||||||
|
rdb.Del(c.Context(), "secret"+hash(PEPPER_SECRETS+userId))
|
||||||
|
|
||||||
|
return c.SendStatus(204)
|
||||||
|
})
|
||||||
|
// #endregion
|
||||||
|
|
||||||
app.Get("/", func(c *fiber.Ctx) error {
|
app.Get("/", func(c *fiber.Ctx) error {
|
||||||
return c.Redirect(ROOT_REDIRECT, 307)
|
return c.Redirect(ROOT_REDIRECT, 307)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user