mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
2.0 KiB
65 lines
2.0 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Orleans;
|
|
using Squidex.Areas.Api.Controllers.Backups.Models;
|
|
using Squidex.Domain.Apps.Entities.Backup;
|
|
using Squidex.Infrastructure.Commands;
|
|
using Squidex.Infrastructure.Security;
|
|
using Squidex.Pipeline;
|
|
using Squidex.Shared;
|
|
|
|
namespace Squidex.Areas.Api.Controllers.Backups
|
|
{
|
|
/// <summary>
|
|
/// Restores backups.
|
|
/// </summary>
|
|
[ApiModelValidation(true)]
|
|
public class RestoreController : ApiController
|
|
{
|
|
private readonly IGrainFactory grainFactory;
|
|
|
|
public RestoreController(ICommandBus commandBus, IGrainFactory grainFactory)
|
|
: base(commandBus)
|
|
{
|
|
this.grainFactory = grainFactory;
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("apps/restore/")]
|
|
[ApiPermission(Permissions.AdminRestoreRead)]
|
|
public async Task<IActionResult> GetJob()
|
|
{
|
|
var restoreGrain = grainFactory.GetGrain<IRestoreGrain>(User.OpenIdSubject());
|
|
|
|
var job = await restoreGrain.GetJobAsync();
|
|
|
|
if (job.Value == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
var response = RestoreJobDto.FromJob(job.Value);
|
|
|
|
return Ok(response);
|
|
}
|
|
|
|
[HttpPost]
|
|
[Route("apps/restore/")]
|
|
[ApiPermission(Permissions.AdminRestoreCreate)]
|
|
public async Task<IActionResult> PostRestore([FromBody] RestoreRequest request)
|
|
{
|
|
var restoreGrain = grainFactory.GetGrain<IRestoreGrain>(User.OpenIdSubject());
|
|
|
|
await restoreGrain.RestoreAsync(request.Url, request.Name);
|
|
|
|
return NoContent();
|
|
}
|
|
}
|
|
}
|
|
|