Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions backend/terabox/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,44 @@ func (f *Fs) apiFileLocateUpload(ctx context.Context) error {
return nil
}

func (f *Fs) apiShare(ctx context.Context, path string, expire fs.Duration) (string, error) {
// 0, 1, 7, and 30 are the only valid periods, with 0 being permanent
var period int
hours := time.Duration(expire).Hours()
if hours <= 24 {
period = 1
} else if hours <= 168 {
period = 7
} else if hours <= 720 {
period = 30
}

data := url.Values{}
data.Set("schannel", "0")
data.Set("channel_list", "[0]")
data.Set("period", fmt.Sprintf("%d", period))
data.Set("path_list", fmt.Sprintf("[\"%s\"]", TBPath(path)))
// fid_list is set here officially, but seems to be optional.
// it has been excluded, otherwise we would have to use apiItemInfo.
data.Set("pwd", "")
data.Set("public", "1")

opt := NewRequest(http.MethodPost, "/share/pset")
opt.ContentType = "application/x-www-form-urlencoded"
opt.Body = strings.NewReader(data.Encode())

var res api.ResponseShare
err := f.apiExec(ctx, opt, &res)
if err != nil {
return "", err
}
if res.Err() != nil {
return "", res.Err()
}

return res.Link, nil
}

func (f *Fs) _apiFileUploadPrecreate(ctx context.Context, path string, size int64, modTime time.Time) (*api.ResponsePrecreate, error) {
opt := NewRequest(http.MethodPost, "/api/precreate")

Expand Down
6 changes: 6 additions & 0 deletions backend/terabox/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ type ResponseDownload struct {
} `json:"file_info"`
}

// ResponseShare contain Share link
type ResponseShare struct {
ErrorAPI
Link string `json:"link"`
}

// ResponseHomeInfo download file sign
type ResponseHomeInfo struct {
ErrorAPI
Expand Down
11 changes: 11 additions & 0 deletions backend/terabox/terabox.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
var (
_ fs.Fs = (*Fs)(nil)
_ fs.Abouter = (*Fs)(nil)
_ fs.PublicLinker = (*Fs)(nil)
_ fs.Copier = (*Fs)(nil)
_ fs.Mover = (*Fs)(nil)
_ fs.DirMover = (*Fs)(nil)
Expand Down Expand Up @@ -288,6 +289,16 @@ func (f *Fs) About(ctx context.Context) (*fs.Usage, error) {
return &fs.Usage{Total: &info.Total, Used: &info.Used, Free: &free}, nil
}

//
// fs.PublicLinker Interface implementation [optional]
//------------------------------------------------------------------------------------------------------------------------

// PublicLink returns a link for downloading without an account.
func (f *Fs) PublicLink(ctx context.Context, remote string, expire fs.Duration, unlink bool) (string, error) {
debug(f.opt, 1, "PublicLink %s; %s;", remote, expire.String())
return f.apiShare(ctx, f.opt.Enc.FromStandardPath(libPath.Join(f.root, remote)), expire)
}

//
// fs.Fs interface implementation
//------------------------------------------------------------------------------------------------------------------------
Expand Down