Skip to content

Commit

Permalink
build
Browse files Browse the repository at this point in the history
  • Loading branch information
URenko committed May 25, 2024
1 parent 8e2b9c6 commit a6135a8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
11 changes: 4 additions & 7 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,16 @@ BuildDev() {
curl -L -o "${i}.tgz" "${url}"
sudo tar xf "${i}.tgz" --strip-components 1 -C /usr/local
done
OS_ARCHES=(linux-musl-amd64 linux-musl-arm64)
CGO_ARGS=(x86_64-linux-musl-gcc aarch64-linux-musl-gcc)
OS_ARCHES=(linux-amd64)
for i in "${!OS_ARCHES[@]}"; do
os_arch=${OS_ARCHES[$i]}
cgo_cc=${CGO_ARGS[$i]}
echo building for ${os_arch}
export GOOS=${os_arch%%-*}
export GOARCH=${os_arch##*-}
export CC=${cgo_cc}
export GOAMD64=v3
export CGO_ENABLED=1
go build -o ./dist/$appName-$os_arch -ldflags="$muslflags" -tags=jsoniter .
go build -o ./dist/$appName-$os_arch -ldflags="$ldflags" -tags=jsoniter .
done
xgo -targets=windows/amd64,darwin/amd64,darwin/arm64 -out "$appName" -ldflags="$ldflags" -tags=jsoniter .
xgo -targets=windows/amd64 -out "$appName" -ldflags="$ldflags" -tags=jsoniter .
mv alist-* dist
cd dist
cp ./alist-windows-amd64.exe ./alist-windows-amd64-upx.exe
Expand Down
20 changes: 14 additions & 6 deletions drivers/terabox/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
stdpath "path"
"strconv"
"strings"
"time"

"github.com/alist-org/alist/v3/drivers/base"
"github.com/alist-org/alist/v3/pkg/utils"
Expand Down Expand Up @@ -157,17 +158,22 @@ func (d *Terabox) Put(ctx context.Context, dstDir model.Obj, stream model.FileSt
rawPath := stdpath.Join(dstDir.GetPath(), stream.GetName())
path := encodeURIComponent(rawPath)
block_list_str := fmt.Sprintf("[%s]", strings.Join(block_list, ","))
data := fmt.Sprintf("path=%s&size=%d&isdir=0&autoinit=1&block_list=%s",
path, stream.GetSize(),
block_list_str)
params := map[string]string{}
data := map[string]string{
"path": rawPath,
"autoinit": "1",
"target_path": dstDir.GetPath(),
"block_list": block_list_str,
"local_mtime": string(time.Now().Unix()),
}
var precreateResp PrecreateResp
_, err = d.post("/api/precreate", params, data, &precreateResp)
log.Debugln(data)
res, err := d.post_form("/api/precreate", nil, data, &precreateResp)
if err != nil {
return err
}
log.Debugf("%+v", precreateResp)
if precreateResp.Errno != 0 {
log.Debugln(string(res))
return fmt.Errorf("[terabox] failed to precreate file, errno: %d", precreateResp.Errno)
}
if precreateResp.ReturnType == 2 {
Expand Down Expand Up @@ -216,7 +222,9 @@ func (d *Terabox) Put(ctx context.Context, dstDir model.Obj, stream model.FileSt
up(float64(i) * 100 / float64(len(precreateResp.BlockList)))
}
}
_, err = d.create(rawPath, stream.GetSize(), 0, precreateResp.Uploadid, block_list_str)
res, err = d.create(rawPath, stream.GetSize(), 0, precreateResp.Uploadid, block_list_str)
log.Debugln(string(res))
time.Sleep(time.Duration(len(precreateResp.BlockList)/16+10) * time.Second)
return err
}

Expand Down
11 changes: 10 additions & 1 deletion drivers/terabox/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ func (d *Terabox) post(pathname string, params map[string]string, data interface
}, resp)
}

func (d *Terabox) post_form(pathname string, params map[string]string, data map[string]string, resp interface{}) ([]byte, error) {
return d.request("https://www.terabox.com"+pathname, http.MethodPost, func(req *resty.Request) {
if params != nil {
req.SetQueryParams(params)
}
req.SetFormData(data)
}, resp)
}

func (d *Terabox) getFiles(dir string) ([]File, error) {
page := 1
num := 100
Expand Down Expand Up @@ -238,7 +247,7 @@ func (d *Terabox) manage(opera string, filelist interface{}) ([]byte, error) {
}

func (d *Terabox) create(path string, size int64, isdir int, uploadid, block_list string) ([]byte, error) {
params := map[string]string{}
params := map[string]string{"rtype": "1"}
data := fmt.Sprintf("path=%s&size=%d&isdir=%d", encodeURIComponent(path), size, isdir)
if uploadid != "" {
data += fmt.Sprintf("&uploadid=%s&block_list=%s", uploadid, block_list)
Expand Down

0 comments on commit a6135a8

Please sign in to comment.