forked from Kieran/void.cat
Allow setting None
paywall service
This commit is contained in:
parent
fb74a1a311
commit
90cbcec11d
@ -83,7 +83,7 @@ public class DownloadController : Controller
|
||||
}
|
||||
|
||||
// check paywall
|
||||
if (meta.Paywall != default)
|
||||
if (meta.Paywall != default && meta.Paywall.Service != PaywallServices.None)
|
||||
{
|
||||
var orderId = Request.Headers.GetHeader("V-OrderId") ?? Request.Query["orderId"];
|
||||
if (!await IsOrderPaid(orderId))
|
||||
|
@ -125,7 +125,9 @@ namespace VoidCat.Controllers
|
||||
return Ok();
|
||||
}
|
||||
|
||||
return BadRequest();
|
||||
// if none set, set NoPaywallConfig
|
||||
await _paywall.SetConfig(gid, new NoPaywallConfig());
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,8 @@ public enum PaywallServices
|
||||
|
||||
public abstract record PaywallConfig(PaywallServices Service, PaywallMoney Cost);
|
||||
|
||||
public record NoPaywallConfig() : PaywallConfig(PaywallServices.None, new PaywallMoney(0m, PaywallCurrencies.BTC));
|
||||
|
||||
public record StrikePaywallConfig(PaywallMoney Cost) : PaywallConfig(PaywallServices.Strike, Cost)
|
||||
{
|
||||
public string Handle { get; init; }
|
||||
|
@ -20,6 +20,7 @@ public class RedisPaywallStore : IPaywallStore
|
||||
var cfg = json.HasValue ? JsonConvert.DeserializeObject<PaywallBlank>(json) : default;
|
||||
return cfg?.Service switch
|
||||
{
|
||||
PaywallServices.None => JsonConvert.DeserializeObject<NoPaywallConfig>(json),
|
||||
PaywallServices.Strike => JsonConvert.DeserializeObject<StrikePaywallConfig>(json),
|
||||
_ => default
|
||||
};
|
||||
|
@ -2,6 +2,7 @@ import {useState} from "react";
|
||||
|
||||
import "./FileEdit.css";
|
||||
import {StrikePaywallConfig} from "./StrikePaywallConfig";
|
||||
import {NoPaywallConfig} from "./NoPaywallConfig";
|
||||
|
||||
export function FileEdit(props) {
|
||||
const file = props.file;
|
||||
@ -12,10 +13,24 @@ export function FileEdit(props) {
|
||||
return null;
|
||||
}
|
||||
|
||||
async function saveConfig(cfg) {
|
||||
let req = await fetch(`/upload/${file.id}/paywall`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(cfg),
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
});
|
||||
return req.ok;
|
||||
}
|
||||
|
||||
function renderPaywallConfig() {
|
||||
switch (paywall) {
|
||||
case 0: {
|
||||
return <NoPaywallConfig privateFile={privateFile} onSaveConfig={saveConfig}/>;
|
||||
}
|
||||
case 1: {
|
||||
return <StrikePaywallConfig file={file} privateFile={privateFile}/>
|
||||
return <StrikePaywallConfig file={file} privateFile={privateFile} onSaveConfig={saveConfig}/>
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -21,7 +21,7 @@ export function FilePreview() {
|
||||
}
|
||||
|
||||
function renderTypes() {
|
||||
if (info.paywall) {
|
||||
if (info.paywall && info.paywall.service !== 0) {
|
||||
if (!order) {
|
||||
return <FilePaywall file={info} onPaid={loadInfo}/>;
|
||||
}
|
||||
|
27
VoidCat/spa/src/NoPaywallConfig.js
Normal file
27
VoidCat/spa/src/NoPaywallConfig.js
Normal file
@ -0,0 +1,27 @@
|
||||
import FeatherIcon from "feather-icons-react";
|
||||
import {useState} from "react";
|
||||
|
||||
export function NoPaywallConfig(props) {
|
||||
const [saveStatus, setSaveStatus] = useState();
|
||||
const privateFile = props.privateFile;
|
||||
const onSaveConfig = props.onSaveConfig;
|
||||
|
||||
async function saveConfig(e) {
|
||||
e.target.disabled = true;
|
||||
let cfg = {
|
||||
editSecret: privateFile.metadata.editSecret
|
||||
};
|
||||
|
||||
if (typeof onSaveConfig === "function") {
|
||||
setSaveStatus(await onSaveConfig(cfg));
|
||||
}
|
||||
e.target.disabled = false;
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<button onClick={saveConfig}>Save</button>
|
||||
{saveStatus ? <FeatherIcon icon={saveStatus === true ? "check-circle" : "alert-circle"}/> : null}
|
||||
</div>
|
||||
)
|
||||
}
|
@ -5,15 +5,15 @@ import {PaywallCurrencies} from "./Const";
|
||||
export function StrikePaywallConfig(props) {
|
||||
const file = props.file;
|
||||
const privateFile = props.privateFile;
|
||||
const onSaveConfig = props.onSaveConfig;
|
||||
const paywall = file.paywall;
|
||||
const editSecret = privateFile.metadata.editSecret;
|
||||
const id = file.id;
|
||||
|
||||
const [username, setUsername] = useState(paywall?.handle ?? "hrf");
|
||||
const [currency, setCurrency] = useState(paywall?.cost.currency ?? PaywallCurrencies.USD);
|
||||
const [price, setPrice] = useState(paywall?.cost.amount ?? 1);
|
||||
const [saveStatus, setSaveStatus] = useState();
|
||||
|
||||
|
||||
async function saveStrikeConfig(e) {
|
||||
e.target.disabled = true;
|
||||
let cfg = {
|
||||
@ -27,17 +27,14 @@ export function StrikePaywallConfig(props) {
|
||||
}
|
||||
};
|
||||
|
||||
let req = await fetch(`/upload/${id}/paywall`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(cfg),
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
if (typeof onSaveConfig === "function") {
|
||||
if (await onSaveConfig(cfg)) {
|
||||
setSaveStatus(true);
|
||||
} else {
|
||||
alert("Error settings paywall config!");
|
||||
setSaveStatus(false);
|
||||
}
|
||||
});
|
||||
if (!req.ok) {
|
||||
alert("Error settings paywall config!");
|
||||
}
|
||||
setSaveStatus(req.ok);
|
||||
e.target.disabled = false;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user