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?
|
// 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)
|
templates.ForbiddenPage(w, r)
|
||||||
return
|
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?
|
// Are we saving the changes?
|
||||||
if r.Method == http.MethodPost {
|
if r.Method == http.MethodPost {
|
||||||
var (
|
var (
|
||||||
|
@ -119,15 +131,6 @@ func Edit() http.HandlerFunc {
|
||||||
models.RemoveNotification("photos", photo.ID)
|
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.
|
// Return the user to their gallery.
|
||||||
templates.Redirect(w, "/photo/u/"+currentUser.Username)
|
templates.Redirect(w, "/photo/u/"+currentUser.Username)
|
||||||
return
|
return
|
||||||
|
@ -177,11 +180,23 @@ func Delete() http.HandlerFunc {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do we have permission for this photo?
|
// 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)
|
templates.ForbiddenPage(w, r)
|
||||||
return
|
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?
|
// Confirm deletion?
|
||||||
if r.Method == http.MethodPost {
|
if r.Method == http.MethodPost {
|
||||||
confirm := r.PostFormValue("confirm") == "true"
|
confirm := r.PostFormValue("confirm") == "true"
|
||||||
|
@ -224,17 +239,9 @@ func Delete() http.HandlerFunc {
|
||||||
|
|
||||||
session.Flash(w, r, "Photo deleted!")
|
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.
|
// Return the user to their gallery.
|
||||||
templates.Redirect(w, "/photo/u/"+currentUser.Username)
|
templates.Redirect(w, "/photo/u/"+currentUser.Username)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var vars = map[string]interface{}{
|
var vars = map[string]interface{}{
|
||||||
|
|
|
@ -520,7 +520,7 @@
|
||||||
</div>
|
</div>
|
||||||
{{else}}
|
{{else}}
|
||||||
<a href="/photo/view?id={{$Body.Photo.ID}}">
|
<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>
|
</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
|
|
|
@ -220,7 +220,7 @@
|
||||||
</video>
|
</video>
|
||||||
{{else}}
|
{{else}}
|
||||||
<div class="mt-4 is-clipped">
|
<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>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
|
@ -463,7 +463,7 @@
|
||||||
<source src="{{PhotoURL .Filename}}" type="video/mp4">
|
<source src="{{PhotoURL .Filename}}" type="video/mp4">
|
||||||
</video>
|
</video>
|
||||||
{{else}}
|
{{else}}
|
||||||
<img src="{{PhotoURL .Filename}}"{{if BlurExplicit .}} class="blurred-explicit"{{end}}>
|
<img src="{{PhotoURL .Filename}}" loading="lazy"{{if BlurExplicit .}} class="blurred-explicit"{{end}}>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -575,7 +575,7 @@
|
||||||
<a href="{{PhotoURL .Filename}}" target="_blank"
|
<a href="{{PhotoURL .Filename}}" target="_blank"
|
||||||
class="js-modal-trigger" data-target="detail-modal"
|
class="js-modal-trigger" data-target="detail-modal"
|
||||||
onclick="setModalImage(this.href)">
|
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>
|
</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user