feat: transcoding and player datastores and configuration

This commit is contained in:
Deluan
2020-02-29 20:01:09 -05:00
committed by Deluan Quintão
parent a0e0fbad58
commit 8ec78900c5
32 changed files with 783 additions and 29 deletions
+27 -4
View File
@@ -1,7 +1,7 @@
package server
import (
"context"
"encoding/json"
"fmt"
"time"
@@ -29,14 +29,17 @@ func initialSetup(ds model.DataStore) {
}
}
if err = createDefaultTranscodings(ds); err != nil {
return err
}
err = ds.Property(nil).Put(consts.InitialSetupFlagKey, time.Now().String())
return err
})
}
func createInitialAdminUser(ds model.DataStore) error {
ctx := context.Background()
c, err := ds.User(ctx).CountAll()
c, err := ds.User(nil).CountAll()
if err != nil {
panic(fmt.Sprintf("Could not access User table: %s", err))
}
@@ -56,7 +59,7 @@ func createInitialAdminUser(ds model.DataStore) error {
Password: initialPassword,
IsAdmin: true,
}
err := ds.User(ctx).Put(&initialUser)
err := ds.User(nil).Put(&initialUser)
if err != nil {
log.Error("Could not create initial admin user", "user", initialUser, err)
}
@@ -77,3 +80,23 @@ func createJWTSecret(ds model.DataStore) error {
}
return err
}
func createDefaultTranscodings(ds model.DataStore) error {
repo := ds.Transcoding(nil)
for _, d := range consts.DefaultTranscodings {
var j []byte
var err error
if j, err = json.Marshal(d); err != nil {
return err
}
var t model.Transcoding
if err = json.Unmarshal(j, &t); err != nil {
return err
}
log.Info("Creating default transcoding config", "name", t.Name)
if err = repo.Put(&t); err != nil {
return err
}
}
return nil
}