@@ -206,16 +206,16 @@ func SharingDown(c *gin.Context) {
206206 err = errors .New ("cannot get sharing root link" )
207207 }
208208 }
209- if dealError (c , err ) {
209+ if dealErrorPage (c , err ) {
210210 return
211211 }
212212 unwrapPath , err := op .GetSharingUnwrapPath (s , path )
213213 if err != nil {
214- common .ErrorStrResp (c , "failed get sharing unwrap path" , 500 )
214+ common .ErrorPage (c , errors . New ( "failed get sharing unwrap path" ) , 500 )
215215 return
216216 }
217217 storage , actualPath , err := op .GetStorageAndActualPath (unwrapPath )
218- if dealError (c , err ) {
218+ if dealErrorPage (c , err ) {
219219 return
220220 }
221221 if setting .GetBool (conf .ShareForceProxy ) || common .ShouldProxy (storage , stdpath .Base (actualPath )) {
@@ -224,7 +224,7 @@ func SharingDown(c *gin.Context) {
224224 Type : c .Query ("type" ),
225225 })
226226 if err != nil {
227- common .ErrorResp (c , errors .WithMessage (err , "failed get sharing link" ), 500 )
227+ common .ErrorPage (c , errors .WithMessage (err , "failed get sharing link" ), 500 )
228228 return
229229 }
230230 _ = countAccess (c .ClientIP (), s )
@@ -237,7 +237,7 @@ func SharingDown(c *gin.Context) {
237237 Redirect : true ,
238238 })
239239 if err != nil {
240- common .ErrorResp (c , errors .WithMessage (err , "failed get sharing link" ), 500 )
240+ common .ErrorPage (c , errors .WithMessage (err , "failed get sharing link" ), 500 )
241241 return
242242 }
243243 _ = countAccess (c .ClientIP (), s )
@@ -247,7 +247,7 @@ func SharingDown(c *gin.Context) {
247247
248248func SharingArchiveExtract (c * gin.Context ) {
249249 if ! setting .GetBool (conf .ShareArchivePreview ) {
250- common .ErrorStrResp (c , "sharing archives previewing is not allowed" , 403 )
250+ common .ErrorPage (c , errors . New ( "sharing archives previewing is not allowed" ) , 403 )
251251 return
252252 }
253253 sid := c .Request .Context ().Value (conf .SharingIDKey ).(string )
@@ -265,16 +265,16 @@ func SharingArchiveExtract(c *gin.Context) {
265265 err = errors .New ("cannot extract sharing root" )
266266 }
267267 }
268- if dealError (c , err ) {
268+ if dealErrorPage (c , err ) {
269269 return
270270 }
271271 unwrapPath , err := op .GetSharingUnwrapPath (s , path )
272272 if err != nil {
273- common .ErrorStrResp (c , "failed get sharing unwrap path" , 500 )
273+ common .ErrorPage (c , errors . New ( "failed get sharing unwrap path" ) , 500 )
274274 return
275275 }
276276 storage , actualPath , err := op .GetStorageAndActualPath (unwrapPath )
277- if dealError (c , err ) {
277+ if dealErrorPage (c , err ) {
278278 return
279279 }
280280 args := model.ArchiveInnerArgs {
@@ -290,21 +290,21 @@ func SharingArchiveExtract(c *gin.Context) {
290290 if _ , ok := storage .(driver.ArchiveReader ); ok {
291291 if setting .GetBool (conf .ShareForceProxy ) || common .ShouldProxy (storage , stdpath .Base (actualPath )) {
292292 link , obj , err := op .DriverExtract (c .Request .Context (), storage , actualPath , args )
293- if dealError (c , err ) {
293+ if dealErrorPage (c , err ) {
294294 return
295295 }
296296 proxy (c , link , obj , storage .GetStorage ().ProxyRange )
297297 } else {
298298 args .Redirect = true
299299 link , _ , err := op .DriverExtract (c .Request .Context (), storage , actualPath , args )
300- if dealError (c , err ) {
300+ if dealErrorPage (c , err ) {
301301 return
302302 }
303303 redirect (c , link )
304304 }
305305 } else {
306306 rc , size , err := op .InternalExtract (c .Request .Context (), storage , actualPath , args )
307- if dealError (c , err ) {
307+ if dealErrorPage (c , err ) {
308308 return
309309 }
310310 fileName := stdpath .Base (innerPath )
@@ -329,6 +329,23 @@ func dealError(c *gin.Context, err error) bool {
329329 return true
330330}
331331
332+ func dealErrorPage (c * gin.Context , err error ) bool {
333+ if err == nil {
334+ return false
335+ } else if errors .Is (err , errs .SharingNotFound ) {
336+ common .ErrorPage (c , errors .New ("the share does not exist" ), 500 )
337+ } else if errors .Is (err , errs .InvalidSharing ) {
338+ common .ErrorPage (c , errors .New ("the share has expired or is no longer valid" ), 500 )
339+ } else if errors .Is (err , errs .WrongShareCode ) {
340+ common .ErrorPage (c , err , 403 )
341+ } else if errors .Is (err , errs .WrongArchivePassword ) {
342+ common .ErrorPage (c , err , 202 )
343+ } else {
344+ common .ErrorPage (c , err , 500 )
345+ }
346+ return true
347+ }
348+
332349type SharingResp struct {
333350 * model.Sharing
334351 CreatorName string `json:"creator"`
0 commit comments