From f53f43a6b9c7e3f6cc18126a8653ff43d3f104df Mon Sep 17 00:00:00 2001 From: xue jiahao Date: Thu, 12 Mar 2026 23:03:01 +0800 Subject: [PATCH] update main ts --- src/main/ipc-handlers.ts | 43 +++++----- src/main/kintone-api.ts | 78 +++++-------------- .../src/components/AppDetail/AppDetail.tsx | 8 +- src/shared/types/kintone.ts | 30 +------ 4 files changed, 48 insertions(+), 111 deletions(-) diff --git a/src/main/ipc-handlers.ts b/src/main/ipc-handlers.ts index 656e3ee..ca9742e 100644 --- a/src/main/ipc-handlers.ts +++ b/src/main/ipc-handlers.ts @@ -38,6 +38,7 @@ import type { DownloadMetadata, BackupMetadata, } from "@shared/types/version"; +import type { AppCustomizeResponse } from "@shared/types/kintone"; // Cache for Kintone clients const clientCache = new Map(); @@ -317,7 +318,7 @@ function registerDeploy(): void { const backupFileList: BackupMetadata["files"] = []; // Add JS files to backup - for (const js of appDetail.customization?.javascript?.pc || []) { + for (const js of appDetail.customization?.desktop?.js || []) { if (js.file?.fileKey) { const fileContent = await client.getFileContent(js.file.fileKey); const content = Buffer.from(fileContent.content || "", "base64"); @@ -334,7 +335,7 @@ function registerDeploy(): void { } // Add CSS files to backup - for (const css of appDetail.customization?.stylesheet?.pc || []) { + for (const css of appDetail.customization?.desktop?.css || []) { if (css.file?.fileKey) { const fileContent = await client.getFileContent(css.file.fileKey); const content = Buffer.from(fileContent.content || "", "base64"); @@ -349,7 +350,6 @@ function registerDeploy(): void { }); } } - // Save backup const backupMetadata: BackupMetadata = { backedUpAt: new Date().toISOString(), @@ -382,39 +382,40 @@ function registerDeploy(): void { // Build new customization config // Note: This is simplified - real implementation would merge with existing config - const newConfig = { - javascript: { - pc: uploadedFiles + const newConfig: AppCustomizeResponse = { + desktop: { + js: uploadedFiles .filter((f) => f.type === "js" && f.position.startsWith("pc_")) .map((f) => ({ type: "FILE" as const, file: { fileKey: f.fileKey }, })), - mobile: uploadedFiles - .filter((f) => f.type === "js" && f.position.startsWith("mobile_")) - .map((f) => ({ - type: "FILE" as const, - file: { fileKey: f.fileKey }, - })), - }, - stylesheet: { - pc: uploadedFiles + css: uploadedFiles .filter((f) => f.type === "css" && f.position === "pc_css") .map((f) => ({ type: "FILE" as const, file: { fileKey: f.fileKey }, })), - mobile: uploadedFiles + }, + mobile: { + js: uploadedFiles + .filter((f) => f.type === "js" && f.position.startsWith("mobile_")) + .map((f) => ({ + type: "FILE" as const, + file: { fileKey: f.fileKey }, + })), + css: uploadedFiles .filter((f) => f.type === "css" && f.position === "mobile_css") .map((f) => ({ type: "FILE" as const, file: { fileKey: f.fileKey }, })), }, + scope: "ALL", + revision: "-1", }; // Update app customization - await client.updateAppCustomize(params.appId, newConfig); // Deploy the changes await client.deployApp(params.appId); @@ -458,12 +459,12 @@ function registerDownload(): void { for (const fileType of fileTypes) { const files = fileType === "pc_js" - ? appDetail.customization?.javascript?.pc + ? appDetail.customization?.desktop?.js : fileType === "pc_css" - ? appDetail.customization?.stylesheet?.pc + ? appDetail.customization?.desktop?.css : fileType === "mobile_js" - ? appDetail.customization?.javascript?.mobile - : appDetail.customization?.stylesheet?.mobile; + ? appDetail.customization?.mobile?.js + : appDetail.customization?.mobile?.css; for (const file of files || []) { if (file.file?.fileKey) { diff --git a/src/main/kintone-api.ts b/src/main/kintone-api.ts index 0fd5865..9fdbb8d 100644 --- a/src/main/kintone-api.ts +++ b/src/main/kintone-api.ts @@ -3,11 +3,9 @@ import type { KintoneRestAPIError } from "@kintone/rest-api-client"; import type { DomainWithPassword } from "@shared/types/domain"; import type { AppResponse, - AppsResponse, AppCustomizeResponse, AppDetail, FileContent, - AppCustomizationConfig, KintoneApiError, FileConfig, } from "@shared/types/kintone"; @@ -82,34 +80,19 @@ export class SelfKintoneClient { } } - private mapResource( - resource: - | Awaited["desktop"]["js"][number] - | Awaited["desktop"]["css"][number], - ): FileConfig { - // Return SDK type directly - no conversion needed - return resource; - } - private buildCustomizeSection( - js?: FileConfig[], - css?: FileConfig[], - ): Parameters< - KintoneRestAPIClient["app"]["updateAppCustomize"] - >[0]["desktop"] { - if (!js && !css) return undefined; + files?: FileConfig[], + ): NonNullable< + Parameters[0]["desktop"] + >["js"] { + if (!files || files.length === 0) return undefined; - const mapItem = (item: FileConfig) => { + return files.map((item) => { if (item.type === "FILE" && item.file) { return { type: "FILE" as const, file: { fileKey: item.file.fileKey } }; } return { type: "URL" as const, url: item.url || "" }; - }; - - return { - js: js?.map(mapItem), - css: css?.map(mapItem), - }; + }); } // ==================== App APIs ==================== @@ -161,32 +144,9 @@ export class SelfKintoneClient { this.client.app.getAppCustomize({ app: appId }), ]); - const customization: AppCustomizationConfig = { - javascript: { - pc: customizeInfo.desktop.js?.map((js) => this.mapResource(js)) || [], - mobile: - customizeInfo.mobile.js?.map((js) => this.mapResource(js)) || [], - }, - stylesheet: { - pc: - customizeInfo.desktop.css?.map((css) => this.mapResource(css)) || - [], - mobile: - customizeInfo.mobile.css?.map((css) => this.mapResource(css)) || [], - }, - }; - return { - appId: appInfo.appId, - name: appInfo.name, - code: appInfo.code, - description: appInfo.description, - spaceId: appInfo.spaceId || undefined, - createdAt: appInfo.createdAt, - creator: appInfo.creator, - modifiedAt: appInfo.modifiedAt, - modifier: appInfo.modifier, - customization, + ...appInfo, + customization: customizeInfo, }; }); } @@ -226,20 +186,20 @@ export class SelfKintoneClient { async updateAppCustomize( appId: string, - config: AppCustomizationConfig, + config: AppCustomizeResponse, ): Promise { return this.withErrorHandling(async () => { await this.client.app.updateAppCustomize({ app: appId, - desktop: this.buildCustomizeSection( - config.javascript?.pc, - config.stylesheet?.pc, - ), - mobile: this.buildCustomizeSection( - config.javascript?.mobile, - config.stylesheet?.mobile, - ), - scope: "ALL", + desktop: { + js: this.buildCustomizeSection(config.desktop?.js), + css: this.buildCustomizeSection(config.desktop?.css), + }, + mobile: { + js: this.buildCustomizeSection(config.mobile?.js), + css: this.buildCustomizeSection(config.mobile?.css), + }, + scope: config.scope || "ALL", }); }); } diff --git a/src/renderer/src/components/AppDetail/AppDetail.tsx b/src/renderer/src/components/AppDetail/AppDetail.tsx index 6d376e9..5f9299e 100644 --- a/src/renderer/src/components/AppDetail/AppDetail.tsx +++ b/src/renderer/src/components/AppDetail/AppDetail.tsx @@ -282,7 +282,7 @@ const AppDetail: React.FC = () => { key: "pc-js", label: "PC端 JS", children: renderFileList( - currentApp.customization?.javascript?.pc, + currentApp.customization?.desktop?.js, "js", ), }, @@ -290,7 +290,7 @@ const AppDetail: React.FC = () => { key: "pc-css", label: "PC端 CSS", children: renderFileList( - currentApp.customization?.stylesheet?.pc, + currentApp.customization?.desktop?.css, "css", ), }, @@ -298,7 +298,7 @@ const AppDetail: React.FC = () => { key: "mobile-js", label: "移动端 JS", children: renderFileList( - currentApp.customization?.javascript?.mobile, + currentApp.customization?.mobile?.js, "js", ), }, @@ -306,7 +306,7 @@ const AppDetail: React.FC = () => { key: "mobile-css", label: "移动端 CSS", children: renderFileList( - currentApp.customization?.stylesheet?.mobile, + currentApp.customization?.mobile?.css, "css", ), }, diff --git a/src/shared/types/kintone.ts b/src/shared/types/kintone.ts index d08358f..8f5560e 100644 --- a/src/shared/types/kintone.ts +++ b/src/shared/types/kintone.ts @@ -12,19 +12,11 @@ type KintoneClient = KintoneRestAPIClient; /** App response from getApp/getApps */ export type AppResponse = Awaited>; -/** Apps list response */ -export type AppsResponse = Awaited>; - /** App customization response */ export type AppCustomizeResponse = Awaited< ReturnType >; -/** File upload response */ -export type FileUploadResponse = Awaited< - ReturnType ->; - // ==================== Custom Business Types ==================== // These types represent business-layer aggregation or additional metadata @@ -33,7 +25,7 @@ export type FileUploadResponse = Awaited< * This is a business-layer type that aggregates data from multiple API calls */ export interface AppDetail extends AppResponse { - customization?: AppCustomizationConfig; + customization?: AppCustomizeResponse; } /** @@ -48,27 +40,11 @@ export interface FileContent { content?: string; // Base64 encoded or text } -/** - * App customization config - * Uses SDK's customize types structure (desktop/mobile) but simplified for internal use - * Note: SDK uses { js: [], css: [] } but we use { javascript: { pc, mobile } } for easier UI binding - */ -export interface AppCustomizationConfig { - javascript?: { - pc?: FileConfig[]; - mobile?: FileConfig[]; - }; - stylesheet?: { - pc?: FileConfig[]; - mobile?: FileConfig[]; - }; -} - -/** + /** * File config for customization * Using SDK's type directly from AppCustomizeResponse */ -export type FileConfig = Awaited["desktop"]["js"][number]; +export type FileConfig = NonNullable[number]; /** * API Error - simplified from SDK's KintoneRestAPIError