add fast share create command

This commit is contained in:
tickstep 2024-12-03 11:15:38 +08:00
parent 4a59f246f2
commit 2eaba0c3c8
2 changed files with 65 additions and 26 deletions

View File

@ -93,12 +93,27 @@ func CmdShare() cli.Command {
sharePwd = RandomStr(4) sharePwd = RandomStr(4)
} }
// 模式
modeFlag := "3"
if c.IsSet("mode") {
modeFlag = c.String("mode")
}
if modeFlag == "1" || modeFlag == "2" {
if config.Config.ActiveUser().ActiveDriveId != config.Config.ActiveUser().DriveList.GetResourceDriveId() { if config.Config.ActiveUser().ActiveDriveId != config.Config.ActiveUser().DriveList.GetResourceDriveId() {
// 只有资源库才支持私有、公开分享 // 只有资源库才支持私有、公开分享
fmt.Println("只有资源库才支持创建分享链接") fmt.Println("只有资源库才支持分享链接,其他请使用快传链接")
return nil return nil
} }
RunOpenShareSet(parseDriveId(c), c.Args(), et, sharePwd) }
if modeFlag == "1" {
if sharePwd == "" {
sharePwd = RandomStr(4)
}
} else {
sharePwd = ""
}
RunOpenShareSet(modeFlag, parseDriveId(c), c.Args(), et, sharePwd)
return nil return nil
}, },
Flags: []cli.Flag{ Flags: []cli.Flag{
@ -112,6 +127,11 @@ func CmdShare() cli.Command {
Usage: "有效期0-永久1-1天2-7天", Usage: "有效期0-永久1-1天2-7天",
Value: "0", Value: "0",
}, },
cli.StringFlag{
Name: "mode",
Usage: "模式1-私密分享2-公开分享3-快传",
Value: "3",
},
cli.StringFlag{ cli.StringFlag{
Name: "sharePwd", Name: "sharePwd",
Usage: "自定义私密分享密码4个字符没有指定则随机生成", Usage: "自定义私密分享密码4个字符没有指定则随机生成",
@ -124,7 +144,7 @@ func CmdShare() cli.Command {
} }
// RunOpenShareSet 执行分享 // RunOpenShareSet 执行分享
func RunOpenShareSet(driveId string, paths []string, expiredTime string, sharePwd string) { func RunOpenShareSet(modeFlag, driveId string, paths []string, expiredTime string, sharePwd string) {
if len(paths) <= 0 { if len(paths) <= 0 {
fmt.Println("请指定文件路径") fmt.Println("请指定文件路径")
return return
@ -159,7 +179,26 @@ func RunOpenShareSet(driveId string, paths []string, expiredTime string, sharePw
return return
} }
// 创建分享 // 创建分享类型
if modeFlag == "3" {
// 快传
r, err1 := panClient.OpenapiPanClient().FastShareLinkCreate(aliyunpan.FastShareCreateParam{
DriveId: driveId,
FileIdList: fidList,
})
if err1 != nil || r == nil {
if err1.Code == apierror.ApiCodeFileShareNotAllowed {
fmt.Printf("创建快传链接失败: 该文件类型不允许分享\n")
} else {
fmt.Printf("创建快传链接失败: %s\n", err1)
}
return
}
fmt.Printf("创建快传链接成功\n")
fmt.Printf("链接:%s\n", r.ShareUrl)
} else {
// 分享
r, err1 := panClient.OpenapiPanClient().ShareLinkCreate(aliyunpan.ShareCreateParam{ r, err1 := panClient.OpenapiPanClient().ShareLinkCreate(aliyunpan.ShareCreateParam{
DriveId: driveId, DriveId: driveId,
SharePwd: sharePwd, SharePwd: sharePwd,
@ -181,4 +220,5 @@ func RunOpenShareSet(driveId string, paths []string, expiredTime string, sharePw
} else { } else {
fmt.Printf("链接:%s\n", r.ShareUrl) fmt.Printf("链接:%s\n", r.ShareUrl)
} }
}
} }

View File

@ -18,7 +18,6 @@ import (
"fmt" "fmt"
"github.com/tickstep/aliyunpan-api/aliyunpan" "github.com/tickstep/aliyunpan-api/aliyunpan"
"github.com/tickstep/aliyunpan-api/aliyunpan/apierror" "github.com/tickstep/aliyunpan-api/aliyunpan/apierror"
"github.com/tickstep/aliyunpan-api/aliyunpan_web"
"github.com/tickstep/aliyunpan/cmder" "github.com/tickstep/aliyunpan/cmder"
"github.com/tickstep/aliyunpan/cmder/cmdtable" "github.com/tickstep/aliyunpan/cmder/cmdtable"
"github.com/tickstep/aliyunpan/internal/config" "github.com/tickstep/aliyunpan/internal/config"
@ -270,7 +269,7 @@ func RunShareSet(modeFlag, driveId string, paths []string, expiredTime string, s
if modeFlag == "3" { if modeFlag == "3" {
// 快传 // 快传
r, err1 := panClient.WebapiPanClient().FastShareLinkCreate(aliyunpan_web.FastShareCreateParam{ r, err1 := panClient.WebapiPanClient().FastShareLinkCreate(aliyunpan.FastShareCreateParam{
DriveId: driveId, DriveId: driveId,
FileIdList: fidList, FileIdList: fidList,
}) })