[go: up one dir, main page]

Skip to content

Commit

Permalink
Merge pull request #85 from Yatogaii/master
Browse files Browse the repository at this point in the history
修复了GoFile的上传功能,并且更新了部分Readme中的过时信息
  • Loading branch information
Mikubill authored Aug 24, 2023
2 parents 0d08fb7 + 56e9f65 commit 9227a05
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 18 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Beta 即为实时构建版本,不一定能正常运行,仅建议用作测试
| Infura (ipfs) | `inf` | https://infura.io/ | 128M |
| Musetransfer | `muse` | https://musetransfer.com | 5GB |
| Quickfile | `qf` | https://quickfile.cn | 512M |
| Anonfile | `anon` | https://anonfile.com | 10G |
| Anonfile | `anon` | https://anonfile.com | 20G |
| DownloadGG | `gg` | https://download.gg/ | - |

需要登录才能使用的服务:
Expand Down Expand Up @@ -164,7 +164,7 @@ Use "transfer [command] --help" for more information about a command.

### upload & download

所有上传操作都建议指定一个 API,如不指定将使用默认 (filelink.Backend)。加上想要传输的文件/文件夹即可。
所有上传操作都建议指定一个 API,如不指定将使用默认 (fileio.Backend)。加上想要传输的文件/文件夹即可。

```text
Expand Down
1 change: 1 addition & 0 deletions apis/public/gofile/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type goFile struct {
folderID string
folderName string

downloadLink string
// baseBody []byte

// boundary string
Expand Down
13 changes: 13 additions & 0 deletions apis/public/gofile/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,16 @@ type fileDetails struct {
Link string `json:"link"`
Thumbnail string `json:"thumbnail"`
}

type uploadRespData struct {
DownLoadPage string `json:"downLoadPage"`
Code string `json:"code"`
ParentFolder string `json:"parentFolder"`
FileId string `json:"fileId"`
FileName string `json:"fileName"`
Md5 string `json:"md5"`
}
type uploadResp struct {
Status string `json:"name"`
Data uploadRespData `json:"data"`
}
27 changes: 21 additions & 6 deletions apis/public/gofile/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ const (
getServer = "https://api.gofile.io/getServer"
createAccount = "https://api.gofile.io/createAccount"
createFolder = "https://api.gofile.io/createFolder"
setFolder = "https://api.gofile.io/setFolderOption"
setFolder = "https://api.gofile.io/setOption"
getUserAccount = "https://api.gofile.io/getAccountDetails?token=%s"
createFolderPostString = "parentFolderId=%s&token=%s"
setPrimPostString = "folderId=%s&token=%s&option=public&value=true"
createFolderPostString = "parentFolderId=%s&folderName=%s&token=%s"
setPrimPostString = "contentId=%s&token=%s&option=public&value=true"
shareFolder = "https://api.gofile.io/shareFolder?folderId=%s&token=%s"
)

Expand Down Expand Up @@ -93,7 +93,7 @@ func (b *goFile) createFolder() error {

body.Body.Close()
rootFolderID := sevData1.Data.RootFolder
postString := fmt.Sprintf(createFolderPostString, rootFolderID, b.userToken)
postString := fmt.Sprintf(createFolderPostString, rootFolderID, "tfolder", b.userToken)

// then create new folder
if apis.DebugMode {
Expand Down Expand Up @@ -187,12 +187,24 @@ func (b *goFile) selectServer() error {

func (b *goFile) DoUpload(name string, size int64, file io.Reader) error {

_, err := b.newMultipartUpload(uploadConfig{
body, err := b.newMultipartUpload(uploadConfig{
fileSize: size,
fileName: name,
fileReader: file,
debug: apis.DebugMode,
})

// Get download link from response
var respData uploadResp
err = json.Unmarshal(body, &respData)
if err != nil {
if apis.DebugMode {
log.Printf("parse response error: %v", err)
}
return err
}

b.downloadLink = respData.Data.DownLoadPage
if err != nil {
return fmt.Errorf("upload returns error: %s", err)
}
Expand Down Expand Up @@ -264,13 +276,15 @@ func (b *goFile) newMultipartUpload(config uploadConfig) ([]byte, error) {
}
return nil, err
}

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
if config.debug {
log.Printf("read response returns: %v", err)
}
return nil, err
}

_ = resp.Body.Close()
if config.debug {
log.Printf("returns: %v", string(body))
Expand Down Expand Up @@ -298,7 +312,8 @@ func (b *goFile) FinishUpload([]string) (string, error) {
}

link := fmt.Sprintf("https://gofile.io/?c=%s", b.folderName)
fmt.Printf("Download Link: %s\nUser Token: %s\n", link, b.userToken)
// fmt.Printf("Download Link: %s\nUser Token: %s\n", link, b.userToken)
fmt.Printf("Download Link: %s\nUser Token: %s\n", b.downloadLink, b.userToken)

return link, nil

Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ require (

require (
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/cheggaaa/pb v1.0.29
github.com/fatih/color v1.13.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
Expand Down
9 changes: 0 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow=
github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4=
github.com/cheggaaa/pb v1.0.29 h1:FckUN5ngEk2LpvuG0fw1GEFx6LtyY2pWI/Z2QgCnEYo=
github.com/cheggaaa/pb v1.0.29/go.mod h1:W40334L7FMC5JKWldsTWbdGjLo0RxUKK73K+TuPxX30=
github.com/cheggaaa/pb/v3 v3.0.8 h1:bC8oemdChbke2FHIIGy9mn4DPJ2caZYQnfbRqwmdCoA=
github.com/cheggaaa/pb/v3 v3.0.8/go.mod h1:UICbiLec/XO6Hw6k+BHEtHeQFzzBH4i2/qk/ow1EJTA=
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
Expand All @@ -42,8 +35,6 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ=
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down

0 comments on commit 9227a05

Please sign in to comment.