Skip to content

Commit

Permalink
feat: add support for musetransfer, quickfile, anonfile and download.gg.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikubill committed Apr 14, 2022
1 parent 6da9944 commit e4edf71
Show file tree
Hide file tree
Showing 92 changed files with 1,913 additions and 1,256 deletions.
20 changes: 20 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.227.0/containers/go/.devcontainer/base.Dockerfile

# [Choice] Go version (use -bullseye variants on local arm64/Apple Silicon): 1, 1.16, 1.17, 1-bullseye, 1.16-bullseye, 1.17-bullseye, 1-buster, 1.16-buster, 1.17-buster
ARG VARIANT="1.18-bullseye"
FROM mcr.microsoft.com/vscode/devcontainers/go:0-${VARIANT}

# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
ARG NODE_VERSION="none"
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>

# [Optional] Uncomment the next lines to use go get to install anything else you need
# USER vscode
# RUN go get -x <your-dependency-or-tool>

# [Optional] Uncomment this line to install global node packages.
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
38 changes: 38 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.227.0/containers/go
{
"name": "Go",
"build": {
"dockerfile": "Dockerfile",
"args": {
// Update the VARIANT arg to pick a version of Go: 1, 1.18, 1.17
// Append -bullseye or -buster to pin to an OS version.
// Use -bullseye variants on local arm64/Apple Silicon.
"VARIANT": "1-bullseye",
// Options
"NODE_VERSION": "none"
}
},
"runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ],

// Set *default* container specific settings.json values on container create.
"settings": {
"go.toolsManagement.checkForUpdates": "local",
"go.useLanguageServer": true,
"go.gopath": "/go"
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"golang.Go"
],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "go version",

// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.idea/*
.idea
.DS_Store
.DS_Store
**.js
transfer
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ Beta 即为实时构建版本,不一定能正常运行,仅建议用作测试

## support

文件上传范例

```bash
./transfer <backend> <your-file-path>

./transfer wet /home/user/file.bin
```

目前支持的文件传输服务:

| Name | Command | Site | Limit |
Expand All @@ -46,7 +54,11 @@ Beta 即为实时构建版本,不一定能正常运行,仅建议用作测试
| LitterBox | `lit` | https://litterbox.catbox.moe/ | 1GB |
| 1Fichier | `fic` | https://www.1fichier.com/ | 300GB |
| Null | `null` | https://0x0.st/ | 512M |
| Infura (ipfs) | `inf` | https://infura.io/ | - |
| 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 |
| DownloadGG | `gg` | https://download.gg/ | - |

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

Expand All @@ -69,6 +81,16 @@ Beta 即为实时构建版本,不一定能正常运行,仅建议用作测试

[登陆上传相关说明](https://github.com/Mikubill/transfer#login)

## picbed support

图床上传范例

```bash
./transfer image <your-image-path> -b <backend>

./transfer image /home/user/image.png -b tg
```

目前支持的图床:

| Name | Command | Site |
Expand Down
24 changes: 6 additions & 18 deletions apis/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io"
"net/http"

"github.com/Mikubill/transfer/apis/methods"
"github.com/cheggaaa/pb/v3"
"github.com/spf13/cobra"
)
Expand All @@ -15,20 +16,9 @@ type BaseBackend interface {
LinkMatcher(string) bool
}

type DownloaderConfig struct {
Link string
Config DownConfig
Modifier func(r *http.Request)
RespHandler func(r *http.Response) bool
}

type DownConfig struct {
Prefix string
BytesMode bool
DebugMode bool
ForceMode bool
Ticket string
Parallel int
methods.DownloaderConfig
Ticket string
}

type Uploader interface {
Expand Down Expand Up @@ -83,11 +73,9 @@ func (b Backend) PostUpload(string, int64) (string, error) {
}

func (b Backend) DoDownload(link string, config DownConfig) error {
return DownloadFile(&DownloaderConfig{
Link: link,
Config: config,
Modifier: AddHeaders,
})
config.Link = link
config.Modifier = AddHeaders
return DownloadFile(config)
}

func AddHeaders(req *http.Request) {
Expand Down
26 changes: 14 additions & 12 deletions apis/command.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
package apis

import (
"github.com/Mikubill/transfer/apis/methods"
"github.com/spf13/cobra"
)

var (
Crypto bool
Key string
DebugMode bool
NoBarMode bool
MuteMode bool
transferConfig methods.TransferConfig
DebugMode bool
MuteMode bool
)

func InitCmd(cmd *cobra.Command) {
cmd.PersistentFlags().BoolVarP(&Crypto,
cmd.PersistentFlags().BoolVarP(&transferConfig.CryptoMode,
"encrypt", "", false, "encrypt stream when upload")
cmd.PersistentFlags().StringVarP(&Key,
cmd.PersistentFlags().StringVarP(&transferConfig.CryptoKey,
"encrypt-key", "", "", "specify the encrypt key")
cmd.PersistentFlags().BoolVarP(&NoBarMode,
cmd.PersistentFlags().BoolVarP(&transferConfig.NoBarMode,
"no-progress", "", false, "disable progress bar to reduce output")
cmd.PersistentFlags().BoolVarP(&MuteMode,
"silent", "", false, "enable silent mode to mute output")
cmd.PersistentFlags().BoolVarP(&DebugMode,
"verbose", "v", false, "enable verbose mode to debug")
cmd.Flags().StringVarP(&downConf.Prefix,
// workround
transferConfig.DebugMode = &DebugMode

cmd.Flags().StringVarP(&DownloadConfig.Prefix,
"output", "o", ".", "download to another file/folder")
cmd.Flags().BoolVarP(&downConf.ForceMode,
cmd.Flags().BoolVarP(&DownloadConfig.ForceMode,
"force", "f", false, "attempt to download file regardless error")
cmd.Flags().IntVarP(&downConf.Parallel,
cmd.Flags().IntVarP(&DownloadConfig.Parallel,
"parallel", "p", 3, "set download task count")
cmd.Flags().StringVarP(&downConf.Ticket,
cmd.Flags().StringVarP(&DownloadConfig.Ticket,
"ticket", "t", "", "set download ticket")
cmd.HelpFunc()
}
8 changes: 4 additions & 4 deletions apis/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import (
)

var (
downConf DownConfig
DownloadConfig DownConfig
)

func Download(link string, backend BaseBackend) {
if MuteMode {
NoBarMode = true
transferConfig.NoBarMode = true
os.Stdout, _ = os.Open(os.DevNull)
}
downConf.DebugMode = DebugMode
err := backend.DoDownload(link, downConf)
DownloadConfig.TransferConfig = transferConfig
err := backend.DoDownload(link, DownloadConfig)
if err != nil {
fmt.Printf("Download %s Error: %s", link, err)
}
Expand Down
2 changes: 1 addition & 1 deletion apis/image/alibaba.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/Mikubill/transfer/utils"
"io/ioutil"
"mime/multipart"
"net/http"
"regexp"
"time"
"github.com/Mikubill/transfer/utils"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion apis/image/baidu.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/Mikubill/transfer/utils"
"io/ioutil"
"mime/multipart"
"net/http"
"regexp"
"time"
"github.com/Mikubill/transfer/utils"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion apis/image/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package image
import (
"bytes"
"fmt"
"github.com/Mikubill/transfer/utils"
"io"
"io/ioutil"
"mime/multipart"
Expand All @@ -12,7 +13,6 @@ import (
"strings"
"sync"
"time"
"github.com/Mikubill/transfer/utils"

"github.com/cheggaaa/pb/v3"
cmap "github.com/orcaman/concurrent-map"
Expand Down
6 changes: 5 additions & 1 deletion apis/image/chevereto.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/Mikubill/transfer/utils"
"io/ioutil"
"mime/multipart"
"net/http"
Expand All @@ -13,7 +14,6 @@ import (
"strconv"
"strings"
"time"
"github.com/Mikubill/transfer/utils"
)

var (
Expand Down Expand Up @@ -72,6 +72,10 @@ func (s Chevereto) getToken() (string, error) {
}

func (s *Chevereto) newUpload(data []byte, dest string) (string, error) {
if dest == "" {
return "", fmt.Errorf("chevereto dest is empty")
}

if strings.HasPrefix(dest, "http") {
s.dest = dest
} else {
Expand Down
31 changes: 16 additions & 15 deletions apis/image/imgbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/textproto"
"strconv"
"time"

"github.com/Mikubill/transfer/utils"
)

Expand All @@ -24,21 +25,21 @@ type ImgBox struct {

type ImgBoxResp struct {
Files []struct {
ID string `json:"id"`
Slug string `json:"slug"`
Name string `json:"name"`
NameHTMLEscaped string `json:"name_html_escaped"`
CreatedAt time.Time `json:"created_at"`
CreatedAtHuman string `json:"created_at_human"`
UpdatedAt time.Time `json:"updated_at"`
GalleryID interface{} `json:"gallery_id"`
URL string `json:"url"`
OriginalURL string `json:"original_url"`
ThumbnailURL string `json:"thumbnail_url"`
SquareURL string `json:"square_url"`
Selected bool `json:"selected"`
CommentsEnabled int `json:"comments_enabled"`
CommentsCount int `json:"comments_count"`
ID string `json:"id"`
Slug string `json:"slug"`
Name string `json:"name"`
NameHTMLEscaped string `json:"name_html_escaped"`
CreatedAt time.Time `json:"created_at"`
CreatedAtHuman string `json:"created_at_human"`
UpdatedAt time.Time `json:"updated_at"`
GalleryID any `json:"gallery_id"`
URL string `json:"url"`
OriginalURL string `json:"original_url"`
ThumbnailURL string `json:"thumbnail_url"`
SquareURL string `json:"square_url"`
Selected bool `json:"selected"`
CommentsEnabled int `json:"comments_enabled"`
CommentsCount int `json:"comments_count"`
} `json:"files"`
}

Expand Down
2 changes: 1 addition & 1 deletion apis/image/suning.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/Mikubill/transfer/utils"
"io/ioutil"
"mime/multipart"
"net/http"
"regexp"
"time"
"github.com/Mikubill/transfer/utils"
)

var (
Expand Down
Loading

0 comments on commit e4edf71

Please sign in to comment.