forked from DevBetterCom/DevBetterWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use vimeo package (DevBetterCom#1169)
* 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
1 parent
860ec65
commit 6c9c486
Showing
251 changed files
with
765 additions
and
17,362 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/DevBetterWeb.Core/Interfaces/IAddCreatedVideoToFolderService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/DevBetterWeb.Core/Services/AddCreatedVideoToFolderService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.