create content version

This commit is contained in:
venture
2026-11-15 10:01:30 +01:00
parent 29a6ab40f0
commit 610192e2d5
13 changed files with 2226 additions and 3 deletions
+34
View File
@@ -4,6 +4,7 @@ import (
"bytes"
"context"
"database/sql"
"encoding/json"
"errors"
"fmt"
"mediarr/cluster"
@@ -33,10 +34,43 @@ func (n *Node) Up() error {
}
}
if err := n.ensureStorageBackend(ctx); err != nil {
return err
}
return n.ensureClusterIdentity(ctx)
}
func (n *Node) ensureStorageBackend(ctx context.Context) error {
_, err := n.db.Queries.GetStorageBackend(ctx, n.backendID)
switch {
case err == nil:
return nil
case !errors.Is(err, sql.ErrNoRows):
return fmt.Errorf("stockage : lecture du backend : %w", err)
}
config, err := json.Marshal(map[string]string{"root": n.storagePath})
if err != nil {
return err
}
if err := n.db.WriteQueries.CreateStorageBackend(ctx, database.CreateStorageBackendParams{
ID: n.backendID,
Kind: "hub_fs",
Name: "local",
Config: string(config),
Enabled: 1,
State: "ok",
CreatedAt: time.Now().UnixMilli(),
}); err != nil {
return fmt.Errorf("stockage : création du backend : %w", err)
}
return nil
}
func (n *Node) ensureClusterIdentity(ctx context.Context) error {
principal, err := n.db.Queries.GetClusterPrincipal(ctx)