@@ -11,6 +11,24 @@ local SyncService = require("frontend/apps/cloudstorage/syncservice")
1111local Merge = require (" merge" )
1212local rapidjson = require (" rapidjson" )
1313
14+ local function dir_exists (path )
15+ local ok , _ , code = os.rename (path , path )
16+ if not ok then
17+ -- Código 13 = permission denied, mas o diretório existe
18+ return code == 13
19+ end
20+ return true
21+ end
22+
23+ local function ensure_dir_exists (path )
24+ if not dir_exists (path ) then
25+ local result = os.execute (' mkdir -p "' .. path .. ' "' )
26+ if not result then
27+ error (" Failed to create directory: " .. path )
28+ end
29+ end
30+ end
31+
1432local Highlightsync = WidgetContainer :extend {
1533 name = " Highlightsync" ,
1634 is_doc_only = false ,
6179
6280function Highlightsync .onSync (local_path , cached_path , income_path )
6381
64- local local_highlights = read_json_file (local_path ) or {}
82+ local local_highlights = DataAnnotations -- read_json_file(local_path) or {}
6583 local cached_highlights = read_json_file (cached_path ) or {}
6684 local income_highlights = read_json_file (income_path ) or {}
67- local annotations = Merge .merge_highlights (local_highlights ,income_highlights ,cached_highlights )
85+ local annotations = Merge .Merge_highlights (local_highlights ,income_highlights ,cached_highlights )
6886
6987 write_json_file (SidecarDir .. " /" .. FileName .. " .json" , annotations ) -- Save annotations local
7088 DataAnnotations = annotations
@@ -94,9 +112,10 @@ function Highlightsync:onSyncBookHighlights()
94112 })
95113
96114 UIManager :nextTick (function ()
97- DataAnnotations = self .ui .doc_settings .data .annotations
115+ DataAnnotations = self .ui .annotation . annotations -- self.ui. doc_settings.data.annotations
98116 SidecarDir = self .ui .doc_settings .doc_sidecar_dir
99117 FileName = SidecarDir :match (" ([^/]+)/*$" )
118+ ensure_dir_exists (SidecarDir )
100119 write_json_file (SidecarDir .. " /" .. FileName .. " .json" , self .ui .annotation .annotations ) -- Save annotations local
101120 SyncService .sync (self .settings .sync_server , SidecarDir .. " /" .. FileName .. " .json" , self .onSync )
102121 self .ui .annotation .annotations = DataAnnotations
0 commit comments