public override async Task <int> Execute() { var toDelete = await FindFilesToDelete(); var log = new[] { $"CDNDelete ({toDelete.CDNDelete.Length}):\n\n" } .Concat(toDelete.CDNDelete) .Concat(new[] { $"SQLDelete ({toDelete.SQLDelete.Length}" }) .Concat(toDelete.SQLDelete) .Concat(new[] { $"CDNRemain ({toDelete.CDNNotDeleted.Length}" }) .Concat(toDelete.CDNNotDeleted) .Concat(new[] { $"SQLRemain ({toDelete.SQLNotDeleted.Length}" }) .Concat(toDelete.SQLNotDeleted) .ToArray(); //await AbsolutePath.EntryPoint.Combine("cdn_delete_log.txt").WriteAllLinesAsync(log); foreach (var sqlFile in toDelete.SQLDelete) { Utils.Log($"Deleting {sqlFile} from SQL"); await _sql.DeleteFileDefinition(await _sql.GetCDNFileDefinition(sqlFile)); } using var queue = new WorkQueue(6); await toDelete.CDNDelete.Select((d, idx) => (d, idx)).PMap(queue, async cdnFile => { using var conn = await(await BunnyCdnFtpInfo.GetCreds(StorageSpace.AuthoredFiles)).GetClient(); Utils.Log($"Deleting {cdnFile} from CDN"); await _discord.Send(Channel.Ham, new DiscordMessage { Content = $"({cdnFile.idx}/{toDelete.CDNDelete.Length}) {cdnFile.d} is no longer referenced by any modlist and will be removed from the CDN" }); if (await conn.DirectoryExistsAsync(cdnFile.d)) { await conn.DeleteDirectoryAsync(cdnFile.d); } if (await conn.FileExistsAsync(cdnFile.d)) { await conn.DeleteFileAsync(cdnFile.d); } }); return(toDelete.CDNDelete.Length + toDelete.SQLDelete.Length); }
public async Task <IActionResult> DeleteUpload(string serverAssignedUniqueId) { var user = User.FindFirstValue(ClaimTypes.Name); var definition = await _sql.GetCDNFileDefinition(serverAssignedUniqueId); if (definition.Author != user) { return(Forbid("File Id does not match authorized user")); } _logger.Log(LogLevel.Information, $"Finalizing file upload {definition.OriginalFileName}"); await DeleteFolderOrSilentlyFail($"{definition.MungedName}"); await _sql.DeleteFileDefinition(definition); return(Ok()); }