88using Intersect . Framework . Core . AssetManagement ;
99using Intersect . Framework . Reflection ;
1010using Intersect . Server . Web . Extensions ;
11+ using Intersect . Server . Web . Http ;
1112using Intersect . Server . Web . Pages . Shared ;
13+ using Intersect . Server . Web . Types ;
1214using Microsoft . AspNetCore . Authorization ;
1315using Microsoft . AspNetCore . Mvc ;
1416using Microsoft . AspNetCore . Mvc . Filters ;
@@ -74,13 +76,19 @@ public override void OnActionExecuting(ActionExecutingContext context)
7476
7577 [ HttpGet ( "{**path}" ) ]
7678 [ AllowAnonymous ]
79+ [ ProducesResponseType ( typeof ( string ) , ( int ) HttpStatusCode . OK , ContentTypes . Json ) ]
80+ [ ProducesResponseType ( typeof ( byte [ ] ) , ( int ) HttpStatusCode . OK , ContentTypes . OctetStream ) ]
81+ [ ProducesResponseType ( typeof ( StatusMessageResponseBody ) , ( int ) HttpStatusCode . Forbidden , ContentTypes . Json ) ]
82+ [ ProducesResponseType ( typeof ( StatusMessageResponseBody ) , ( int ) HttpStatusCode . InternalServerError , ContentTypes . Json ) ]
83+ [ ProducesResponseType ( typeof ( StatusMessageResponseBody ) , ( int ) HttpStatusCode . BadRequest , ContentTypes . Json ) ]
84+ [ ProducesResponseType ( typeof ( StatusMessageResponseBody ) , ( int ) HttpStatusCode . NotFound , ContentTypes . Json ) ]
7785 public IActionResult AssetGet ( [ FromRoute ] string ? path = default )
7886 {
7987 if ( ! ( path ? . StartsWith ( "client" ) ?? false ) )
8088 {
8189 if ( ! User . HasRole ( "Editor" ) )
8290 {
83- return Forbidden ( ) ;
91+ return Forbidden ( message : $ "No access to { path } " ) ;
8492 }
8593 }
8694
@@ -90,7 +98,7 @@ public IActionResult AssetGet([FromRoute] string? path = default)
9098 var assetFileSystemInfo = AssetFileSystemInfo . From ( assetRootPath , pathToInspect ) ;
9199 if ( assetFileSystemInfo == default )
92100 {
93- return Ok ( Array . Empty < AssetFileSystemInfo > ( ) ) ;
101+ return NotFound ( message : $ "Path not found: { path } " ) ;
94102 }
95103
96104 if ( assetFileSystemInfo . Type == AssetFileSystemInfoType . File )
@@ -118,13 +126,18 @@ public IActionResult AssetGet([FromRoute] string? path = default)
118126 }
119127 catch ( Exception exception )
120128 {
121- _logger . LogError ( exception , "Failed to generate client update manifest" ) ;
129+ _logger . LogError ( exception , "Failed to retrieve results for {Path}" , path ) ;
122130
123- object ? data = default ;
131+ object ? data = $ "An error occurred when retrieving results for { path } " ;
124132#if DEBUG
125133 data = exception ;
126134#endif
127135
136+ if ( data is string message )
137+ {
138+ return InternalServerError ( message : message ) ;
139+ }
140+
128141 return InternalServerError ( data ) ;
129142 }
130143 }
@@ -216,13 +229,16 @@ string resolvedDestinationPath
216229 }
217230
218231 [ HttpPost ]
232+ [ ProducesResponseType ( typeof ( string ) , ( int ) HttpStatusCode . OK , ContentTypes . Html ) ]
233+ [ ProducesResponseType ( typeof ( string ) , ( int ) HttpStatusCode . MultiStatus , ContentTypes . Html ) ]
234+ [ ProducesResponseType ( typeof ( StatusMessageResponseBody ) , ( int ) HttpStatusCode . BadRequest , ContentTypes . Json ) ]
219235 public IActionResult AssetsUpload ( [ FromForm ] string folder , [ FromForm ] List < IFormFile > files )
220236 {
221237 if ( string . IsNullOrWhiteSpace ( folder ) )
222238 {
223239 if ( ! Request . IsHtmx ( ) )
224240 {
225- return BadRequest ( "No destination folder" ) ;
241+ return BadRequest ( message : "No destination folder" ) ;
226242 }
227243
228244 var partial = PartialView (
@@ -250,7 +266,7 @@ public IActionResult AssetsUpload([FromForm] string folder, [FromForm] List<IFor
250266
251267 if ( ! Request . IsHtmx ( ) )
252268 {
253- return BadRequest ( "Destination folder does not exist" ) ;
269+ return BadRequest ( message : "Destination folder does not exist" ) ;
254270 }
255271
256272 var partial = PartialView (
@@ -277,7 +293,7 @@ public IActionResult AssetsUpload([FromForm] string folder, [FromForm] List<IFor
277293 {
278294 if ( ! Request . IsHtmx ( ) )
279295 {
280- return BadRequest ( $ "Multiple files uploaded with the name '{ file . FileName } '") ;
296+ return BadRequest ( message : $ "Multiple files uploaded with the name '{ file . FileName } '") ;
281297 }
282298
283299 var partial = PartialView (
@@ -380,6 +396,8 @@ public IActionResult AssetsUpload([FromForm] string folder, [FromForm] List<IFor
380396 }
381397
382398 [ HttpPost ( "{**path}" ) ]
399+ [ ProducesResponseType ( typeof ( string ) , ( int ) HttpStatusCode . OK , ContentTypes . Json ) ]
400+ [ ProducesResponseType ( typeof ( StatusMessageResponseBody ) , ( int ) HttpStatusCode . BadRequest , ContentTypes . Json ) ]
383401 public IActionResult AssetPost ( string ? path = default , [ FromHeader ( Name = "Move-To" ) ] string ? destinationPath = default )
384402 {
385403 if ( string . IsNullOrWhiteSpace ( path ) )
@@ -414,6 +432,10 @@ public IActionResult AssetPost(string? path = default, [FromHeader(Name = "Move-
414432 }
415433
416434 [ HttpDelete ( "{**path}" ) ]
435+ [ ProducesResponseType ( typeof ( string ) , ( int ) HttpStatusCode . OK , ContentTypes . Json ) ]
436+ [ ProducesResponseType ( typeof ( StatusMessageResponseBody ) , ( int ) HttpStatusCode . BadRequest , ContentTypes . Json ) ]
437+ [ ProducesResponseType ( typeof ( StatusMessageResponseBody ) , ( int ) HttpStatusCode . NotFound , ContentTypes . Json ) ]
438+ [ ProducesResponseType ( typeof ( StatusMessageResponseBody ) , ( int ) HttpStatusCode . InternalServerError , ContentTypes . Json ) ]
417439 public IActionResult BrowseDelete ( string ? path = default )
418440 {
419441 var assetRootPath = AssetRootPath ;
@@ -423,19 +445,28 @@ public IActionResult BrowseDelete(string? path = default)
423445
424446 try
425447 {
426- var fileSystemInfo = assetFileSystemInfo . FileSystemInfo ;
448+ var fileSystemInfo = assetFileSystemInfo ? . FileSystemInfo ;
427449 if ( fileSystemInfo is not { Exists : true } )
428450 {
429- return NotFound ( ) ;
451+ return NotFound ( message : $ "Unable to delete missing resource: { path } " ) ;
430452 }
431453
432454 fileSystemInfo . Delete ( ) ;
433- return Ok ( ) ;
455+ return Ok ( message : $ "Deleted { path } " ) ;
434456 }
435457 catch ( Exception exception )
436458 {
437- _logger . LogWarning ( exception , "Failed to delete asset: {Path}" , string . IsNullOrWhiteSpace ( path ) ? "<empty>" : path ) ;
438- return InternalServerError ( ) ;
459+ _logger . LogWarning (
460+ exception ,
461+ "Failed to delete asset: {Path}" ,
462+ string . IsNullOrWhiteSpace ( path ) ? "<empty>" : path
463+ ) ;
464+
465+ #if DEBUG
466+ return InternalServerError ( exception ) ;
467+ #else
468+ return InternalServerError ( "Failed to generate manifest" ) ;
469+ #endif
439470 }
440471 }
441472
@@ -444,6 +475,10 @@ public IActionResult BrowseDelete(string? path = default)
444475
445476 [ AllowAnonymous ]
446477 [ HttpGet ( "client/update.json" ) ]
478+ [ ProducesResponseType ( typeof ( string ) , ( int ) HttpStatusCode . OK , ContentTypes . Json ) ]
479+ [ ProducesResponseType ( typeof ( StatusMessageResponseBody ) , ( int ) HttpStatusCode . BadRequest , ContentTypes . Json ) ]
480+ [ ProducesResponseType ( typeof ( StatusMessageResponseBody ) , ( int ) HttpStatusCode . NotFound , ContentTypes . Json ) ]
481+ [ ProducesResponseType ( typeof ( StatusMessageResponseBody ) , ( int ) HttpStatusCode . InternalServerError , ContentTypes . Json ) ]
447482 public IActionResult ClientUpdateManifest ( )
448483 {
449484 try
@@ -457,7 +492,7 @@ public IActionResult ClientUpdateManifest()
457492
458493 if ( ! TryGenerateUpdateManifestFrom ( "client" , out var manifest ) )
459494 {
460- return InternalServerError ( ) ;
495+ return InternalServerError ( "Failed to generate manifest" ) ;
461496 }
462497
463498 _clientUpdateManifestCacheExpiry = DateTime . UtcNow . Add ( ManifestCacheExpiry ) ;
@@ -468,12 +503,11 @@ public IActionResult ClientUpdateManifest()
468503 {
469504 _logger . LogError ( exception , "Failed to generate client update manifest" ) ;
470505
471- object ? data = default ;
472506#if DEBUG
473- data = exception ;
507+ return InternalServerError ( exception ) ;
508+ #else
509+ return InternalServerError ( "Failed to generate manifest" ) ;
474510#endif
475-
476- return InternalServerError ( data ) ;
477511 }
478512 }
479513
@@ -486,16 +520,21 @@ public IActionResult ClientUpdateManifest()
486520
487521
488522 [ HttpDelete ( "client/update.json" ) ]
523+ [ ProducesResponseType ( typeof ( string ) , ( int ) HttpStatusCode . OK , ContentTypes . Json ) ]
489524 public IActionResult ClearClientUpdateManifestCache ( )
490525 {
491526 _clientUpdateManifest = default ;
492- return Ok ( ) ;
527+ return Ok ( message : "Cache cleared" ) ;
493528 }
494529
495530 [ HttpDelete ( "editor" ) ]
496531 public IActionResult ClearEditorAssets ( ) => DeleteAssets ( "editor" ) ;
497532
498533 [ HttpGet ( "editor/update.json" ) ]
534+ [ ProducesResponseType ( typeof ( string ) , ( int ) HttpStatusCode . OK , ContentTypes . Json ) ]
535+ [ ProducesResponseType ( typeof ( StatusMessageResponseBody ) , ( int ) HttpStatusCode . BadRequest , ContentTypes . Json ) ]
536+ [ ProducesResponseType ( typeof ( StatusMessageResponseBody ) , ( int ) HttpStatusCode . NotFound , ContentTypes . Json ) ]
537+ [ ProducesResponseType ( typeof ( StatusMessageResponseBody ) , ( int ) HttpStatusCode . InternalServerError , ContentTypes . Json ) ]
499538 public IActionResult EditorUpdateManifest ( )
500539 {
501540 try
@@ -508,7 +547,7 @@ public IActionResult EditorUpdateManifest()
508547
509548 if ( ! TryGenerateUpdateManifestFrom ( "editor" , out var manifest ) )
510549 {
511- return InternalServerError ( ) ;
550+ return InternalServerError ( "Failed to generate manifest" ) ;
512551 }
513552
514553 _editorUpdateManifestCacheExpiry = DateTime . UtcNow . Add ( ManifestCacheExpiry ) ;
@@ -519,20 +558,20 @@ public IActionResult EditorUpdateManifest()
519558 {
520559 _logger . LogError ( exception , "Failed to generate editor update manifest" ) ;
521560
522- object ? data = default ;
523561#if DEBUG
524- data = exception ;
562+ return InternalServerError ( exception ) ;
563+ #else
564+ return InternalServerError ( "Failed to generate manifest" ) ;
525565#endif
526-
527- return InternalServerError ( data ) ;
528566 }
529567 }
530568
531569 [ HttpDelete ( "editor/update.json" ) ]
570+ [ ProducesResponseType ( typeof ( string ) , ( int ) HttpStatusCode . OK , ContentTypes . Json ) ]
532571 public IActionResult ClearEditorUpdateManifestCache ( )
533572 {
534573 _editorUpdateManifest = default ;
535- return Ok ( ) ;
574+ return Ok ( message : "Cache cleared" ) ;
536575 }
537576
538577 private IActionResult DeleteAssets ( string subdirectory )
0 commit comments