mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-11-18 23:01:23 +00:00
feat(openai): 支持用户级 Fast/Flex 策略
This commit is contained in:
1 parent
9a2f11b4e2
commit
f2966530c5
15 files changed
+482
-17
No files matched your search
@@ -1189,6 +1189,72 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- User Scope -->
|
||||
<div class="mt-3">
|
||||
<label
|
||||
class="mb-1 block text-xs font-medium text-gray-600 dark:text-gray-400"
|
||||
>
|
||||
{{ t("admin.settings.openaiFastPolicy.userIds") }}
|
||||
</label>
|
||||
<p class="mb-2 text-xs text-gray-400 dark:text-gray-500">
|
||||
{{ t("admin.settings.openaiFastPolicy.userIdsHint") }}
|
||||
</p>
|
||||
<div
|
||||
v-for="(_, userIDIndex) in rule.user_ids || []"
|
||||
:key="userIDIndex"
|
||||
class="mb-1.5 flex items-center gap-2"
|
||||
>
|
||||
<input
|
||||
v-model.number="rule.user_ids![userIDIndex]"
|
||||
type="number"
|
||||
min="1"
|
||||
step="1"
|
||||
class="input input-sm flex-1"
|
||||
:placeholder="t('admin.settings.openaiFastPolicy.userIdPlaceholder')"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
@click="removeOpenAIFastPolicyUserID(rule, userIDIndex)"
|
||||
class="shrink-0 rounded p-1 text-red-400 transition-colors hover:bg-red-50 hover:text-red-600 dark:hover:bg-red-900/20"
|
||||
:title="t('admin.settings.openaiFastPolicy.removeUserId')"
|
||||
>
|
||||
<svg
|
||||
class="h-4 w-4"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
>
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
d="M6 18L18 6M6 6l12 12"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
@click="addOpenAIFastPolicyUserID(rule)"
|
||||
class="mb-2 inline-flex items-center gap-1 text-xs text-primary-600 transition-colors hover:text-primary-700 dark:text-primary-400 dark:hover:text-primary-300"
|
||||
>
|
||||
<svg
|
||||
class="h-3.5 w-3.5"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
>
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
d="M12 4v16m8-8H4"
|
||||
/>
|
||||
</svg>
|
||||
{{ t("admin.settings.openaiFastPolicy.addUserId") }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Error Message (only when action=block) -->
|
||||
<div v-if="rule.action === 'block'" class="mt-3">
|
||||
<label
|
||||
@@ -9144,6 +9210,7 @@ async function loadSettings() {
|
||||
openaiFastPolicyForm.rules =
|
||||
settings.openai_fast_policy_settings.rules.map((rule) => ({
|
||||
...rule,
|
||||
user_ids: rule.user_ids ? [...rule.user_ids] : [],
|
||||
model_whitelist: rule.model_whitelist
|
||||
? [...rule.model_whitelist]
|
||||
: [],
|
||||
@@ -9651,6 +9718,10 @@ async function saveSettings() {
|
||||
service_tier: rule.service_tier,
|
||||
action: rule.action,
|
||||
scope: rule.scope,
|
||||
user_ids:
|
||||
rule.user_ids && rule.user_ids.length > 0
|
||||
? [...rule.user_ids]
|
||||
: undefined,
|
||||
error_message:
|
||||
rule.action === "block" ? rule.error_message : undefined,
|
||||
model_whitelist: hasWhitelist ? whitelist : undefined,
|
||||
@@ -9727,6 +9798,7 @@ async function saveSettings() {
|
||||
openaiFastPolicyForm.rules =
|
||||
updated.openai_fast_policy_settings.rules.map((rule) => ({
|
||||
...rule,
|
||||
user_ids: rule.user_ids ? [...rule.user_ids] : [],
|
||||
model_whitelist: rule.model_whitelist
|
||||
? [...rule.model_whitelist]
|
||||
: [],
|
||||
@@ -10142,6 +10214,7 @@ function addOpenAIFastPolicyRule() {
|
||||
service_tier: "priority",
|
||||
action: "filter",
|
||||
scope: "all",
|
||||
user_ids: [],
|
||||
error_message: "",
|
||||
model_whitelist: [],
|
||||
fallback_action: "pass",
|
||||
@@ -10153,6 +10226,18 @@ function removeOpenAIFastPolicyRule(index: number) {
|
||||
openaiFastPolicyForm.rules.splice(index, 1);
|
||||
}
|
||||
|
||||
function addOpenAIFastPolicyUserID(rule: OpenAIFastPolicyRule) {
|
||||
if (!rule.user_ids) rule.user_ids = [];
|
||||
rule.user_ids.push(0);
|
||||
}
|
||||
|
||||
function removeOpenAIFastPolicyUserID(
|
||||
rule: OpenAIFastPolicyRule,
|
||||
idx: number,
|
||||
) {
|
||||
rule.user_ids?.splice(idx, 1);
|
||||
}
|
||||
|
||||
function addOpenAIFastPolicyModelPattern(rule: OpenAIFastPolicyRule) {
|
||||
if (!rule.model_whitelist) rule.model_whitelist = [];
|
||||
rule.model_whitelist.push("");
|
||||
|
||||
Reference in new issue
Block a user