mirror of https://github.com/Xhofe/alist
feat(doubao): add get_download_info API and download_api option (#8428)
parent
f541489d7d
commit
b2b91a9281
|
@ -3,6 +3,11 @@ package doubao
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/alist-org/alist/v3/drivers/base"
|
"github.com/alist-org/alist/v3/drivers/base"
|
||||||
"github.com/alist-org/alist/v3/internal/driver"
|
"github.com/alist-org/alist/v3/internal/driver"
|
||||||
"github.com/alist-org/alist/v3/internal/errs"
|
"github.com/alist-org/alist/v3/internal/errs"
|
||||||
|
@ -10,10 +15,6 @@ import (
|
||||||
"github.com/alist-org/alist/v3/pkg/utils"
|
"github.com/alist-org/alist/v3/pkg/utils"
|
||||||
"github.com/go-resty/resty/v2"
|
"github.com/go-resty/resty/v2"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Doubao struct {
|
type Doubao struct {
|
||||||
|
@ -97,6 +98,20 @@ func (d *Doubao) Link(ctx context.Context, file model.Obj, args model.LinkArgs)
|
||||||
var downloadUrl string
|
var downloadUrl string
|
||||||
|
|
||||||
if u, ok := file.(*Object); ok {
|
if u, ok := file.(*Object); ok {
|
||||||
|
switch d.DownloadApi {
|
||||||
|
case "get_download_info":
|
||||||
|
var r GetDownloadInfoResp
|
||||||
|
_, err := d.request("/samantha/aispace/get_download_info", http.MethodPost, func(req *resty.Request) {
|
||||||
|
req.SetBody(base.Json{
|
||||||
|
"requests": []base.Json{{"node_id": file.GetID()}},
|
||||||
|
})
|
||||||
|
}, &r)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
downloadUrl = r.Data.DownloadInfos[0].MainURL
|
||||||
|
case "get_file_url":
|
||||||
switch u.NodeType {
|
switch u.NodeType {
|
||||||
case VideoType, AudioType:
|
case VideoType, AudioType:
|
||||||
var r GetVideoFileUrlResp
|
var r GetVideoFileUrlResp
|
||||||
|
@ -125,6 +140,9 @@ func (d *Doubao) Link(ctx context.Context, file model.Obj, args model.LinkArgs)
|
||||||
|
|
||||||
downloadUrl = r.Data.FileUrls[0].MainURL
|
downloadUrl = r.Data.FileUrls[0].MainURL
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
return nil, errs.NotImplement
|
||||||
|
}
|
||||||
|
|
||||||
// 生成标准的Content-Disposition
|
// 生成标准的Content-Disposition
|
||||||
contentDisposition := generateContentDisposition(u.Name)
|
contentDisposition := generateContentDisposition(u.Name)
|
||||||
|
|
|
@ -12,6 +12,7 @@ type Addition struct {
|
||||||
// define other
|
// define other
|
||||||
Cookie string `json:"cookie" type:"text"`
|
Cookie string `json:"cookie" type:"text"`
|
||||||
UploadThread string `json:"upload_thread" default:"3"`
|
UploadThread string `json:"upload_thread" default:"3"`
|
||||||
|
DownloadApi string `json:"download_api" type:"select" options:"get_file_url,get_download_info" default:"get_file_url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var config = driver.Config{
|
var config = driver.Config{
|
||||||
|
|
|
@ -3,8 +3,9 @@ package doubao
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/alist-org/alist/v3/internal/model"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/alist-org/alist/v3/internal/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BaseResp struct {
|
type BaseResp struct {
|
||||||
|
@ -38,6 +39,17 @@ type File struct {
|
||||||
UpdateTime int64 `json:"update_time"`
|
UpdateTime int64 `json:"update_time"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GetDownloadInfoResp struct {
|
||||||
|
BaseResp
|
||||||
|
Data struct {
|
||||||
|
DownloadInfos []struct {
|
||||||
|
NodeID string `json:"node_id"`
|
||||||
|
MainURL string `json:"main_url"`
|
||||||
|
BackupURL string `json:"backup_url"`
|
||||||
|
} `json:"download_infos"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
type GetFileUrlResp struct {
|
type GetFileUrlResp struct {
|
||||||
BaseResp
|
BaseResp
|
||||||
Data struct {
|
Data struct {
|
||||||
|
|
Loading…
Reference in New Issue