Skip to content

Commit

Permalink
Merge branch 'release/v1.0.31'
Browse files Browse the repository at this point in the history
  • Loading branch information
SheltonZhu committed Dec 8, 2024
2 parents ef9f5e7 + ac02b81 commit 4f7a713
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pkg/driver/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package driver

const (
ApiGetVersion = "https://appversion.115.com/1/web/1.0/api/chrome"

// login
ApiLoginCheck = "https://passportapi.115.com/app/1.0/web/1.0/check/sso"
ApiUserInfo = "https://my.115.com/?ct=ajax&ac=nav"
Expand All @@ -14,6 +15,7 @@ const (
ApiFileMove = "https://webapi.115.com/files/move"
ApiFileCopy = "https://webapi.115.com/files/copy"
ApiFileRename = "https://webapi.115.com/files/batch_rename"
ApiFileIndexInfo = "https://webapi.115.com/files/index_info"

ApiFileList = "https://webapi.115.com/files"
ApiFileListByName = "https://aps.115.com/natsort/files.php"
Expand Down
1 change: 1 addition & 0 deletions pkg/driver/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
CookieNameUid = "UID"
CookieNameCid = "CID"
CookieNameSeid = "SEID"
CookieNameKid = "KID"
)

const (
Expand Down
9 changes: 9 additions & 0 deletions pkg/driver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,12 @@ func TestGetVersion(t *testing.T) {
assert.NoError(t, err)
assert.NotEmpty(t, vers)
}

func TestGetInfo(t *testing.T) {
down := teardown(t)
defer down(t)

info, err := client.GetInfo()
assert.NoError(t, err)
assert.NotEmpty(t, info.SpaceInfo)
}
76 changes: 76 additions & 0 deletions pkg/driver/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package driver

// GetInfo get space info and login device info.
func (c *Pan115Client) GetInfo() (InfoData, error) {
result := InfoResponse{}
req := c.NewRequest().
SetResult(&result).
ForceContentType("application/json;charset=UTF-8")

resp, err := req.Get(ApiFileIndexInfo)

if err = CheckErr(err, &result, resp); err != nil {
return InfoData{}, err
}
return result.Data, nil
}

type InfoResponse struct {
BasicResp
Data InfoData `json:"data"`
}

type InfoData struct {
SpaceInfo SpaceInfo `json:"space_info"`
LoginDevicesInfo LoginDevicesInfo `json:"login_devices_info"`
ImeiInfo bool `json:"imei_info"`
}

type TotalSize struct {
Size int64 `json:"size"`
SizeFormat string `json:"size_format"`
}

type RemainSize struct {
Size int64 `json:"size"`
SizeFormat string `json:"size_format"`
}

type UseSize struct {
Size int64 `json:"size"`
SizeFormat string `json:"size_format"`
}

type SpaceInfo struct {
AllTotal TotalSize `json:"all_total"`
AllRemain RemainSize `json:"all_remain"`
AllUse UseSize `json:"all_use"`
}

type LastDevice struct {
IP string `json:"ip"`
Device string `json:"device"`
DeviceID string `json:"device_id"`
Network string `json:"network"`
Os string `json:"os"`
City string `json:"city"`
Utime int `json:"utime"`
}

type Device struct {
IsCurrent int `json:"is_current"`
Ssoent string `json:"ssoent"`
Utime int `json:"utime"`
Device string `json:"device"`
Name string `json:"name"`
Icon string `json:"icon"`
Desc string `json:"desc"`
IP string `json:"ip"`
City string `json:"city"`
IsUnusual int `json:"is_unusual"`
}

type LoginDevicesInfo struct {
Last LastDevice `json:"last"`
List []Device `json:"list"`
}
5 changes: 4 additions & 1 deletion pkg/driver/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func (c *Pan115Client) ImportCredential(cr *Credential) *Pan115Client {
CookieNameUid: cr.UID,
CookieNameCid: cr.CID,
CookieNameSeid: cr.SEID,
CookieNameKid: cr.KID,
}
c.ImportCookies(cookies, CookieDomain115)
return c
Expand Down Expand Up @@ -70,6 +71,7 @@ type Credential struct {
UID string `json:"UID"`
CID string `json:"CID"`
SEID string `json:"SEID"`
KID string `json:"KID"`
}

// FromCookie get uid, cid, seid from cookie string
Expand All @@ -92,7 +94,8 @@ func (cr *Credential) FromCookie(cookie string) error {
cr.UID = cookieMap["UID"]
cr.CID = cookieMap["CID"]
cr.SEID = cookieMap["SEID"]
if cr.CID == "" || cr.UID == "" || cr.SEID == "" {
cr.KID = cookieMap["KID"]
if cr.CID == "" || cr.UID == "" || cr.SEID == "" || cr.KID == "" {
return errors.Wrap(ErrBadCookie, "bad cookie, miss UID, CID or SEID")
}
return nil
Expand Down

0 comments on commit 4f7a713

Please sign in to comment.