Skip to content

Commit

Permalink
use vimeo package (DevBetterCom#1169)
Browse files Browse the repository at this point in the history
* apply new vimeo package.

* replace some services and use V1.0.4

* 2 endpoints with services are added.

* mark old ednpoints to old.

* Old video upload endpoints are removed.

* Build success and old vimeo package is removed.

* tests build is fixed.

* DevBetter video working.

* Videos cache is removed.

* Fixing usings

---------

Co-authored-by: Sarah Dutkiewicz <[email protected]>
Co-authored-by: Steve Smith <[email protected]>
  • Loading branch information
3 people authored Oct 24, 2023
1 parent 860ec65 commit 6c9c486
Show file tree
Hide file tree
Showing 251 changed files with 765 additions and 17,362 deletions.
30 changes: 0 additions & 30 deletions DevBetterWeb.sln
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevBetterWeb.Vimeo", "src\DevBetterWeb.Vimeo\DevBetterWeb.Vimeo.csproj", "{07B190B4-A1AD-4967-896B-A1A7040DDB76}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevBetterWeb.Vimeo.Tests", "tests\DevBetterWeb.Vimeo.Tests\DevBetterWeb.Vimeo.Tests.csproj", "{77FEAB83-ACCB-4287-8011-84426B8636BB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevBetterWeb.UnitTests", "tests\DevBetterWeb.UnitTests\DevBetterWeb.UnitTests.csproj", "{0AB375BC-E7AD-4BD9-8D28-AC07351CE37A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevBetterWeb.FunctionalTests", "tests\DevBetterWeb.FunctionalTests\DevBetterWeb.FunctionalTests.csproj", "{26C52F3F-8053-4891-9D9D-E8BB99D566A5}"
Expand Down Expand Up @@ -95,30 +91,6 @@ Global
{AEE17BAB-D187-4BC5-B640-40CC0749566C}.Release|x64.Build.0 = Release|Any CPU
{AEE17BAB-D187-4BC5-B640-40CC0749566C}.Release|x86.ActiveCfg = Release|Any CPU
{AEE17BAB-D187-4BC5-B640-40CC0749566C}.Release|x86.Build.0 = Release|Any CPU
{07B190B4-A1AD-4967-896B-A1A7040DDB76}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{07B190B4-A1AD-4967-896B-A1A7040DDB76}.Debug|Any CPU.Build.0 = Debug|Any CPU
{07B190B4-A1AD-4967-896B-A1A7040DDB76}.Debug|x64.ActiveCfg = Debug|Any CPU
{07B190B4-A1AD-4967-896B-A1A7040DDB76}.Debug|x64.Build.0 = Debug|Any CPU
{07B190B4-A1AD-4967-896B-A1A7040DDB76}.Debug|x86.ActiveCfg = Debug|Any CPU
{07B190B4-A1AD-4967-896B-A1A7040DDB76}.Debug|x86.Build.0 = Debug|Any CPU
{07B190B4-A1AD-4967-896B-A1A7040DDB76}.Release|Any CPU.ActiveCfg = Release|Any CPU
{07B190B4-A1AD-4967-896B-A1A7040DDB76}.Release|Any CPU.Build.0 = Release|Any CPU
{07B190B4-A1AD-4967-896B-A1A7040DDB76}.Release|x64.ActiveCfg = Release|Any CPU
{07B190B4-A1AD-4967-896B-A1A7040DDB76}.Release|x64.Build.0 = Release|Any CPU
{07B190B4-A1AD-4967-896B-A1A7040DDB76}.Release|x86.ActiveCfg = Release|Any CPU
{07B190B4-A1AD-4967-896B-A1A7040DDB76}.Release|x86.Build.0 = Release|Any CPU
{77FEAB83-ACCB-4287-8011-84426B8636BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{77FEAB83-ACCB-4287-8011-84426B8636BB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{77FEAB83-ACCB-4287-8011-84426B8636BB}.Debug|x64.ActiveCfg = Debug|Any CPU
{77FEAB83-ACCB-4287-8011-84426B8636BB}.Debug|x64.Build.0 = Debug|Any CPU
{77FEAB83-ACCB-4287-8011-84426B8636BB}.Debug|x86.ActiveCfg = Debug|Any CPU
{77FEAB83-ACCB-4287-8011-84426B8636BB}.Debug|x86.Build.0 = Debug|Any CPU
{77FEAB83-ACCB-4287-8011-84426B8636BB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{77FEAB83-ACCB-4287-8011-84426B8636BB}.Release|Any CPU.Build.0 = Release|Any CPU
{77FEAB83-ACCB-4287-8011-84426B8636BB}.Release|x64.ActiveCfg = Release|Any CPU
{77FEAB83-ACCB-4287-8011-84426B8636BB}.Release|x64.Build.0 = Release|Any CPU
{77FEAB83-ACCB-4287-8011-84426B8636BB}.Release|x86.ActiveCfg = Release|Any CPU
{77FEAB83-ACCB-4287-8011-84426B8636BB}.Release|x86.Build.0 = Release|Any CPU
{0AB375BC-E7AD-4BD9-8D28-AC07351CE37A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0AB375BC-E7AD-4BD9-8D28-AC07351CE37A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0AB375BC-E7AD-4BD9-8D28-AC07351CE37A}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -152,8 +124,6 @@ Global
{220361D6-9C76-4E3F-BD34-3C7B50E2CA4D} = {106AE906-5075-410A-B941-912F811848EE}
{C9751CB7-4CD6-4633-A99A-4F6ADD525437} = {106AE906-5075-410A-B941-912F811848EE}
{AEE17BAB-D187-4BC5-B640-40CC0749566C} = {B31B4797-1D9F-4288-808C-BE9A31A98C7D}
{07B190B4-A1AD-4967-896B-A1A7040DDB76} = {106AE906-5075-410A-B941-912F811848EE}
{77FEAB83-ACCB-4287-8011-84426B8636BB} = {B31B4797-1D9F-4288-808C-BE9A31A98C7D}
{0AB375BC-E7AD-4BD9-8D28-AC07351CE37A} = {B31B4797-1D9F-4288-808C-BE9A31A98C7D}
{26C52F3F-8053-4891-9D9D-E8BB99D566A5} = {B31B4797-1D9F-4288-808C-BE9A31A98C7D}
EndGlobalSection
Expand Down
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<PackageVersion Include="Moq" Version="4.18.4" />
<PackageVersion Include="NETStandard.Library" Version="2.0.3" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="NimblePros.Vimeo" Version="1.0.5" />
<PackageVersion Include="NSubstitute" Version="5.1.0" />
<PackageVersion Include="ReportGenerator" Version="5.1.25" />
<PackageVersion Include="Sendgrid" Version="9.28.1" />
Expand Down
2 changes: 1 addition & 1 deletion src/DevBetterWeb.Core/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static class Constants
public static class ConfigKeys
{
public const string FileStorageConnectionString = "storageconnectionstring";
public const string VimeoToken = "VIMEO_TOKEN";
public const string ApiKey = "API_KEY";
public const string VimeoSettings = "VimeoSettings";
}
}
5 changes: 1 addition & 4 deletions src/DevBetterWeb.Core/DevBetterWeb.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@
<PackageReference Include="Ardalis.Specification" />
<PackageReference Include="CSharpFunctionalExtensions" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" />
<PackageReference Include="NimblePros.Vimeo" />
<PackageReference Include="System.ComponentModel.Annotations" />
<PackageReference Include="NETStandard.Library" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DevBetterWeb.Vimeo\DevBetterWeb.Vimeo.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using DevBetterWeb.Core.Entities;

namespace DevBetterWeb.Core.Interfaces;
public interface IAddCreatedVideoToFolderService
{
Task<bool> ExecuteAsync(bool isBaseFolder, long? folderId, ArchiveVideo archiveVideo, CancellationToken cancellationToken = default);
}
14 changes: 14 additions & 0 deletions src/DevBetterWeb.Core/Interfaces/ICreateVideoService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using NimblePros.Vimeo.VideoTusService;

namespace DevBetterWeb.Core.Interfaces;
public interface ICreateVideoService
{
Task<string> StartAsync(string videoName, long videoSize, string domain, CancellationToken cancellationToken = default);
Task<UploadChunkStatus> UploadChunkAsync(bool isBaseFolder, string sessionId, string chunk, string? description, long? folderId, CancellationToken cancellationToken = default);
}
11 changes: 0 additions & 11 deletions src/DevBetterWeb.Core/Interfaces/IVideosCacheService.cs

This file was deleted.

1 change: 0 additions & 1 deletion src/DevBetterWeb.Core/Interfaces/IVideosService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace DevBetterWeb.Core.Interfaces;
public interface IVideosService
{
Task UpdateVideosThumbnail(AppendOnlyStringList? messages, CancellationToken cancellationToken = default);
Task UpdateVideosCache(AppendOnlyStringList? messages);
Task DeleteVideosNotExistOnVimeoFromDatabase(AppendOnlyStringList? messages);
Task DeleteVideosNotExistOnVimeoFromVimeo(AppendOnlyStringList? messages);
Task AddArchiveVideoInfo(ArchiveVideo archiveVideo, CancellationToken cancellationToken = default);
Expand Down
71 changes: 71 additions & 0 deletions src/DevBetterWeb.Core/Services/AddCreatedVideoToFolderService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using DevBetterWeb.Core.Entities;
using DevBetterWeb.Core.Interfaces;
using NimblePros.Vimeo.FolderServices;
using NimblePros.Vimeo.Models;

namespace DevBetterWeb.Core.Services;
public class AddCreatedVideoToFolderService : IAddCreatedVideoToFolderService
{
private readonly GetFolderService _getFolderService;
private readonly AddVideoToFolderService _addVideoToFolderService;

public AddCreatedVideoToFolderService(GetFolderService getFolderService, AddVideoToFolderService addVideoToFolderService)
{
_getFolderService = getFolderService;
_addVideoToFolderService = addVideoToFolderService;
}

public async Task<bool> ExecuteAsync(bool isBaseFolder, long? folderId, ArchiveVideo archiveVideo, CancellationToken cancellationToken = default)
{
if (!ValidateInputs(folderId, archiveVideo))
{
return false;
}

var folder = await GetVimeoFolderAsync((int)folderId!.Value, cancellationToken);
if (folder == null)
{
return false;
}

var isVideoAdded = await AddVideoToFolderInVimeoAsync((int)folderId.Value, int.Parse(archiveVideo.VideoId!), cancellationToken);
if (!isVideoAdded)
{
return false;
}

return true;
}

private bool ValidateInputs(long? folderId, ArchiveVideo archiveVideo)
{
return folderId != null && !string.IsNullOrWhiteSpace(archiveVideo.VideoId);
}

private async Task<Folder?> GetVimeoFolderAsync(int folderId, CancellationToken cancellationToken)
{
var getFolderRequest = new GetFolderRequest(folderId);
var getFolderResult = await _getFolderService.ExecuteAsync(getFolderRequest, cancellationToken);

if (!getFolderResult.IsSuccess)
{
return null;
}

return new Folder().SetId((int)getFolderResult.Data.Id).SetName(getFolderResult.Data.Name);
}

private async Task<bool> AddVideoToFolderInVimeoAsync(int folderId, int videoId, CancellationToken cancellationToken)
{
var addVideoToFolderRequest = new AddVideoToFolderRequest(folderId, videoId);
var addVideoToFolder = await _addVideoToFolderService.ExecuteAsync(addVideoToFolderRequest, cancellationToken);

return addVideoToFolder.IsSuccess;
}
}
106 changes: 106 additions & 0 deletions src/DevBetterWeb.Core/Services/CreateVideoService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using DevBetterWeb.Core.Entities;
using DevBetterWeb.Core.Events;
using DevBetterWeb.Core.Interfaces;
using DevBetterWeb.Core.Specs;
using NimblePros.Vimeo.Interfaces;
using NimblePros.Vimeo.Models;
using NimblePros.Vimeo.VideoServices;
using NimblePros.Vimeo.VideoTusService;

namespace DevBetterWeb.Core.Services;
public class CreateVideoService : ICreateVideoService
{
private readonly GetVideoService _getVideoService;
private readonly IUploadVideoTusService _uploadVideoTusService;
private readonly IRepository<ArchiveVideo> _repositoryArchiveVideo;
private readonly IAddCreatedVideoToFolderService _addCreatedVideoToFolderService;

public CreateVideoService(GetVideoService getVideoService, IUploadVideoTusService uploadVideoTusService, IRepository<ArchiveVideo> repositoryArchiveVideo, IAddCreatedVideoToFolderService addCreatedVideoToFolderService)
{
_getVideoService = getVideoService;
_uploadVideoTusService = uploadVideoTusService;
_repositoryArchiveVideo = repositoryArchiveVideo;
_addCreatedVideoToFolderService = addCreatedVideoToFolderService;
}

public async Task<string> StartAsync(string videoName, long videoSize, string domain, CancellationToken cancellationToken = default)
{
var uploadVideoRequest = new UploadVideoRequest(UploadApproach.Tus)
{
Name = videoName,
Upload = { Size = videoSize },
Embed = new Embed { Title = new Title { Owner = EmbedOwnerTitle.Hide } },
Privacy = new Privacy { Embed = EmbedPrivacy.Whitelist, View = PrivacyView.Disable, Download = false },
EmbedDomains = new List<string> { domain },
HideFromVimeo = true
};
var sessionId = await _uploadVideoTusService.StartAsync(uploadVideoRequest, cancellationToken);

return sessionId;
}

public async Task<UploadChunkStatus> UploadChunkAsync(bool isBaseFolder, string sessionId, string chunk, string? description, long? folderId, CancellationToken cancellationToken = default)
{
var result = await _uploadVideoTusService.UploadChunkAsync(sessionId, Convert.FromBase64String(chunk), cancellationToken);
if (result.UploadChunkStatus == UploadChunkStatus.Completed)
{
var addArchive = await AddArchiveVideoAsync(result.VideoId, description, cancellationToken);
if (addArchive == null)
{
return UploadChunkStatus.Error;
}

_ = await _addCreatedVideoToFolderService.ExecuteAsync(isBaseFolder, folderId, addArchive, cancellationToken);
}

return result.UploadChunkStatus;
}

private async Task<ArchiveVideo?> AddArchiveVideoAsync(long videoId, string? description, CancellationToken cancellationToken = default)
{
if (videoId <= 0)
{
return null;
}
var response = await _getVideoService.ExecuteAsync(videoId, cancellationToken);
if (!response.IsSuccess)
{
return null;
}
var archiveVideo = new ArchiveVideo
{
Title = response.Data.Name,
DateCreated = response.Data.CreatedTime,
DateUploaded = DateTimeOffset.UtcNow,
Duration = response.Data.Duration * 1000,
VideoId = response.Data.Id.ToString(),
VideoUrl = response.Data.Uri,
Description = description
};

var spec = new ArchiveVideoByVideoIdSpec(archiveVideo.VideoId);
var existVideo = await _repositoryArchiveVideo.FirstOrDefaultAsync(spec, cancellationToken);
if (existVideo == null)
{
var videoAddedEvent = new VideoAddedEvent(archiveVideo);
archiveVideo.Events.Add(videoAddedEvent);

_ = await _repositoryArchiveVideo.AddAsync(archiveVideo, cancellationToken);

return archiveVideo;
}
existVideo.Description = archiveVideo.Description;
existVideo.Title = archiveVideo.Title;
existVideo.Duration = archiveVideo.Duration;

await _repositoryArchiveVideo.UpdateAsync(existVideo, cancellationToken);

return existVideo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
using DevBetterWeb.Infrastructure.IssuingHandler.StripeIssuingHandler;
using DevBetterWeb.Infrastructure.Logging;
using DevBetterWeb.Infrastructure.Services;
using DevBetterWeb.Vimeo.Extensions;
using Microsoft.AspNetCore.Identity.UI.Services;
using NimblePros.Vimeo.Extensions;
using Stripe;
using Stripe.Issuing;
using CardService = Stripe.Issuing.CardService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

<ItemGroup>
<ProjectReference Include="..\DevBetterWeb.Core\DevBetterWeb.Core.csproj" />
<ProjectReference Include="..\DevBetterWeb.Vimeo\DevBetterWeb.Vimeo.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Ardalis.Specification.EntityFrameworkCore" />
<PackageReference Include="Markdig" />
<PackageReference Include="NimblePros.Vimeo" />
<PackageReference Include="Sendgrid" />
<PackageReference Include="Ardalis.EFCore.Extensions" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public async Task Handle(DailyCheckInitiatedEvent domainEvent)
await _videosService.DeleteVideosNotExistOnVimeoFromVimeo(messages);
await _videosService.DeleteVideosNotExistOnVimeoFromDatabase(messages);
await _videosService.UpdateVideosThumbnail(messages);
await _videosService.UpdateVideosCache(messages);

await _dailyCheckPingService.PingAdminsAboutAlmostAlumsIfNeeded(messages);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ namespace DevBetterWeb.Core.Handlers;
public class DiscordLogVideoAddedHandler : IHandle<VideoAddedEvent>
{
private readonly CoachingSessionsWebhook _webhook;
private readonly IVideosCacheService _videosCacheService;

public DiscordLogVideoAddedHandler(CoachingSessionsWebhook webhook, IVideosCacheService videosCacheService)
public DiscordLogVideoAddedHandler(CoachingSessionsWebhook webhook)
{
_webhook = webhook;
_videosCacheService = videosCacheService;
}

public static string ReturnWebhookMessageString(VideoAddedEvent domainEvent)
Expand All @@ -24,8 +22,6 @@ public static string ReturnWebhookMessageString(VideoAddedEvent domainEvent)

public Task Handle(VideoAddedEvent domainEvent)
{
_ = _videosCacheService.UpdateAllVideosAsync();

var message = ReturnWebhookMessageString(domainEvent);
return _webhook.SendAsync(message);
}
Expand Down
Loading

0 comments on commit 6c9c486

Please sign in to comment.