-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Part of #45 - the only thing missing is a way to quarantine all media in a room
- Loading branch information
Showing
15 changed files
with
286 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE media DROP COLUMN quarantined; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE media ADD COLUMN quarantined BOOL NOT NULL DEFAULT FALSE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/github.com/turt2live/matrix-media-repo/client/r0/quarantine.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package r0 | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/gorilla/mux" | ||
"github.com/sirupsen/logrus" | ||
"github.com/turt2live/matrix-media-repo/client" | ||
"github.com/turt2live/matrix-media-repo/matrix" | ||
"github.com/turt2live/matrix-media-repo/services/media_service" | ||
"github.com/turt2live/matrix-media-repo/util" | ||
) | ||
|
||
type MediaQuarantinedResponse struct { | ||
IsQuarantined bool `json:"is_quarantined"` | ||
} | ||
|
||
func QuarantineMedia(w http.ResponseWriter, r *http.Request, log *logrus.Entry) interface{} { | ||
accessToken := util.GetAccessTokenFromRequest(r) | ||
userId, err := matrix.GetUserIdFromToken(r.Context(), r.Host, accessToken) | ||
if err != nil || userId == "" { | ||
if err != nil { | ||
log.Error("Error verifying token: " + err.Error()) | ||
} | ||
return client.AuthFailed() | ||
} | ||
isAdmin := util.IsGlobalAdmin(userId) | ||
if !isAdmin { | ||
log.Warn("User " + userId + " is not a repository administrator") | ||
return client.AuthFailed() | ||
} | ||
|
||
params := mux.Vars(r) | ||
|
||
server := params["server"] | ||
mediaId := params["mediaId"] | ||
|
||
log = log.WithFields(logrus.Fields{ | ||
"server": server, | ||
"mediaId": mediaId, | ||
"userId": userId, | ||
}) | ||
|
||
// We don't bother clearing the cache because it's still probably useful there | ||
mediaSvc := media_service.New(r.Context(), log) | ||
media, err := mediaSvc.GetMediaDirect(server, mediaId) | ||
if err != nil { | ||
log.Error("Error fetching media: " + err.Error()) | ||
return client.BadRequest("media not found or other error encountered - see logs") | ||
} | ||
|
||
err = mediaSvc.SetMediaQuarantined(media, true) | ||
if err != nil { | ||
log.Error("Error quarantining media: " + err.Error()) | ||
return client.InternalServerError("Error quarantining media") | ||
} | ||
|
||
return &MediaQuarantinedResponse{ | ||
IsQuarantined: true, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.