Skip to content

Commit

Permalink
fix: ul/dl error on cow(#48), add valid-days support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikubill committed Feb 10, 2022
1 parent 79c42a0 commit f1abf0a
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
- name: test - multi
run: |
./ci-test-linux-amd64 cow --no-progress crypto
./ci-test-linux-amd64 cow --no-progress -s crypto
./ci-test-linux-amd64 wet --no-progress crypto
./ci-test-linux-amd64 wet --no-progress -s crypto
- name: test - all
run: |
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,23 @@ Beta即为实时构建版本,不一定能正常运行,仅建议用作测试
| ---- | ---- | ---- |
| Airportal | https://airportal.cn/ | - |
| CatBox | https://catbox.moe/ | 200MB |
| CowTransfer | https://www.cowtransfer.com/ | 2GB |
| Fileio | https://file.io/ | 100MB |
| GoFile | https://gofile.io/ | - |
| Wenshushu | https://wenshushu.cn/ | 2GB |
| WeTransfer | https://wetransfer.com/ | 2GB |
| Transfer.sh | https://transfer.sh/ | - |
| LitterBox | https://litterbox.catbox.moe/ | 1GB |
| Lanzous | https://www.lanzous.com/ | login |
| Notion | https://www.notion.so/ | login |
| 1Fichier | https://www.1fichier.com/ | 300GB |
| Null | https://0x0.st/ | 512M |

需要登录才能使用的服务:

| Name | Site |
| ---- | ---- |
| Lanzous | https://www.lanzous.com/ |
| Notion | https://www.notion.so/ |
| CowTransfer | https://www.cowtransfer.com/ |

已失效或不可用的服务:

| Name | Site |
Expand Down
2 changes: 2 additions & 0 deletions apis/public/cowtransfer/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type cowTransfer struct {
}

func (b *cowTransfer) SetArgs(cmd *cobra.Command) {
cmd.Flags().IntVarP(&b.Config.validDays, "valid", "", 0, "Set the valid days for transfer")

cmd.Flags().IntVarP(&b.Config.Parallel, "parallel", "p", 2, "Set the number of upload threads")
cmd.Flags().StringVarP(&b.Config.token, "cookie", "c", "", "Your user cookie (optional)")
cmd.Flags().StringVarP(&b.Config.authCode, "auth", "a", "", "Your auth code (optional)")
Expand Down
16 changes: 11 additions & 5 deletions apis/public/cowtransfer/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import (
)

const (
downloadDetails = "https://cowtransfer.com/api/transfer/transferdetail?url=%s&treceive=undefined&passcode=%s"
downloadFiles = "https://cowtransfer.com/api/transfer/files?page=0&guid=%s"
downloadDetails = "https://cowtransfer.com/api/transfer/v2/transferdetail?url=%s&treceive=undefined&passcode=%s"
downloadFiles = "https://cowtransfer.com/api/transfer/v2/files?page=0&guid=%s"
downloadConfig = "https://cowtransfer.com/api/transfer/download?guid=%s"
)

var (
matcher = regexp.MustCompile("(cowtransfer\\.com|c-t\\.work)/s/[0-9a-f]{14}")
matcher = regexp.MustCompile(`(cowtransfer\.com|c-t\.work)/s/[0-9a-f]{14}`)
reg = regexp.MustCompile("[0-9a-f]{14}")
)

Expand All @@ -42,6 +42,9 @@ func (b cowTransfer) initDownload(v string, config apis.DownConfig) error {
fmt.Printf("Remote: %s\n", v)

body, err := fetchWithCookie(fmt.Sprintf(downloadDetails, fileID, config.Ticket), fileID)
if err != nil {
return fmt.Errorf("request DownloadDetails returns error: %s", err)
}

if config.DebugMode {
log.Printf("returns: %v\n", string(body))
Expand All @@ -65,6 +68,9 @@ func (b cowTransfer) initDownload(v string, config apis.DownConfig) error {
}

body, err = fetchWithCookie(fmt.Sprintf(downloadFiles, details.GUID), fileID)
if err != nil {
return fmt.Errorf("request FileDetails returns error: %s", err)
}

if config.DebugMode {
log.Printf("returns: %v\n", string(body))
Expand All @@ -78,7 +84,7 @@ func (b cowTransfer) initDownload(v string, config apis.DownConfig) error {
for _, item := range files.Details {
err = downloadItem(item, config)
if err != nil {
fmt.Println(err)
return err
}
}
return nil
Expand Down Expand Up @@ -108,7 +114,7 @@ func downloadItem(item downloadDetailsBlock, baseConf apis.DownConfig) error {
if baseConf.DebugMode {
log.Println("step2 -> api/getConf")
log.Printf("fileName: %s\n", item.FileName)
log.Printf("fileSize: %s\n", item.Size)
log.Printf("fileSize: %2.f\n", item.Size)
log.Printf("GUID: %s\n", item.GUID)
}
configURL := fmt.Sprintf(downloadConfig, item.GUID)
Expand Down
5 changes: 4 additions & 1 deletion apis/public/cowtransfer/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"net/http"
"time"
"transfer/apis"
"transfer/utils"
)

func (b cowTransfer) blockPut(postURL string, buf []byte, token string) (string, error) {
Expand Down Expand Up @@ -129,6 +130,7 @@ func (b cowTransfer) newMultipartRequest(url string, params map[string]string, c
}
buf := &bytes.Buffer{}
writer := multipart.NewWriter(buf)
writer.SetBoundary("----WebKitFormBoundary" + utils.GenRandString(16))
for key, val := range params {
_ = writer.WriteField(key, val)
}
Expand Down Expand Up @@ -198,11 +200,12 @@ func (b cowTransfer) addTk(req *http.Request) {

req.Header.Set("cookie", ck)
req.Header.Set("authorization", b.Config.authCode)
addHeaders(req)
}

func addHeaders(req *http.Request) {
req.Header.Set("Referer", "https://cowtransfer.com/")
req.Header.Set("User-Agent", "Chrome/80.0.3987.149 Transfer")
req.Header.Set("User-Agent", "Mozilla/5.0 DevOps; Transfer/1.1 (KHTML, like Gecko) Chrome/97.0")
req.Header.Set("Origin", "https://cowtransfer.com/")
req.Header.Set("Cookie", fmt.Sprintf("%scf-cs-k-20181214=%d;", req.Header.Get("Cookie"), time.Now().UnixNano()))
}
9 changes: 5 additions & 4 deletions apis/public/cowtransfer/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type cowOptions struct {
blockSize int64
hashCheck bool
passCode string
validDays int
}

type initResp struct {
Expand Down Expand Up @@ -97,13 +98,13 @@ type downloadDetailsResponse struct {
}

type downloadFilesResponse struct {
Details []downloadDetailsBlock `json:"transferFileDtos"`
Details []downloadDetailsBlock `json:"files"`
}

type downloadDetailsBlock struct {
GUID string `json:"guid"`
FileName string `json:"fileName"`
Size string `json:"size"`
GUID string `json:"guid"`
FileName string `json:"fileName"`
Size float64 `json:"sizeInByte"`
}

type uploadResult struct {
Expand Down
18 changes: 10 additions & 8 deletions apis/public/cowtransfer/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (
)

const (
prepareSend = "https://cowtransfer.com/api/transfer/preparesend"
prepareSend = "https://cowtransfer.com/api/transfer/v2/preparesend"
setPassword = "https://cowtransfer.com/api/transfer/v2/bindpasscode"
beforeUpload = "https://cowtransfer.com/api/transfer/beforeupload"
uploadFinish = "https://cowtransfer.com/api/transfer/uploaded"
uploadComplete = "https://cowtransfer.com/api/transfer/complete"
beforeUpload = "https://cowtransfer.com/api/transfer/v2/beforeupload"
uploadFinish = "https://cowtransfer.com/api/transfer/v2/uploaded"
uploadComplete = "https://cowtransfer.com/api/transfer/v2/complete"
initUpload = "https://upload.qiniup.com/buckets/cftransfer/objects/%s/uploads"
doUpload = "https://upload.qiniup.com/buckets/cftransfer/objects/%s/uploads/%s/%d"
finUpload = "https://upload.qiniup.com/buckets/cftransfer/objects/%s/uploads/%s"
Expand Down Expand Up @@ -256,7 +256,7 @@ func (b cowTransfer) completeUpload() (string, error) {
if err := json.Unmarshal(body, &rBody); err != nil {
return "", fmt.Errorf("read finish resp failed: %s", err)
}
if rBody.Status != true {
if !rBody.Status {
return "", fmt.Errorf("finish upload failed: complete is not true")
}
//fmt.Printf("Short Download Code: %s\n\n", rBody.TempDownloadCode)
Expand All @@ -265,8 +265,10 @@ func (b cowTransfer) completeUpload() (string, error) {

func (b cowTransfer) getSendConfig(totalSize int64) (*prepareSendResp, error) {
data := map[string]string{
"validDays": "1",
"totalSize": strconv.FormatInt(totalSize, 10),
"validDays": strconv.Itoa(b.Config.validDays),
"totalSize": strconv.FormatInt(totalSize, 10),
"enableDownload": "true",
"enablePreview": "true",
}
body, err := b.newMultipartRequest(prepareSend, data, requestConfig{
debug: apis.DebugMode,
Expand All @@ -282,7 +284,7 @@ func (b cowTransfer) getSendConfig(totalSize int64) (*prepareSendResp, error) {
if err != nil {
return nil, err
}
if config.Error != false {
if config.Error {
return nil, fmt.Errorf(config.ErrorMessage)
}
if b.Config.passCode != "" {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ require (
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/spf13/cobra v1.3.0
golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838
golang.org/x/sys v0.0.0-20220207234003-57398862261d // indirect
golang.org/x/crypto v0.0.0-20220209195652-db638375bc3a
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 // indirect
golang.org/x/text v0.3.7
golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 h1:0es+/5331RGQPcXlMfP+Wr
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838 h1:71vQrMauZZhcTVK6KdYM+rklehEEwb3E+ZhaE5jrPrE=
golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220209195652-db638375bc3a h1:atOEWVSedO4ksXBe/UrlbSLVxQQ9RxM/tT2Jy10IaHo=
golang.org/x/crypto v0.0.0-20220209195652-db638375bc3a/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down Expand Up @@ -600,6 +602,8 @@ golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+R
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220207234003-57398862261d h1:Bm7BNOQt2Qv7ZqysjeLjgCBanX+88Z/OtdvsrEv1Djc=
golang.org/x/sys v0.0.0-20220207234003-57398862261d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c=
golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down

0 comments on commit f1abf0a

Please sign in to comment.