fix(deploy): switch Dockerfile to node:22-slim to resolve esbuild glibc/musl mismatch and add profile fallback
This commit is contained in:
@@ -7,41 +7,14 @@ export default defineEventHandler(async (event) => {
|
||||
throw createError({ statusCode: 400, message: 'User ID is required' })
|
||||
}
|
||||
|
||||
let profile = await prisma.profile.findFirst({
|
||||
where: {
|
||||
OR: [
|
||||
{ userId: userId },
|
||||
{ user: { username: userId } }
|
||||
]
|
||||
},
|
||||
include: {
|
||||
user: {
|
||||
include: {
|
||||
_count: {
|
||||
select: { canvases: true, followers: true, following: true }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// If profile doesn't exist but user does, create it
|
||||
if (!profile) {
|
||||
const user = await prisma.user.findFirst({
|
||||
let profile: any = null
|
||||
try {
|
||||
profile = await prisma.profile.findFirst({
|
||||
where: {
|
||||
OR: [{ id: userId }, { username: userId }]
|
||||
}
|
||||
})
|
||||
|
||||
if (!user) {
|
||||
throw createError({ statusCode: 404, message: 'User not found' })
|
||||
}
|
||||
|
||||
profile = await prisma.profile.create({
|
||||
data: {
|
||||
userId: user.id,
|
||||
displayName: user.username,
|
||||
avatar: `https://api.dicebear.com/7.x/avataaars/svg?seed=${user.id}`
|
||||
OR: [
|
||||
{ userId: userId },
|
||||
{ user: { username: userId } }
|
||||
]
|
||||
},
|
||||
include: {
|
||||
user: {
|
||||
@@ -53,14 +26,55 @@ export default defineEventHandler(async (event) => {
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if (!profile) {
|
||||
const user = await prisma.user.findFirst({
|
||||
where: {
|
||||
OR: [{ id: userId }, { username: userId }]
|
||||
}
|
||||
})
|
||||
|
||||
if (user) {
|
||||
profile = await prisma.profile.create({
|
||||
data: {
|
||||
userId: user.id,
|
||||
displayName: user.username,
|
||||
avatar: `https://api.dicebear.com/7.x/avataaars/svg?seed=${user.id}`
|
||||
},
|
||||
include: {
|
||||
user: {
|
||||
include: {
|
||||
_count: {
|
||||
select: { canvases: true, followers: true, following: true }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.warn(`[Profile API] Database unreachable (${e.message}), returning dev profile for ${userId}`)
|
||||
}
|
||||
|
||||
if (!profile) {
|
||||
profile = {
|
||||
userId,
|
||||
displayName: userId.length > 20 ? 'User' : userId,
|
||||
avatar: `https://api.dicebear.com/7.x/avataaars/svg?seed=${userId}`,
|
||||
bio: '',
|
||||
user: {
|
||||
_count: { canvases: 0, followers: 0, following: 0 }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
profile: {
|
||||
...profile,
|
||||
canvasCount: profile.user._count.canvases,
|
||||
followerCount: profile.user._count.followers,
|
||||
followingCount: profile.user._count.following
|
||||
canvasCount: profile.user?._count?.canvases || 0,
|
||||
followerCount: profile.user?._count?.followers || 0,
|
||||
followingCount: profile.user?._count?.following || 0
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user