@@ -6,8 +6,9 @@ import db from "../../infra/db.js";
66import { BadRequestError , ForbiddenError , NotFoundError } from "../../lib/errors.js" ;
77import { notifyDiscordQuiltProposal } from "./discord.js" ;
88
9- const REVIEW_WINDOW_MS = 60 * 60 * 1000 ;
9+ const MS_PER_MINUTE = 60 * 1000 ;
1010const MAX_PIXELS_PER_SUBMISSION = 4096 ;
11+ const MAX_REVIEW_WINDOW_MINUTES = 60 * 24 * 30 ;
1112
1213export const quiltCreateSchema = z . object ( {
1314 name : z . string ( ) . trim ( ) . min ( 1 ) . max ( 120 ) ,
@@ -20,6 +21,12 @@ export const quiltCreateSchema = z.object({
2021 description : z . string ( ) . trim ( ) . max ( 1000 ) . optional ( ) . nullable ( ) ,
2122 width : z . coerce . number ( ) . int ( ) . min ( 8 ) . max ( 512 ) ,
2223 height : z . coerce . number ( ) . int ( ) . min ( 8 ) . max ( 512 ) ,
24+ reviewWindowMinutes : z . coerce
25+ . number ( )
26+ . int ( )
27+ . min ( 0 )
28+ . max ( MAX_REVIEW_WINDOW_MINUTES )
29+ . optional ( ) ,
2330 endsAt : z . coerce . date ( ) ,
2431} ) ;
2532
@@ -127,6 +134,10 @@ function canonicalPixels(pixels: QuiltPixel[]) {
127134 ) ;
128135}
129136
137+ function submissionResolvesAt ( now : Date , reviewWindowMinutes : number ) {
138+ return new Date ( now . getTime ( ) + reviewWindowMinutes * MS_PER_MINUTE ) ;
139+ }
140+
130141function serializeSubmission (
131142 submission : QuiltSubmissionWithRelations ,
132143 viewerId ?: number ,
@@ -324,6 +335,7 @@ export async function listQuilts(tenantId?: string | null) {
324335 description : quilt . description ,
325336 width : quilt . width ,
326337 height : quilt . height ,
338+ reviewWindowMinutes : quilt . reviewWindowMinutes ,
327339 endsAt : quilt . endsAt . toISOString ( ) ,
328340 createdAt : quilt . createdAt . toISOString ( ) ,
329341 submissionCount : quilt . _count . submissions ,
@@ -349,6 +361,7 @@ export async function createQuilt({
349361 description : input . description ?. trim ( ) || null ,
350362 width : input . width ,
351363 height : input . height ,
364+ reviewWindowMinutes : input . reviewWindowMinutes ,
352365 endsAt : input . endsAt ,
353366 tenantId : resolvedTenantId ( tenantId ) ,
354367 } ,
@@ -389,6 +402,7 @@ export async function getQuiltDetail({
389402 description : quilt . description ,
390403 width : quilt . width ,
391404 height : quilt . height ,
405+ reviewWindowMinutes : quilt . reviewWindowMinutes ,
392406 endsAt : quilt . endsAt . toISOString ( ) ,
393407 createdAt : quilt . createdAt . toISOString ( ) ,
394408 isEnded : quilt . endsAt . getTime ( ) <= Date . now ( ) ,
@@ -467,7 +481,7 @@ export async function submitQuiltPixels({
467481 pixels : normalizedPixels ,
468482 canvasWidth : quilt . width ,
469483 canvasHeight : quilt . height ,
470- resolvesAt : new Date ( now . getTime ( ) + REVIEW_WINDOW_MS ) ,
484+ resolvesAt : submissionResolvesAt ( now , quilt . reviewWindowMinutes ) ,
471485 votes : {
472486 create : {
473487 userId : actor . id ,
@@ -545,6 +559,7 @@ export async function updateQuiltSubmission({
545559 slug : true ,
546560 width : true ,
547561 height : true ,
562+ reviewWindowMinutes : true ,
548563 endsAt : true ,
549564 } ,
550565 } ,
@@ -578,7 +593,10 @@ export async function updateQuiltSubmission({
578593 canvasWidth : submission . quilt . width ,
579594 canvasHeight : submission . quilt . height ,
580595 status : QuiltSubmissionStatus . PENDING ,
581- resolvesAt : new Date ( now . getTime ( ) + REVIEW_WINDOW_MS ) ,
596+ resolvesAt : submissionResolvesAt (
597+ now ,
598+ submission . quilt . reviewWindowMinutes ,
599+ ) ,
582600 resolvedAt : null ,
583601 removedAt : null ,
584602 removedById : null ,
0 commit comments