[PR #5046] [MERGED] feat(storage): clean up abandoned avatar files #6602

Closed
opened 2026-10-23 04:11:58 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5046
Author: @SpicyMarinara
Created: 8/15/2026
Status: ✅ Merged
Merged: 8/15/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/5039-avatar-storage-cleanup


📝 Commits (4)

  • 1dc26b4 feat(storage): clean up abandoned avatar files
  • 6d082a7 fix: rate limit avatar storage maintenance
  • 4a9f491 Merge remote-tracking branch 'origin/staging' into fix/5039-avatar-storage-cleanup
  • 1805952 Merge remote-tracking branch 'origin/staging' into fix/5039-avatar-storage-cleanup

📊 Changes

8 files changed (+362 additions, -9 deletions)

View changed files

📝 CHANGELOG.md (+4 -0)
📝 packages/client/src/components/panels/SettingsPanel.tsx (+130 -0)
📝 packages/client/src/localization/locales/en.json (+16 -0)
📝 packages/server/src/middleware/rate-limit.ts (+28 -1)
📝 packages/server/src/routes/admin.routes.ts (+26 -4)
📝 packages/server/src/services/image/avatar-file-lifecycle.ts (+109 -2)
📝 scripts/regressions/avatar-file-deletion.regression.ts (+31 -1)
📝 scripts/regressions/request-host-security.regression.ts (+18 -1)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #5039

Why this change

  • Avatar deletion is fixed for current operations, but older Engine versions could leave hundreds of unreferenced images behind. Users need a safe in-app cleanup path instead of manually guessing which files can be removed.

What changed

  • Add a privileged scan endpoint that compares direct avatar image files against current characters, personas, groups, and saved card versions.
  • Add a separately confirmed cleanup endpoint that re-scans under the avatar lifecycle lock before deleting anything.
  • Ignore nested NPC avatar folders, non-image files, referenced files, and files newer than ten minutes.
  • Add a localized Advanced Settings Storage Optimization section with scan results, reclaimed size, and explicit deletion confirmation.
  • Extend avatar lifecycle regression coverage and add an Unreleased changelog entry.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • pnpm check passed.
  • pnpm regression:avatar-delete passed after building the shared package.
  • pnpm localization:check passed.
  • Browser click-through remains pending while this PR is in draft.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] <paths> follow-up issue opened
  • Version/release files updated (only if this PR includes a version bump)

Risk proof

  • Core claim: cleanup deletes only old direct avatar images with no live or historical database reference.
  • Risk type: destructive filesystem and user-data maintenance.
  • Entrypoints touched: Advanced Settings, /api/admin/avatar-storage/abandoned, /api/admin/avatar-storage/cleanup, avatar lifecycle service.
  • Positive row: an old unreferenced direct PNG is reported and deleted with its byte count.
  • Negative rows: referenced Professor Mari avatar, recent unreferenced image, non-image file, nested NPC avatar, unsafe external paths, and missing files are preserved/tolerated.
  • Concurrency: scan and cleanup use the existing avatar lifecycle lock; cleanup re-scans after confirmation, and a ten-minute age gate protects uploads not yet attached to a database row.
  • Manual blocker: no real user storage directory was mutated during validation; regression proof used isolated temporary directories.

Summary by CodeRabbit

  • New Features

    • Added Advanced Settings controls to scan for abandoned avatar images and view their storage usage.
    • Added an explicit confirmation step before permanently deleting unreferenced avatar files.
    • Added success and error feedback for storage cleanup actions.
  • Bug Fixes

    • Added safeguards to preserve referenced, recent, non-image, and nested files.
    • Added rate limiting for avatar-storage management actions.
  • Documentation

    • Added an Unreleased changelog entry for the storage optimization feature.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/5046 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 8/15/2026 **Status:** ✅ Merged **Merged:** 8/15/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/5039-avatar-storage-cleanup` --- ### 📝 Commits (4) - [`1dc26b4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1dc26b4e108f0fc589c81a98ed9b9e21be13dd14) feat(storage): clean up abandoned avatar files - [`6d082a7`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6d082a714f78d93fb38d5e768bacb3c077e347a3) fix: rate limit avatar storage maintenance - [`4a9f491`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4a9f491b624f570a58b1c17a16ea19b672ce0475) Merge remote-tracking branch 'origin/staging' into fix/5039-avatar-storage-cleanup - [`1805952`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1805952342e9975ee2c80423392b944157e1a725) Merge remote-tracking branch 'origin/staging' into fix/5039-avatar-storage-cleanup ### 📊 Changes **8 files changed** (+362 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+4 -0) 📝 `packages/client/src/components/panels/SettingsPanel.tsx` (+130 -0) 📝 `packages/client/src/localization/locales/en.json` (+16 -0) 📝 `packages/server/src/middleware/rate-limit.ts` (+28 -1) 📝 `packages/server/src/routes/admin.routes.ts` (+26 -4) 📝 `packages/server/src/services/image/avatar-file-lifecycle.ts` (+109 -2) 📝 `scripts/regressions/avatar-file-deletion.regression.ts` (+31 -1) 📝 `scripts/regressions/request-host-security.regression.ts` (+18 -1) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. ## Linked issue Closes #5039 ## Why this change - Avatar deletion is fixed for current operations, but older Engine versions could leave hundreds of unreferenced images behind. Users need a safe in-app cleanup path instead of manually guessing which files can be removed. ## What changed - Add a privileged scan endpoint that compares direct avatar image files against current characters, personas, groups, and saved card versions. - Add a separately confirmed cleanup endpoint that re-scans under the avatar lifecycle lock before deleting anything. - Ignore nested NPC avatar folders, non-image files, referenced files, and files newer than ten minutes. - Add a localized Advanced Settings Storage Optimization section with scan results, reclaimed size, and explicit deletion confirmation. - Extend avatar lifecycle regression coverage and add an Unreleased changelog entry. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes - `pnpm check` passed. - `pnpm regression:avatar-delete` passed after building the shared package. - `pnpm localization:check` passed. - Browser click-through remains pending while this PR is in draft. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n] <paths>` follow-up issue opened - [ ] Version/release files updated (only if this PR includes a version bump) ## Risk proof - Core claim: cleanup deletes only old direct avatar images with no live or historical database reference. - Risk type: destructive filesystem and user-data maintenance. - Entrypoints touched: Advanced Settings, `/api/admin/avatar-storage/abandoned`, `/api/admin/avatar-storage/cleanup`, avatar lifecycle service. - Positive row: an old unreferenced direct PNG is reported and deleted with its byte count. - Negative rows: referenced Professor Mari avatar, recent unreferenced image, non-image file, nested NPC avatar, unsafe external paths, and missing files are preserved/tolerated. - Concurrency: scan and cleanup use the existing avatar lifecycle lock; cleanup re-scans after confirmation, and a ten-minute age gate protects uploads not yet attached to a database row. - Manual blocker: no real user storage directory was mutated during validation; regression proof used isolated temporary directories. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added Advanced Settings controls to scan for abandoned avatar images and view their storage usage. * Added an explicit confirmation step before permanently deleting unreferenced avatar files. * Added success and error feedback for storage cleanup actions. * **Bug Fixes** * Added safeguards to preserve referenced, recent, non-image, and nested files. * Added rate limiting for avatar-storage management actions. * **Documentation** * Added an Unreleased changelog entry for the storage optimization feature. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:11:58 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#6602
No description provided.