// 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.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
+using OpenTween.Models;
namespace OpenTween.Thumbnail.Services
{
{
protected Regex regex;
protected string thumb_replacement;
- protected string fullsize_replacement;
-
- protected readonly HttpClient http;
+ protected string? fullsize_replacement;
public SimpleThumbnailService(string pattern, string replacement)
- : this(null, pattern, replacement, null)
- {
- }
-
- public SimpleThumbnailService(HttpClient http, string pattern, string replacement)
- : this(http, pattern, replacement, null)
+ : this(pattern, replacement, null)
{
}
- public SimpleThumbnailService(string pattern, string replacement, string file_replacement)
- : this(null, pattern, replacement, file_replacement)
+ public SimpleThumbnailService(string pattern, string replacement, string? file_replacement)
{
- }
-
- public SimpleThumbnailService(HttpClient http, string pattern, string replacement, string file_replacement)
- {
- this.http = http ?? MyCommon.CreateHttpClient();
this.regex = new Regex(pattern, RegexOptions.IgnoreCase);
this.thumb_replacement = replacement;
this.fullsize_replacement = file_replacement;
}
- public override Task<ThumbnailInfo> GetThumbnailInfoAsync(string url, PostClass post, CancellationToken token)
+ public override Task<ThumbnailInfo?> GetThumbnailInfoAsync(string url, PostClass post, CancellationToken token)
{
return Task.Run(() =>
{
return new ThumbnailInfo
{
- ImageUrl = url,
- ThumbnailUrl = thumbnailUrl,
+ MediaPageUrl = url,
+ ThumbnailImageUrl = thumbnailUrl,
TooltipText = null,
FullSizeImageUrl = ReplaceUrl(url, this.fullsize_replacement)
};
}, token);
}
- protected string ReplaceUrl(string url)
- {
- return ReplaceUrl(url, this.thumb_replacement);
- }
+ protected string? ReplaceUrl(string url)
+ => this.ReplaceUrl(url, this.thumb_replacement);
- protected string ReplaceUrl(string url, string replacement)
+ protected string? ReplaceUrl(string url, string? replacement)
{
if (replacement == null) return null;
var match = this.regex.Match(url);