storage: make exists async
This commit is contained in:
@@ -102,21 +102,19 @@ function upload(apiConfig, backupFilePath, sourceStream, callback) {
|
||||
sourceStream.pipe(uploadStream);
|
||||
}
|
||||
|
||||
function exists(apiConfig, backupFilePath, callback) {
|
||||
async function exists(apiConfig, backupFilePath) {
|
||||
assert.strictEqual(typeof apiConfig, 'object');
|
||||
assert.strictEqual(typeof backupFilePath, 'string');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
const bucket = getBucket(apiConfig);
|
||||
|
||||
if (!backupFilePath.endsWith('/')) {
|
||||
const file = bucket.file(backupFilePath);
|
||||
file.getMetadata(function (error) {
|
||||
if (error && error.code === 404) return callback(null, false);
|
||||
if (error) return callback(new BoxError(BoxError.EXTERNAL_ERROR, error.message));
|
||||
const [error] = await safe(file.getMetadata());
|
||||
if (error && error.code === 404) return false;
|
||||
if (error) throw new BoxError(BoxError.EXTERNAL_ERROR, error.message);
|
||||
|
||||
callback(null, true);
|
||||
});
|
||||
return true;
|
||||
} else {
|
||||
const query = {
|
||||
prefix: backupFilePath,
|
||||
@@ -124,11 +122,10 @@ function exists(apiConfig, backupFilePath, callback) {
|
||||
autoPaginate: true
|
||||
};
|
||||
|
||||
bucket.getFiles(query, function (error, files) {
|
||||
if (error) return callback(error);
|
||||
const [error, files] = await safe(bucket.getFiles(query));
|
||||
if (error) throw new BoxError(BoxError.EXTERNAL_ERROR, error.message);
|
||||
|
||||
callback(null, files.length !== 0);
|
||||
});
|
||||
return files.length !== 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user