Files
pc_builder/start/routes.ts
T
Kevin L'Hereec da71d33450
Build & Deploy / build (push) Failing after 5s
Build & Deploy / docker (push) Skipped
feat: add public read-only sharing for computers
Adds the ability for an owner to share a computer build via a public,
unauthenticated link, inspired by a feature request from the original
pcbuilder repo (no such feature actually existed there — implemented
from scratch here).

- New columns on computers: share_token (unique, nullable), share_enabled,
  share_show_sell_price, share_show_cost
- computer_share_service.ts: generates a non-guessable share token
  (crypto.randomBytes, base64url), enables/disables sharing, and supports
  rotating the token to invalidate previously distributed links
- ComputerShareController (authenticated, owner-scoped like the rest of
  the app): PUT /computers/:id/share to update settings, POST
  /computers/:id/share/rotate to rotate the token
- PublicComputerController + GET /share/:token (outside any auth/guest
  group, reachable anonymously): resolves only computers with
  share_enabled = true, 404 otherwise
- ComputerPublicTransformer: dedicated read-only projection that never
  leaks userId, and only includes sellPrice/cost when the owner opted in
  via share_show_sell_price / share_show_cost — everything else (title,
  scores, state, components, pictures) is always visible on a shared link
- ComputerShareModal.vue: owner-facing UI (toggle sharing, choose which
  prices to expose, copy the public link, revoke/rotate it) wired into
  computers/show.vue via a new 'Share' button
- share/show.vue: public page rendered with EmptyLayout (no authenticated
  header/sidebar)
- Boolean columns use a  cast since MySQL returns tinyint(1),
  not native booleans, through Lucid
- 6 new functional tests covering: enabling sharing, price visibility
  toggles, disabling sharing revokes the link, cross-user protection on
  the share settings endpoint (404), token rotation invalidating the old
  link, and anonymous access to a shared computer
2026-07-23 11:43:38 +02:00

69 lines
2.6 KiB
TypeScript

/*
|--------------------------------------------------------------------------
| Routes file
|--------------------------------------------------------------------------
|
| The routes file is used for defining the HTTP routes.
|
*/
import { middleware } from '#start/kernel'
import { controllers } from '#generated/controllers'
import router from '@adonisjs/core/services/router'
router
.get('/', async ({ response }) => {
return response.redirect('/auth/login')
})
.as('home')
router
.group(() => {
router.get('signup', [controllers.NewAccount, 'create']).as('new_account.create')
router.post('signup', [controllers.NewAccount, 'store']).as('new_account.store')
router.get('login', [controllers.Session, 'create']).as('session.create')
router.post('login', [controllers.Session, 'store']).as('session.store')
})
.prefix('/auth')
.use(middleware.guest())
router
.group(() => {
router.post('logout', [controllers.Session, 'destroy'])
})
.prefix('/auth')
.use(middleware.auth())
router
.group(() => {
router.get('/', [controllers.Computers, 'index']).as('computers.index')
router.get('/create', [controllers.Computers, 'create']).as('computers.create')
router.post('/', [controllers.Computers, 'store']).as('computers.store')
router.get('/:id', [controllers.Computers, 'show']).as('computers.show')
router.get('/:id/edit', [controllers.Computers, 'edit']).as('computers.edit')
router.put('/:id', [controllers.Computers, 'update']).as('computers.update')
router.delete('/:id', [controllers.Computers, 'destroy']).as('computers.destroy')
router.put('/:id/share', [controllers.ComputerShare, 'update']).as('computers.share.update')
router
.post('/:id/share/rotate', [controllers.ComputerShare, 'rotate'])
.as('computers.share.rotate')
})
.prefix('/computers')
.use(middleware.auth())
router.get('/share/:token', [controllers.PublicComputer, 'show']).as('share.show')
router
.group(() => {
router.get('/', [controllers.Components, 'index']).as('components.index')
router.get('/create', [controllers.Components, 'create']).as('components.create')
router.post('/', [controllers.Components, 'store']).as('components.store')
router.get('/:id', [controllers.Components, 'show']).as('components.show')
router.get('/:id/edit', [controllers.Components, 'edit']).as('components.edit')
router.put('/:id', [controllers.Components, 'update']).as('components.update')
router.delete('/:id', [controllers.Components, 'destroy']).as('components.destroy')
})
.prefix('/components')
.use(middleware.auth())