Add Blossom blob storage server and subscription management

- Introduced the `initializeBlossomServer` function to set up the Blossom blob storage server with dynamic base URL handling and ACL configuration.
- Implemented the `blossomHandler` method to manage incoming requests to the Blossom API, ensuring proper URL handling and context management.
- Enhanced the `PaymentProcessor` to support Blossom service levels, allowing for subscription extensions based on payment metadata.
- Added methods for parsing and validating Blossom service levels, including storage quota management and subscription extension logic.
- Updated the configuration to include Blossom service level settings, facilitating dynamic service level management.
- Integrated storage quota checks in the blob upload process to prevent exceeding allocated limits.
- Refactored existing code to improve organization and maintainability, including the removal of unused blob directory configurations.
- Added tests to ensure the robustness of new functionalities and maintain existing behavior across blob operations.
This commit is contained in:
2025-11-02 22:23:01 +00:00
parent 3567bb26a4
commit edcdec9c7e
10 changed files with 421 additions and 24 deletions

53
app/blossom.go Normal file
View File

@@ -0,0 +1,53 @@
package app
import (
"context"
"net/http"
"strings"
"lol.mleku.dev/log"
"next.orly.dev/app/config"
"next.orly.dev/pkg/acl"
"next.orly.dev/pkg/database"
blossom "next.orly.dev/pkg/blossom"
)
// initializeBlossomServer creates and configures the Blossom blob storage server
func initializeBlossomServer(
ctx context.Context, cfg *config.C, db *database.D,
) (*blossom.Server, error) {
// Create blossom server configuration
blossomCfg := &blossom.Config{
BaseURL: "", // Will be set dynamically per request
MaxBlobSize: 100 * 1024 * 1024, // 100MB default
AllowedMimeTypes: nil, // Allow all MIME types by default
RequireAuth: cfg.AuthRequired || cfg.AuthToWrite,
}
// Create blossom server with relay's ACL registry
bs := blossom.NewServer(db, acl.Registry, blossomCfg)
// Override baseURL getter to use request-based URL
// We'll need to modify the handler to inject the baseURL per request
// For now, we'll use a middleware approach
log.I.F("blossom server initialized with ACL mode: %s", cfg.ACLMode)
return bs, nil
}
// blossomHandler wraps the blossom server handler to inject baseURL per request
func (s *Server) blossomHandler(w http.ResponseWriter, r *http.Request) {
// Strip /blossom prefix and pass to blossom handler
r.URL.Path = strings.TrimPrefix(r.URL.Path, "/blossom")
if !strings.HasPrefix(r.URL.Path, "/") {
r.URL.Path = "/" + r.URL.Path
}
// Set baseURL in request context for blossom server to use
baseURL := s.ServiceURL(r) + "/blossom"
type baseURLKey struct{}
r = r.WithContext(context.WithValue(r.Context(), baseURLKey{}, baseURL))
s.blossomServer.Handler().ServeHTTP(w, r)
}