- Folder PrivateURL fixed;

This commit is contained in:
naudachu 2023-06-21 18:55:25 +05:00
parent 8b84480e74
commit a19263e97e
5 changed files with 63 additions and 110 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

18
ext/xml_test.go Normal file
View File

@ -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)
}

View File

@ -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)
}