2022-09-22 17:45:33 +00:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2023-01-02 10:06:13 +00:00
|
|
|
// The root nextcloud user where the files are stored
|
|
|
|
// and the files for onlyoffice jobs are defined
|
|
|
|
type NextcloudUser struct {
|
|
|
|
NextcloudBaseUrl string `json:"nextcloudUrl"`
|
|
|
|
Username string `json:"username"`
|
|
|
|
Password string `json:"password"`
|
|
|
|
|
|
|
|
// OnlyOffice
|
|
|
|
ConvertJobs []NcConvertJob `json:"jobs"`
|
|
|
|
|
|
|
|
// BookStack
|
|
|
|
BookStack BookStack `json:"bookStack"`
|
2022-09-22 17:45:33 +00:00
|
|
|
}
|
|
|
|
|
2023-01-02 10:06:13 +00:00
|
|
|
// A OnlyOffice docs convert job
|
|
|
|
type NcConvertJob struct {
|
|
|
|
JobName string `json:"jobName"`
|
|
|
|
SourceDir string `json:"sourceDir"`
|
|
|
|
DestinationDir string `json:"destinationDir"`
|
|
|
|
KeepFolders string `json:"keepFolders"`
|
|
|
|
Recursive string `json:"recursive"`
|
|
|
|
Execution string `json:"execution"`
|
2022-09-22 17:45:33 +00:00
|
|
|
}
|
|
|
|
|
2022-09-23 09:58:53 +00:00
|
|
|
type NcConvertUsers struct {
|
2023-01-02 10:06:13 +00:00
|
|
|
Users []NextcloudUser `json:"nextcloudUsers"`
|
2022-09-22 17:45:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Parses the given file to the in memory struct
|
2022-09-23 09:58:53 +00:00
|
|
|
func ParseConvertUsers(filePath string) (*NcConvertUsers, error) {
|
2022-09-22 17:45:33 +00:00
|
|
|
|
2022-09-23 09:58:53 +00:00
|
|
|
file, err := os.OpenFile(filePath, os.O_APPEND|os.O_CREATE, 0644)
|
2022-09-22 17:45:33 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("failed to open the file '%s': %s", filePath, err)
|
|
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
|
|
|
|
byteValue, err := ioutil.ReadAll(file)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("failed to parse 'ncConverter.json': %s", err)
|
|
|
|
}
|
|
|
|
|
2022-09-23 09:58:53 +00:00
|
|
|
var conv NcConvertUsers
|
2022-09-22 17:45:33 +00:00
|
|
|
|
|
|
|
json.Unmarshal(byteValue, &conv)
|
|
|
|
|
|
|
|
return &conv, nil
|
2023-01-02 10:06:13 +00:00
|
|
|
}
|