mirror of
https://github.com/Luzifer/ots.git
synced 2025-07-22 06:08:51 -04:00
Implement attachment checking in CLI (#141)
This commit is contained in:
parent
34275baa2f
commit
9a530e1c66
16 changed files with 374 additions and 17 deletions
79
pkg/customization/customize.go
Normal file
79
pkg/customization/customize.go
Normal file
|
@ -0,0 +1,79 @@
|
|||
// Package customization contains the structure for the customization
|
||||
// file to configure the OTS web- and command-line interface
|
||||
package customization
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/fs"
|
||||
"os"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
type (
|
||||
// Customize holds the structure of the customization file
|
||||
Customize struct {
|
||||
AppIcon string `json:"appIcon,omitempty" yaml:"appIcon"`
|
||||
AppTitle string `json:"appTitle,omitempty" yaml:"appTitle"`
|
||||
DisableAppTitle bool `json:"disableAppTitle,omitempty" yaml:"disableAppTitle"`
|
||||
DisablePoweredBy bool `json:"disablePoweredBy,omitempty" yaml:"disablePoweredBy"`
|
||||
DisableQRSupport bool `json:"disableQRSupport,omitempty" yaml:"disableQRSupport"`
|
||||
DisableThemeSwitcher bool `json:"disableThemeSwitcher,omitempty" yaml:"disableThemeSwitcher"`
|
||||
|
||||
DisableExpiryOverride bool `json:"disableExpiryOverride,omitempty" yaml:"disableExpiryOverride"`
|
||||
ExpiryChoices []int64 `json:"expiryChoices,omitempty" yaml:"expiryChoices"`
|
||||
|
||||
AcceptedFileTypes string `json:"acceptedFileTypes" yaml:"acceptedFileTypes"`
|
||||
DisableFileAttachment bool `json:"disableFileAttachment" yaml:"disableFileAttachment"`
|
||||
MaxAttachmentSizeTotal int64 `json:"maxAttachmentSizeTotal" yaml:"maxAttachmentSizeTotal"`
|
||||
|
||||
OverlayFSPath string `json:"-" yaml:"overlayFSPath"`
|
||||
UseFormalLanguage bool `json:"-" yaml:"useFormalLanguage"`
|
||||
}
|
||||
)
|
||||
|
||||
// Load retrieves the Customization file from filesystem
|
||||
func Load(filename string) (cust Customize, err error) {
|
||||
if filename == "" {
|
||||
// None given, take a shortcut
|
||||
cust.applyFixes()
|
||||
return cust, nil
|
||||
}
|
||||
|
||||
cf, err := os.Open(filename) //#nosec:G304 // Loading a custom file is the intention here
|
||||
if err != nil {
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
logrus.Warn("customize file given but not found")
|
||||
return cust, nil
|
||||
}
|
||||
return cust, errors.Wrap(err, "opening customize file")
|
||||
}
|
||||
defer func() {
|
||||
if err := cf.Close(); err != nil {
|
||||
logrus.WithError(err).Error("closing customize file (leaked fd)")
|
||||
}
|
||||
}()
|
||||
|
||||
if err = yaml.NewDecoder(cf).Decode(&cust); err != nil {
|
||||
return cust, errors.Wrap(err, "decoding customize file")
|
||||
}
|
||||
|
||||
cust.applyFixes()
|
||||
|
||||
return cust, nil
|
||||
}
|
||||
|
||||
// ToJSON is a templating helper which returns the customization
|
||||
// serialized as JSON in a string
|
||||
func (c Customize) ToJSON() (string, error) {
|
||||
j, err := json.Marshal(c)
|
||||
return string(j), errors.Wrap(err, "marshalling JSON")
|
||||
}
|
||||
|
||||
func (c *Customize) applyFixes() {
|
||||
if len(c.AppTitle) == 0 {
|
||||
c.AppTitle = "OTS - One Time Secrets"
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue