修复了部分日程没有提醒时间的问题。
This commit is contained in:
@@ -126,9 +126,11 @@ export class AccountStore {
|
||||
const store: preferences.Preferences =
|
||||
await preferences.getPreferences(context, AccountStore.STORE);
|
||||
const count: number = await store.get(AccountStore.COUNT_KEY, 0) as number;
|
||||
console.info(`[AccountStore] loadAll: count=${count}`);
|
||||
for (let i = 0; i < count; i++) {
|
||||
const raw = await store.get(`acc_${i}`, '') as string;
|
||||
if (raw === '') {
|
||||
console.warn(`[AccountStore] loadAll: acc_${i} 为空`);
|
||||
continue;
|
||||
}
|
||||
const acc = AccountStore.decodeAccount(raw);
|
||||
@@ -139,6 +141,8 @@ export class AccountStore {
|
||||
migrated = true;
|
||||
}
|
||||
result.push(acc);
|
||||
} else {
|
||||
console.error(`[AccountStore] loadAll: acc_${i} 解码失败,raw 长度=${raw.length}`);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
@@ -157,10 +161,19 @@ export class AccountStore {
|
||||
return result;
|
||||
}
|
||||
|
||||
static async saveAll(context: common.Context, accounts: DavAccount[]): Promise<void> {
|
||||
/**
|
||||
* 保存全部账号。
|
||||
* 防御:存储里已有账号时,禁止用空列表覆盖(调用方若因读取异常拿到空列表再回写,
|
||||
* 会把所有账号抹掉)。仅删除账号的合法场景通过 force=true 放行。
|
||||
*/
|
||||
static async saveAll(context: common.Context, accounts: DavAccount[], force: boolean = false): Promise<void> {
|
||||
const store: preferences.Preferences =
|
||||
await preferences.getPreferences(context, AccountStore.STORE);
|
||||
const oldCount: number = await store.get(AccountStore.COUNT_KEY, 0) as number;
|
||||
if (accounts.length === 0 && oldCount > 0 && !force) {
|
||||
console.error(`[AccountStore] 拒绝用空列表覆盖账号存储(原有 ${oldCount} 个账号)`);
|
||||
throw new Error('账号列表为空,已阻止覆盖存储(保护原有账号数据)');
|
||||
}
|
||||
for (let i = 0; i < oldCount; i++) {
|
||||
store.delete(`acc_${i}`);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import { preferences } from '@kit.ArkData';
|
||||
import { common } from '@kit.AbilityKit';
|
||||
import { BusinessError } from '@kit.BasicServicesKit';
|
||||
import { LogUtil } from './LogUtil';
|
||||
|
||||
export class AppSettings {
|
||||
private static readonly STORE: string = 'sync_settings';
|
||||
@@ -12,6 +13,50 @@ export class AppSettings {
|
||||
private static readonly KEY_SYS_MODE: string = 'sys_cal_mode'; // 'display' | 'backup'
|
||||
private static readonly KEY_BACKUP_KEY: string = 'sys_backup_cal_key'; // 备份目标 DAV 日历本
|
||||
private static readonly KEY_MANUAL_READONLY: string = 'manual_readonly_keys'; // 手动标记只读的 calKey
|
||||
private static readonly KEY_FULL_REFETCH: string = 'full_refetch_done'; // 一次性全量重拉已完成
|
||||
|
||||
/**
|
||||
* 是否还需要一次性全量重拉:修复历史同步(REPORT 剥离 VALARM 时期)落库的残缺数据。
|
||||
* 全量重拉期间忽略 etag 复用,所有资源 GET 完整 ICS;成功完成后标记,恢复增量模式。
|
||||
*/
|
||||
static async isFullRefetchPending(context: common.Context): Promise<boolean> {
|
||||
try {
|
||||
const store: preferences.Preferences =
|
||||
await preferences.getPreferences(context, AppSettings.STORE);
|
||||
return !(await store.get(AppSettings.KEY_FULL_REFETCH, false) as boolean);
|
||||
} catch (err) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
static async markFullRefetchDone(context: common.Context): Promise<void> {
|
||||
try {
|
||||
const store: preferences.Preferences =
|
||||
await preferences.getPreferences(context, AppSettings.STORE);
|
||||
await store.put(AppSettings.KEY_FULL_REFETCH, true);
|
||||
await store.flush();
|
||||
} catch (err) {
|
||||
const e = err as BusinessError;
|
||||
console.error(`标记全量重拉完成失败: ${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动重置全量重拉标记:下次同步忽略 etag 复用,所有资源 GET 完整 ICS 重建本地数据。
|
||||
* 用于修复历史落库的残缺字段(如 reminder=0 但 etag 从未变化,增量同步永远无法纠正)。
|
||||
*/
|
||||
static async resetFullRefetch(context: common.Context): Promise<void> {
|
||||
try {
|
||||
const store: preferences.Preferences =
|
||||
await preferences.getPreferences(context, AppSettings.STORE);
|
||||
await store.put(AppSettings.KEY_FULL_REFETCH, false);
|
||||
await store.flush();
|
||||
LogUtil.write('已重置全量重拉标记:下次同步将 GET 全部资源重建本地数据');
|
||||
} catch (err) {
|
||||
const e = err as BusinessError;
|
||||
console.error(`重置全量重拉标记失败: ${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动标记为只读的日历本 calKey 列表。
|
||||
|
||||
@@ -110,6 +110,28 @@ export class DavClient {
|
||||
return 'Basic ' + buffer.from(`${username}:${password}`).toString('base64');
|
||||
}
|
||||
|
||||
/** GET 拉取单个资源的原始 ICS(调试诊断用) */
|
||||
static async getRaw(url: string, auth: string): Promise<string> {
|
||||
const httpRequest = http.createHttp();
|
||||
try {
|
||||
const resp: http.HttpResponse = await httpRequest.request(url, {
|
||||
method: http.RequestMethod.GET,
|
||||
header: {
|
||||
'Authorization': auth,
|
||||
'User-Agent': 'SyncCalendar/1.0'
|
||||
},
|
||||
connectTimeout: 10000,
|
||||
readTimeout: 15000
|
||||
});
|
||||
if (resp.responseCode >= 200 && resp.responseCode < 300) {
|
||||
return resp.result as string;
|
||||
}
|
||||
return `HTTP ${resp.responseCode}`;
|
||||
} finally {
|
||||
httpRequest.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 写权限探测:向日历本 PUT 一个探测资源——
|
||||
* 2xx → 可写(随后删除探测资源);403/401 等 → 只读;网络异常 → 乐观按可写。
|
||||
@@ -170,6 +192,58 @@ export class DavClient {
|
||||
return DavClient.reportComponents(href, auth, 'VEVENT', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* REPORT calendar-query:仅拉取 href + getetag(不含 calendar-data)。
|
||||
* 部分服务器(如群晖)的 REPORT calendar-data 会剥离 VALARM 导致提醒丢失,
|
||||
* 因此数据改为对变更资源逐个 GET 补拉(GET 返回完整 ICS)。
|
||||
*/
|
||||
static async reportEtags(href: string, auth: string): Promise<RemoteItem[]> {
|
||||
const body: string = '<?xml version="1.0" encoding="utf-8"?>' +
|
||||
'<c:calendar-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">' +
|
||||
'<d:prop><d:getetag/></d:prop>' +
|
||||
'<c:filter><c:comp-filter name="VCALENDAR">' +
|
||||
'<c:comp-filter name="VEVENT">' +
|
||||
'</c:comp-filter></c:comp-filter></c:filter></c:calendar-query>';
|
||||
const httpRequest = http.createHttp();
|
||||
try {
|
||||
const resp: http.HttpResponse = await httpRequest.request(href, {
|
||||
method: 'REPORT' as http.RequestMethod,
|
||||
header: {
|
||||
'Authorization': auth,
|
||||
'Content-Type': 'application/xml; charset=utf-8',
|
||||
'Depth': '1',
|
||||
'User-Agent': 'SyncCalendar/1.0'
|
||||
},
|
||||
extraData: body,
|
||||
connectTimeout: 10000,
|
||||
readTimeout: 30000
|
||||
});
|
||||
LogUtil.write(`HTTP REPORT(etag) ${href} → ${resp.responseCode}`);
|
||||
if (resp.responseCode < 200 || resp.responseCode >= 300) {
|
||||
throw new Error(`服务器返回状态码 ${resp.responseCode}`);
|
||||
}
|
||||
const xml: string = resp.result as string;
|
||||
const items: RemoteItem[] = [];
|
||||
const blocks: string[] = xml.split(/<\/[\w-]*:?response>/i);
|
||||
for (const block of blocks) {
|
||||
if (!/<[\w-]*:?response[\s>]/i.test(block)) {
|
||||
continue;
|
||||
}
|
||||
const resHref: string = DavClient.extractTag(block, 'href');
|
||||
if (resHref === '') {
|
||||
continue;
|
||||
}
|
||||
const item = new RemoteItem();
|
||||
item.href = resHref;
|
||||
item.etag = DavClient.extractTag(block, 'getetag').replace(/"/g, '');
|
||||
items.push(item);
|
||||
}
|
||||
return items;
|
||||
} finally {
|
||||
httpRequest.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
/** REPORT calendar-query:拉取某日历本内所有 VTODO 待办(不限时间范围,量小) */
|
||||
static async reportTodos(href: string, auth: string): Promise<RemoteItem[]> {
|
||||
return DavClient.reportComponents(href, auth, 'VTODO', '');
|
||||
|
||||
@@ -409,6 +409,23 @@ export class EventDb {
|
||||
return `新增${added} 更新${updated} 删除${removed} 不变${unchanged}`;
|
||||
}
|
||||
|
||||
/** 查询某日历本下同类型的全部行(同步 etag 比对用,含 dirty 行) */
|
||||
static async queryByCalKey(context: common.Context, calKey: string, kind: string): Promise<LocalEvent[]> {
|
||||
const store = await EventDb.getDb(context);
|
||||
const predicates = new relationalStore.RdbPredicates('events');
|
||||
predicates.equalTo('cal_key', calKey).and().equalTo('kind', kind);
|
||||
const rs = await store.query(predicates);
|
||||
const list: LocalEvent[] = [];
|
||||
try {
|
||||
while (rs.goToNextRow()) {
|
||||
list.push(EventDb.fromRow(rs));
|
||||
}
|
||||
} finally {
|
||||
rs.close();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/** 按 UID 判断事件是否已存在(系统日历备份导入的幂等判重) */
|
||||
static async uidExists(context: common.Context, uid: string): Promise<boolean> {
|
||||
const store = await EventDb.getDb(context);
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
// entry/src/main/ets/common/ScreenKeeper.ets
|
||||
// 同步期间保持屏幕常亮:鸿蒙熄屏后应用进程会被挂起,网络请求停摆导致同步超时。
|
||||
// 引用计数支持多处同步(首页/账号页/后台入口)叠加,最后一个释放时才恢复熄屏。
|
||||
import { window } from '@kit.ArkUI';
|
||||
import { common } from '@kit.AbilityKit';
|
||||
|
||||
export class ScreenKeeper {
|
||||
private static count: number = 0;
|
||||
|
||||
/** 同步开始时调用:保持屏幕常亮(失败静默,不影响同步) */
|
||||
static async acquire(context: common.UIAbilityContext): Promise<void> {
|
||||
ScreenKeeper.count++;
|
||||
try {
|
||||
const win = await window.getLastWindow(context);
|
||||
await win.setWindowKeepScreenOn(true);
|
||||
} catch (err) {
|
||||
// 获取窗口失败(如页面已销毁)不影响同步
|
||||
}
|
||||
}
|
||||
|
||||
/** 同步结束时调用:恢复系统默认熄屏策略 */
|
||||
static async release(context: common.UIAbilityContext): Promise<void> {
|
||||
ScreenKeeper.count = Math.max(0, ScreenKeeper.count - 1);
|
||||
if (ScreenKeeper.count > 0) {
|
||||
return; // 还有其他同步在进行,保持常亮
|
||||
}
|
||||
try {
|
||||
const win = await window.getLastWindow(context);
|
||||
await win.setWindowKeepScreenOn(false);
|
||||
} catch (err) {
|
||||
// 忽略
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,16 @@ import { BusinessError } from '@kit.BasicServicesKit';
|
||||
import { DavAccount } from './AccountStore';
|
||||
import { EventDb, LocalEvent, RemoteEvent } from './EventDb';
|
||||
import { IcsUtil } from './IcsUtil';
|
||||
import { DavClient, DavColorEntry } from './DavClient';
|
||||
import { DavClient, DavColorEntry, RemoteItem } from './DavClient';
|
||||
import { LogUtil } from './LogUtil';
|
||||
import { AppSettings } from './AppSettings';
|
||||
|
||||
export class SyncEngine {
|
||||
/** 正在同步中的账号 id → 开始时间:防止超时后的"僵尸同步"与新一轮同步并发写库 */
|
||||
private static activeSyncs: Map<string, number> = new Map();
|
||||
/** 互斥锁最长持有时间:超过视为异常残留(如进程挂起后网络停摆),允许抢占 */
|
||||
private static readonly LOCK_STALE_MS: number = 15 * 60 * 1000;
|
||||
|
||||
/**
|
||||
* 给异步操作加超时保护,防止网络挂起导致界面一直转圈
|
||||
*/
|
||||
@@ -26,11 +32,28 @@ export class SyncEngine {
|
||||
* 返回远端事件总数(拉取侧)。带 120 秒超时保护。
|
||||
*/
|
||||
static async syncAccount(context: common.Context, acc: DavAccount): Promise<number> {
|
||||
// 同一账号互斥:超时被掐断后内层任务仍在后台运行,期间不允许再次同步该账号。
|
||||
// 锁超过 LOCK_STALE_MS 未释放(如熄屏挂起导致任务冻结)则视为残留,允许抢占
|
||||
const heldSince: number | undefined = SyncEngine.activeSyncs.get(acc.id);
|
||||
if (heldSince !== undefined) {
|
||||
if (Date.now() - heldSince < SyncEngine.LOCK_STALE_MS) {
|
||||
throw new Error('该账号正在同步中,请稍后再试');
|
||||
}
|
||||
LogUtil.write(`同步互斥锁超时残留(${acc.name}),强制释放并重新同步`);
|
||||
}
|
||||
SyncEngine.activeSyncs.set(acc.id, Date.now());
|
||||
const t0: number = Date.now();
|
||||
LogUtil.write(`========== 同步账号「${acc.name}」开始:服务器 ${acc.serverUrl},共 ${acc.calendarHrefs.length} 个日历本 ==========`);
|
||||
try {
|
||||
const r: number = await SyncEngine.withTimeout<number>(
|
||||
SyncEngine.syncAccountInner(context, acc), 120000);
|
||||
// 全量重拉(升级后首次)要逐个 GET 所有资源,放宽超时到 10 分钟;常规 5 分钟
|
||||
const fullRefetch: boolean = await AppSettings.isFullRefetchPending(context);
|
||||
const timeoutMs: number = fullRefetch ? 600000 : 300000;
|
||||
// 内层任务真正结束(无论成败)才释放互斥锁;超时后它仍会在后台跑完
|
||||
const inner: Promise<number> = SyncEngine.syncAccountInner(context, acc);
|
||||
inner.catch((): void => {}).finally((): void => {
|
||||
SyncEngine.activeSyncs.delete(acc.id);
|
||||
});
|
||||
const r: number = await SyncEngine.withTimeout<number>(inner, timeoutMs);
|
||||
LogUtil.write(`同步账号「${acc.name}」完成:拉取 ${r} 条日程,耗时 ${Math.round((Date.now() - t0) / 1000)} 秒`);
|
||||
return r;
|
||||
} catch (err) {
|
||||
@@ -46,7 +69,14 @@ export class SyncEngine {
|
||||
await SyncEngine.refreshCalendarColors(acc, auth);
|
||||
// 1) 推送该账号日历本下的本地修改
|
||||
await SyncEngine.pushDirtyForAccount(context, acc, auth);
|
||||
// 2) 拉取远端变更(全量 REPORT,etag 增量落库)
|
||||
// 2) 拉取远端变更:REPORT 仅取 etag;新增/变化的资源用 GET 补拉完整 ICS。
|
||||
// 原因:群晖等服务器的 REPORT calendar-data 会剥离 VALARM(提醒丢失),
|
||||
// 而 GET 返回完整 ICS;etag 未变的资源直接复用本地完整数据,几乎零开销。
|
||||
// 首次升级后执行一次全量重拉,修复旧模式落库的残缺数据(如 reminder=0)。
|
||||
const fullRefetch: boolean = await AppSettings.isFullRefetchPending(context);
|
||||
if (fullRefetch) {
|
||||
LogUtil.write('一次性全量重拉:忽略 etag 复用,全部资源 GET 完整 ICS');
|
||||
}
|
||||
let changed: number = 0;
|
||||
for (let i = 0; i < acc.calendarHrefs.length; i++) {
|
||||
const href: string = acc.calendarHrefs[i];
|
||||
@@ -54,36 +84,82 @@ export class SyncEngine {
|
||||
const calName: string = i < acc.calendarNames.length ? acc.calendarNames[i] : `日历本${i}`;
|
||||
LogUtil.write(`日历本[${i}]「${calName}」开始同步:${href}`);
|
||||
const t1: number = Date.now();
|
||||
const items = await DavClient.reportCalendar(href, auth);
|
||||
const items: RemoteItem[] = await DavClient.reportEtags(href, auth);
|
||||
LogUtil.write(`日历本[${i}]「${calName}」REPORT 返回 ${items.length} 个资源`);
|
||||
// 现有行按 uid 分组(同一资源的覆盖实例共享 uid 与 etag)
|
||||
const existingRows: LocalEvent[] = await EventDb.queryByCalKey(context, calKey, 'event');
|
||||
const byUid: Map<string, LocalEvent[]> = new Map();
|
||||
for (const row of existingRows) {
|
||||
const arr: LocalEvent[] | undefined = byUid.get(row.uid);
|
||||
if (arr === undefined) {
|
||||
byUid.set(row.uid, [row]);
|
||||
} else {
|
||||
arr.push(row);
|
||||
}
|
||||
}
|
||||
const originMatch = /https?:\/\/[^/]+/i.exec(href);
|
||||
const origin: string = originMatch !== null ? originMatch[0] : '';
|
||||
const remote: RemoteEvent[] = [];
|
||||
let fetched: number = 0;
|
||||
let parseFail: number = 0;
|
||||
let failSample: string = '';
|
||||
const needFetch: RemoteItem[] = [];
|
||||
for (const it of items) {
|
||||
const parsed: RemoteEvent[] = IcsUtil.parse(it.ics);
|
||||
if (parsed.length === 0) {
|
||||
parseFail++;
|
||||
if (failSample === '') {
|
||||
failSample = it.ics.replace(/\r?\n/g, ' ⏎ ').substring(0, 600);
|
||||
const resUid: string = SyncEngine.resUidFromHref(it.href);
|
||||
const group: LocalEvent[] | undefined = byUid.get(resUid);
|
||||
if (!fullRefetch && group !== undefined && group.length > 0 && !group[0].dirty
|
||||
&& group[0].etag === it.etag) {
|
||||
// etag 未变:直接用本地行还原远端数据(含 reminder 等完整字段)
|
||||
for (const row of group) {
|
||||
remote.push(SyncEngine.rowToRemote(row, it.etag));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// 一个资源可能包含主事件 + 单次覆盖实例(RECURRENCE-ID),全部入库
|
||||
for (const r of parsed) {
|
||||
if (r.uid === 'syncprobe') {
|
||||
continue; // 写权限探测资源(万一删除失败),不入库展示
|
||||
needFetch.push(it);
|
||||
}
|
||||
// 并发 GET 补拉(每批 5 个),避免全量重拉时串行请求超时
|
||||
const batchSize: number = 5;
|
||||
for (let b: number = 0; b < needFetch.length; b += batchSize) {
|
||||
const batch: RemoteItem[] = needFetch.slice(b, b + batchSize);
|
||||
const results: RemoteEvent[][] = await Promise.all(batch.map(async (it: RemoteItem): Promise<RemoteEvent[]> => {
|
||||
const url: string = it.href.startsWith('http') ? it.href : origin + it.href;
|
||||
try {
|
||||
const raw: string = await DavClient.getRaw(url, auth);
|
||||
if (!raw.startsWith('BEGIN:VCALENDAR')) {
|
||||
return [];
|
||||
}
|
||||
const resUid: string = SyncEngine.resUidFromHref(it.href);
|
||||
const parsed: RemoteEvent[] = IcsUtil.parse(raw);
|
||||
const out: RemoteEvent[] = [];
|
||||
for (const r of parsed) {
|
||||
if (r.uid === 'syncprobe') {
|
||||
continue; // 写权限探测资源(万一删除失败),不入库展示
|
||||
}
|
||||
if (r.uid === '') {
|
||||
r.uid = resUid;
|
||||
}
|
||||
r.etag = it.etag;
|
||||
out.push(r);
|
||||
}
|
||||
return out;
|
||||
} catch (err) {
|
||||
return [];
|
||||
}
|
||||
if (r.uid === '') {
|
||||
r.uid = SyncEngine.uidFromHref(it.href);
|
||||
}));
|
||||
for (const arr of results) {
|
||||
if (arr.length === 0) {
|
||||
parseFail++;
|
||||
} else {
|
||||
fetched++;
|
||||
for (const r of arr) {
|
||||
remote.push(r);
|
||||
}
|
||||
}
|
||||
r.etag = it.etag;
|
||||
remote.push(r);
|
||||
}
|
||||
}
|
||||
if (parseFail > 0) {
|
||||
LogUtil.write(`日历本[${i}]「${calName}」有 ${parseFail} 个资源解析出 0 条日程,首个样本: ${failSample}`);
|
||||
LogUtil.write(`日历本[${i}]「${calName}」有 ${parseFail} 个资源拉取/解析失败`);
|
||||
}
|
||||
LogUtil.write(`日历本[${i}]「${calName}」解析出 ${remote.length} 条日程,开始落库`);
|
||||
LogUtil.write(`日历本[${i}]「${calName}」补拉变更资源 ${fetched} 个,共 ${remote.length} 条日程,开始落库`);
|
||||
const stat: string = await EventDb.applyRemote(context, calKey, href, remote, false);
|
||||
LogUtil.write(`日历本[${i}]「${calName}」日程落库完成:${stat},耗时 ${Math.round((Date.now() - t1) / 1000)} 秒`);
|
||||
changed += remote.length;
|
||||
@@ -167,6 +243,43 @@ export class SyncEngine {
|
||||
return last.endsWith('.ics') ? last.substring(0, last.length - 4) : last;
|
||||
}
|
||||
|
||||
/** 从资源 URL 提取 UID(URL 解码后,用于与 DB 中 parse 出的真实 uid 匹配) */
|
||||
private static resUidFromHref(href: string): string {
|
||||
const segs: string[] = href.split('/').filter((s: string): boolean => s !== '');
|
||||
if (segs.length === 0) {
|
||||
return String(Date.now());
|
||||
}
|
||||
let last: string = segs[segs.length - 1];
|
||||
if (last.endsWith('.ics')) {
|
||||
last = last.substring(0, last.length - 4);
|
||||
}
|
||||
try {
|
||||
last = decodeURIComponent(last);
|
||||
} catch (err) {
|
||||
// 解码失败保持原样
|
||||
}
|
||||
return last;
|
||||
}
|
||||
|
||||
/** 本地行 → 远端事件(etag 未变的资源复用本地完整数据,含 reminder) */
|
||||
private static rowToRemote(e: LocalEvent, etag: string): RemoteEvent {
|
||||
const r = new RemoteEvent();
|
||||
r.uid = e.uid;
|
||||
r.etag = etag;
|
||||
r.title = e.title;
|
||||
r.description = e.description;
|
||||
r.location = e.location;
|
||||
r.startTime = e.startTime;
|
||||
r.endTime = e.endTime;
|
||||
r.isAllDay = e.isAllDay;
|
||||
r.recurring = e.recurring;
|
||||
r.completed = e.completed;
|
||||
r.rrule = e.rrule;
|
||||
r.exdate = e.exdate;
|
||||
r.reminder = e.reminder;
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送指定账号日历本下的待同步事件(新建/修改 → PUT;删除 → DELETE)
|
||||
*/
|
||||
@@ -237,6 +350,11 @@ export class SyncEngine {
|
||||
*/
|
||||
static async pruneOrphanRows(context: common.Context, accounts: DavAccount[]): Promise<void> {
|
||||
try {
|
||||
// 防御:账号列表为空时(如同步中途读取异常),绝不能把所有 CalDAV 日程当孤儿清理
|
||||
if (accounts.length === 0) {
|
||||
LogUtil.write('清理孤儿日程行跳过:账号列表为空(防御保护)');
|
||||
return;
|
||||
}
|
||||
const accIds: string[] = accounts.map((a: DavAccount): string => a.id);
|
||||
const removed: number = await EventDb.pruneOrphanCalKeys(context, accIds);
|
||||
if (removed > 0) {
|
||||
|
||||
Reference in New Issue
Block a user