types.ts

3.7 KB v1.0
// 前后端共享的数据结构定义
export type Language = 'zh' | 'en';
export type ThemeMode = 'light' | 'dark' | 'system';
export type Density = 'comfortable' | 'compact';
export type FontFamily = 'sans' | 'serif';
export type ContentWidth = 'narrow' | 'standard' | 'wide' | 'full';
export type Folder = 'inbox' | 'sent' | 'drafts' | 'trash';
export type SettingsSection =
  | 'appearance'
  | 'accounts'
  | 'backup'
  | 'editor'
  | 'account'
  | 'sync'
  | 'notifications'
  | 'about';

export interface AppearanceSettings {
  language: Language;
  theme: ThemeMode;
  accent: string;
  density: Density;
  fontFamily: FontFamily;
  fontSize: number;
  lineHeight: number;
  contentWidth: ContentWidth;
}

export interface SyncSettings {
  rangeDays: number;
  folderLimit: number;
  autoEnabled: boolean;
  intervalMinutes: number;
}

export interface EditorSettings {
  signature: string;
  fontFamily: FontFamily;
  fontSize: number;
  lineHeight: number;
  defaultAccountId: number | null;
}

export interface BackupSettings {
  webdavUrl: string;
  webdavUsername: string;
  hasWebdavPassword?: boolean;
  remotePath: string;
  autoEnabled: boolean;
  intervalHours: number;
  includeBodies: boolean;
  includeAttachments: boolean;
  days: number;
  accountIds: number[];
  lastBackupAt: number | null;
}

export interface NotificationSettings {
  enabled: boolean;
  hasBotToken?: boolean;
  hasChatId?: boolean;
}

export interface AppSettings {
  appearance: AppearanceSettings;
  sync: SyncSettings;
  editor: EditorSettings;
  backup: BackupSettings;
  notifications: NotificationSettings;
}

export interface User {
  id: number;
  username: string;
  role: 'admin' | 'user';
  disabled: boolean;
  createdAt: number;
}

export interface Account {
  id: number;
  name: string;
  email: string;
  imapHost: string;
  imapPort: number;
  imapSecure: boolean;
  smtpHost: string;
  smtpPort: number;
  smtpSecure: boolean;
  username: string;
  color: string;
  createdAt: number;
  lastSyncAt: number | null;
  syncError: string | null;
  syncing: boolean;
  hasPassword: boolean;
  unread: number;
}

export interface AccountInput {
  id?: number;
  name: string;
  email: string;
  imapHost: string;
  imapPort: number;
  imapSecure: boolean;
  smtpHost: string;
  smtpPort: number;
  smtpSecure: boolean;
  username: string;
  password: string;
  color: string;
}

export interface AttachmentMeta {
  id: number;
  filename: string;
  mime: string;
  size: number;
}

export interface MessageSummary {
  id: number;
  accountId: number;
  folder: Folder;
  subject: string;
  fromName: string;
  fromAddr: string;
  toAddrs: string;
  date: number;
  snippet: string;
  seen: boolean;
  hasAttachments: boolean;
  size: number;
}

export interface MessageDetail extends MessageSummary {
  prevFolder: string | null;
  messageId: string;
  ccAddrs: string;
  bccAddrs: string;
  bodyText: string;
  bodyHtml: string;
  attachments: AttachmentMeta[];
}

export interface FolderCounts {
  inbox: { total: number; unread: number };
  sent: { total: number; unread: number };
  drafts: { total: number; unread: number };
  trash: { total: number; unread: number };
}

export interface RemoteBackupFile {
  name: string;
  size: number;
  lastModified: number | null;
  isCollection: boolean;
}

export interface SyncAccountStatus {
  id: number;
  name: string;
  email: string;
  lastSyncAt: number | null;
  syncError: string | null;
}

export interface ComposeAttachment {
  filename: string;
  mime: string;
  size: number;
  data: string; // base64,不含 data: 前缀
}

export interface DraftData {
  id: number;
  accountId: number;
  subject: string;
  to: string;
  cc: string;
  bcc: string;
  bodyText: string;
  attachments: AttachmentMeta[];
}