@@ -143,14 +143,6 @@ func getIconHandler(c echo.Context) error {
143
143
return echo .NewHTTPError (http .StatusInternalServerError , "failed to get user icon: " + err .Error ())
144
144
}
145
145
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
-
154
146
return c .Blob (http .StatusOK , "image/jpeg" , image )
155
147
156
148
// 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 {
177
169
178
170
iconHash := sha256 .Sum256 (req .Image )
179
171
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
-
190
172
os .WriteFile (fmt .Sprintf ("../img/user-%d.jpg" , userID ), req .Image , 0644 )
191
173
192
174
tx , err := dbConn .BeginTxx (ctx , nil )
@@ -195,25 +177,11 @@ func postIconHandler(c echo.Context) error {
195
177
}
196
178
defer tx .Rollback ()
197
179
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
-
207
180
_ , err = tx .ExecContext (ctx , "UPDATE users SET icon_hash = ? WHERE id = ?" , fmt .Sprintf ("%x" , iconHash ), userID )
208
181
if err != nil {
209
182
return echo .NewHTTPError (http .StatusInternalServerError , "failed to insert new user icon: " + err .Error ())
210
183
}
211
184
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
-
217
185
if err := tx .Commit (); err != nil {
218
186
return echo .NewHTTPError (http .StatusInternalServerError , "failed to commit: " + err .Error ())
219
187
}
0 commit comments