23 lines
648 B
TypeScript
23 lines
648 B
TypeScript
import { and, eq } from 'drizzle-orm'
|
|
|
|
import { db } from '../db/db_index'
|
|
import { uploadUrlStatus } from '../db/schema'
|
|
|
|
export const createUploadUrlStatus = async (key: string): Promise<void> => {
|
|
await db.insert(uploadUrlStatus).values({
|
|
key,
|
|
status: 'pending',
|
|
})
|
|
}
|
|
|
|
export const claimUploadUrlStatus = async (key: string): Promise<void> => {
|
|
const result = await db
|
|
.update(uploadUrlStatus)
|
|
.set({ status: 'claimed' })
|
|
.where(and(eq(uploadUrlStatus.key, key), eq(uploadUrlStatus.status, 'pending')))
|
|
.returning()
|
|
|
|
if (result.length === 0) {
|
|
throw new Error('Upload URL not found or already claimed')
|
|
}
|
|
}
|