// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
// Boston, MA 02110-1301, USA.
+#nullable enable
+
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
+using System.Threading;
+using System.Threading.Tasks;
+using OpenTween.Models;
namespace OpenTween.Thumbnail.Services
{
class SimpleThumbnailService : IThumbnailService
{
protected Regex regex;
- protected string replacement;
- protected string file_replacement;
+ protected string thumb_replacement;
+ protected string? fullsize_replacement;
public SimpleThumbnailService(string pattern, string replacement)
+ : this(pattern, replacement, null)
{
- this.regex = new Regex(pattern, RegexOptions.IgnoreCase);
- this.replacement = replacement;
}
- public SimpleThumbnailService(string pattern, string replacement, string file_replacement)
+ public SimpleThumbnailService(string pattern, string replacement, string? file_replacement)
{
this.regex = new Regex(pattern, RegexOptions.IgnoreCase);
- this.replacement = replacement;
- this.file_replacement = file_replacement;
+ this.thumb_replacement = replacement;
+ this.fullsize_replacement = file_replacement;
}
- public override ThumbnailInfo GetThumbnailInfo(string url, PostClass post)
+ public override Task<ThumbnailInfo?> GetThumbnailInfoAsync(string url, PostClass post, CancellationToken token)
{
- var thumbnailUrl = this.ReplaceUrl(url);
- if (thumbnailUrl == null) return null;
-
- return new ThumbnailInfo()
+ return Task.Run(() =>
{
- ImageUrl = url,
- ThumbnailUrl = thumbnailUrl,
- TooltipText = null,
- ImageFileUrl = ReplaceUrl(url, this.file_replacement)
- };
- }
+ var thumbnailUrl = this.ReplaceUrl(url);
+ if (thumbnailUrl == null) return null;
- protected string ReplaceUrl(string url)
- {
- return ReplaceUrl(url, this.replacement);
+ return new ThumbnailInfo
+ {
+ MediaPageUrl = url,
+ ThumbnailImageUrl = thumbnailUrl,
+ TooltipText = null,
+ FullSizeImageUrl = ReplaceUrl(url, this.fullsize_replacement)
+ };
+ }, token);
}
- protected string ReplaceUrl(string url, string replacement)
+ protected string? ReplaceUrl(string url)
+ => this.ReplaceUrl(url, this.thumb_replacement);
+
+ protected string? ReplaceUrl(string url, string? replacement)
{
if (replacement == null) return null;
var match = this.regex.Match(url);