update disk space setting to new api

This commit is contained in:
zeppi 2021-12-15 17:51:00 -05:00
parent a0917908bb
commit 2c8fdc434b
3 changed files with 89 additions and 32 deletions

View file

@ -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)", "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", "Use official LBRY wallet servers": "Use official LBRY wallet servers",
"Enable Prerelease Updates": "Enable Prerelease Updates", "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--" "--end--": "--end--"
} }

View file

@ -41,8 +41,11 @@ type DaemonSettings = {
type DaemonStatus = { type DaemonStatus = {
disk_space: { disk_space: {
running: boolean, content_blobs_storage_used_mb: string,
space_used: 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 [clearingCache, setClearingCache] = React.useState(false);
const [storedPassword, setStoredPassword] = React.useState(false); const [storedPassword, setStoredPassword] = React.useState(false);
const { disk_space } = daemonStatus; 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 blobLimitSetting = daemonSettings[DAEMON_SETTINGS.BLOB_STORAGE_LIMIT_MB];
const [blobSpaceLimitGB, setBlobSpaceLimit] = React.useState(blobLimitSetting ? blobLimitSetting / 1024 : 0); const networkLimitSetting = daemonSettings[DAEMON_SETTINGS.NETWORK_STORAGE_LIMIT_MB];
// const debouncedBlobSpaceLimitGB = useDebounce(blobSpaceLimitGB || 0, 500); 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 [limitSpace, setLimitSpace] = React.useState(Boolean(blobLimitSetting));
const { available: ffmpegAvailable, which: ffmpegPath } = ffmpegStatus; const { available: ffmpegAvailable, which: ffmpegPath } = ffmpegStatus;
@ -109,11 +118,19 @@ export default function SettingSystem(props: Props) {
confirmForgetPassword({ callback: () => setStoredPassword(false) }); confirmForgetPassword({ callback: () => setStoredPassword(false) });
} }
function updateBlobLimitField(gb) { function updateContentBlobLimitField(gb) {
if (gb === 0) { if (gb === 0) {
setBlobSpaceLimit(0); setContentBlobSpaceLimit(0);
} else if (!gb || !isNaN(gb)) { } 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) { if (!value) {
setDaemonSetting(DAEMON_SETTINGS.BLOB_STORAGE_LIMIT_MB, String(0)); setDaemonSetting(DAEMON_SETTINGS.BLOB_STORAGE_LIMIT_MB, String(0));
} else { } else {
const spaceLimitMB = blobSpaceLimitGB * 1024; const spaceLimitMB = contentBlobSpaceLimitGB * 1024;
setDaemonSetting(DAEMON_SETTINGS.BLOB_STORAGE_LIMIT_MB, String(spaceLimitMB)); setDaemonSetting(DAEMON_SETTINGS.BLOB_STORAGE_LIMIT_MB, String(spaceLimitMB));
} }
} }
function handleSetBlobSpaceLimit() { function handleSetContentBlobSpaceLimit() {
const spaceLimitMB = blobSpaceLimitGB * 1024; const spaceLimitMB = contentBlobSpaceLimitGB * 1024;
if (!isNaN(spaceLimitMB) && blobLimitSetting !== spaceLimitMB * 1024) { if (!isNaN(spaceLimitMB) && blobLimitSetting !== spaceLimitMB * 1024) {
setDaemonSetting(DAEMON_SETTINGS.BLOB_STORAGE_LIMIT_MB, String(spaceLimitMB)); 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 // Update ffmpeg variables
React.useEffect(() => { React.useEffect(() => {
const { available } = ffmpegStatus; const { available } = ffmpegStatus;
@ -198,16 +222,23 @@ export default function SettingSystem(props: Props) {
multirow multirow
subtitle={ subtitle={
<React.Fragment> <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 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.')}{' '} {__('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" />. <Button button="link" label={__('Learn more')} href="https://lbry.com/faq/host-content" />.
<p className={'help'}> <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] daemonSettings[DAEMON_SETTINGS.BLOB_STORAGE_LIMIT_MB]
? formatBytes(daemonSettings[DAEMON_SETTINGS.BLOB_STORAGE_LIMIT_MB] * BYTES_PER_MB) ? formatBytes(daemonSettings[DAEMON_SETTINGS.BLOB_STORAGE_LIMIT_MB] * BYTES_PER_MB)
: 'Unlimited' : 'Unlimited'
}`} }`}
</p> </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> </React.Fragment>
} }
> >
@ -220,33 +251,50 @@ export default function SettingSystem(props: Props) {
label={__('Enable Data Hosting')} label={__('Enable Data Hosting')}
/> />
</fieldset-section> </fieldset-section>
{daemonSettings.save_blobs && (
<fieldset-section> <fieldset-section>
<FormField <FormField
type="checkbox" type="checkbox"
name="limit_space_used" name="limit_space_used"
onChange={() => handleLimitSpace(!limitSpace)} onChange={() => handleLimitSpace(!limitSpace)}
checked={limitSpace} checked={limitSpace}
label={__('Limit Space Used')} label={__('Limit Hosting for Content you Use')}
/> />
</fieldset-section> </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} disabled={!daemonSettings.save_blobs}
onChange={(e) => updateBlobLimitField(e.target.value)} onChange={(e) => updateContentBlobLimitField(e.target.value)}
value={blobSpaceLimitGB} value={contentBlobSpaceLimitGB}
inputButton={ inputButton={
<Button <Button
disabled={isNaN(blobSpaceLimitGB)} disabled={isNaN(contentBlobSpaceLimitGB)}
button="primary" button="primary"
label={__('Apply')} 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> <fieldset-section>
<FormField <FormField
name="max_connections" name="max_connections"

View file

@ -38,3 +38,4 @@ export const USE_UPNP = 'use_upnp';
export const WALLET_DIR = 'wallet_dir'; export const WALLET_DIR = 'wallet_dir';
export const WALLETS = 'wallets'; export const WALLETS = 'wallets';
export const BLOB_STORAGE_LIMIT_MB = 'blob_storage_limit'; export const BLOB_STORAGE_LIMIT_MB = 'blob_storage_limit';
export const NETWORK_STORAGE_LIMIT_MB = 'network_storage_limit';