create content version
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user