Move transcodings initialization to a migration

This will make it run only once, not every
time the transcoding table is empty
This commit is contained in:
Deluan
2020-07-06 23:48:43 -04:00
parent fdc38b5ca5
commit f0a5df7cd7
2 changed files with 43 additions and 29 deletions
-29
View File
@@ -2,7 +2,6 @@ package server
import (
"context"
"encoding/json"
"fmt"
"time"
@@ -15,10 +14,6 @@ import (
func initialSetup(ds model.DataStore) {
_ = ds.WithTx(func(tx model.DataStore) error {
if err := createDefaultTranscodings(ds); err != nil {
return err
}
properties := ds.Property(context.TODO())
_, err := properties.Get(consts.InitialSetupFlagKey)
if err == nil {
@@ -84,27 +79,3 @@ func createJWTSecret(ds model.DataStore) error {
}
return err
}
func createDefaultTranscodings(ds model.DataStore) error {
transcodings := ds.Transcoding(context.TODO())
c, _ := transcodings.CountAll()
if c != 0 {
return 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 = transcodings.Put(&t); err != nil {
return err
}
}
return nil
}