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
119 lines
3.4 KiB
TypeScript
119 lines
3.4 KiB
TypeScript
/**
|
|
* This file is automatically generated
|
|
* DO NOT EDIT manually
|
|
* Run "node ace migration:run" command to re-generate this file
|
|
*/
|
|
|
|
import { BaseModel, column } from '@adonisjs/lucid/orm'
|
|
import { DateTime } from 'luxon'
|
|
|
|
export class ComponentTypeSchema extends BaseModel {
|
|
static $columns = ['id', 'name', 'unique'] as const
|
|
$columns = ComponentTypeSchema.$columns
|
|
@column({ isPrimary: true })
|
|
declare id: number
|
|
@column()
|
|
declare name: string
|
|
@column()
|
|
declare unique: boolean
|
|
}
|
|
|
|
export class ComponentSchema extends BaseModel {
|
|
static $columns = ['computerId', 'createdAt', 'id', 'name', 'price', 'purchaseDate', 'typeId', 'updatedAt', 'userId'] as const
|
|
$columns = ComponentSchema.$columns
|
|
@column()
|
|
declare computerId: number | null
|
|
@column.dateTime({ autoCreate: true })
|
|
declare createdAt: DateTime | null
|
|
@column({ isPrimary: true })
|
|
declare id: number
|
|
@column()
|
|
declare name: string
|
|
@column()
|
|
declare price: string
|
|
@column.date()
|
|
declare purchaseDate: DateTime
|
|
@column()
|
|
declare typeId: number | null
|
|
@column.dateTime({ autoCreate: true, autoUpdate: true })
|
|
declare updatedAt: DateTime | null
|
|
@column()
|
|
declare userId: number | null
|
|
}
|
|
|
|
export class ComputerPictureSchema extends BaseModel {
|
|
static $columns = ['computerId', 'createdAt', 'id', 'link', 'order', 'updatedAt'] as const
|
|
$columns = ComputerPictureSchema.$columns
|
|
@column()
|
|
declare computerId: number | null
|
|
@column.dateTime({ autoCreate: true })
|
|
declare createdAt: DateTime | null
|
|
@column({ isPrimary: true })
|
|
declare id: number
|
|
@column()
|
|
declare link: string
|
|
@column()
|
|
declare order: number
|
|
@column.dateTime({ autoCreate: true, autoUpdate: true })
|
|
declare updatedAt: DateTime | null
|
|
}
|
|
|
|
export class ComputerStateSchema extends BaseModel {
|
|
static $columns = ['id', 'name'] as const
|
|
$columns = ComputerStateSchema.$columns
|
|
@column({ isPrimary: true })
|
|
declare id: number
|
|
@column()
|
|
declare name: string
|
|
}
|
|
|
|
export class ComputerSchema extends BaseModel {
|
|
static $columns = ['cpuScore', 'createdAt', 'globalScore', 'gpuScore', 'id', 'sellPrice', 'shareEnabled', 'shareShowCost', 'shareShowSellPrice', 'shareToken', 'stateId', 'title', 'updatedAt', 'userId'] as const
|
|
$columns = ComputerSchema.$columns
|
|
@column()
|
|
declare cpuScore: number
|
|
@column.dateTime({ autoCreate: true })
|
|
declare createdAt: DateTime | null
|
|
@column()
|
|
declare globalScore: number
|
|
@column()
|
|
declare gpuScore: number
|
|
@column({ isPrimary: true })
|
|
declare id: number
|
|
@column()
|
|
declare sellPrice: number | null
|
|
@column()
|
|
declare shareEnabled: boolean
|
|
@column()
|
|
declare shareShowCost: boolean
|
|
@column()
|
|
declare shareShowSellPrice: boolean
|
|
@column()
|
|
declare shareToken: string | null
|
|
@column()
|
|
declare stateId: number
|
|
@column()
|
|
declare title: string
|
|
@column.dateTime({ autoCreate: true, autoUpdate: true })
|
|
declare updatedAt: DateTime | null
|
|
@column()
|
|
declare userId: number | null
|
|
}
|
|
|
|
export class UserSchema extends BaseModel {
|
|
static $columns = ['createdAt', 'email', 'id', 'name', 'password', 'updatedAt'] as const
|
|
$columns = UserSchema.$columns
|
|
@column.dateTime({ autoCreate: true })
|
|
declare createdAt: DateTime
|
|
@column()
|
|
declare email: string
|
|
@column({ isPrimary: true })
|
|
declare id: number
|
|
@column()
|
|
declare name: string | null
|
|
@column({ serializeAs: null })
|
|
declare password: string
|
|
@column.dateTime({ autoCreate: true, autoUpdate: true })
|
|
declare updatedAt: DateTime | null
|
|
}
|