-
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.
Merge pull request #1 from skybrud/expired-imgs
feat: avoid expired thumbnails
- Loading branch information
Showing
4 changed files
with
67 additions
and
16 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
src/Skybrud.VideoPicker.Skyfish/Controllers/SkyfishController.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,45 @@ | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Web.Http; | ||
using Limbo.Integrations.Skyfish; | ||
using Skybrud.VideoPicker.Exceptions; | ||
using Skybrud.VideoPicker.Services; | ||
using Skybrud.WebApi.Json; | ||
using Umbraco.Web.WebApi; | ||
|
||
namespace Skybrud.VideoPicker.Skyfish.Controllers { | ||
[JsonOnlyConfiguration] | ||
public class SkyfishController : UmbracoApiController { | ||
|
||
private readonly VideoPickerService _videoPickerService; | ||
|
||
public SkyfishController(VideoPickerService videoPickerService) { | ||
_videoPickerService = videoPickerService; | ||
} | ||
|
||
[Route("umbraco/api/skyfish/GetThumbnail")] | ||
public object GetThumbnail(string uniqueMediaId) { | ||
|
||
if (!_videoPickerService.Providers.TryGet(out SkyfishVideoProvider provider)) return Request.CreateResponse(HttpStatusCode.NotFound); | ||
if (!_videoPickerService.Config.TryGetConfig(provider, out SkyfishConfig config)) return Request.CreateResponse(HttpStatusCode.NotFound); | ||
|
||
// Get the first credentials (or trigger an error if none) | ||
SkyfishCredentials credentials = config.Credentials.FirstOrDefault(); | ||
if (credentials == null) throw new VideosException("Skyfish provider is not configured (1)."); | ||
if (credentials.IsConfigured == false) throw new VideosException("Skyfish provider is not configured (2)."); | ||
|
||
// Initialize a new service for the Skyfish API | ||
SkyfishHttpService api = SkyfishHttpService.CreateFromKeys(credentials.PublicKey, credentials.SecretKey, credentials.Username, credentials.Password); | ||
SkyfishHttpHelper skyHelper = new SkyfishHttpHelper(api); | ||
|
||
var thumbnailUrl = skyHelper.GetVideoByUniqueMediaId(int.Parse(uniqueMediaId)).ThumbnailUrl; | ||
|
||
if (!string.IsNullOrWhiteSpace(thumbnailUrl)) return Redirect(thumbnailUrl); | ||
return Request.CreateResponse(HttpStatusCode.NotFound); | ||
|
||
} | ||
|
||
} | ||
|
||
} |
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