Tweak subscriptions some more

This commit is contained in:
Pixeldrain-Server committed 2026-10-06 00:46:54 +02:00
1 parent 1f7238841a
commit a50ac7310f
9 files changed
+107 -372

No files matched your search

+14 -2
View File
@@ -2,6 +2,7 @@
import ProgressBar from "util/ProgressBar.svelte";
import { formatDataVolume, formatEuros } from "util/Formatting"
import { user } from "lib/UserStore";
import { bills_extra } from "lib/NovaAPI";
let { total = 0, used = 0 }: {
total?: number;
@@ -10,8 +11,11 @@ let { total = 0, used = 0 }: {
let frac = $derived(used / total)
let bill_shock = $derived($user !== null && $user.monthly_transfer_cap === total)
let billable = $derived($user !== null && $user.subscription.price_per_tb_bandwidth > 0)
let billed = $derived(billable && $user.usage_based_billing)
let price = $derived($user === null ? 0 : $user.subscription.price_per_tb_bandwidth)
let billed = $derived($user !== null && bills_extra($user, price))
// Usage based billing is on, but the balance is too far below zero for it
let overdrawn = $derived($user !== null && $user.usage_based_billing && price > 0 && !billed)
let included = $derived($user === null ? 0 : $user.subscription.monthly_transfer_cap)
</script>
@@ -50,6 +54,14 @@ let included = $derived($user === null ? 0 : $user.subscription.monthly_transfer
This is your bill shock limit. <a href="/user/sharing">Increase
or disable the limit</a> to continue sharing files.
</p>
{:else if overdrawn}
<p>
Your balance is too far below zero to bill more data transfer.
Top up your credit to continue sharing files.
</p>
<a class="button button_highlight" href="/user/subscription/manage">
<i class="icon">paid</i> Top up credit
</a>
{:else}
<p>
Upgrade your plan or enable
+12 -5
View File
@@ -3,11 +3,12 @@ import { onMount } from "svelte";
import { formatDataVolume, formatEuros } from "util/Formatting";
import ProgressBar from "util/ProgressBar.svelte";
import { loading_run } from "lib/Loading";
import { get_endpoint, put_user } from 'lib/NovaAPI';
import { get_endpoint, period_price, put_user } from 'lib/NovaAPI';
import SuccessMessage from 'util/SuccessMessage.svelte';
import { user } from "lib/UserStore";
let success_message: SuccessMessage = $state()
let transfer_cap = $state($user === null ? 0 : $user.monthly_transfer_cap / 1e12)
const update_user = async (e: SubmitEvent) => {
@@ -99,6 +100,12 @@ onMount(async () => {
{formatEuros($user.subscription.price_per_tb_bandwidth, 2)} per TB
for data transfer.
</p>
<p>
This usage is charged from your account credit afterwards. When
your balance is more than {formatEuros(period_price($user), 2)} below zero
(the price of your subscription period) the limits of your plan
apply again, until you top up your credit.
</p>
<label>
<input type="checkbox" checked={$user.usage_based_billing} onchange={set_usage_based_billing}/>
Enable usage based billing
@@ -125,10 +132,10 @@ onMount(async () => {
<ProgressBar used={transfer_used} total={transfer_cap*1e12} warn></ProgressBar>
<p>
The billshock limit limits how much bandwidth your account can use in a
30 day window. When this limit is reached hotlinking will be disabled
and you will no longer be charged for bandwidth usage. This is mostly
useful for the Prepaid subscription, but it works for Patreon plans too.
Set to 0 to disable the limit.
30 day window. When this limit is reached your files can't be downloaded
until your usage drops below it, and you will no longer be charged for
bandwidth usage. This is mostly useful with usage based billing, but it
works without it too. Set to 0 to disable the limit.
</p>
<h2>Embedding controls</h2>
+17 -2
View File
@@ -2,6 +2,7 @@
import { formatDataVolume, formatEuros } from "util/Formatting"
import ProgressBar from "util/ProgressBar.svelte";
import { user } from "lib/UserStore";
import { bills_extra } from "lib/NovaAPI";
let { total = 0, used = 0 }: {
total?: number;
@@ -9,8 +10,11 @@ let { total = 0, used = 0 }: {
} = $props();
let frac = $derived(total <= 0 ? 0 : used / total)
let billable = $derived($user !== null && $user.subscription.price_per_tb_storage > 0)
let billed = $derived(billable && $user.usage_based_billing)
let price = $derived($user === null ? 0 : $user.subscription.price_per_tb_storage)
let billed = $derived($user !== null && bills_extra($user, price))
// Usage based billing is on, but the balance is too far below zero for it
let overdrawn = $derived($user !== null && $user.usage_based_billing && price > 0 && !billed)
</script>
<ProgressBar total={total} used={used} warn></ProgressBar>
@@ -35,6 +39,17 @@ let billed = $derived(billable && $user.usage_based_billing)
month.
</p>
{/if}
{:else if frac > 1 && overdrawn}
<div class="highlight_yellow">
<p>
You are storing more than your plan includes, and your balance is
too far below zero to bill more storage. You can't upload new files
until you top up your credit. Your existing files stay available.
</p>
<a class="button button_highlight" href="/user/subscription/manage">
<i class="icon">paid</i> Top up credit
</a>
</div>
{:else if frac > 1}
<div class="highlight_yellow">
<p>
+7 -5
View File
@@ -99,11 +99,13 @@ onMount(() => {
<h2>Transaction log</h2>
<p>
Here is a log of all transactions on your account balance. Usage is
calculated per day. The storage charge is divided by the average number
of days in a month (30.4375).
calculated per day. Storage and bandwidth are only charged for what you
use above the amounts included in your plan, and that is the usage which
is listed here. The storage charge is divided by the average number of
days in a month (30.4375).
</p>
<p>
Example: If you have 2 TB stored on your Nova account at €4 per TB
Example: If you store 2 TB more than your plan includes at €4 per TB
then the daily charge will be:<br/>
2 TB * € 4 = € 8<br/>
@@ -129,11 +131,11 @@ onMount(() => {
</li>
<li>
Storage charge: <Euro amount={transactions.total_storage_charge} precision="4"/>
(used {formatDataVolume(transactions.total_storage_used, 3)})
({formatDataVolume(transactions.total_storage_used, 3)} above your plan)
</li>
<li>
Bandwidth charge: <Euro amount={transactions.total_bandwidth_charge} precision="4"/>
(used {formatDataVolume(transactions.total_bandwidth_used, 3)})
({formatDataVolume(transactions.total_bandwidth_used, 3)} above your plan)
</li>
<li>
Total charge: <Euro amount={transactions.total_deducted} precision="4"/>
@@ -137,14 +137,14 @@ onMount(() => {
<td>Storage charge</td>
<td>
<Euro amount={transactions.total_storage_charge} precision="4"/>
(used {formatDataVolume(transactions.total_storage_used, 3)})
({formatDataVolume(transactions.total_storage_used, 3)} above your plan)
</td>
</tr>
<tr>
<td>Bandwidth charge</td>
<td>
<Euro amount={transactions.total_bandwidth_charge} precision="4"/>
(used {formatDataVolume(transactions.total_bandwidth_used, 3)})
({formatDataVolume(transactions.total_bandwidth_used, 3)} above your plan)
</td>
</tr>
<tr>
@@ -1,7 +1,33 @@
<script lang="ts">
import { days_per_month, subscription_periods } from "lib/NovaAPI";
import { user } from "lib/UserStore";
import Euro from "util/Euro.svelte";
import { formatDataVolume } from "util/Formatting";
import { formatDataVolume, formatDate, formatEuros } from "util/Formatting";
// What the account costs per day at its current usage, the same sum the server
// charges every night. Data transfer above the plan is left out, it can't be
// predicted
let daily_cost = $derived.by(() => {
if ($user === null || $user.subscription.type !== "subscription") {
return 0
}
const sub = $user.subscription
const discount = subscription_periods.find(
p => p.months === $user.subscription_months,
)?.discount ?? 1
const extra_storage = $user.usage_based_billing ?
Math.max(0, $user.storage_space_used - sub.storage_limit) *
sub.price_per_tb_storage / 1e12 : 0
return (sub.monthly_fee * discount + extra_storage) / days_per_month
})
let credit_until = $derived.by(() => {
const date = new Date()
date.setDate(date.getDate() + Math.floor($user.balance_micro_eur / daily_cost))
return formatDate(date, false, false, false)
})
</script>
{#if $user !== null}
@@ -16,6 +42,18 @@ import { formatDataVolume } from "util/Formatting";
<li>
Current account balance: <Euro amount={$user.balance_micro_eur}></Euro><br/>
{#if daily_cost > 0}
Your plan costs {formatEuros(daily_cost, 4)} per day at your
current usage.
{#if $user.balance_micro_eur > 0}
Your credit lasts until about {credit_until}.
{/if}
{#if $user.usage_based_billing}
Data transfer above your plan is not included.
{/if}
<br/>
{/if}
<i class="icon">account_balance_wallet</i>
<a href="/user/subscription/manage">Deposit credit</a><br/>
@@ -1,5 +1,5 @@
<script lang="ts">
import { get_endpoint, get_user, type User } from "lib/NovaAPI";
import { bills_extra, get_endpoint, get_user, type User } from "lib/NovaAPI";
import { onMount } from "svelte";
import HotlinkProgressBar from "user_home/HotlinkProgressBar.svelte";
import StorageProgressBar from "user_home/StorageProgressBar.svelte";
@@ -37,7 +37,7 @@ onMount(async () => {
// The lowest limit which blocks downloads. With usage based billing the
// plan's limit is billed instead, only the bill shock limit blocks
let caps = [user.monthly_transfer_cap]
if (!user.usage_based_billing || user.subscription.price_per_tb_bandwidth <= 0) {
if (!bills_extra(user, user.subscription.price_per_tb_bandwidth)) {
caps.push(user.subscription.monthly_transfer_cap)
}
caps = caps.filter(cap => cap > 0)