using System.Security.Cryptography;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using YD_Event.Application.Auth;
using YD_Event.Application.Common;
using YD_Event.Core.Infrastructure.Aliyun.Oss;
using YD_Event.Core.Options;
namespace YD_Event.Application.AppUpdate;
/// 内部 Android 裁判端 APK 发布与升级检查。
[ApiDescriptionSettings("裁判端升级")]
[Route("api/app-updates")]
[Authorize]
public class AppUpdateController : IDynamicApiController
{
private const string PackageName = "com.yd.event.yd_pattern_scoring_system";
private const long MaxApkSize = 200L * 1024 * 1024;
private const string RELEASE_OSS_BUCKET = "yuedong-wechatapplet";
private const string RELEASE_OSS_DOMAIN = "https://yuedong-wechatapplet.oss-cn-shanghai.aliyuncs.com";
// Keep the directory spelling requested for the existing OSS layout.
private const string RELEASE_OSS_PREFIX = "app-realse/";
private readonly ISqlSugarRepository _releases;
private readonly AuthManager _auth;
private readonly IIdGenerator _ids;
private readonly FileService _files;
private readonly OssService _oss;
private readonly ILogger _logger;
private readonly IOptionsMonitor _ossOptions;
private readonly string _channel;
public AppUpdateController(ISqlSugarRepository releases,
AuthManager auth, IIdGenerator ids, FileService files,
IOptionsMonitor ossOptions, OssService oss,
ILogger logger)
{
_releases = releases;
_auth = auth;
_ids = ids;
_files = files;
_oss = oss;
_logger = logger;
_ossOptions = ossOptions;
_channel = Environment.GetEnvironmentVariable("APP_UPDATE_CHANNEL")?.Trim().ToLowerInvariant() ?? "production";
}
/// 登录前即可查询当前环境的最新 APK。
[HttpGet("latest")]
[AllowAnonymous]
public async Task