🗑️ Remove independent mode

This commit is contained in:
LittleSheep 2024-07-28 01:15:52 +08:00
parent 36d13f4b81
commit 763977c8f0
3 changed files with 7 additions and 25 deletions

View File

@ -74,12 +74,10 @@ func getAttachmentMeta(c *fiber.Ctx) error {
func createAttachment(c *fiber.Ctx) error { func createAttachment(c *fiber.Ctx) error {
var user *models.Account var user *models.Account
if gap.H != nil { if err := gap.H.EnsureAuthenticated(c); err != nil {
if err := gap.H.EnsureAuthenticated(c); err != nil { return err
return err
}
user = lo.ToPtr(c.Locals("user").(models.Account))
} }
user = lo.ToPtr(c.Locals("user").(models.Account))
destName := c.Query("destination", viper.GetString("preferred_destination")) destName := c.Query("destination", viper.GetString("preferred_destination"))
@ -97,10 +95,8 @@ func createAttachment(c *fiber.Ctx) error {
return err return err
} }
if gap.H != nil { if err := gap.H.EnsureGrantedPerm(c, "CreateAttachments", file.Size); err != nil {
if err := gap.H.EnsureGrantedPerm(c, "CreateAttachments", file.Size); err != nil { return err
return err
}
} }
usermeta := make(map[string]any) usermeta := make(map[string]any)
@ -136,10 +132,6 @@ func createAttachment(c *fiber.Ctx) error {
func updateAttachmentMeta(c *fiber.Ctx) error { func updateAttachmentMeta(c *fiber.Ctx) error {
id, _ := c.ParamsInt("id", 0) id, _ := c.ParamsInt("id", 0)
if gap.H == nil {
return fiber.NewError(fiber.StatusUnprocessableEntity, "server running in independent mode, unable to modify attachment meta")
}
if err := gap.H.EnsureAuthenticated(c); err != nil { if err := gap.H.EnsureAuthenticated(c); err != nil {
return err return err
} }
@ -176,10 +168,6 @@ func updateAttachmentMeta(c *fiber.Ctx) error {
func deleteAttachment(c *fiber.Ctx) error { func deleteAttachment(c *fiber.Ctx) error {
id, _ := c.ParamsInt("id", 0) id, _ := c.ParamsInt("id", 0)
if gap.H == nil {
return fiber.NewError(fiber.StatusUnprocessableEntity, "server running in independent mode, unable to delete attachment")
}
if err := gap.H.EnsureAuthenticated(c); err != nil { if err := gap.H.EnsureAuthenticated(c); err != nil {
return err return err
} }

View File

@ -44,12 +44,8 @@ func main() {
} }
// Connect other services // Connect other services
if !viper.GetBool("independent_mode") { if err := gap.RegisterService(); err != nil {
if err := gap.RegisterService(); err != nil { log.Error().Err(err).Msg("An error occurred when registering service to dealer...")
log.Error().Err(err).Msg("An error occurred when registering service to dealer...")
}
} else {
log.Warn().Msg("WATCHOUT! Running in independent mode, everyone with access to API can upload their file without authenticate!")
} }
// Configure timed tasks // Configure timed tasks

View File

@ -5,8 +5,6 @@ grpc_bind = "0.0.0.0:7443"
domain = "usercontent.solsynth.dev" domain = "usercontent.solsynth.dev"
secret = "LtTjzAGFLshwXhN4ZD4nG5KlMv1MWcsvfv03TSZYnT1VhiAnLIZFTnHUwR0XhGgi" secret = "LtTjzAGFLshwXhN4ZD4nG5KlMv1MWcsvfv03TSZYnT1VhiAnLIZFTnHUwR0XhGgi"
independent_mode = false
preferred_destination = "local" preferred_destination = "local"
accepts_usage = ["p.avatar", "p.banner", "i.attachment", "m.attachment"] accepts_usage = ["p.avatar", "p.banner", "i.attachment", "m.attachment"]