update disk space setting to new api #7356
3 changed files with 89 additions and 32 deletions
|
@ -2226,5 +2226,14 @@
|
|||
"This is information like error logging, performance tracking, and usage statistics. It includes your IP address and basic system details, but no other identifying information (unless you connect to a cloud service)": "This is information like error logging, performance tracking, and usage statistics. It includes your IP address and basic system details, but no other identifying information (unless you connect to a cloud service)",
|
||||
"Use official LBRY wallet servers": "Use official LBRY wallet servers",
|
||||
"Enable Prerelease Updates": "Enable Prerelease Updates",
|
||||
"Enable Upgrade to Test Builds": "Enable Upgrade to Test Builds",
|
||||
"Prereleases may break things and we may not be able to fix them for you.": "Prereleases may break things and we may not be able to fix them for you.",
|
||||
"Limit (GB)": "Limit (GB)",
|
||||
"Limit Hosting for Content you Use": "Limit Hosting for Content you Use",
|
||||
"Allow (GB)": "Allow (GB)",
|
||||
"Content Data Hosting helps to seed things that you watch and download.": "Content Data Hosting helps to seed things that you watch and download.",
|
||||
"Network Data Hosting allows the p2p network to store blobs unrelated to your browsing.": "Network Data Hosting allows the p2p network to store blobs unrelated to your browsing.",
|
||||
"Content: Limit (GB)": "Content: Limit (GB)",
|
||||
"Network: Allow (GB)": "Network: Allow (GB)",
|
||||
"--end--": "--end--"
|
||||
}
|
||||
|
|
|
@ -41,8 +41,11 @@ type DaemonSettings = {
|
|||
|
||||
type DaemonStatus = {
|
||||
disk_space: {
|
||||
running: boolean,
|
||||
space_used: string,
|
||||
content_blobs_storage_used_mb: string,
|
||||
published_blobs_storage_used_mb: string,
|
||||
running: true,
|
||||
seed_blobs_storage_used_mb: string,
|
||||
total_used_mb: string,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -90,10 +93,16 @@ export default function SettingSystem(props: Props) {
|
|||
const [clearingCache, setClearingCache] = React.useState(false);
|
||||
const [storedPassword, setStoredPassword] = React.useState(false);
|
||||
const { disk_space } = daemonStatus;
|
||||
const spaceUsed = Number(disk_space.space_used);
|
||||
const contentSpaceUsed = Number(disk_space.content_blobs_storage_used_mb);
|
||||
const networkSpaceUsed = Number(disk_space.seed_blobs_storage_used_mb);
|
||||
const blobLimitSetting = daemonSettings[DAEMON_SETTINGS.BLOB_STORAGE_LIMIT_MB];
|
||||
const [blobSpaceLimitGB, setBlobSpaceLimit] = React.useState(blobLimitSetting ? blobLimitSetting / 1024 : 0);
|
||||
// const debouncedBlobSpaceLimitGB = useDebounce(blobSpaceLimitGB || 0, 500);
|
||||
const networkLimitSetting = daemonSettings[DAEMON_SETTINGS.NETWORK_STORAGE_LIMIT_MB];
|
||||
const [contentBlobSpaceLimitGB, setContentBlobSpaceLimit] = React.useState(
|
||||
blobLimitSetting ? blobLimitSetting / 1024 : 0
|
||||
);
|
||||
const [networkBlobSpaceLimitGB, setNetworkBlobSpaceLimit] = React.useState(
|
||||
networkLimitSetting ? networkLimitSetting / 1024 : 0
|
||||
);
|
||||
const [limitSpace, setLimitSpace] = React.useState(Boolean(blobLimitSetting));
|
||||
const { available: ffmpegAvailable, which: ffmpegPath } = ffmpegStatus;
|
||||
|
||||
|
@ -109,11 +118,19 @@ export default function SettingSystem(props: Props) {
|
|||
confirmForgetPassword({ callback: () => setStoredPassword(false) });
|
||||
}
|
||||
|
||||
function updateBlobLimitField(gb) {
|
||||
function updateContentBlobLimitField(gb) {
|
||||
if (gb === 0) {
|
||||
setBlobSpaceLimit(0);
|
||||
setContentBlobSpaceLimit(0);
|
||||
} else if (!gb || !isNaN(gb)) {
|
||||
setBlobSpaceLimit(gb);
|
||||
setContentBlobSpaceLimit(gb);
|
||||
}
|
||||
}
|
||||
|
||||
function updateNetworkBlobLimitField(gb) {
|
||||
if (gb === 0) {
|
||||
setNetworkBlobSpaceLimit(0);
|
||||
} else if (!gb || !isNaN(gb)) {
|
||||
setNetworkBlobSpaceLimit(gb);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,18 +139,25 @@ export default function SettingSystem(props: Props) {
|
|||
if (!value) {
|
||||
setDaemonSetting(DAEMON_SETTINGS.BLOB_STORAGE_LIMIT_MB, String(0));
|
||||
} else {
|
||||
const spaceLimitMB = blobSpaceLimitGB * 1024;
|
||||
const spaceLimitMB = contentBlobSpaceLimitGB * 1024;
|
||||
setDaemonSetting(DAEMON_SETTINGS.BLOB_STORAGE_LIMIT_MB, String(spaceLimitMB));
|
||||
}
|
||||
}
|
||||
|
||||
function handleSetBlobSpaceLimit() {
|
||||
const spaceLimitMB = blobSpaceLimitGB * 1024;
|
||||
function handleSetContentBlobSpaceLimit() {
|
||||
const spaceLimitMB = contentBlobSpaceLimitGB * 1024;
|
||||
if (!isNaN(spaceLimitMB) && blobLimitSetting !== spaceLimitMB * 1024) {
|
||||
setDaemonSetting(DAEMON_SETTINGS.BLOB_STORAGE_LIMIT_MB, String(spaceLimitMB));
|
||||
}
|
||||
}
|
||||
|
||||
function handleSetNetworkBlobSpaceLimit() {
|
||||
const spaceLimitMB = networkBlobSpaceLimitGB * 1024;
|
||||
if (!isNaN(spaceLimitMB) && blobLimitSetting !== spaceLimitMB * 1024) {
|
||||
setDaemonSetting(DAEMON_SETTINGS.NETWORK_STORAGE_LIMIT_MB, String(spaceLimitMB));
|
||||
}
|
||||
}
|
||||
|
||||
// Update ffmpeg variables
|
||||
React.useEffect(() => {
|
||||
const { available } = ffmpegStatus;
|
||||
|
@ -198,16 +222,23 @@ export default function SettingSystem(props: Props) {
|
|||
multirow
|
||||
subtitle={
|
||||
<React.Fragment>
|
||||
{__('Content Data Hosting helps to seed things that you watch and download.')}{' '}
|
||||
{__('Network Data Hosting allows the p2p network to store blobs unrelated to your browsing.')}{' '}
|
||||
{__("If disabled, LBRY will be very sad and you won't be helping improve the network.")}{' '}
|
||||
{__('If you set a limit, playing videos may exceed your limit until cleanup runs every 30 minutes.')}{' '}
|
||||
<Button button="link" label={__('Learn more')} href="https://lbry.com/faq/host-content" />.
|
||||
<p className={'help'}>
|
||||
{`Using ${formatBytes(spaceUsed * BYTES_PER_MB)} of ${
|
||||
{`Content Hosting using ${formatBytes(contentSpaceUsed * BYTES_PER_MB)} of ${
|
||||
daemonSettings[DAEMON_SETTINGS.BLOB_STORAGE_LIMIT_MB]
|
||||
? formatBytes(daemonSettings[DAEMON_SETTINGS.BLOB_STORAGE_LIMIT_MB] * BYTES_PER_MB)
|
||||
: 'Unlimited'
|
||||
}`}
|
||||
</p>
|
||||
<p className={'help'}>
|
||||
{`Network Hosting using ${formatBytes(networkSpaceUsed * BYTES_PER_MB)} of ${formatBytes(
|
||||
daemonSettings[DAEMON_SETTINGS.NETWORK_STORAGE_LIMIT_MB] * BYTES_PER_MB
|
||||
)}`}
|
||||
</p>
|
||||
</React.Fragment>
|
||||
}
|
||||
>
|
||||
|
@ -220,33 +251,50 @@ export default function SettingSystem(props: Props) {
|
|||
label={__('Enable Data Hosting')}
|
||||
/>
|
||||
</fieldset-section>
|
||||
{daemonSettings.save_blobs && (
|
||||
<fieldset-section>
|
||||
<FormField
|
||||
type="checkbox"
|
||||
name="limit_space_used"
|
||||
onChange={() => handleLimitSpace(!limitSpace)}
|
||||
checked={limitSpace}
|
||||
label={__('Limit Space Used')}
|
||||
label={__('Limit Hosting for Content you Use')}
|
||||
/>
|
||||
</fieldset-section>
|
||||
|
||||
{limitSpace && (
|
||||
<FormField
|
||||
name="blob_limit_gb"
|
||||
type="text"
|
||||
label={__(`Limit (GB)`)}
|
||||
helper={__(
|
||||
'Data over the limit will be deleted within 30 minutes. This will make the Yrbl cry a little bit.'
|
||||
)}
|
||||
|
||||
{daemonSettings.save_blobs && limitSpace && (
|
||||
<FormField
|
||||
name="content_blob_limit_gb"
|
||||
type="text"
|
||||
label={__(`Content: Limit (GB)`)}
|
||||
disabled={!daemonSettings.save_blobs}
|
||||
onChange={(e) => updateBlobLimitField(e.target.value)}
|
||||
value={blobSpaceLimitGB}
|
||||
onChange={(e) => updateContentBlobLimitField(e.target.value)}
|
||||
value={contentBlobSpaceLimitGB}
|
||||
inputButton={
|
||||
<Button
|
||||
disabled={isNaN(blobSpaceLimitGB)}
|
||||
disabled={isNaN(contentBlobSpaceLimitGB)}
|
||||
button="primary"
|
||||
label={__('Apply')}
|
||||
onClick={handleSetBlobSpaceLimit}
|
||||
onClick={handleSetContentBlobSpaceLimit}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
{daemonSettings.save_blobs && (
|
||||
<FormField
|
||||
name="network_blob_limit_gb"
|
||||
type="text"
|
||||
label={__(`Network: Allow (GB)`)}
|
||||
disabled={!daemonSettings.save_blobs}
|
||||
onChange={(e) => updateNetworkBlobLimitField(e.target.value)}
|
||||
value={networkBlobSpaceLimitGB}
|
||||
inputButton={
|
||||
<Button
|
||||
disabled={isNaN(networkBlobSpaceLimitGB)}
|
||||
button="primary"
|
||||
label={__('Apply')}
|
||||
onClick={handleSetNetworkBlobSpaceLimit}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
|
@ -427,7 +475,6 @@ export default function SettingSystem(props: Props) {
|
|||
)}
|
||||
/>
|
||||
*/}
|
||||
|
||||
<fieldset-section>
|
||||
<FormField
|
||||
name="max_connections"
|
||||
|
|
|
@ -38,3 +38,4 @@ export const USE_UPNP = 'use_upnp';
|
|||
export const WALLET_DIR = 'wallet_dir';
|
||||
export const WALLETS = 'wallets';
|
||||
export const BLOB_STORAGE_LIMIT_MB = 'blob_storage_limit';
|
||||
export const NETWORK_STORAGE_LIMIT_MB = 'network_storage_limit';
|
||||
|
|
Loading…
Reference in a new issue