Extract Files seam, WebDAV, and Visit from CheckDNS.
Publish go-nc-files v1 with local/WebDAV Root, DefaultPathStore, and neutral Working Folder language; depends on go-nc-exapp v0.1.0. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
package goncfiles
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// DefaultPathStore persists the Saved Default Working Folder path (User Files Root–relative).
|
||||
type DefaultPathStore interface {
|
||||
GetDefault() (string, error)
|
||||
SetDefault(rel string) error
|
||||
}
|
||||
|
||||
// FileStore is the local-adapter settings JSON file.
|
||||
type FileStore struct {
|
||||
Path string
|
||||
}
|
||||
|
||||
type settingsFile struct {
|
||||
DefaultPath string `json:"defaultPath"`
|
||||
}
|
||||
|
||||
// GetDefault reads the saved default; empty means the caller should use the product initial default.
|
||||
func (s FileStore) GetDefault() (string, error) {
|
||||
body, err := os.ReadFile(s.Path)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return "", nil
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
var sf settingsFile
|
||||
if err := json.Unmarshal(body, &sf); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return strings.TrimSpace(sf.DefaultPath), nil
|
||||
}
|
||||
|
||||
// SetDefault writes the saved Working Folder path.
|
||||
func (s FileStore) SetDefault(rel string) error {
|
||||
body, err := json.MarshalIndent(settingsFile{DefaultPath: rel}, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Dir(s.Path), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(s.Path, append(body, '\n'), 0o644)
|
||||
}
|
||||
|
||||
// Memory is an in-memory DefaultPathStore for tests.
|
||||
type Memory struct {
|
||||
Value string
|
||||
}
|
||||
|
||||
// GetDefault returns the in-memory value.
|
||||
func (m *Memory) GetDefault() (string, error) { return m.Value, nil }
|
||||
|
||||
// SetDefault stores the value in memory.
|
||||
func (m *Memory) SetDefault(rel string) error {
|
||||
m.Value = rel
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user