Renaming refused on hosted drives because encrypted names and contents are bound to their path. The encrypting client now renames itself: readable files keep s3d's server-side copy, the rest are decrypted and encrypted again for their new place. A drive with shared folders or links is not renamed, since its rules belong to the old name. Free space is forwarded to the server, whose s3d answers for its own folder, instead of reporting nothing. space.js now builds on sia-account.js, so BLAKE2b and the indexer request signing exist once.
29 lines
1.2 KiB
JavaScript
29 lines
1.2 KiB
JavaScript
// Free space on the Sia account behind this s3d, as the indexer reports it.
|
|
// The key reading, BLAKE2b-256 and request signing live in one place
|
|
// (sia-account.js, blake2b.js); this keeps the names the space route and its
|
|
// tests use.
|
|
|
|
import { readConnection, signRequest, accountInfo } from './sia-account.js';
|
|
|
|
export { blake2b256 } from './blake2b.js';
|
|
|
|
export const signIndexerUrl = (appKey, method, endpointUrl, validUntilSec) => signRequest(appKey, method, endpointUrl, validUntilSec);
|
|
|
|
export async function readAppKey(dataDir) {
|
|
const c = await readConnection(dataDir).catch(() => null);
|
|
return c?.appKey && c.indexerUrl ? { appKey: c.appKey, indexerUrl: c.indexerUrl } : null;
|
|
}
|
|
|
|
// { maxPinnedData, pinnedData, remainingStorage, indexer } in bytes, or null
|
|
// when this s3d is not connected. Throws when the indexer does not answer.
|
|
export async function accountSpace(dataDir, { fetchImpl = fetch } = {}) {
|
|
const a = await accountInfo(dataDir, { fetchImpl, timeoutMs: 15_000 });
|
|
if (!a.connected) return null;
|
|
if (a.error) throw new Error(a.error);
|
|
return {
|
|
maxPinnedData: Number(a.maxPinnedData),
|
|
pinnedData: Number(a.pinnedData),
|
|
remainingStorage: Number(a.remainingStorage),
|
|
indexer: new URL(a.indexerUrl).host,
|
|
};
|
|
}
|