@@ -85,18 +85,31 @@ func (h *Hupload) patchShare(w http.ResponseWriter, r *http.Request) {
85
85
// We ignore unmarshalling of JSON body as it is optional.
86
86
_ = json .NewDecoder (r .Body ).Decode (& options )
87
87
88
- result , err := h .Config .Storage .UpdateShare (r .Context (), r .PathValue ("share" ), options )
88
+ share , err := h .Config .Storage .GetShare (r .Context (), r .PathValue ("share" ))
89
89
if err != nil {
90
90
slog .Error ("patchShare" , slog .String ("error" , err .Error ()))
91
91
switch {
92
92
case errors .Is (err , storage .ErrInvalidShareName ):
93
93
writeError (w , http .StatusBadRequest , "invalid share name" )
94
94
return
95
95
case errors .Is (err , storage .ErrShareNotFound ):
96
- writeError (w , http .StatusNotFound , "share does not exists" )
96
+ writeError (w , http .StatusNotFound , "share not found" )
97
+ return
98
+ }
99
+ writeError (w , http .StatusInternalServerError , err .Error ())
100
+ return
101
+ }
102
+
103
+ if h .Config .Values .HideOtherShares {
104
+ if share .Owner != user {
105
+ writeError (w , http .StatusForbidden , "unauthorized" )
97
106
return
98
107
}
108
+ }
99
109
110
+ result , err := h .Config .Storage .UpdateShare (r .Context (), share .Name , options )
111
+ if err != nil {
112
+ slog .Error ("patchShare" , slog .String ("error" , err .Error ()))
100
113
writeError (w , http .StatusInternalServerError , err .Error ())
101
114
return
102
115
}
@@ -222,6 +235,16 @@ func (h *Hupload) getShares(w http.ResponseWriter, r *http.Request) {
222
235
}
223
236
user , _ := auth .AuthForRequest (r )
224
237
238
+ if h .Config .Values .HideOtherShares {
239
+ tmpShares := []storage.Share {}
240
+ for s := range shares {
241
+ if shares [s ].Owner == user {
242
+ tmpShares = append (tmpShares , shares [s ])
243
+ }
244
+ }
245
+ shares = tmpShares
246
+ }
247
+
225
248
if user == "" {
226
249
writeSuccessJSON (w , storage .PublicShares (shares ))
227
250
} else {
0 commit comments