Merge branch 'fix8'
Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
commit
9ef2e8554c
39 files changed
+1175
-232
No files matched your search
@@ -264,7 +264,7 @@ const HttpUrl = z
|
||||
export const BrowserProviderCreate = z.object({
|
||||
name: z.string().min(1).max(64),
|
||||
baseUrl: HttpUrl,
|
||||
accessKey: z.string().min(1).max(512).optional(),
|
||||
accessKey: z.string().max(512).optional(),
|
||||
enabled: z.boolean().optional(),
|
||||
});
|
||||
export type BrowserProviderCreate = z.infer<typeof BrowserProviderCreate>;
|
||||
@@ -272,7 +272,8 @@ export type BrowserProviderCreate = z.infer<typeof BrowserProviderCreate>;
|
||||
/** 改地址 / 凭据 / 启用;accessKey = null 清除凭据 */
|
||||
export const BrowserProviderUpdate = z.object({
|
||||
baseUrl: HttpUrl.optional(),
|
||||
accessKey: z.string().min(1).max(512).nullable().optional(),
|
||||
/** 省略或空串 = 不变 */
|
||||
accessKey: z.string().max(512).nullable().optional(),
|
||||
enabled: z.boolean().optional(),
|
||||
});
|
||||
export type BrowserProviderUpdate = z.infer<typeof BrowserProviderUpdate>;
|
||||
|
||||
@@ -8,6 +8,21 @@ export type Id = z.infer<typeof Id>;
|
||||
export const Timestamp = z.iso.datetime({ offset: true });
|
||||
export type Timestamp = z.infer<typeof Timestamp>;
|
||||
|
||||
/**
|
||||
* 只写凭证输入(API Key、密码、Cookie、令牌)。全站统一语义:
|
||||
* 省略或空串(含纯空白)= 保持原值;null = 清除(只在允许清除的更新接口上);非空 = 替换。
|
||||
* 明文只在请求里出现,服务端加密为 secret 后丢弃,响应只给是否已设置(和个别接口的掩码)。
|
||||
*/
|
||||
export const WriteOnlySecret = (max = 4096) => z.string().max(max);
|
||||
|
||||
/** 归一只写凭证输入:空串 → undefined(不改);null 原样(清除);其余去首尾空白 */
|
||||
export function secretInput(v: string | null | undefined): string | null | undefined {
|
||||
if (v === null) return null;
|
||||
if (v === undefined) return undefined;
|
||||
const s = v.trim();
|
||||
return s === "" ? undefined : s;
|
||||
}
|
||||
|
||||
/** 游标分页请求:cursor 为不透明字符串,由服务端编码 */
|
||||
export const CursorQuery = z.object({
|
||||
cursor: z.string().min(1).optional(),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { z } from "zod";
|
||||
import { EntityBase, Id, JsonObject, SERVER_MANAGED, Timestamp } from "./common.ts";
|
||||
import { EntityBase, Id, JsonObject, SERVER_MANAGED, Timestamp, WriteOnlySecret } from "./common.ts";
|
||||
import { SiteCredentialsBody } from "./sources.ts";
|
||||
|
||||
// 实例域:媒体库根、下载器实例、媒体服务器实例、路径映射(REQ §7.1、§8.4、§12.5)
|
||||
@@ -44,8 +44,8 @@ export type LibraryRootCreate = z.infer<typeof LibraryRootCreate>;
|
||||
export const LibraryRootUpdate = LibraryRootCreate.partial();
|
||||
export type LibraryRootUpdate = z.infer<typeof LibraryRootUpdate>;
|
||||
|
||||
/** 只写凭证:明文仅在请求中出现,绝不回显 */
|
||||
const Credential = z.string().min(1).max(4096);
|
||||
/** 只写凭证:明文仅在请求中出现,绝不回显;空串 = 不设置 / 不修改 */
|
||||
const Credential = WriteOnlySecret(4096);
|
||||
|
||||
export const DownloaderKind = z.enum(["qbittorrent"]);
|
||||
export type DownloaderKind = z.infer<typeof DownloaderKind>;
|
||||
@@ -91,7 +91,10 @@ export const DownloaderInstanceCreate = DownloaderInstance.pick({
|
||||
authKind: DownloaderAuthKind.optional(),
|
||||
});
|
||||
export type DownloaderInstanceCreate = z.infer<typeof DownloaderInstanceCreate>;
|
||||
export const DownloaderInstanceUpdate = DownloaderInstanceCreate.partial();
|
||||
/** 更新:credential 省略或空串 = 不变,null = 清除 */
|
||||
export const DownloaderInstanceUpdate = DownloaderInstanceCreate.partial().extend({
|
||||
credential: Credential.nullable().optional(),
|
||||
});
|
||||
export type DownloaderInstanceUpdate = z.infer<typeof DownloaderInstanceUpdate>;
|
||||
|
||||
export const MediaServerKind = z.enum(["emby", "jellyfin"]);
|
||||
@@ -121,7 +124,10 @@ export const MediaServerInstanceCreate = MediaServerInstance.pick({
|
||||
.partial({ kind: true, userId: true, enabled: true, settings: true })
|
||||
.extend({ credential: Credential.optional() });
|
||||
export type MediaServerInstanceCreate = z.infer<typeof MediaServerInstanceCreate>;
|
||||
export const MediaServerInstanceUpdate = MediaServerInstanceCreate.partial();
|
||||
/** 更新:credential 省略或空串 = 不变,null = 清除 */
|
||||
export const MediaServerInstanceUpdate = MediaServerInstanceCreate.partial().extend({
|
||||
credential: Credential.nullable().optional(),
|
||||
});
|
||||
export type MediaServerInstanceUpdate = z.infer<typeof MediaServerInstanceUpdate>;
|
||||
|
||||
export const PathViewKind = z.enum(["downloader", "media_server"]);
|
||||
@@ -191,7 +197,7 @@ export const SiteCredentialsLegacyPut = z.object({
|
||||
label: z.string().min(1).max(80).default("default"),
|
||||
authKind: z.enum(["cookie", "passkey", "api_key", "password"]),
|
||||
/** 只写明文 */
|
||||
credential: Credential,
|
||||
credential: z.string().min(1).max(4096),
|
||||
/** authKind=password 时的登录名 */
|
||||
username: z.string().max(200).optional(),
|
||||
enabled: z.boolean().optional(),
|
||||
|
||||
@@ -100,7 +100,7 @@ export const PiUpstreamExtra = z
|
||||
compat: z.record(z.string(), z.unknown()).optional(),
|
||||
headers: z.record(z.string().min(1).max(128), z.string().max(2048)).optional(),
|
||||
/** 自定义模型的上下文窗口(openai-compatible) */
|
||||
contextWindow: z.number().int().min(1024).max(10_000_000).optional(),
|
||||
contextWindow: z.number().int().min(1000).max(10_000_000).optional(),
|
||||
note: z.string().max(500).optional(),
|
||||
})
|
||||
.strict();
|
||||
@@ -226,7 +226,8 @@ export const PiUpstreamList = z.object({
|
||||
});
|
||||
export type PiUpstreamList = z.infer<typeof PiUpstreamList>;
|
||||
|
||||
const ApiKeyInput = z.string().min(1).max(8192);
|
||||
/** 只写;空串 = 不设置 / 不修改 */
|
||||
const ApiKeyInput = z.string().max(8192);
|
||||
|
||||
/** 新建上游。apiKey 只写(存 secret 表);oauth 型建好后走 /oauth/start 登录 */
|
||||
export const PiUpstreamCreate = z
|
||||
@@ -244,7 +245,7 @@ export const PiUpstreamCreate = z
|
||||
makeDefault: z.boolean().optional(),
|
||||
})
|
||||
.superRefine((v, ctx) => {
|
||||
if (v.authKind !== "api_key" && v.apiKey !== undefined)
|
||||
if (v.authKind !== "api_key" && v.apiKey?.trim())
|
||||
ctx.addIssue({ code: "custom", path: ["apiKey"], message: "只有 api_key 型模型服务可以填 apiKey" });
|
||||
if (v.authKind === "oauth" && v.baseUrl)
|
||||
ctx.addIssue({ code: "custom", path: ["baseUrl"], message: "订阅登录型模型服务不能覆盖 baseUrl" });
|
||||
|
||||
@@ -86,7 +86,7 @@ export const PiSettings = z.object({
|
||||
/** @deprecated 上游级 thinkingLevel 见 pi_upstream */
|
||||
thinkingLevel: ThinkingLevel,
|
||||
/** 上下文预算(token) */
|
||||
contextBudget: z.number().int().min(4096).max(2_000_000),
|
||||
contextBudget: z.number().int().min(4000).max(2_000_000),
|
||||
compaction: z.object({
|
||||
enabled: z.boolean(),
|
||||
/** 达到上下文预算的该比例时触发压缩 */
|
||||
@@ -675,8 +675,8 @@ export const GlobalSettingsUpdate = z.object({
|
||||
webSearch: WebSearchSettings.omit({ apiKeySecretRef: true })
|
||||
.partial()
|
||||
.extend({
|
||||
/** 只写:搜索服务 API Key,服务端存为 secret 并回填 apiKeySecretRef;null 清除 */
|
||||
apiKey: z.string().min(1).max(4096).nullable().optional(),
|
||||
/** 只写:搜索服务 API Key,服务端存为 secret 并回填 apiKeySecretRef;空串不变,null 清除 */
|
||||
apiKey: z.string().max(4096).nullable().optional(),
|
||||
})
|
||||
.optional(),
|
||||
})
|
||||
@@ -684,8 +684,8 @@ export const GlobalSettingsUpdate = z.object({
|
||||
metadata: MetadataSettings.omit({ tmdbApiKeySecretRef: true })
|
||||
.partial()
|
||||
.extend({
|
||||
/** 只写:TMDB API Key(v3 key 或 v4 read token),服务端存为 secret 并回填 tmdbApiKeySecretRef;null 清除 */
|
||||
tmdbApiKey: z.string().min(1).max(4096).nullable().optional(),
|
||||
/** 只写:TMDB API Key(v3 key 或 v4 read token),服务端存为 secret 并回填 tmdbApiKeySecretRef;空串不变,null 清除 */
|
||||
tmdbApiKey: z.string().max(4096).nullable().optional(),
|
||||
})
|
||||
.optional(),
|
||||
sites: SitesSettings.partial().optional(),
|
||||
|
||||
@@ -186,19 +186,22 @@ export type SiteHealthResult = z.infer<typeof SiteHealthResult>;
|
||||
|
||||
const CredLabel = z.string().min(1).max(80).default("default");
|
||||
const CredSecret = z.string().min(1).max(16384);
|
||||
/** 已有同类账号时可省略或留空 = 保持已存的值(只写凭证统一语义);新账号或换类型时必填 */
|
||||
const CredSecretKeep = z.string().max(16384).optional();
|
||||
const CredUa = z.string().min(1).max(500);
|
||||
/**
|
||||
* PUT /sites/{id}/credentials 新格式(按 kind 判别)。按 (siteId, label) 建立或更新账号;明文加密为 secret,不回显。
|
||||
* 更新凭证:账号回到 unknown,关闭该站 site-auth / site-login 待处理。
|
||||
* 同类账号更新时 password / cookie / apiKey 省略或空串 = 保持原值;totpSecret 省略或空串 = 保持,null = 清除。
|
||||
*/
|
||||
export const SiteCredentialsBody = z.discriminatedUnion("kind", [
|
||||
z.object({
|
||||
kind: z.literal("password"),
|
||||
label: CredLabel,
|
||||
username: z.string().min(1).max(200),
|
||||
password: CredSecret,
|
||||
password: CredSecretKeep,
|
||||
/** TOTP 密钥(base32);表单有二次验证字段时自动填当前 6 位码 */
|
||||
totpSecret: z.string().min(1).max(200).optional(),
|
||||
totpSecret: z.string().max(200).nullable().optional(),
|
||||
/** 只换 Cookie:登录成功后凭证类型落为 cookie,密码与 TOTP 丢弃 */
|
||||
saveCookieOnly: z.boolean().optional(),
|
||||
userAgent: CredUa.optional(),
|
||||
@@ -207,11 +210,11 @@ export const SiteCredentialsBody = z.discriminatedUnion("kind", [
|
||||
z.object({
|
||||
kind: z.literal("cookie"),
|
||||
label: CredLabel,
|
||||
cookie: CredSecret,
|
||||
cookie: CredSecretKeep,
|
||||
userAgent: CredUa.optional(),
|
||||
enabled: z.boolean().optional(),
|
||||
}),
|
||||
z.object({ kind: z.literal("api_key"), label: CredLabel, apiKey: CredSecret, enabled: z.boolean().optional() }),
|
||||
z.object({ kind: z.literal("api_key"), label: CredLabel, apiKey: CredSecretKeep, enabled: z.boolean().optional() }),
|
||||
/** passkey 附加到同账号(RSS / 下载用,不参与登录);账号不存在时新建 passkey 型账号 */
|
||||
z.object({ kind: z.literal("passkey"), label: CredLabel, passkey: CredSecret, enabled: z.boolean().optional() }),
|
||||
]);
|
||||
|
||||
Reference in new issue
Block a user