This commit is contained in:
@@ -498,71 +498,35 @@ namespace AyaNova.Api.Controllers
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Trigger immediate AttachmentMaintenanceJob
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns>Job Id</returns>
|
||||
[HttpPost("maintenance")]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> PostTriggerAttachmentMaintenanceJob()
|
||||
{
|
||||
if (serverState.IsClosed)
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
if (!Authorized.HasModifyRole(HttpContext.Items, AyaType.FileAttachment))
|
||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
var JobName = $"Attachment maintenance (demand)";
|
||||
OpsJob j = new OpsJob();
|
||||
j.Name = JobName;
|
||||
j.ObjectType = AyaType.FileAttachment;
|
||||
j.JobType = JobType.AttachmentMaintenance;
|
||||
j.SubType = JobSubType.NotSet;
|
||||
j.Exclusive = true;
|
||||
await JobsBiz.AddJobAsync(j);
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.ServerJob, AyaEvent.Created, JobName), ct);
|
||||
return Accepted(new { JobId = j.GId });
|
||||
}
|
||||
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
|
||||
#region sample html form to work with this
|
||||
/*
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title></title>
|
||||
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
|
||||
crossorigin="anonymous"></script>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
$("#upload").click(function (evt) {
|
||||
var fileUpload = $("#files").get(0);
|
||||
var files = fileUpload.files;
|
||||
var data = new FormData();
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
data.append(files[i].name, files[i]);
|
||||
}
|
||||
|
||||
//attachment test
|
||||
data.append('AttachToObjectType','2');//object 2 is widget
|
||||
data.append('AttachToObjectId','200');//there should normally always be a widget with id 1
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "http://localhost:7575/api/v8.0/Attachment",
|
||||
headers: {
|
||||
Authorization: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOiIxNTIxNTY5ODE5IiwiZXhwIjoiMTUyNDE2MTgxOSIsImlzcyI6IkF5YU5vdmEiLCJpZCI6IjEifQ.4PzkzZNYK5mJkbfCHGQ2N2248atAvvcDgApoz65oIC0"
|
||||
},
|
||||
contentType: false,
|
||||
processData: false,
|
||||
data: data,
|
||||
success: function (message) {
|
||||
alert("upload successful!");
|
||||
console.log(message);
|
||||
},
|
||||
error: function (error) {
|
||||
console.log(error);
|
||||
alert("There was an error uploading files!");
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
<input type="file" id="files" name="files" multiple />
|
||||
<!-- <input type="file" accept=".zip,application/zip" id="files" name="files" multiple /> -->
|
||||
<input type="button" id="upload" value="Upload file(s)" />
|
||||
|
||||
|
||||
|
||||
|
||||
</form>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
*/
|
||||
#endregion
|
||||
@@ -64,6 +64,9 @@ namespace AyaNova.Biz
|
||||
await JobsBiz.LogJobAsync(job.GId, $"Starting...");
|
||||
apiServerState.SetOpsOnly("Attachment file maintenance");
|
||||
|
||||
|
||||
|
||||
|
||||
// EXISTENCE CHECK
|
||||
//iterate all records in chunks
|
||||
bool moreRecords = true;
|
||||
@@ -93,9 +96,9 @@ namespace AyaNova.Biz
|
||||
}
|
||||
|
||||
} while (moreRecords);
|
||||
// long totalRecs = await ct.FileAttachment.LongCountAsync();
|
||||
|
||||
// long totalRecs = await ct.FileAttachment.LongCountAsync();
|
||||
|
||||
var allAttachments = FileUtil.GetAllAttachmentFilePaths();
|
||||
|
||||
// iterate FileAttachment records, if physically present then flag as such
|
||||
// make sure it has a short circuit that if there are NO files physically then all are out of sync
|
||||
|
||||
@@ -512,8 +512,7 @@ namespace AyaNova.Util
|
||||
/// <summary>
|
||||
/// Confirm if a file exists in the attachment folder
|
||||
/// </summary>
|
||||
/// <param name="fileName">name of attachment file </param>
|
||||
/// <returns>duh!</returns>
|
||||
/// <param name="fileName">name of attachment file </param>
|
||||
internal static bool AttachmentFileExists(string fileName)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(fileName))
|
||||
|
||||
Reference in New Issue
Block a user