Delete old avatar files to avoid dead files from building up in /uploads/ and potentially causing issues.

Make the thumbnailer more resiliant when the avatar it's supposed to be thumbnailing doesn't exist.
/uploads/ should be set to 2755 to reduce the probability of permission issues.

WebSockets now re-connects after a while after the connection drops. This is slightly experimental.
This commit is contained in:
Azareal 2019-03-05 14:46:43 +10:00
parent a28b6c2690
commit 836a148ee8
4 changed files with 29 additions and 0 deletions

View File

@ -31,6 +31,14 @@ func ThumbTask(thumbChan chan bool) {
_, _ = acc.Delete("users_avatar_queue").Where("uid = ?").Run(uid) _, _ = acc.Delete("users_avatar_queue").Where("uid = ?").Run(uid)
return nil return nil
} }
_, err = os.Stat("./uploads/avatar_" + strconv.Itoa(user.ID) + user.RawAvatar)
if os.IsNotExist(err) {
_, _ = acc.Delete("users_avatar_queue").Where("uid = ?").Run(uid)
return nil
} else if err != nil {
return errors.WithStack(err)
}
// This means it's an external image, they aren't currently implemented, but this is here for when they are // This means it's an external image, they aren't currently implemented, but this is here for when they are
if user.RawAvatar[0] != '.' { if user.RawAvatar[0] != '.' {
return nil return nil

View File

@ -74,6 +74,8 @@ Type in a strong password for the `gosora` user, please oh please... Don't use "
`chmod 2775 logs` `chmod 2775 logs`
`chmod 2775 uploads`
`chmod 755 ./install-linux` `chmod 755 ./install-linux`
`./install-linux` `./install-linux`

View File

@ -173,6 +173,7 @@ function runWebSockets() {
console.log(err); console.log(err);
} }
// TODO: Sync alerts, topic list, etc.
conn.onopen = () => { conn.onopen = () => {
console.log("The WebSockets connection was opened"); console.log("The WebSockets connection was opened");
conn.send("page " + document.location.pathname + '\r'); conn.send("page " + document.location.pathname + '\r');
@ -185,6 +186,7 @@ function runWebSockets() {
conn.onclose = () => { conn.onclose = () => {
conn = false; conn = false;
console.log("The WebSockets connection was closed"); console.log("The WebSockets connection was closed");
setTimeout(() => runWebSockets(), 60 * 1000);
} }
conn.onmessage = (event) => { conn.onmessage = (event) => {

View File

@ -506,6 +506,23 @@ func AccountEditAvatarSubmit(w http.ResponseWriter, r *http.Request, user common
if err != nil { if err != nil {
return common.InternalError(err, w, r) return common.InternalError(err, w, r)
} }
// Clean up the old avatar data, so we don't end up with too many dead files in /uploads/
if len(user.RawAvatar) > 2 {
if user.RawAvatar[0] == '.' && user.RawAvatar[1] == '.' {
err := os.Remove("./uploads/avatar_" + strconv.Itoa(user.ID) + "_tmp" + user.RawAvatar[1:])
if err != nil && !os.IsNotExist(err) {
common.LogWarning(err)
return common.LocalError("Something went wrong", w, r, user)
}
err = os.Remove("./uploads/avatar_" + strconv.Itoa(user.ID) + "_w48" + user.RawAvatar[1:])
if err != nil && !os.IsNotExist(err) {
common.LogWarning(err)
return common.LocalError("Something went wrong", w, r, user)
}
}
}
// TODO: Only schedule a resize if the avatar isn't tiny // TODO: Only schedule a resize if the avatar isn't tiny
err = user.ScheduleAvatarResize() err = user.ScheduleAvatarResize()
if err != nil { if err != nil {