- Folder PrivateURL fixed;
This commit is contained in:
parent
8b84480e74
commit
a19263e97e
|
|
@ -76,7 +76,7 @@ func (wc *WorkflowController) Workflow(name string) (string, error) {
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
yt.UpdateIssue(issue, cloud.FolderURL, git, gitBuild)
|
yt.UpdateIssue(issue, cloud.PrivateURL, git, gitBuild)
|
||||||
}
|
}
|
||||||
return issue.Key, nil
|
return issue.Key, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
package domain
|
package domain
|
||||||
|
|
||||||
type Cloud struct {
|
type Cloud struct {
|
||||||
FolderName string // "k"
|
FolderName string // k
|
||||||
FolderPath string // "/temp/k"
|
FolderPath string // /temp/k
|
||||||
FolderURL string // "http://82.151.222.22:7000/apps/files/?dir=/temp/k"
|
FolderURL string // http://82.151.222.22:7000/apps/files/?dir=/temp/k
|
||||||
PublicURL string
|
PrivateURL string // http://82.151.222.22:7000/f/00000
|
||||||
}
|
}
|
||||||
|
|
|
||||||
78
ext/cloud.go
78
ext/cloud.go
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"ticket-pimp/domain"
|
"ticket-pimp/domain"
|
||||||
"ticket-pimp/helpers"
|
"ticket-pimp/helpers"
|
||||||
"time"
|
"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) {
|
func (c *Cloud) CreateFolder(name string) (*domain.Cloud, error) {
|
||||||
rootDir := os.Getenv("ROOTDIR")
|
rootDir := os.Getenv("ROOTDIR")
|
||||||
|
|
||||||
|
|
@ -54,37 +72,6 @@ func (c *Cloud) CreateFolder(name string) (*domain.Cloud, error) {
|
||||||
|
|
||||||
cloud.FolderURL = c.BaseURL + cloud.FolderPath
|
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")
|
xmlFile, err := ioutil.ReadFile("./fileid.xml")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -92,24 +79,39 @@ func (c *Cloud) CreateFolder(name string) (*domain.Cloud, error) {
|
||||||
return nil, err // fix this return;
|
return nil, err // fix this return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var id ResponseObj
|
|
||||||
|
|
||||||
resp, _ := c.R().
|
resp, _ := c.R().
|
||||||
SetBody(xmlFile).
|
SetBody(xmlFile).
|
||||||
Send("PROPFIND", os.Getenv("HOMEPATH")+os.Getenv("ROOTDIR")+cloud.FolderName)
|
Send("PROPFIND", os.Getenv("HOMEPATH")+os.Getenv("ROOTDIR")+cloud.FolderName)
|
||||||
|
|
||||||
xmlEncodingErr := resp.UnmarshalXml(&id)
|
id, err := getFileIDFromRespBody(resp.Bytes())
|
||||||
if xmlEncodingErr != nil {
|
|
||||||
log.Print(err)
|
if err != nil {
|
||||||
|
log.Print(err) // [ ] Если тут проблема - надо пытаться засетать полную ссылку
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Print(resp)
|
cloud.PrivateURL = os.Getenv("CLOUD_BASE_URL") + "/f/" + strconv.Itoa(id)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return &cloud, err
|
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) {
|
func (c *Cloud) ShareToExternals(cloud *domain.Cloud) (*domain.Cloud, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
package ext
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
EXAMPLE = "<?xml version=\"1.0\"?>\n<d:multistatus xmlns:d=\"DAV:\" xmlns:s=\"http://sabredav.org/ns\" xmlns:oc=\"http://owncloud.org/ns\"><d:response><d:href>/remote.php/dav/files/naudachu/temp/id/</d:href><d:propstat><d:prop><oc:fileid>33225</oc:fileid></d:prop><d:status>HTTP/1.1 200 OK</d:status></d:propstat></d:response></d:multistatus>\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
// [ ] todo normal test...
|
||||||
|
func TestGetFileID(t *testing.T) {
|
||||||
|
|
||||||
|
str, err := getFileIDFromRespBody([]byte(EXAMPLE))
|
||||||
|
log.Print(str, err)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,67 +0,0 @@
|
||||||
package helpers
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/xml"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
<?xml version=\"1.0\"?>
|
|
||||||
<d:multistatus xmlns:d=\"DAV:\" xmlns:s=\"http://sabredav.org/ns\" xmlns:oc=\"http://owncloud.org/ns\">
|
|
||||||
<d:response>
|
|
||||||
<d:href>/remote.php/dav/files/naudachu/temp/id/</d:href>
|
|
||||||
<d:propstat>
|
|
||||||
<d:prop>
|
|
||||||
<oc:fileid>33225</oc:fileid>
|
|
||||||
</d:prop>
|
|
||||||
<d:status>HTTP/1.1 200 OK</d:status>
|
|
||||||
</d:propstat>
|
|
||||||
</d:response>
|
|
||||||
</d:multistatus>
|
|
||||||
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
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 = "<?xml version=\"1.0\"?>\n<d:multistatus xmlns:d=\"DAV:\" xmlns:s=\"http://sabredav.org/ns\" xmlns:oc=\"http://owncloud.org/ns\"><d:response><d:href>/remote.php/dav/files/naudachu/temp/id/</d:href><d:propstat><d:prop><oc:fileid>33225</oc:fileid></d:prop><d:status>HTTP/1.1 200 OK</d:status></d:propstat></d:response></d:multistatus>\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)
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue