storage: add getStatus hook
This commit is contained in:
@@ -10,6 +10,7 @@ exports = module.exports = {
|
||||
injectPrivateFields,
|
||||
|
||||
getAvailableSize,
|
||||
getStatus,
|
||||
|
||||
upload,
|
||||
exists,
|
||||
@@ -156,6 +157,23 @@ async function getAvailableSize(apiConfig) {
|
||||
return Number.POSITIVE_INFINITY;
|
||||
}
|
||||
|
||||
async function getStatus(apiConfig) {
|
||||
assert.strictEqual(typeof apiConfig, 'object');
|
||||
|
||||
const s3 = createS3Client(apiConfig, { retryStrategy: RETRY_STRATEGY });
|
||||
|
||||
const listParams = {
|
||||
Bucket: apiConfig.bucket,
|
||||
Prefix: path.join(apiConfig.prefix, 'snapshot'),
|
||||
MaxKeys: 1
|
||||
};
|
||||
|
||||
const [listError] = await safe(s3.listObjectsV2(listParams));
|
||||
if (listError) return { status: 'inactive', message: `Error listing objects. ${formatError(listError)}` };
|
||||
|
||||
return { state: 'active' };
|
||||
}
|
||||
|
||||
async function upload(apiConfig, remotePath) {
|
||||
assert.strictEqual(typeof apiConfig, 'object');
|
||||
assert.strictEqual(typeof remotePath, 'string');
|
||||
|
||||
Reference in New Issue
Block a user