2021-10-21 11:22:43 +02:00
|
|
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2022-10-17 01:29:26 +02:00
|
|
|
package system
|
2021-10-21 11:22:43 +02:00
|
|
|
|
|
|
|
import (
|
2022-10-17 01:29:26 +02:00
|
|
|
"code.gitea.io/gitea/models/system"
|
2021-10-21 11:22:43 +02:00
|
|
|
"code.gitea.io/gitea/modules/json"
|
|
|
|
|
|
|
|
"github.com/yuin/goldmark/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
// DBStore can be used to store app state items in local filesystem
|
2022-01-20 18:46:10 +01:00
|
|
|
type DBStore struct{}
|
2021-10-21 11:22:43 +02:00
|
|
|
|
|
|
|
// Get reads the state item
|
|
|
|
func (f *DBStore) Get(item StateItem) error {
|
2022-10-17 01:29:26 +02:00
|
|
|
content, err := system.GetAppStateContent(item.Name())
|
2021-10-21 11:22:43 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if content == "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return json.Unmarshal(util.StringToReadOnlyBytes(content), item)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set saves the state item
|
|
|
|
func (f *DBStore) Set(item StateItem) error {
|
|
|
|
b, err := json.Marshal(item)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-10-17 01:29:26 +02:00
|
|
|
return system.SaveAppStateContent(item.Name(), util.BytesToReadOnlyString(b))
|
2021-10-21 11:22:43 +02:00
|
|
|
}
|