1// Copyright (C) 2021 Storj Labs, Inc.
2// See LICENSE for copying information.
3
4import { StorageClient } from '@/api/storage';
5import { DiskSpace, DiskSpaceUsage } from '@/storage';
6
7/**
8 * Exposes all bandwidth related logic
9 */
10export class StorageService {
11    private readonly storage: StorageClient;
12
13    public constructor(bandwidth: StorageClient) {
14        this.storage = bandwidth;
15    }
16
17    /**
18     * Returns storage usage for selected satellite and node if any.
19     *
20     * @throws {@link BadRequestError}
21     * This exception is thrown if the input is not a valid.
22     *
23     * @throws {@link UnauthorizedError}
24     * Thrown if the auth cookie is missing or invalid.
25     *
26     * @throws {@link InternalError}
27     * Thrown if something goes wrong on server side.
28     */
29    public async usage(satelliteId: string | null, nodeId: string | null): Promise<DiskSpaceUsage> {
30        return await this.storage.usage(satelliteId, nodeId);
31    }
32
33    /**
34     * Returns total storage usage for selected node if any.
35     *
36     * @throws {@link BadRequestError}
37     * This exception is thrown if the input is not a valid.
38     *
39     * @throws {@link UnauthorizedError}
40     * Thrown if the auth cookie is missing or invalid.
41     *
42     * @throws {@link InternalError}
43     * Thrown if something goes wrong on server side.
44     */
45    public async diskSpace(nodeId: string | null): Promise<DiskSpace> {
46        return await this.storage.diskSpace(nodeId);
47    }
48}
49