1- using Newtonsoft . Json ;
1+ using Asp . Versioning ;
2+ using Microsoft . AspNetCore . Authorization ;
3+ using Microsoft . AspNetCore . Mvc ;
4+ using Newtonsoft . Json ;
5+ using Umbraco . Cms . Api . Common . Attributes ;
6+ using Umbraco . Cms . Api . Common . Filters ;
7+ using Umbraco . Cms . Core ;
28using Umbraco . Cms . Core . Hosting ;
3- using Umbraco . Cms . Infrastructure . Migrations . Expressions . Delete ;
4- using Umbraco . Cms . Web . BackOffice . Controllers ;
5- using Umbraco . Cms . Web . Common . Attributes ;
6- using uSync . BackOffice ;
7- using uSync . BackOffice . Configuration ;
9+ using Umbraco . Cms . Web . Common . Filters ;
10+ using uSync . Backoffice . Management . Api . Configuration ;
11+ using uSync . BackOffice . Authorization ;
812using uSync . BackOffice . Services ;
913
1014namespace uSync . History . Controllers
1115{
12- [ PluginController ( "uSync" ) ]
13- public class uSyncHistoryController : UmbracoAuthorizedApiController
16+ [ ApiController ]
17+ [ uSyncVersionedRoute ( "history" ) ]
18+ [ Authorize ( Policy = SyncAuthorizationPolicies . TreeAccessuSync ) ]
19+ [ MapToApi ( "uSync.History" ) ]
20+ [ DisableBrowserCache ]
21+ [ JsonOptionsName ( Constants . JsonOptionsNames . BackOffice ) ]
22+ [ ApiVersion ( "1.0" ) ]
23+ [ ApiExplorerSettings ( GroupName = "History" ) ]
24+ public class uSyncHistoryController : ControllerBase
1425 {
1526 private readonly IHostingEnvironment _hostingEnvironment ;
16- private readonly SyncFileService _syncFileService ;
27+ private readonly ISyncFileService _syncFileService ;
1728
18- public uSyncHistoryController ( SyncFileService syncFileService , IHostingEnvironment hostingEnvironment )
29+ public uSyncHistoryController ( ISyncFileService syncFileService , IHostingEnvironment hostingEnvironment )
1930 {
2031 _syncFileService = syncFileService ;
2132 _hostingEnvironment = hostingEnvironment ;
2233 }
2334
24- public bool GetApi ( ) => true ;
25-
26- public IEnumerable < HistoryInfo > GetHistory ( )
35+ [ HttpGet ( "GetHistory" ) ]
36+ [ ProducesResponseType ( 200 ) ]
37+ public async Task < IEnumerable < HistoryInfo > > GetHistory ( )
2738 {
2839 string historyFolder = GetHistoryFolder ( ) ;
2940 var files = _syncFileService . GetFiles ( historyFolder , "*.json" )
@@ -32,19 +43,23 @@ public IEnumerable<HistoryInfo> GetHistory()
3243 var list = new List < HistoryInfo > ( ) ;
3344 foreach ( var file in files )
3445 {
35- list . Add ( LoadHistory ( file ) ) ;
46+ list . Add ( await LoadHistoryAsync ( file ) ) ;
3647 }
3748
3849 return list . OrderByDescending ( x => x . Date ) ;
3950 }
4051
52+ [ HttpGet ( "GetHistoryFolder" ) ]
53+ [ ProducesResponseType ( 200 ) ]
4154 private string GetHistoryFolder ( )
4255 {
4356 var rootFolder = _syncFileService . GetAbsPath ( _hostingEnvironment . LocalTempPath ) ;
4457 var historyFolder = Path . GetFullPath ( Path . Combine ( rootFolder , "uSync" , "history" ) ) ;
4558 return historyFolder ;
4659 }
4760
61+ [ HttpGet ( "ClearHistory" ) ]
62+ [ ProducesResponseType ( 200 ) ]
4863 public bool ClearHistory ( )
4964 {
5065 // 1. get history folder
@@ -60,11 +75,13 @@ public bool ClearHistory()
6075 return true ;
6176 }
6277
63- public HistoryInfo LoadHistory ( string filePath )
78+ [ HttpGet ( "HistoryInfo" ) ]
79+ [ ProducesResponseType ( 200 ) ]
80+ public async Task < HistoryInfo > LoadHistoryAsync ( string filePath )
6481 {
6582 string historyFolder = GetHistoryFolder ( ) ;
6683 var fullPath = Path . Combine ( historyFolder , filePath ) ;
67- string contents = _syncFileService . LoadContent ( fullPath ) ;
84+ string contents = await _syncFileService . LoadContentAsync ( fullPath ) ;
6885
6986 var actions = JsonConvert . DeserializeObject < HistoryInfo > ( contents ) ;
7087
0 commit comments