allow filename to be provided during module export

This commit is contained in:
sbwalker
2025-05-15 10:58:55 -04:00
parent 51ba3a01f5
commit 5d077e843d
5 changed files with 25 additions and 14 deletions

View File

@ -256,15 +256,15 @@ namespace Oqtane.Controllers
return content;
}
// POST api/<controller>/export?moduleid=x&pageid=y&folderid=z
// POST api/<controller>/export?moduleid=x&pageid=y&folderid=z&filename=a
[HttpPost("export")]
[Authorize(Roles = RoleNames.Registered)]
public Result Export(int moduleid, int pageid, int folderid)
public Result Export(int moduleid, int pageid, int folderid, string filename)
{
var result = new Result(false);
var module = _modules.GetModule(moduleid);
if (module != null && module.SiteId == _alias.SiteId && _userPermissions.IsAuthorized(User, module.SiteId, EntityNames.Page, pageid, PermissionNames.Edit) &&
_userPermissions.IsAuthorized(User, module.SiteId, EntityNames.Folder, folderid, PermissionNames.Edit))
_userPermissions.IsAuthorized(User, module.SiteId, EntityNames.Folder, folderid, PermissionNames.Edit) && !string.IsNullOrEmpty(filename))
{
// get content
var content = _modules.ExportModule(moduleid);
@ -277,8 +277,8 @@ namespace Oqtane.Controllers
Directory.CreateDirectory(folderPath);
}
// create text file
var filename = Utilities.GetTypeNameLastSegment(module.ModuleDefinitionName, 0) + moduleid.ToString() + ".json";
// create json file
filename = Path.GetFileNameWithoutExtension(filename) + ".json";
string filepath = Path.Combine(folderPath, filename);
if (System.IO.File.Exists(filepath))
{