| 1 | using Zipelo.Core; |
| 2 | using Zipelo.Runtime; |
| 3 | using Zipelo.Ui; |
| 4 | |
| 5 | namespace Zipelo.Ubuntu; |
| 6 | |
| 7 | public interface IUbuntuArchiveWorkspace |
| 8 | { |
| 9 | bool CanListZip { get; } |
| 10 | bool CanCreateZip { get; } |
| 11 | Task<CreationResult> CreateAsync(Guid jobId, IReadOnlyList<CreationSource> sources, |
| 12 | string destination, CancellationToken cancellationToken); |
| 13 | string AvailabilityMessage { get; } |
| 14 | Task<JobResult> ListAsync(Guid jobId, Stream input, CancellationToken cancellationToken); |
| 15 | } |
| 16 | |
| 17 | public sealed class UbuntuWorkspace : IUbuntuArchiveWorkspace |
| 18 | { |
| 19 | private readonly string directory = Path.Combine(AppContext.BaseDirectory, "worker"); |
| 20 | |
| 21 | // Linux 작업자는 같은 배포 폴더의 apphost만 사용함. PATH나 현재 폴더를 검색하지 않음. |
| 22 | private string WorkerPath => WorkerPlatform.GetWorkerPath(AppContext.BaseDirectory); |
| 23 | |
| 24 | public bool CanListZip => OperatingSystem.IsLinux() && HasRequiredFiles() && |
| 25 | new ZipWorkerClient(WorkerPath).Capabilities.Any(capability => |
| 26 | capability.Format.Equals("zip", StringComparison.OrdinalIgnoreCase) && capability.Action == ArchiveAction.List); |
| 27 | |
| 28 | public bool CanCreateZip => CanListZip && ZipCreationWorkflow.ValidationEnabled && NewZipPublisher.IsSupportedPlatform; |
| 29 | |
| 30 | public Task<CreationResult> CreateAsync(Guid jobId, IReadOnlyList<CreationSource> sources, |
| 31 | string destination, CancellationToken cancellationToken) |
| 32 | { |
| 33 | if (!CanCreateZip) { throw new ArchiveException(ArchiveError.UnsupportedOperation); } |
| 34 | return ZipCreationWorkflow.RunAsync(new ZipWorkerClient(WorkerPath), jobId, sources, destination, cancellationToken); |
| 35 | } |
| 36 | |
| 37 | public string AvailabilityMessage => CanListZip |
| 38 | ? "Ubuntu UI 개발 중입니다. ZIP 목록을 연결했습니다. " + |
| 39 | (ZipCreationWorkflow.ValidationEnabled ? ZipCreationWorkflow.ScopeMessage : "생성 연결은 개발 검증 빌드에서만 사용할 수 있습니다.") |
| 40 | : "목록 읽기에 필요한 프로그램 파일이 준비되지 않았습니다. 생성과 압축 풀기도 준비 중입니다."; |
| 41 | |
| 42 | public async Task<JobResult> ListAsync(Guid jobId, Stream input, CancellationToken cancellationToken) |
| 43 | { |
| 44 | if (!CanListZip) |
| 45 | { |
| 46 | throw new ArchiveException(ArchiveError.EngineUnavailable); |
| 47 | } |
| 48 | var limits = new JobLimits(1024, 16L * 1024 * 1024, 16L * 1024 * 1024, |
| 49 | TimeSpan.FromMinutes(2), 3); |
| 50 | var result = await new ZipWorkerClient(WorkerPath).ListAsync(jobId, input, limits, cancellationToken) |
| 51 | .ConfigureAwait(false); |
| 52 | if (result.Job.JobId != jobId) |
| 53 | { |
| 54 | throw new ArchiveException(ArchiveError.EngineFailure); |
| 55 | } |
| 56 | return result.Job; |
| 57 | } |
| 58 | |
| 59 | private bool HasRequiredFiles() |
| 60 | { |
| 61 | string[] required = |
| 62 | [ |
| 63 | WorkerPlatform.ExecutableName, "Zipelo.Worker.dll", "Zipelo.Worker.runtimeconfig.json", |
| 64 | "Zipelo.Worker.deps.json", "Zipelo.Core.dll", "Zipelo.Runtime.dll" |
| 65 | ]; |
| 66 | return required.All(name => File.Exists(Path.Combine(directory, name))); |
| 67 | } |
| 68 | } |