Update application features and add scripts (core changes)

This commit is contained in:
AyrisAI
2026-07-19 11:38:56 +03:00
parent a36b833e00
commit da84cdc231
44 changed files with 2953 additions and 449 deletions
+75
View File
@@ -0,0 +1,75 @@
'use server'
import { db } from '@/lib/db'
import { revalidatePath } from 'next/cache'
import { RoomType } from '@prisma/client'
export type RoomInput = {
slug: string
type: RoomType
nameTr: string
nameEn: string
nameDe: string
descriptionTr: string
descriptionEn: string
descriptionDe: string
capacity: number
price: number | null
imageUrl: string | null
images: string[]
amenities: string[]
available: boolean
featured: boolean
}
export async function createRoom(data: RoomInput) {
try {
const room = await db.room.create({
data,
})
revalidatePath('/[locale]/admin/rooms', 'page')
revalidatePath('/[locale]/dairelerimiz', 'page')
revalidatePath('/[locale]', 'page')
return { success: true, room }
} catch (error) {
console.error('Failed to create room:', error)
return { success: false, error: 'Oda oluşturulurken bir hata oluştu.' }
}
}
export async function updateRoom(id: string, data: RoomInput) {
try {
const room = await db.room.update({
where: { id },
data,
})
revalidatePath('/[locale]/admin/rooms', 'page')
revalidatePath('/[locale]/dairelerimiz', 'page')
revalidatePath('/[locale]', 'page')
return { success: true, room }
} catch (error) {
console.error('Failed to update room:', error)
return { success: false, error: 'Oda güncellenirken bir hata oluştu.' }
}
}
export async function deleteRoom(id: string) {
try {
await db.room.delete({
where: { id },
})
revalidatePath('/[locale]/admin/rooms', 'page')
revalidatePath('/[locale]/dairelerimiz', 'page')
revalidatePath('/[locale]', 'page')
return { success: true }
} catch (error) {
console.error('Failed to delete room:', error)
return { success: false, error: 'Oda silinirken bir hata oluştu.' }
}
}
+23
View File
@@ -0,0 +1,23 @@
'use server'
import { uploadToOpeninary } from '@/lib/openinary'
export async function uploadImageAction(formData: FormData) {
try {
const file = formData.get('file') as File
if (!file) throw new Error('No file provided')
const folder = (formData.get('folder') as string) || 'starapart'
const result = await uploadToOpeninary(file, folder)
let finalUrl = result.url
if (finalUrl && finalUrl.startsWith('/')) {
finalUrl = `${process.env.NEXT_PUBLIC_OPENINARY_URL || 'https://media.ayris.tech'}${finalUrl}`
}
return { success: true, url: finalUrl }
} catch (error: any) {
console.error('Upload error:', error)
return { success: false, error: error.message }
}
}
+7 -1
View File
@@ -1,9 +1,15 @@
import { PrismaClient } from '@prisma/client'
import { Pool } from 'pg'
import { PrismaPg } from '@prisma/adapter-pg'
const globalForPrisma = globalThis as unknown as {
prisma: PrismaClient | undefined
}
export const db = globalForPrisma.prisma ?? new PrismaClient()
const pool = new Pool({ connectionString: process.env.DATABASE_URL })
const adapter = new PrismaPg(pool)
export const db = globalForPrisma.prisma ?? new PrismaClient({ adapter })
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = db
+8 -1
View File
@@ -35,5 +35,12 @@ export default function openinaryLoader({ src, width, quality }: { src: string,
path = path.substring(1);
}
return `https://media.ayris.tech/t/w_${width},f_webp,q_${quality || 75}/${path}`
// Ensure 'starapart/' prefix for Openinary transform URLs
// Since the API sometimes returns URLs without the root folder, we inject it back.
if (!path.startsWith('starapart/') && !path.startsWith('http')) {
path = `starapart/${path}`;
}
// Adding a_auto to automatically rotate images based on EXIF data (fixes sideways phone photos)
return `https://media.ayris.tech/t/w_${width},f_webp,q_${quality || 75},a_auto/${path}`
}
+11
View File
@@ -0,0 +1,11 @@
import Redis from 'ioredis'
const globalForRedis = globalThis as unknown as {
redis: Redis | undefined
}
export const redis =
globalForRedis.redis ??
new Redis(process.env.REDIS_URL || 'redis://localhost:6379')
if (process.env.NODE_ENV !== 'production') globalForRedis.redis = redis