Skip to content

Commit

Permalink
update settings api (#121)
Browse files Browse the repository at this point in the history
* update settings api

* chore: auto-fix linting and formatting issues
  • Loading branch information
uubulb authored Feb 28, 2025
1 parent 41d4d7f commit 1ee664f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 74 deletions.
4 changes: 2 additions & 2 deletions src/components/install-commands.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { useAuth } from "@/hooks/useAuth"
import useSettings from "@/hooks/useSetting"
import { copyToClipboard } from "@/lib/utils"
import { ModelConfig, ModelProfile } from "@/types"
import { ModelProfile, ModelSetting } from "@/types"
import i18next from "i18next"
import { Check, Clipboard } from "lucide-react"
import { forwardRef, useState } from "react"
Expand Down Expand Up @@ -88,7 +88,7 @@ export const InstallCommandsMenu = forwardRef<HTMLButtonElement, ButtonProps>((p

const generateCommand = (
type: number,
{ agent_secret_key, install_host, tls }: ModelConfig,
{ agent_secret_key, install_host, tls }: ModelSetting,
{ agent_secret, role }: ModelProfile,
) => {
if (!install_host) throw new Error(i18next.t("Results.InstallHostRequired"))
Expand Down
7 changes: 2 additions & 5 deletions src/hooks/useSetting.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { swrFetcher } from "@/api/api"
import { GithubComNezhahqNezhaModelSettingResponseModelConfig } from "@/types"
import { ModelSettingResponse } from "@/types"
import useSWR from "swr"

export default function useSetting() {
return useSWR<GithubComNezhahqNezhaModelSettingResponseModelConfig>(
"/api/v1/setting",
swrFetcher,
)
return useSWR<ModelSettingResponse>("/api/v1/setting", swrFetcher)
}
116 changes: 49 additions & 67 deletions src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,6 @@ export interface GithubComNezhahqNezhaModelCommonResponseArrayUint64 {
success: boolean
}

export interface GithubComNezhahqNezhaModelCommonResponseGithubComNezhahqNezhaModelSettingResponseModelConfig {
data: GithubComNezhahqNezhaModelSettingResponseModelConfig
error: string
success: boolean
}

export interface GithubComNezhahqNezhaModelCommonResponseModelLoginResponse {
data: ModelLoginResponse
error: string
Expand All @@ -123,6 +117,12 @@ export interface GithubComNezhahqNezhaModelCommonResponseModelServiceResponse {
success: boolean
}

export interface GithubComNezhahqNezhaModelCommonResponseModelSettingResponse {
data: ModelSettingResponse
error: string
success: boolean
}

export interface GithubComNezhahqNezhaModelCommonResponseString {
data: string
error: string
Expand All @@ -147,12 +147,6 @@ export interface GithubComNezhahqNezhaModelPaginatedResponseArrayModelWAFApiMock
success: boolean
}

export interface GithubComNezhahqNezhaModelSettingResponseModelConfig {
config: ModelConfig
frontend_templates: ModelFrontendTemplate[]
version: string
}

export interface GithubComNezhahqNezhaModelValueArrayModelOnlineUser {
pagination: ModelPagination
value: ModelOnlineUser[]
Expand Down Expand Up @@ -194,47 +188,6 @@ export interface ModelAlertRuleForm {
trigger_mode: number
}

export interface ModelConfig {
admin_template: string
agent_secret_key: string
avg_ping_count: number
/** 覆盖范围(0:提醒未被 IgnoredIPNotification 包含的所有服务器; 1:仅提醒被 IgnoredIPNotification 包含的服务器;) */
cover: number
custom_code: string
custom_code_dashboard: string
/** debug模式开关 */
debug: boolean
dns_servers: string
/** IP变更提醒 */
enable_ip_change_notification: boolean
/** 通知信息IP不打码 */
enable_plain_ip_in_notification: boolean
/** 强制要求认证 */
force_auth: boolean
/** 特定服务器IP(多个服务器用逗号分隔) */
ignored_ip_notification: string
/** [ServerID] -> bool(值为true代表当前ServerID在特定服务器列表内) */
ignored_ip_notification_server_ids: Record<string, boolean>
install_host: string
ip_change_notification_group_id: number
jwt_secret_key: string
/** 系统语言,默认 zh_CN */
language: string
listen_host: string
listen_port: number
/** 时区,默认为 Asia/Shanghai */
location: string
/** oauth2 配置 */
oauth2: Record<string, ModelOauth2Config>
/** oauth2 供应商列表,无需配置,自动生成 */
oauth2_providers: string[]
/** 真实IP */
real_ip_header: string
site_name: string
tls: boolean
user_template: string
}

export interface ModelCreateFMResponse {
session_id: string
}
Expand Down Expand Up @@ -463,20 +416,6 @@ export interface ModelNotificationGroupResponseItem {
notifications: number[]
}

export interface ModelOauth2Config {
client_id: string
client_secret: string
endpoint: ModelOauth2Endpoint
scopes: string[]
user_id_path: string
user_info_url: string
}

export interface ModelOauth2Endpoint {
auth_url: string
token_url: string
}

export interface ModelOauth2LoginResponse {
redirect: string
}
Expand Down Expand Up @@ -690,6 +629,43 @@ export interface ModelServiceResponseItem {
up: number[]
}

export interface ModelSetting {
admin_template: string
agent_secret_key: string
avg_ping_count: number
/** 覆盖范围(0:提醒未被 IgnoredIPNotification 包含的所有服务器; 1:仅提醒被 IgnoredIPNotification 包含的服务器;) */
cover: number
custom_code: string
custom_code_dashboard: string
/** debug模式开关 */
debug: boolean
dns_servers: string
/** IP变更提醒 */
enable_ip_change_notification: boolean
/** 通知信息IP不打码 */
enable_plain_ip_in_notification: boolean
/** 强制要求认证 */
force_auth: boolean
/** 特定服务器IP(多个服务器用逗号分隔) */
ignored_ip_notification: string
/** [ServerID] -> bool(值为true代表当前ServerID在特定服务器列表内) */
ignored_ip_notification_server_ids: Record<string, boolean>
install_host: string
ip_change_notification_group_id: number
/** 系统语言,默认 zh_CN */
language: string
/** 时区,默认为 Asia/Shanghai */
location: string
/** oauth2 供应商列表,无需配置,自动生成 */
oauth2_providers: string[]
/** 真实IP */
real_ip_header: string
site_name: string
/** 用于前端判断生成的安装命令是否启用 TLS */
tls: boolean
user_template: string
}

export interface ModelSettingForm {
cover: number
custom_code?: string
Expand All @@ -711,6 +687,12 @@ export interface ModelSettingForm {
user_template?: string
}

export interface ModelSettingResponse {
config: ModelSetting
frontend_templates: ModelFrontendTemplate[]
version: string
}

export interface ModelStreamServer {
country_code: string
/** 展示排序,越大越靠前 */
Expand Down

0 comments on commit 1ee664f

Please sign in to comment.