umputun / remark42

comment engine
https://remark42.com
MIT License
4.81k stars 374 forks source link

Image are not deleted once admin deletes a comment with it #1698

Closed Ivan-Chupin closed 7 months ago

Ivan-Chupin commented 9 months ago

I discovered that deleting a comment does not delete the image file attached to the comment on the server. I have quite a bit of space on the server to store dead information. It would be logical to delete the image file along with the comment.

umputun commented 9 months ago

Can you provide more details? I just tested it by adding a comment with the image and removed the comment after this. The image was removed as well. Pls, note - this image removal works asynchronously and may take some time. This is the log:

2023/11/09 12:16:14.978 [DEBUG] {image/image.go:306 image.resize} resizing image is smaller that the limit or has 0 size
2023/11/09 12:16:14.980 [DEBUG] {image/fs_store.go:47 image.(*FileSystem).Save} file var/pictures.staging/github_ef0f706a79cc24b17bbbb374cd234a691d034128/62/cl6i3rkpjegi5ordohj0 saved for image github_ef0f706a79cc24b17bbbb374cd234a691d034128/cl6i3rkpjegi5ordohj0, size=178638
2023/11/09 12:16:14.982 [DEBUG] {logger/logger.go:134 logger.(*Middleware).Handler.func1.1} POST - /api/v1/picture?site=remark - 172.28.0.21 - b02b9c00b7dc - 200 (78) - 160.1077ms
2023/11/09 12:16:24.832 [DEBUG] {image/image.go:110 image.(*Service).Submit.func1} image submitter activated
2023/11/09 12:16:24.833 [DEBUG] {service/service.go:275 service.(*DataStore).submitImages.func1} image ids extracted from 87bc1fad-82d9-4e7e-bb6c-30ff50039cc4 - [github_ef0f706a79cc24b17bbbb374cd234a691d034128/cl6i3rkpjegi5ordohj0]
2023/11/09 12:16:24.835 [DEBUG] {api/rest_private.go:176 api.(*private).createCommentCtrl} created comment {ID:87bc1fad-82d9-4e7e-bb6c-30ff50039cc4 ParentID: Text:<p><img src="https://demo.remark42.com/api/v1/picture/github_ef0f706a79cc24b17bbbb374cd234a691d034128/cl6i3rkpjegi5ordohj0" alt="231109115144.png" loading="lazy"/></p>

<p>test with image</p>
 Orig:![231109115144.png](https://demo.remark42.com/api/v1/picture/github_ef0f706a79cc24b17bbbb374cd234a691d034128/cl6i3rkpjegi5ordohj0)

test with image User:{Name:Umputun ID:github_ef0f706a79cc24b17bbbb374cd234a691d034128 Picture:https://demo.remark42.com/api/v1/avatar/cb42ff493ade696d88a3a590f136ae9e34de7c1b.image IP:b02b9c00b7dc8c936f3acd4c6764317fecf25960 Admin:true Blocked:false Verified:false EmailSubscription:false SiteID:remark PaidSub:false} Locator:{SiteID:remark URL:https://remark42.com/demo/} Score:0 Votes:map[] VotedIPs:map[] Vote:0 Controversy:0 Timestamp:2023-11-09 12:16:24.822874594 -0600 CST Edit:<nil> Pin:false Deleted:false Imported:false PostTitle:Demo | Remark42}
2023/11/09 12:16:24.836 [INFO]  {logger/logger.go:134 logger.(*Middleware).Handler.func1.1} POST - /api/v1/comment?site=remark - 172.28.0.21 - b02b9c00b7dc - 201 (888) - 15.071676ms - {"title":"Demo | Remark42","text":"![231109115144.png](https://demo.remark42.com/api/v1/picture/github_ef0f706a79cc24b17bbbb374cd234a691d034128/cl6i3rkpjegi5ordohj0)\n\ntest with image","locator":{"site":"remark","url":"https://remark42.com/demo/"},"site":"remark"}
2023/11/09 12:16:24.836 [DEBUG] {notify/telegram.go:47 notify.(*Telegram).Send} send telegram notification for comment ID 87bc1fad-82d9-4e7e-bb6c-30ff50039cc4
2023/11/09 12:16:24.931 [INFO]  {logger/logger.go:134 logger.(*Middleware).Handler.func1.1} GET - /api/v1/picture/github_ef0f706a79cc24b17bbbb374cd234a691d034128/cl6i3rkpjegi5ordohj0 - 172.28.0.21 - b02b9c00b7dc - 200 (178638) - 5.21814ms

2023/11/09 12:16:52.183 [INFO]  {api/admin.go:49 api.(*admin).deleteCommentCtrl} delete comment 87bc1fad-82d9-4e7e-bb6c-30ff50039cc4
2023/11/09 12:16:52.191 [INFO]  {logger/logger.go:134 logger.(*Middleware).Handler.func1.1} DELETE - /api/v1/admin/comment/87bc1fad-82d9-4e7e-bb6c-30ff50039cc4?site=remark&url=https://remark42.com/demo/ - 172.28.0.21 - b02b9c00b7dc - 200 (109) - 7.568839ms
2023/11/09 12:19:37.307 [INFO]  {image/fs_store.go:126 image.(*FileSystem).Cleanup.func1} remove staging image var/pictures.staging/github_ef0f706a79cc24b17bbbb374cd234a691d034128/66/cl6i084pjegnjia9459g, age 10m50.678055991s

As you can see, the relevant image was detected on staging and removed in 30 seconds. To me, it looks fine.

cc: @paskal

Ivan-Chupin commented 9 months ago

I have the same as you

2023/11/10 13:38:30.373 [INFO]  {api/admin.go:49 api.(*admin).deleteCommentCtrl} delete comment b48d0739-b2f6-4961-acda-0ae497cef3fc
2023/11/10 13:38:30.375 [INFO]  {logger/logger.go:134 logger.(*Middleware).Handler.func1.1} DELETE - /api/v1/admin/comment/b48d0739-b2f6-4961-acda-0ae497cef3fc?site=smarthdd.com&url=https://smarthdd.com/rus/ide.htm - smarthdd.com - ed27be1c52ef - 200 (121) - 3.881738ms

But the last line is missing like yours

2023/11/09 12:19:37.307 [INFO]  {image/fs_store.go:126 image.(*FileSystem).Cleanup.func1} remove staging image var/pictures.staging/github_ef0f706a79cc24b17bbbb374cd234a691d034128/66/cl6i084pjegnjia9459g, age 10m50.678055991s
Ivan-Chupin commented 9 months ago

Remark42 version is 1.12.1. Installed following the example - https://blog.lasall.dev/post/hugo-and-comments-with-remark42/

Ivan-Chupin commented 9 months ago

Rights and owner of the image file: ls -l

-rw------- 1 remark42 remark42 7096 Nov 10 13:32 cl6ulctm3e6s0kfq5j2g

paskal commented 9 months ago

@umputun, the staging image is deleted if it was not committed, e.g. if a comment was not submitted or removed before the commit happened. We currently have no cleanup mechanism for images except for the mechanism outlined in the previous sentence.

umputun commented 9 months ago

confused - why do we even need to support this? the window of edit/delete is limited and as long as the image stays in staging during this window, we should be fine unless I missed the point.

paskal commented 9 months ago

Seems like we need to start deleting images once they are deleted by the admin outside of the edit window.