@ -7,6 +7,7 @@ import {
GuestCommentValidationError ,
GuestCommentValidationError ,
normalizeGuestDisplayName ,
normalizeGuestDisplayName ,
validateGuestCommentBody ,
validateGuestCommentBody ,
validateGuestCommentEmail ,
} from "#server/utils/post-comment-guest" ;
} from "#server/utils/post-comment-guest" ;
import type { MinimalUser } from "#server/service/auth" ;
import type { MinimalUser } from "#server/service/auth" ;
@ -128,6 +129,8 @@ export async function createComment(input: {
parentId : number | null ;
parentId : number | null ;
viewer : MinimalUser | null ;
viewer : MinimalUser | null ;
guestDisplayName? : string ;
guestDisplayName? : string ;
guestEmail? : string ;
guestIsAnonymous? : boolean ;
body : string ;
body : string ;
} ) : Promise < number > {
} ) : Promise < number > {
if ( input . parentId != null ) {
if ( input . parentId != null ) {
@ -144,6 +147,8 @@ export async function createComment(input: {
let kind : string ;
let kind : string ;
let authorUserId : number | null ;
let authorUserId : number | null ;
let guestDisplayName : string | null ;
let guestDisplayName : string | null ;
let guestEmail : string | null ;
let guestIsAnonymous : boolean ;
let body : string ;
let body : string ;
if ( input . viewer != null ) {
if ( input . viewer != null ) {
@ -157,10 +162,14 @@ export async function createComment(input: {
kind = "user" ;
kind = "user" ;
authorUserId = input . viewer . id ;
authorUserId = input . viewer . id ;
guestDisplayName = null ;
guestDisplayName = null ;
guestEmail = null ;
guestIsAnonymous = false ;
} else {
} else {
try {
try {
guestIsAnonymous = input . guestIsAnonymous === true ;
guestDisplayName = normalizeGuestDisplayName ( input . guestDisplayName ? ? "" ) ;
guestDisplayName = normalizeGuestDisplayName ( input . guestDisplayName ? ? "" ) ;
body = validateGuestCommentBody ( input . body ) ;
body = validateGuestCommentBody ( input . body ) ;
guestEmail = validateGuestCommentEmail ( input . guestEmail , guestIsAnonymous ) ;
} catch ( e ) {
} catch ( e ) {
if ( e instanceof GuestCommentValidationError ) {
if ( e instanceof GuestCommentValidationError ) {
throw createError ( { statusCode : 400 , statusMessage : e.message } ) ;
throw createError ( { statusCode : 400 , statusMessage : e.message } ) ;
@ -178,6 +187,8 @@ export async function createComment(input: {
parentId : input.parentId ,
parentId : input.parentId ,
authorUserId ,
authorUserId ,
guestDisplayName ,
guestDisplayName ,
guestEmail ,
guestIsAnonymous ,
body ,
body ,
kind ,
kind ,
} ) ;
} ) ;