fork of indigo with slightly nicer lexgen

Handle max user counts more gracefully

Changed files
+33 -2
bgs
cmd
ts
bgs-dash
+4
Makefile
··· 74 74 .env: 75 75 if [ ! -f ".env" ]; then cp example.dev.env .env; fi 76 76 77 + .PHONY: run-postgres 78 + run-postgres: .env ## Runs a local postgres instance 79 + docker compose -f cmd/bigsky/docker-compose.yml up -d 80 + 77 81 .PHONY: run-dev-bgs 78 82 run-dev-bgs: .env ## Runs 'bigsky' BGS for local dev 79 83 GOLOG_LOG_LEVEL=info go run ./cmd/bigsky --admin-key localdev
+24 -1
bgs/bgs.go
··· 264 264 e.HideBanner = true 265 265 266 266 e.Use(middleware.CORSWithConfig(middleware.CORSConfig{ 267 - AllowOrigins: []string{"http://localhost:*", "https://bgs.bsky-sandbox.dev"}, 267 + AllowOrigins: []string{"*"}, 268 268 AllowHeaders: []string{echo.HeaderOrigin, echo.HeaderContentType, echo.HeaderAccept, echo.HeaderAuthorization}, 269 269 })) 270 270 ··· 1052 1052 return nil, fmt.Errorf("refusing to create user on PDS at max repo limit") 1053 1053 } 1054 1054 1055 + // Increment the repo count for the PDS 1056 + res := s.db.Model(&models.PDS{}).Where("id = ? AND repo_count < repo_limit", peering.ID).Update("repo_count", gorm.Expr("repo_count + 1")) 1057 + if res.Error != nil { 1058 + return nil, fmt.Errorf("failed to increment repo count for pds: %w", res.Error) 1059 + } 1060 + 1061 + if res.RowsAffected == 0 { 1062 + return nil, fmt.Errorf("refusing to create user on PDS at max repo limit") 1063 + } 1064 + 1065 + successfullyCreated := false 1066 + 1067 + // Release the count if we fail to create the user 1068 + defer func() { 1069 + if !successfullyCreated { 1070 + if err := s.db.Model(&models.PDS{}).Where("id = ?", peering.ID).Update("repo_count", gorm.Expr("repo_count - 1")).Error; err != nil { 1071 + log.Errorf("failed to decrement repo count for pds: %s", err) 1072 + } 1073 + } 1074 + }() 1075 + 1055 1076 ban, err := s.domainIsBanned(ctx, durl.Host) 1056 1077 if err != nil { 1057 1078 return nil, fmt.Errorf("failed to check pds ban status: %w", err) ··· 1215 1236 if err := s.db.Create(subj).Error; err != nil { 1216 1237 return nil, err 1217 1238 } 1239 + 1240 + successfullyCreated = true 1218 1241 1219 1242 return subj, nil 1220 1243 }
+2
cmd/bigsky/docker-compose.yml
··· 10 10 target: /var/lib/postgresql/data 11 11 restart: always 12 12 environment: 13 + POSTGRES_USER: bgs 13 14 POSTGRES_PASSWORD: 33pAstcHDMszLedQah2EVYNgnxbCP 15 + POSTGRES_DB: bgs
+3 -1
ts/bgs-dash/src/constants.ts
··· 1 1 const BGS_HOST = `${window.location.protocol}//${window.location.hostname}:${ 2 - window.location.hostname === "localhost" ? "2470" : window.location.port 2 + window.location.hostname === "localhost" || "jaz1" 3 + ? "2470" 4 + : window.location.port 3 5 }`; 4 6 5 7 export { BGS_HOST };