public async Task <Session> CreateSupporterCheckoutAsync(DbUser user, double amount, CancellationToken cancellationToken = default) { var options = _options.CurrentValue; var duration = (int)Math.Floor(amount / options.SupporterPrice); return(await new SessionService(_stripe).CreateAsync(new SessionCreateOptions { Mode = "payment", PaymentMethodTypes = new List <string> { "card" }, SuccessUrl = _link.GetWebLink("/support/pending"), CancelUrl = _link.GetWebLink("/support"), ClientReferenceId = user.Id, CustomerEmail = user.Email, LineItems = new List <SessionLineItemOptions> { new SessionLineItemOptions { PriceData = new SessionLineItemPriceDataOptions { UnitAmount = (long)Math.Floor(amount * 100), Currency = "usd", ProductData = new SessionLineItemPriceDataProductDataOptions { Name = "nhitomi supporter", Description = $"{duration} {(duration == 1 ? "month" : "months")} of nhitomi supporter.", Images = new List <string> { _link.GetWebLink("/logo-192x192.png") } } }, Quantity = 1 } }, Metadata = new Dictionary <string, string> { ["duration"] = duration.ToString(), ["amount"] = amount.ToString(CultureInfo.InvariantCulture) } }, null, cancellationToken)); }
public nhitomiDummyBookScraper(IServiceProvider services, ILogger <nhitomiDummyBookScraper> logger, IElasticClient client, ILinkGenerator link) : base(services, Extensions.GetOptionsMonitor(new Options()), logger) { _client = client; _link = link; var hostname = new Uri(_link.GetWebLink("/")).Authority; UrlRegex = new ScraperUrlRegex($@"(nhitomi(\/|\s+)|(https?:\/\/)?{Regex.Escape(hostname)}\/books\/)(?<id>\w{{1,{Snowflake.MaxLength}}})((\/contents)?\/(?<contentId>\w{{1,{Snowflake.MaxLength}}}))?\/?"); }
public GetInfoResponse GetInfo() => new GetInfoResponse { PublicUrl = _link.GetWebLink("/"), Version = VersionInfo.Commit, RecaptchaSiteKey = _recaptchaOptions.SiteKey, DiscordOAuthUrl = _discordOAuth.AuthorizeUrl, Scrapers = _scrapers.ToArray(s => new ScraperInfo { Name = s.Name, Type = s.Type, Category = s.Category, Enabled = s.Enabled, Url = s.Url, GalleryRegexLax = s.UrlRegex?.Lax.ToString(), GalleryRegexStrict = s.UrlRegex?.Strict.ToString() }) };
public GetInfoResponse GetInfo() => new GetInfoResponse { PublicUrl = _link.GetWebLink("/"), Version = VersionInfo.Version, RecaptchaSiteKey = _recaptchaOptions.CurrentValue.SiteKey, DiscordOAuthUrl = _discordOAuth.AuthorizeUrl, Scrapers = _scrapers.ToArray(s => new ScraperInfo { Name = s.Name, Type = s.Type, Category = s.Category, Enabled = s.Enabled, Url = s.Url, GalleryRegexLax = s.UrlRegex?.Lax.ToString(), GalleryRegexStrict = s.UrlRegex?.Strict.ToString() }), Maintenance = _serverOptions.CurrentValue.BlockDatabaseWrites };
public async Task <DbUser> GetOrCreateUserAsync(string code, string redirectUri = null, CancellationToken cancellationToken = default) { var user = await ExchangeCodeAsync(code, redirectUri ?? _link.GetWebLink("oauth/discord"), cancellationToken); return(await GetOrCreateUserAsync(user, cancellationToken)); }