-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New API for downloading LDML files from projects that allow sharing W…
…S data (#1309) * Add "ldmlzip" command to hg command runner Will return 403 Forbidden if project does not allow sharing ws data with SLDR. Will also return same 403 Forbidden error code if project does not exist, to avoid possibly leaking project codes. If project exists and allows data sharing, command will return a zipfile containing CachedSettings/WritingSystems/*.ldml from the tip revision. * Add /api/projects/sldr-export endpoint Returns 404 if there are no SLDR files available, which is unlikely to happen in production but can happen in dev environments since none of our test projects have `addToSldr="true"`. Otherwise it returns a zip file with projects identified only by project ID.
- Loading branch information
Showing
10 changed files
with
161 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using Quartz; | ||
|
||
namespace LexBoxApi.Jobs; | ||
|
||
public class DeleteTempDirectoryJob() : LexJob | ||
{ | ||
public static async Task Queue(ISchedulerFactory schedulerFactory, | ||
string path, | ||
TimeSpan delay, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
if (!PathIsInTempDir(path)) return; | ||
await QueueJob(schedulerFactory, | ||
Key, | ||
new JobDataMap { { nameof(Path), path } }, | ||
delay, | ||
cancellationToken); | ||
} | ||
|
||
public static JobKey Key { get; } = new(nameof(DeleteTempDirectoryJob), "CleanupJobs"); | ||
public string? Path { get; set; } | ||
|
||
protected override Task ExecuteJob(IJobExecutionContext context) | ||
{ | ||
ArgumentException.ThrowIfNullOrEmpty(Path); | ||
if (!PathIsInTempDir(Path)) return Task.CompletedTask; | ||
if (Directory.Exists(Path) && PathIsSafeToDelete(Path)) Directory.Delete(Path, true); | ||
return Task.CompletedTask; | ||
} | ||
|
||
private static bool PathIsInTempDir(string path) | ||
{ | ||
// Only safe to delete files from the system temp directory | ||
var prefix = System.IO.Path.GetTempPath(); | ||
return (!string.IsNullOrEmpty(prefix)) && path.StartsWith(prefix); | ||
} | ||
|
||
private static bool PathIsSafeToDelete(string path) | ||
{ | ||
try | ||
{ | ||
var attributes = File.GetAttributes(path); | ||
// Must be a directory *and* must not be a symlink | ||
return attributes.HasFlag(FileAttributes.Directory) && !attributes.HasFlag(FileAttributes.ReparsePoint); | ||
} | ||
catch | ||
{ | ||
return false; // If anything at all goes wrong, we want to abort | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters