/* * AgentMail 鸿蒙客户端 — 日历 API * GET /calendar/events?from=&to= * * 与 WebUI 同源同参(`client/electron/src/api/client.ts` 的 listCalendarEvents): * from/to 是 **RFC3339 区间**,服务端按 `event_time` 落在区间内筛。 * * 区间必须按**网格**算,不是按月首月末算 —— 月视图首尾会显示上/下月的格子, * 只查当月会让那几个格子永远空着(看着像"那天没事件",其实是没查)。 */ import { ApiClient } from './ApiClient'; import { CalendarListResponse, CalendarEvent, CalendarEventInput, CalendarDeleteResponse } from '../model/Models'; export class CalendarApi { private client: ApiClient; constructor(client: ApiClient) { this.client = client; } /** * 列区间内的事件。 * * `from`/`to` 走 `encodeURIComponent`:RFC3339 里的 `+08:00` 若不编码, * 查询串里的 `+` 会被服务端解成空格,`time.Parse` 直接失败 ⇒ 静默返回空列表 * (界面表现为"这个月没有日程",而实际是参数被吃掉了)。 */ async listEvents(from: string, to: string): Promise { const query: string = 'from=' + encodeURIComponent(from) + '&to=' + encodeURIComponent(to); return this.client.get('/calendar/events', query); } /** * 新建日程。 * * 服务端在**建事件时**就校验收件地址("地址在这里就校验而不是等到触发时:建事件时报错 * 人能立刻改,而触发时报错只会进 journalctl")。所以这里的 400 必须**显示给用户**, * 不许吞成"保存失败"——错误文案("收件地址无法解析:…")是唯一能让人立刻改的东西。 */ async createEvent(input: CalendarEventInput): Promise { return this.client.post('/calendar/events', input); } /** 编辑日程(PUT 与 POST 同形,见 `CalendarEventInput` 的说明)。 */ async updateEvent(id: string, input: CalendarEventInput): Promise { return this.client.put('/calendar/events/' + encodeURIComponent(id), input); } /** 删除日程。 */ async deleteEvent(id: string): Promise { return this.client.del('/calendar/events/' + encodeURIComponent(id)); } }