@@ -143,14 +143,6 @@ func getIconHandler(c echo.Context) error {
143143 return echo .NewHTTPError (http .StatusInternalServerError , "failed to get user icon: " + err .Error ())
144144 }
145145
146- // if err := tx.GetContext(ctx, &image, "SELECT image FROM icons WHERE user_id = ?", user.ID); err != nil {
147- // if errors.Is(err, sql.ErrNoRows) {
148- // return c.File(fallbackImage)
149- // } else {
150- // return echo.NewHTTPError(http.StatusInternalServerError, "failed to get user icon: "+err.Error())
151- // }
152- // }
153-
154146 return c .Blob (http .StatusOK , "image/jpeg" , image )
155147
156148 // c.Response().Header().Set("x-accel-redirect", fmt.Sprintf("/img/%s", filepath.Base(files[0])))
@@ -177,16 +169,6 @@ func postIconHandler(c echo.Context) error {
177169
178170 iconHash := sha256 .Sum256 (req .Image )
179171
180- // files, err := filepath.Glob(fmt.Sprintf("../img/user-%d-*.jpg", userID))
181- // if err != nil {
182- // return echo.NewHTTPError(http.StatusInternalServerError, "failed to glob: "+err.Error())
183- // }
184- // for _, f := range files {
185- // if err := os.Remove(f); err != nil {
186- // return echo.NewHTTPError(http.StatusInternalServerError, "failed to remove file: "+err.Error())
187- // }
188- // }
189-
190172 os .WriteFile (fmt .Sprintf ("../img/user-%d.jpg" , userID ), req .Image , 0644 )
191173
192174 tx , err := dbConn .BeginTxx (ctx , nil )
@@ -195,25 +177,11 @@ func postIconHandler(c echo.Context) error {
195177 }
196178 defer tx .Rollback ()
197179
198- // if _, err := tx.ExecContext(ctx, "DELETE FROM icons WHERE user_id = ?", userID); err != nil {
199- // return echo.NewHTTPError(http.StatusInternalServerError, "failed to delete old user icon: "+err.Error())
200- // }
201-
202- // _, err = tx.ExecContext(ctx, "INSERT INTO icons (user_id, image) VALUES (?, ?)", userID, req.Image)
203- // if err != nil {
204- // return echo.NewHTTPError(http.StatusInternalServerError, "failed to insert new user icon: "+err.Error())
205- // }
206-
207180 _ , err = tx .ExecContext (ctx , "UPDATE users SET icon_hash = ? WHERE id = ?" , fmt .Sprintf ("%x" , iconHash ), userID )
208181 if err != nil {
209182 return echo .NewHTTPError (http .StatusInternalServerError , "failed to insert new user icon: " + err .Error ())
210183 }
211184
212- // // iconID, err := rs.LastInsertId()
213- // // if err != nil {
214- // // return echo.NewHTTPError(http.StatusInternalServerError, "failed to get last inserted icon id: "+err.Error())
215- // // }
216-
217185 if err := tx .Commit (); err != nil {
218186 return echo .NewHTTPError (http .StatusInternalServerError , "failed to commit: " + err .Error ())
219187 }
0 commit comments