2023-03-26 11:37:20 -05:00
|
|
|
|
using B2Net;
|
|
|
|
|
|
|
|
|
|
namespace Api;
|
|
|
|
|
|
|
|
|
|
public class EpisodeUrl {
|
|
|
|
|
public required string Url { get; set; }
|
|
|
|
|
public required string Token { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class B2ApiClient {
|
|
|
|
|
private static string? KeyId => Environment.GetEnvironmentVariable("KEY_ID");
|
|
|
|
|
private static string? Key => Environment.GetEnvironmentVariable("SECRET_KEY");
|
|
|
|
|
private static string? BucketId => Environment.GetEnvironmentVariable("BUCKET_ID");
|
|
|
|
|
private static string? Bucket => Environment.GetEnvironmentVariable("BUCKET");
|
|
|
|
|
|
|
|
|
|
private readonly B2Client _client;
|
|
|
|
|
|
|
|
|
|
public B2ApiClient() {
|
|
|
|
|
_client = new B2Client(KeyId, Key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<EpisodeUrl> GetDownloadLink(string file) {
|
2023-03-26 22:15:50 -05:00
|
|
|
|
var auth = await _client.Files.GetDownloadAuthorization(file, 14400, BucketId);
|
2023-03-26 11:37:20 -05:00
|
|
|
|
return new EpisodeUrl {
|
|
|
|
|
Url = _client.Files.GetFriendlyDownloadUrl(file, Bucket),
|
|
|
|
|
Token = auth.AuthorizationToken,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|