You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
875 B
37 lines
875 B
3 years ago
|
// 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.
|
||
|
|
||
2 years ago
|
package system
|
||
3 years ago
|
|
||
|
import (
|
||
2 years ago
|
"code.gitea.io/gitea/models/system"
|
||
3 years ago
|
"code.gitea.io/gitea/modules/json"
|
||
|
|
||
|
"github.com/yuin/goldmark/util"
|
||
|
)
|
||
|
|
||
|
// DBStore can be used to store app state items in local filesystem
|
||
3 years ago
|
type DBStore struct{}
|
||
3 years ago
|
|
||
|
// Get reads the state item
|
||
|
func (f *DBStore) Get(item StateItem) error {
|
||
2 years ago
|
content, err := system.GetAppStateContent(item.Name())
|
||
3 years ago
|
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
|
||
|
}
|
||
2 years ago
|
return system.SaveAppStateContent(item.Name(), util.BytesToReadOnlyString(b))
|
||
3 years ago
|
}
|