Photo edit/delete fixes, lazy load images

face-detect
Noah Petherbridge 2023-12-21 14:37:16 -08:00
parent da7e8d5899
commit 483e5a2db3
4 changed files with 35 additions and 28 deletions

View File

@ -42,9 +42,21 @@ 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 {
templates.ForbiddenPage(w, r) if !currentUser.IsAdmin {
return 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? // Are we saving the changes?
@ -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,9 +180,21 @@ 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 {
templates.ForbiddenPage(w, r) if !currentUser.IsAdmin {
return 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? // Confirm deletion?
@ -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{}{

View File

@ -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}}

View File

@ -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}}

View File

@ -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>