@@ -120,7 +120,10 @@ func (d *ILanZou) Link(ctx context.Context, file model.Obj, args model.LinkArgs)
120120 if err != nil {
121121 return nil , err
122122 }
123- ts , ts_str , _ := getTimestamp (d .conf .secret )
123+ ts , tsStr , err := getTimestamp (d .conf .secret )
124+ if err != nil {
125+ return nil , err
126+ }
124127
125128 params := []string {
126129 "uuid=" + url .QueryEscape (d .UUID ),
@@ -129,9 +132,9 @@ func (d *ILanZou) Link(ctx context.Context, file model.Obj, args model.LinkArgs)
129132 "devModel=chrome" ,
130133 "devVersion=" + url .QueryEscape (d .conf .devVersion ),
131134 "appVersion=" ,
132- "timestamp=" + ts_str ,
135+ "timestamp=" + tsStr ,
133136 "appToken=" + url .QueryEscape (d .Token ),
134- "enable=0 " ,
137+ "enable=1 " ,
135138 }
136139
137140 downloadId , err := mopan .AesEncrypt ([]byte (fmt .Sprintf ("%s|%s" , file .GetID (), d .userID )), d .conf .secret )
@@ -149,10 +152,12 @@ func (d *ILanZou) Link(ctx context.Context, file model.Obj, args model.LinkArgs)
149152 u .RawQuery = strings .Join (params , "&" )
150153 realURL := u .String ()
151154 // get the url after redirect
152- req := base .NoRedirectClient .R ()
153-
155+ req := base .NoRedirectClient .R ().SetContext (ctx )
154156 req .SetHeaders (map [string ]string {
155- "Referer" : d .conf .site + "/" ,
157+ "Origin" : d .conf .site ,
158+ "Referer" : d .conf .site + "/" ,
159+ "Accept-Encoding" : "gzip" ,
160+ "Accept-Language" : "zh-CN,zh;q=0.9,en-US,en;q=0.8" ,
156161 })
157162 if d .Addition .Ip != "" {
158163 req .SetHeader ("X-Forwarded-For" , d .Addition .Ip )
@@ -162,10 +167,13 @@ func (d *ILanZou) Link(ctx context.Context, file model.Obj, args model.LinkArgs)
162167 if err != nil {
163168 return nil , err
164169 }
165- if res .StatusCode () == 302 {
166- realURL = res .Header ().Get ("location" )
170+ location := res .Header ().Get ("location" )
171+ if location != "" && utils .SliceContains ([]int {http .StatusMovedPermanently , http .StatusFound , http .StatusSeeOther , http .StatusTemporaryRedirect , http .StatusPermanentRedirect }, res .StatusCode ()) {
172+ realURL = location
173+ } else if res .StatusCode () == http .StatusOK && location != "" {
174+ realURL = location
167175 } else {
168- return nil , fmt .Errorf ("redirect failed, status: %d, msg: %s" , res .StatusCode (), utils .Json .Get (res .Body (), "msg" ).ToString ())
176+ return nil , fmt .Errorf ("redirect failed, status: %d, location: %s, msg: %s" , res .StatusCode (), location , utils .Json .Get (res .Body (), "msg" ).ToString ())
169177 }
170178 link := model.Link {URL : realURL }
171179 return & link , nil
0 commit comments