Skip to content

Commit

Permalink
fix: upload issue on musetransfer (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikubill committed Apr 17, 2022
1 parent 7a44ca3 commit c79005e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
13 changes: 6 additions & 7 deletions apis/public/bitsend/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (b bitSend) DoDownload(link string, config apis.DownConfig) error {

func (b bitSend) download(v string, config apis.DownConfig) error {
var link string
if config.DebugMode {
if apis.DebugMode {
log.Printf("fetching: %v", v)
}
fmt.Printf("fetching ticket..")
Expand All @@ -45,18 +45,17 @@ func (b bitSend) download(v string, config apis.DownConfig) error {
}
_ = resp.Body.Close()
link = "https://bitsend.jp/" + regex.FindString(string(body))
if config.DebugMode {
if apis.DebugMode {
log.Printf("dest: %v", link)
}
b.Ticket = resp.Header.Get("Set-Cookie")
*end <- struct{}{}
fmt.Printf("ok\n")

return apis.DownloadFile(&apis.DownloaderConfig{
Link: link,
Config: config,
Modifier: b.addRef(v),
})
config.Link = link
config.Modifier = b.addRef(v)

return apis.DownloadFile(config)
}

func (b bitSend) addRef(ref string) func(req *http.Request) {
Expand Down
2 changes: 1 addition & 1 deletion apis/public/musetransfer/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type muse struct {
apis.Backend

Config museOptions
EtagMap sync.Map
EtagMap *sync.Map
Assets []int64
Commands [][]string
}
Expand Down
8 changes: 3 additions & 5 deletions apis/public/musetransfer/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func (b *muse) getUploadToken() (*s3Token, error) {
}

func (b *muse) newTransfer() error {
b.EtagMap = new(sync.Map)
fmt.Printf("fetching upload tickets..")
end := utils.DotTicker()

Expand Down Expand Up @@ -245,9 +246,6 @@ func (b *muse) DoUpload(name string, size int64, file io.Reader) error {
return err
}
b.ossSigner(req, auth)
if apis.DebugMode {
log.Println("usq header: ", req.Header)
}
http.DefaultClient.Timeout = time.Duration(b.Config.interval) * time.Second
resp, err = http.DefaultClient.Do(req)
if err != nil {
Expand All @@ -261,8 +259,8 @@ func (b *muse) DoUpload(name string, size int64, file io.Reader) error {

func (b *muse) generate_payload(max int64) string {
var payload string
payload = `<?xml version="1.0" encoding="UTF-8"?>`
payload += "<CompleteMultipartUpload>"
payload = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
payload += "<CompleteMultipartUpload>\n"
for i := int64(1); i <= max; i++ {
if v, ok := b.EtagMap.LoadAndDelete(i); ok {
payload += fmt.Sprintf("<Part><PartNumber>%d</PartNumber><ETag>%s</ETag></Part>", i, v)
Expand Down

0 comments on commit c79005e

Please sign in to comment.