2019-03-23 14:56:59 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"github.com/stashapp/stash/pkg/manager/config"
|
|
|
|
"github.com/stashapp/stash/pkg/models"
|
|
|
|
"github.com/stashapp/stash/pkg/utils"
|
2019-03-24 17:04:31 +00:00
|
|
|
"path/filepath"
|
2019-03-23 14:56:59 +00:00
|
|
|
)
|
|
|
|
|
2019-03-26 15:35:06 +00:00
|
|
|
func (r *mutationResolver) ConfigureGeneral(ctx context.Context, input models.ConfigGeneralInput) (*models.ConfigGeneralResult, error) {
|
2019-03-23 14:56:59 +00:00
|
|
|
if len(input.Stashes) > 0 {
|
|
|
|
for _, stashPath := range input.Stashes {
|
|
|
|
exists, err := utils.DirExists(stashPath)
|
|
|
|
if !exists {
|
|
|
|
return makeConfigGeneralResult(), err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
config.Set(config.Stash, input.Stashes)
|
|
|
|
}
|
|
|
|
|
2019-03-24 17:04:31 +00:00
|
|
|
if input.DatabasePath != nil {
|
|
|
|
ext := filepath.Ext(*input.DatabasePath)
|
|
|
|
if ext != ".db" && ext != ".sqlite" && ext != ".sqlite3" {
|
|
|
|
return makeConfigGeneralResult(), fmt.Errorf("invalid database path, use extension db, sqlite, or sqlite3")
|
|
|
|
}
|
|
|
|
config.Set(config.Database, input.DatabasePath)
|
|
|
|
}
|
|
|
|
|
|
|
|
if input.GeneratedPath != nil {
|
|
|
|
if err := utils.EnsureDir(*input.GeneratedPath); err != nil {
|
|
|
|
return makeConfigGeneralResult(), err
|
|
|
|
}
|
|
|
|
config.Set(config.Generated, input.GeneratedPath)
|
|
|
|
}
|
|
|
|
|
2019-03-23 14:56:59 +00:00
|
|
|
if err := config.Write(); err != nil {
|
|
|
|
return makeConfigGeneralResult(), err
|
|
|
|
}
|
|
|
|
|
|
|
|
return makeConfigGeneralResult(), nil
|
|
|
|
}
|