Add read-only Docspell FUSE mount
This commit is contained in:
@@ -37,16 +37,26 @@ type DocspellItem struct {
|
||||
|
||||
func main() {
|
||||
fmt.Println("##################### START #####################")
|
||||
fmt.Println(" Docspell Import - v0.2")
|
||||
fmt.Println(" Docspell Import - v0.3")
|
||||
fmt.Println(" by jacob1123")
|
||||
fmt.Println(" (based on work by totti4ever) ")
|
||||
fmt.Println("#################################################")
|
||||
fmt.Println()
|
||||
|
||||
uploadMissing := flag.Bool("upload-missing", os.Getenv("DS_CC_UPLOAD_MISSING") == "true", "true, to upload files to docspell that do not yet exist there")
|
||||
flag.Parse()
|
||||
cfg, password := loadConfigAndPassword()
|
||||
|
||||
// Read config from user profile
|
||||
if len(os.Args) > 1 && os.Args[1] == "mount" {
|
||||
if err := runMountCommand(os.Args[2:], cfg, password); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "mount failed:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
runImportCommand(cfg, password, os.Args[1:])
|
||||
}
|
||||
|
||||
func loadConfigAndPassword() (config, string) {
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
fmt.Println("Error getting user home directory:", err)
|
||||
@@ -66,7 +76,6 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Get password from command
|
||||
cmd := exec.Command(cfg.PasswordCommand, cfg.PasswordCommandArgs...)
|
||||
password, err := cmd.Output()
|
||||
if err != nil {
|
||||
@@ -74,10 +83,20 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
return cfg, strings.TrimSpace(string(password))
|
||||
}
|
||||
|
||||
func runImportCommand(cfg config, password string, args []string) {
|
||||
importFlags := flag.NewFlagSet("import", flag.ExitOnError)
|
||||
uploadMissing := importFlags.Bool("upload-missing", os.Getenv("DS_CC_UPLOAD_MISSING") == "true", "true, to upload files to docspell that do not yet exist there")
|
||||
if err := importFlags.Parse(args); err != nil {
|
||||
fmt.Println("Error parsing flags:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
validateConfig(cfg)
|
||||
|
||||
// Login
|
||||
loginCmd := exec.Command("dsc", "login", "--user", cfg.User, "--password", strings.TrimSpace(string(password)))
|
||||
loginCmd := exec.Command("dsc", "login", "--user", cfg.User, "--password", password)
|
||||
if err := loginCmd.Run(); err != nil {
|
||||
fmt.Println("Login failed:", err)
|
||||
os.Exit(0)
|
||||
@@ -102,7 +121,7 @@ func main() {
|
||||
fmt.Printf("Scanning folder '%s'\n", dsConsumedir)
|
||||
fmt.Println()
|
||||
|
||||
err = filepath.Walk(dsConsumedir, func(path string, info os.FileInfo, err error) error {
|
||||
err := filepath.Walk(dsConsumedir, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -114,7 +133,6 @@ func main() {
|
||||
fmt.Println()
|
||||
fmt.Printf("%s:\n", info.Name())
|
||||
|
||||
// Check if file exists in Docspell
|
||||
cmd := exec.Command("dsc", "-f", "json", "file-exists", path)
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
@@ -128,7 +146,7 @@ func main() {
|
||||
return nil
|
||||
}
|
||||
|
||||
if fileExistsResponse[0].Exists {
|
||||
if len(fileExistsResponse) > 0 && fileExistsResponse[0].Exists {
|
||||
err := handleExistingFile(cfg, fileExistsResponse[0])
|
||||
if err != nil {
|
||||
fmt.Println(" ERROR", err)
|
||||
|
||||
Reference in New Issue
Block a user