Photo edit/delete fixes, lazy load images
This commit is contained in:
parent
da7e8d5899
commit
483e5a2db3
|
@ -42,11 +42,23 @@ func Edit() http.HandlerFunc {
|
|||
}
|
||||
|
||||
// Do we have permission for this photo?
|
||||
if photo.UserID != currentUser.ID && !currentUser.IsAdmin {
|
||||
if photo.UserID != currentUser.ID {
|
||||
if !currentUser.IsAdmin {
|
||||
templates.ForbiddenPage(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
// Find the owner of this photo and assume currentUser is them for the remainder
|
||||
// of this controller.
|
||||
if user, err := models.GetUser(photo.UserID); err != nil {
|
||||
session.FlashError(w, r, "Couldn't get the owner User for this photo!")
|
||||
templates.Redirect(w, "/")
|
||||
return
|
||||
} else {
|
||||
currentUser = user
|
||||
}
|
||||
}
|
||||
|
||||
// Are we saving the changes?
|
||||
if r.Method == http.MethodPost {
|
||||
var (
|
||||
|
@ -119,15 +131,6 @@ func Edit() http.HandlerFunc {
|
|||
models.RemoveNotification("photos", photo.ID)
|
||||
}
|
||||
|
||||
// Whose photo gallery to redirect to? if admin editing a user's photo,
|
||||
// go back to the owner's gallery instead of our own.
|
||||
if photo.UserID != currentUser.ID {
|
||||
if owner, err := models.GetUser(photo.UserID); err == nil {
|
||||
templates.Redirect(w, "/photo/u/"+owner.Username)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Return the user to their gallery.
|
||||
templates.Redirect(w, "/photo/u/"+currentUser.Username)
|
||||
return
|
||||
|
@ -177,11 +180,23 @@ func Delete() http.HandlerFunc {
|
|||
}
|
||||
|
||||
// Do we have permission for this photo?
|
||||
if photo.UserID != currentUser.ID && !currentUser.IsAdmin {
|
||||
if photo.UserID != currentUser.ID {
|
||||
if !currentUser.IsAdmin {
|
||||
templates.ForbiddenPage(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
// Find the owner of this photo and assume currentUser is them for the remainder
|
||||
// of this controller.
|
||||
if user, err := models.GetUser(photo.UserID); err != nil {
|
||||
session.FlashError(w, r, "Couldn't get the owner User for this photo!")
|
||||
templates.Redirect(w, "/")
|
||||
return
|
||||
} else {
|
||||
currentUser = user
|
||||
}
|
||||
}
|
||||
|
||||
// Confirm deletion?
|
||||
if r.Method == http.MethodPost {
|
||||
confirm := r.PostFormValue("confirm") == "true"
|
||||
|
@ -224,17 +239,9 @@ func Delete() http.HandlerFunc {
|
|||
|
||||
session.Flash(w, r, "Photo deleted!")
|
||||
|
||||
// Whose photo gallery to redirect to? if admin editing a user's photo,
|
||||
// go back to the owner's gallery instead of our own.
|
||||
if photo.UserID != currentUser.ID {
|
||||
if owner, err := models.GetUser(photo.UserID); err == nil {
|
||||
templates.Redirect(w, "/photo/u/"+owner.Username)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Return the user to their gallery.
|
||||
templates.Redirect(w, "/photo/u/"+currentUser.Username)
|
||||
return
|
||||
}
|
||||
|
||||
var vars = map[string]interface{}{
|
||||
|
|
|
@ -520,7 +520,7 @@
|
|||
</div>
|
||||
{{else}}
|
||||
<a href="/photo/view?id={{$Body.Photo.ID}}">
|
||||
<img src="{{PhotoURL $Body.Photo.Filename}}"{{if BlurExplicit $Body.Photo}} class="blurred-explicit"{{end}}>
|
||||
<img src="{{PhotoURL $Body.Photo.Filename}}" loading="lazy"{{if BlurExplicit $Body.Photo}} class="blurred-explicit"{{end}}>
|
||||
</a>
|
||||
{{end}}
|
||||
|
||||
|
|
|
@ -220,7 +220,7 @@
|
|||
</video>
|
||||
{{else}}
|
||||
<div class="mt-4 is-clipped">
|
||||
<img src="{{PhotoURL .Filename}}"{{if and (or $Root.Forum.Explicit $Root.Thread.Explicit) (eq ($Root.CurrentUser.GetProfileField "blur_explicit") "true")}} class="blurred-explicit"{{end}}>
|
||||
<img src="{{PhotoURL .Filename}}" loading="lazy"{{if and (or $Root.Forum.Explicit $Root.Thread.Explicit) (eq ($Root.CurrentUser.GetProfileField "blur_explicit") "true")}} class="blurred-explicit"{{end}}>
|
||||
</div>
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
|
|
@ -463,7 +463,7 @@
|
|||
<source src="{{PhotoURL .Filename}}" type="video/mp4">
|
||||
</video>
|
||||
{{else}}
|
||||
<img src="{{PhotoURL .Filename}}"{{if BlurExplicit .}} class="blurred-explicit"{{end}}>
|
||||
<img src="{{PhotoURL .Filename}}" loading="lazy"{{if BlurExplicit .}} class="blurred-explicit"{{end}}>
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
|
@ -575,7 +575,7 @@
|
|||
<a href="{{PhotoURL .Filename}}" target="_blank"
|
||||
class="js-modal-trigger" data-target="detail-modal"
|
||||
onclick="setModalImage(this.href)">
|
||||
<img src="{{PhotoURL .Filename}}"{{if BlurExplicit .}} class="blurred-explicit"{{end}}>
|
||||
<img src="{{PhotoURL .Filename}}" loading="lazy"{{if BlurExplicit .}} class="blurred-explicit"{{end}}>
|
||||
</a>
|
||||
{{end}}
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue
Block a user