feat(backend): add static asset serving support (closes #217)#281
Merged
Conversation
…dios#217) Add a NestJS AssetsModule exposing CRUD endpoints for uploaded assets and mount a read-only static asset directory at /static/. New module:\n- BackendAcademy/src/assets/{assets.module.ts,assets.controller.ts,assets.service.ts,interfaces/asset.interface.ts,dto/upload-asset.dto.ts}\n- BackendAcademy/src/assets/assets.controller.spec.ts\n- BackendAcademy/src/assets/assets.service.spec.ts Wiring:\n- BackendAcademy/src/app.module.ts: register AssetsModule\n- BackendAcademy/src/main.ts: useStaticAssets at /static/, typed as NestExpressApplication\n- BackendAcademy/src/config/config.module.ts: Joi schema adds ASSETS_UPLOAD_DIR, ASSETS_MAX_SIZE_MB, ASSETS_BASE_URL, ASSETS_STATIC_DIR\n- BackendAcademy/.env.example: documents the new env vars API surface (URI version /api/v1/):\n- GET /assets list asset metadata (newest|oldest|name)\n- GET /assets/:id fetch asset metadata\n- GET /assets/:id/download stream content with stored MIME type\n- POST /assets multipart upload (multer memoryStorage + UploadAssetDto)\n- DELETE /assets/:id remove asset metadata and underlying file Behavior:\n- In-memory metadata registry mirrored to filesystem at ASSETS_UPLOAD_DIR\n- MIME allowlist: image/*, video/*, audio/*, application/pdf, text/*\n- Sanitized filenames embedding the asset UUID\n- Soft validation on missing on-disk files; orphan tmp files pruned at shutdown Test status:\n- BackendAcademy nest build passes\n- Jest suite: 113 / 117 tests pass (4 pre-existing failures remain in src/rewards/* and are unrelated to this change; verified pre-existing on origin/main) Dependencies:\n- multer ^1.4.5-lts.1 added under dependencies\n- @types/multer ^1.4.12 and typescript-eslint ^7.18.0 added under devDependencies Misc:\n- Removed an extra trailing closing brace in BackendAcademy/src/social/social.service.ts that was blocking TS compilation
|
@otobongdev Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds backend support for serving static and uploaded assets via a new NestJS
AssetsModule, plus a read-only static asset directory mounted from disk. Closes #217.What's new
AssetsModuleunderBackendAcademy/src/assets/:assets.module.ts,assets.controller.ts,assets.service.tsinterfaces/asset.interface.ts(Asset,AssetListResponse,AssetSortOrder)dto/upload-asset.dto.ts(UploadAssetDtowith optionalnameanddescriptiontext fields validated alongside the multipart upload)assets.controller.spec.ts,assets.service.spec.tsapp.module.tsregistersAssetsModulemain.tsis now typed asNestExpressApplicationand mountsASSETS_STATIC_DIR(default./public) under the URL prefix/static/viauseStaticAssets, withmkdirSyncfallback so a fresh clone boots.config/config.module.tsadds Joi-validated env vars:ASSETS_UPLOAD_DIR,ASSETS_MAX_SIZE_MB,ASSETS_BASE_URL,ASSETS_STATIC_DIR..env.exampledocuments the new env vars.multer ^1.4.5-lts.1(now a direct dep soimport { memoryStorage } from 'multer'resolves under pnpm strict mode)@types/multer ^1.4.12andtypescript-eslint ^7.18.0underdevDependencies}inBackendAcademy/src/social/social.service.tsthat was blocking TypeScript compilation.REST surface (URI prefix
/api/v1/thanks to global versioning)/assets?sort=newest|oldest|name, defaultnewest)/assets/:id/assets/:id/downloadContent-Type, length, andContent-Disposition/assetsfile); optionalname/descriptionvalidated againstUploadAssetDto/assets/:idRead-only prebuilt static files under
ASSETS_STATIC_DIRare served at/static/*.Behavior
Map<id, Asset>; the file body is persisted atASSETS_UPLOAD_DIR(default./data/uploads).ASSETS_MAX_SIZE_MB), MIME allowlist (image/*,video/*,audio/*,application/pdf,text/*).ASSETS_UPLOAD_DIR.OnModuleDestroy./api/docs.Tests
pnpm testinBackendAcademyreports 113 of 117 tests passing.src/rewards/rewards.service.spec.ts\u2014 nested test definition;src/rewards/streak.service.spec.ts\u2014 stalegetStreak/checkInassertions) are pre-existing onorigin/mainand unrelated to this change. They are documented here for transparency; fixing them is out of scope for issue Add static asset serving support #217.pnpm build(nest build) compiles cleanly.pnpm lintcurrently fails onorigin/mainbecause the repo useseslint.config.ts(flat config) witheslint@^8.0.0declared indevDependencies. Flat config is supported by eslint 9 or by eslint 8 withESLINT_USE_FLAT_CONFIG=true; align versions in a follow-up PR.Configuration
Closes #217