diff --git a/controller/controller.go b/controller/controller.go
index 0faba9d..1e3df58 100644
--- a/controller/controller.go
+++ b/controller/controller.go
@@ -76,7 +76,7 @@ func (wc *WorkflowController) Workflow(name string) (string, error) {
wg.Wait()
- yt.UpdateIssue(issue, cloud.FolderURL, git, gitBuild)
+ yt.UpdateIssue(issue, cloud.PrivateURL, git, gitBuild)
}
return issue.Key, nil
}
diff --git a/domain/cloud.go b/domain/cloud.go
index 729b48f..1fd744b 100644
--- a/domain/cloud.go
+++ b/domain/cloud.go
@@ -1,8 +1,8 @@
package domain
type Cloud struct {
- FolderName string // "k"
- FolderPath string // "/temp/k"
- FolderURL string // "http://82.151.222.22:7000/apps/files/?dir=/temp/k"
- PublicURL string
+ FolderName string // k
+ FolderPath string // /temp/k
+ FolderURL string // http://82.151.222.22:7000/apps/files/?dir=/temp/k
+ PrivateURL string // http://82.151.222.22:7000/f/00000
}
diff --git a/ext/cloud.go b/ext/cloud.go
index b93fa11..312d844 100644
--- a/ext/cloud.go
+++ b/ext/cloud.go
@@ -6,6 +6,7 @@ import (
"io/ioutil"
"log"
"os"
+ "strconv"
"ticket-pimp/domain"
"ticket-pimp/helpers"
"time"
@@ -34,6 +35,23 @@ func NewCloud(base, user, pass string) *Cloud {
}
}
+type MultistatusObj struct {
+ XMLName xml.Name `xml:"multistatus"`
+ Multistatus struct {
+ XMLName xml.Name `xml:"response"`
+ Propstat struct {
+ XMLName xml.Name `xml:"propstat"`
+ Prop struct {
+ XMLName xml.Name `xml:"prop"`
+ FileID struct {
+ XMLName xml.Name `xml:"fileid"`
+ ID string `xml:",chardata"`
+ }
+ }
+ }
+ }
+}
+
func (c *Cloud) CreateFolder(name string) (*domain.Cloud, error) {
rootDir := os.Getenv("ROOTDIR")
@@ -54,37 +72,6 @@ func (c *Cloud) CreateFolder(name string) (*domain.Cloud, error) {
cloud.FolderURL = c.BaseURL + cloud.FolderPath
- /*
- type ResponseObj struct {
- Multistatus struct {
- Response struct {
- Href struct {
- Propstat struct {
- Prop struct {
- FileID int `json:"oc:fileid"`
- } `json:"d:prop"`
- } `json:"d:propstat"`
- } `json:"d:href"`
- } `json:"d:response"`
- } `json:"d:multistatus"`
- }*/
-
- type ResponseObj struct {
- XMLName xml.Name `xml:"d:multistatus"`
- Multistatus struct {
- XMLName xml.Name `xml:"d:multistatus"`
- Response struct {
- Href struct {
- Propstat struct {
- Prop struct {
- FileID string `xml:"oc:fileid"`
- } `xml:"d:prop"`
- } `xml:"d:propstat"`
- } `xml:"d:href"`
- } `xml:"d:response"`
- } `xml:"d:multistatus"`
- }
-
xmlFile, err := ioutil.ReadFile("./fileid.xml")
if err != nil {
@@ -92,24 +79,39 @@ func (c *Cloud) CreateFolder(name string) (*domain.Cloud, error) {
return nil, err // fix this return;
}
- var id ResponseObj
-
resp, _ := c.R().
SetBody(xmlFile).
Send("PROPFIND", os.Getenv("HOMEPATH")+os.Getenv("ROOTDIR")+cloud.FolderName)
- xmlEncodingErr := resp.UnmarshalXml(&id)
- if xmlEncodingErr != nil {
- log.Print(err)
+ id, err := getFileIDFromRespBody(resp.Bytes())
+
+ if err != nil {
+ log.Print(err) // [ ] Если тут проблема - надо пытаться засетать полную ссылку
}
- log.Print(resp)
-
+ cloud.PrivateURL = os.Getenv("CLOUD_BASE_URL") + "/f/" + strconv.Itoa(id)
}
return &cloud, err
}
+func getFileIDFromRespBody(str []byte) (int, error) {
+
+ var multi MultistatusObj
+
+ err := xml.Unmarshal(str, &multi)
+ if err != nil {
+ return 0, fmt.Errorf("XML Unmarshal error: %v", err)
+ }
+
+ id, err := strconv.Atoi(multi.Multistatus.Propstat.Prop.FileID.ID)
+ if err != nil {
+ return 0, fmt.Errorf("FileID str to int convertion error: %v", err)
+ }
+
+ return id, nil
+}
+
func (c *Cloud) ShareToExternals(cloud *domain.Cloud) (*domain.Cloud, error) {
return nil, nil
}
diff --git a/ext/xml_test.go b/ext/xml_test.go
new file mode 100644
index 0000000..ba59d5c
--- /dev/null
+++ b/ext/xml_test.go
@@ -0,0 +1,18 @@
+package ext
+
+import (
+ "log"
+ "testing"
+)
+
+const (
+ EXAMPLE = "\n/remote.php/dav/files/naudachu/temp/id/33225HTTP/1.1 200 OK\n"
+)
+
+// [ ] todo normal test...
+func TestGetFileID(t *testing.T) {
+
+ str, err := getFileIDFromRespBody([]byte(EXAMPLE))
+ log.Print(str, err)
+
+}
diff --git a/helpers/xml_test.go b/helpers/xml_test.go
deleted file mode 100644
index 183ef83..0000000
--- a/helpers/xml_test.go
+++ /dev/null
@@ -1,67 +0,0 @@
-package helpers
-
-import (
- "encoding/xml"
- "fmt"
- "log"
- "testing"
-)
-
-/*
-
-
-
-
- /remote.php/dav/files/naudachu/temp/id/
-
-
- 33225
-
- HTTP/1.1 200 OK
-
-
-
-
-*/
-/*
-type MultistatusObj struct {
- XMLName xml.Name `xml:"multistatus"`
- Multistatus struct {
- XMLName xml.Name `xml:"response"`
- Other string `xml:",innerxml"`
- }
-}*/
-
-type MultistatusObj struct {
- XMLName xml.Name `xml:"multistatus"`
- Multistatus struct {
- XMLName xml.Name `xml:"response"`
- Propstat struct {
- XMLName xml.Name `xml:"propstat"`
- Prop struct {
- XMLName xml.Name `xml:"prop"`
- Other string `xml:",innerxml"`
- }
- }
- }
-}
-
-const (
- EXAMPLE = "\n/remote.php/dav/files/naudachu/temp/id/33225HTTP/1.1 200 OK\n"
-)
-
-func GetFileID(str string) string {
-
- var multi MultistatusObj
- err := xml.Unmarshal([]byte(str), &multi)
- if err != nil {
- fmt.Print(err)
- }
- return multi.Multistatus.Propstat.Prop.Other
-}
-
-func TestGetFileID(t *testing.T) {
- str := GetFileID(EXAMPLE)
- log.Print(str)
-
-}