Skip to content

Prompt as Code | GPT Image 2 / 2.5 提示词与案例库,530+ 个案例、20+ 套工业级模板与可复用 Skills,新增 2.5 同提示词对比专区,附完整提示词与生成记录,持续更新。

Allow super admin generation without credits

freestylefly8cb1fa131b73
diff --git a/.env.example b/.env.example
index 3f6165e..c2091b4 100644
--- a/.env.example
+++ b/.env.example
@@ -4,4 +4,4 @@ CIYUAN_BASE_URL=https://ciyuan.today
VITE_SUPABASE_URL=
VITE_SUPABASE_ANON_KEY=
SUPABASE_SERVICE_ROLE_KEY=
diff --git a/README.md b/README.md
index 8474c4f..730997e 100644
--- a/README.md
+++ b/README.md
@@ -281,7 +281,7 @@ Required Vercel environment variables:
VITE_SUPABASE_URL=
VITE_SUPABASE_ANON_KEY=
SUPABASE_SERVICE_ROLE_KEY=
CIYUAN_API_KEY=
CIYUAN_BASE_URL=https://ciyuan.today
```
diff --git a/api/generate-image.js b/api/generate-image.js
index 5bad52e..9220b87 100644
--- a/api/generate-image.js
+++ b/api/generate-image.js
@@ -72,6 +72,30 @@ async function reserveGeneration(client, userId, caseId, prompt) {
return reservation;
}
+async function createSuperAdminReservation(client, profile, caseId, prompt) {
+ const { data, error } = await client
+ .from('generation_reservations')
+ .insert({
+ user_id: profile.id,
+ case_id: caseId,
+ prompt,
+ used_free_generation: false,
+ credit_amount: 0
+ })
+ .select('id')
+ .single();
+
+ if (error) throw error;
+
+ return {
+ reservationId: data.id,
+ usedFreeGeneration: false,
+ creditAmount: 0,
+ freeGenerationsUsed: Number(profile.freeGenerationsUsed || 0),
+ creditBalance: Number(profile.creditBalance || 0)
+ };
+}
+
async function completeReservation(client, reservationId) {
const { error } = await client.rpc('complete_generation_reservation', {
p_reservation_id: reservationId
@@ -169,7 +193,9 @@ export default async function handler(req, res) {
let reservation;
try {
- reservation = await reserveGeneration(auth.client, auth.user.id, caseId, prompt);
+ reservation = auth.profile.isSuperAdmin
+ ? await createSuperAdminReservation(auth.client, auth.profile, caseId, prompt)
+ : await reserveGeneration(auth.client, auth.user.id, caseId, prompt);
} catch (error) {
if (error?.code === 'CREDITS_REQUIRED') {
return json(res, 402, { ok: false, error: 'CREDITS_REQUIRED' });
diff --git a/src/main.jsx b/src/main.jsx
index 26fc3f6..f31c60d 100644
--- a/src/main.jsx
+++ b/src/main.jsx
@@ -89,6 +89,7 @@ const copy = {
savedInBrowser: 'Saved in this browser',
resetPrompt: 'Reset Prompt',
oneFreeGeneration: '1 free test image',
+ superAdminGeneration: 'Super admin test mode: credits are not consumed.',
freeLimitReached: 'Free generation used. Credits are coming soon.',
generationBusy: 'The image service is busy. Please try again in a moment.',
generationFailed: 'Generation failed. Please try again later.',
@@ -195,6 +196,7 @@ const copy = {
savedInBrowser: '已保存到本浏览器',
resetPrompt: '重置 Prompt',
oneFreeGeneration: '免费生成 1 张测试图',
+ superAdminGeneration: '超级管理员测试模式:本次生图不消耗积分。',
freeLimitReached: '免费额度已用完,积分购买即将开放。',
generationBusy: '生图服务繁忙,请稍后再试。',
generationFailed: '生成失败,请稍后再试。',
@@ -448,6 +450,7 @@ function getAuthHeaders(session) {
function getGenerationQuotaText(profile, language) {
const t = copy[language];
if (!profile) return t.authRequired;
+ if (profile.isSuperAdmin) return t.superAdminGeneration;
if (!profile.freeUsed) return t.oneFreeGeneration;
if (profile.creditBalance > 0) return t.creditsAvailable(profile.creditBalance);
return t.freeLimitReached;
@@ -1178,7 +1181,10 @@ function PreviewDialog({
const isGenerating = generationState.status === 'generating';
const generatedImage = !isTemplate ? generationState.image : '';
const isSignedIn = Boolean(session?.access_token);
- const isOutOfCredits = isSignedIn && Boolean(profile?.freeUsed) && Number(profile?.creditBalance || 0) <= 0;
+ const isOutOfCredits = isSignedIn
+ && !profile?.isSuperAdmin
+ && Boolean(profile?.freeUsed)
+ && Number(profile?.creditBalance || 0) <= 0;
const generationLocked = isGenerating || isOutOfCredits;
const quotaText = isSignedIn ? getGenerationQuotaText(profile, language) : t.authRequired;