From 836a148ee8792d183709192410ef6916bef76195 Mon Sep 17 00:00:00 2001 From: Azareal Date: Tue, 5 Mar 2019 14:46:43 +1000 Subject: [PATCH] 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. --- common/thumbnailer.go | 8 ++++++++ docs/installation.md | 2 ++ public/global.js | 2 ++ routes/account.go | 17 +++++++++++++++++ 4 files changed, 29 insertions(+) diff --git a/common/thumbnailer.go b/common/thumbnailer.go index 876b73bf..c2b9a259 100644 --- a/common/thumbnailer.go +++ b/common/thumbnailer.go @@ -31,6 +31,14 @@ func ThumbTask(thumbChan chan bool) { _, _ = acc.Delete("users_avatar_queue").Where("uid = ?").Run(uid) 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 if user.RawAvatar[0] != '.' { return nil diff --git a/docs/installation.md b/docs/installation.md index 40ac6262..55b9e5e9 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -74,6 +74,8 @@ Type in a strong password for the `gosora` user, please oh please... Don't use " `chmod 2775 logs` +`chmod 2775 uploads` + `chmod 755 ./install-linux` `./install-linux` diff --git a/public/global.js b/public/global.js index d319c212..37562088 100644 --- a/public/global.js +++ b/public/global.js @@ -173,6 +173,7 @@ function runWebSockets() { console.log(err); } + // TODO: Sync alerts, topic list, etc. conn.onopen = () => { console.log("The WebSockets connection was opened"); conn.send("page " + document.location.pathname + '\r'); @@ -185,6 +186,7 @@ function runWebSockets() { conn.onclose = () => { conn = false; console.log("The WebSockets connection was closed"); + setTimeout(() => runWebSockets(), 60 * 1000); } conn.onmessage = (event) => { diff --git a/routes/account.go b/routes/account.go index 25e49536..a7da3215 100644 --- a/routes/account.go +++ b/routes/account.go @@ -506,6 +506,23 @@ func AccountEditAvatarSubmit(w http.ResponseWriter, r *http.Request, user common if err != nil { 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 err = user.ScheduleAvatarResize() if err != nil {