Merge pull request #615 from Akatsuki-Ousawa/dev
Adding more options for upload disabling
Cette révision appartient à :
révision
a0d5570cdf
3 fichiers modifiés avec 49 ajouts et 13 suppressions
|
@ -9,4 +9,6 @@ const (
|
|||
// TODO: deprecate this and move all files to the same server
|
||||
TorrentCacheLink = "http://anicache.com/torrent/%s.torrent"
|
||||
UploadsDisabled = false
|
||||
AdminsAreStillAllowedTo = true
|
||||
TrustedUsersAreStillAllowedTo = true
|
||||
)
|
||||
|
|
|
@ -96,14 +96,25 @@ func ApiViewHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func ApiUploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if config.UploadsDisabled {
|
||||
http.Error(w, "Error uploads are disabled", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
token := r.Header.Get("Authorization")
|
||||
user := model.User{}
|
||||
db.ORM.Where("api_token = ?", token).First(&user) //i don't like this
|
||||
|
||||
if config.UploadsDisabled {
|
||||
|
||||
if config.AdminsAreStillAllowedTo && user.Status != 2 && config.TrustedUsersAreStillAllowedTo && user.Status != 1 {
|
||||
http.Error(w, "Error uploads are disabled", http.StatusBadRequest)
|
||||
return
|
||||
} else if !config.AdminsAreStillAllowedTo && user.Status == 2 {
|
||||
http.Error(w, "Error uploads are disabled", http.StatusBadRequest)
|
||||
return
|
||||
} else if !config.TrustedUsersAreStillAllowedTo && user.Status == 1 {
|
||||
http.Error(w, "Error uploads are disabled", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if user.ID == 0 {
|
||||
http.Error(w, apiService.ErrApiKey.Error(), http.StatusUnauthorized)
|
||||
return
|
||||
|
@ -173,16 +184,27 @@ func ApiUploadHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func ApiUpdateHandler(w http.ResponseWriter, r *http.Request) {
|
||||
token := r.Header.Get("Authorization")
|
||||
user := model.User{}
|
||||
db.ORM.Where("api_token = ?", token).First(&user) //i don't like this
|
||||
|
||||
if config.UploadsDisabled {
|
||||
http.Error(w, "Error uploads are disabled", http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
if config.AdminsAreStillAllowedTo && user.Status != 2 && config.TrustedUsersAreStillAllowedTo && user.Status != 1 {
|
||||
http.Error(w, "Error uploads are disabled", http.StatusInternalServerError)
|
||||
return
|
||||
} else if !config.AdminsAreStillAllowedTo && user.Status == 2 {
|
||||
http.Error(w, "Error uploads are disabled", http.StatusInternalServerError)
|
||||
return
|
||||
} else if !config.TrustedUsersAreStillAllowedTo && user.Status == 1 {
|
||||
http.Error(w, "Error uploads are disabled", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
contentType := r.Header.Get("Content-Type")
|
||||
if contentType == "application/json" {
|
||||
token := r.Header.Get("Authorization")
|
||||
user := model.User{}
|
||||
db.ORM.Where("api_token = ?", token).First(&user) //i don't like this
|
||||
if user.ID == 0 {
|
||||
http.Error(w, apiService.ErrApiKey.Error(), http.StatusForbidden)
|
||||
return
|
||||
|
|
|
@ -16,14 +16,26 @@ import (
|
|||
)
|
||||
|
||||
func UploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||
user := GetUser(r)
|
||||
|
||||
if config.UploadsDisabled {
|
||||
http.Error(w, "Error uploads are disabled", http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
if config.AdminsAreStillAllowedTo && user.Status != 2 && config.TrustedUsersAreStillAllowedTo && user.Status != 1 {
|
||||
http.Error(w, "Error uploads are disabled", http.StatusInternalServerError)
|
||||
return
|
||||
} else if !config.AdminsAreStillAllowedTo && user.Status == 2 {
|
||||
http.Error(w, "Error uploads are disabled", http.StatusInternalServerError)
|
||||
return
|
||||
} else if !config.TrustedUsersAreStillAllowedTo && user.Status == 1 {
|
||||
http.Error(w, "Error uploads are disabled", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var uploadForm UploadForm
|
||||
if r.Method == "POST" {
|
||||
defer r.Body.Close()
|
||||
user := GetUser(r)
|
||||
if userPermission.NeedsCaptcha(user) {
|
||||
userCaptcha := captcha.Extract(r)
|
||||
if !captcha.Authenticate(userCaptcha) {
|
||||
|
|
Référencer dans un nouveau ticket