feat(ai-gen): 内置免费每日次数额度说明+按钮文案改「或使用自己的提供商/API KEY」
- 模型区右侧实时显示额度:未授权每日10次(DAILY_FREE_LIMIT可调,北京0点重置),生成成功才扣次,已授权不限次,自带KEY不计次 - 新增 POST /relay/ai/quota 额度查询(authorized/limit/used/remaining),挂载时与生成后刷新 - 按钮文案「+使用我的提供商」→「或使用自己的提供商」 - 同步 in-repo relay copy server.py(check_gen+daily计数+/ai/quota)与 README
This commit is contained in:
1 parent
6557d1fe7b
commit
b4e5d6ac6d
3 files changed
+381
-13
No files matched your search
@@ -138,9 +138,32 @@ const EXAMPLES = [
|
||||
|
||||
const canGen = computed(() => !!prompt.value.trim());
|
||||
|
||||
// ---------- 内置免费额度(每日次数,服务端统计;北京时间 0 点重置) ----------
|
||||
const quota = ref<{ authorized: boolean; limit: number; used: number; remaining: number } | null>(null);
|
||||
const quotaText = computed(() => {
|
||||
const q = quota.value;
|
||||
if (!q) return '内置免费 · 有每日次数限制';
|
||||
if (q.authorized) return '已授权 · 不限次数';
|
||||
if (q.remaining <= 0) return `内置免费 · 每日${q.limit}次 · 今日已用完`;
|
||||
return `内置免费 · 每日${q.limit}次 · 今日剩${q.remaining}次`;
|
||||
});
|
||||
const quotaOut = computed(() => !!quota.value && !quota.value.authorized && quota.value.remaining <= 0);
|
||||
async function loadQuota() {
|
||||
try {
|
||||
const res = await fetch('/relay/ai/quota', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ machine: getMachineId() }),
|
||||
});
|
||||
const j = await res.json();
|
||||
if (j.code === 200 && j.data) quota.value = j.data;
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
loadProvider();
|
||||
loadHistory();
|
||||
loadQuota();
|
||||
try {
|
||||
const res = await fetch('/relay/ai/image-models');
|
||||
const j = await res.json();
|
||||
@@ -202,6 +225,7 @@ async function generate() {
|
||||
const dataUrl = j.data.b64 ? b64DataUrl(j.data.b64) : '';
|
||||
resultUrl.value = j.data.img_url || dataUrl || j.data.url;
|
||||
loadHistory();
|
||||
loadQuota(); // 生成后刷新当日剩余次数
|
||||
}
|
||||
catch (e: any) {
|
||||
error.value = String(e?.message || e);
|
||||
@@ -219,7 +243,7 @@ async function generate() {
|
||||
<div class="gen-ctrl">
|
||||
<!-- 模型 -->
|
||||
<div class="gen-sec">
|
||||
<div class="gen-h">模型</div>
|
||||
<div class="gen-h">模型 <span class="gen-quota" :class="{ out: quotaOut }">{{ quotaText }}</span></div>
|
||||
<select v-model="model" class="gen-model-sel">
|
||||
<optgroup label="站内免费模型">
|
||||
<option v-for="m in models.filter(x => !x.custom)" :key="m.id" :value="m.id">{{ m.id }}</option>
|
||||
@@ -244,7 +268,7 @@ async function generate() {
|
||||
<!-- 自定义提供商:KEY 只存本机 -->
|
||||
<div class="prov">
|
||||
<button type="button" class="prov-toggle" @click="provOpen = !provOpen">
|
||||
<span>{{ hasCreds ? '✓ 我的提供商已配置' : '+ 使用我的提供商 / API KEY' }}</span>
|
||||
<span>{{ hasCreds ? '✓ 我的提供商已配置' : '或使用自己的提供商 / API KEY' }}</span>
|
||||
<span class="prov-caret">{{ provOpen ? '▾' : '▸' }}</span>
|
||||
</button>
|
||||
<div v-show="provOpen" class="prov-form">
|
||||
@@ -427,6 +451,21 @@ async function generate() {
|
||||
.gen-h {
|
||||
font-size: 14px;
|
||||
font-weight: 800;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.gen-quota {
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
color: rgba(128, 128, 128, 0.95);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.gen-quota.out {
|
||||
color: #d03050;
|
||||
}
|
||||
|
||||
.gen-model-sel {
|
||||
|
||||
Reference in new issue
Block a user