@@ -287,6 +287,23 @@ export async function saveOutlineToJSON(
287287 ztoolkit . log ( "Save outline to JSON" ) ;
288288}
289289
290+ function migrateOutlineInfo (
291+ raw : any ,
292+ fromSchema : number ,
293+ ) : { outline : OutlineNode [ ] ; baseFontSize : number } {
294+ let outline : OutlineNode [ ] = raw . outline ?? [ ] ;
295+ let baseFontSize = DEFAULT_BASE_FONT_SIZE ;
296+
297+ // v1 → v2: add baseFontSize
298+ if ( fromSchema < 2 ) {
299+ baseFontSize = raw . info ?. baseFontSize ?? DEFAULT_BASE_FONT_SIZE ;
300+ }
301+
302+ // Future v2 → v3 migrations go here
303+
304+ return { outline, baseFontSize } ;
305+ }
306+
290307// 加载时要考虑JSON文件的版本信息,如果版本低,要重新从原文件加载信息
291308export async function loadOutlineInfoFromJSON (
292309 item : Zotero . Item ,
@@ -304,8 +321,12 @@ export async function loadOutlineInfoFromJSON(
304321 } else {
305322 const content = ( await Zotero . File . getContentsAsync ( outlinePath ) ) as string ;
306323 const tmp = JSON . parse ( content ) ;
307- if ( tmp . info . schema < OUTLINE_SCHEMA ) {
308- return null ;
324+ const fileSchema = tmp . info ?. schema ?? 1 ;
325+ if ( fileSchema < OUTLINE_SCHEMA ) {
326+ // Migrate old outline data instead of discarding
327+ const migrated = migrateOutlineInfo ( tmp , fileSchema ) ;
328+ await saveOutlineToJSON ( item , migrated . outline , migrated . baseFontSize ) ;
329+ return migrated ;
309330 } else {
310331 const outlineInfo = JSON . parse ( content ) as OutlineInfo ;
311332 return {
0 commit comments