2016-09-16 12:55:45 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------
|
|
|
|
|
// This file just describes the interface
|
|
|
|
|
//
|
|
|
|
|
// New backends can start from here
|
|
|
|
|
// -------------------------------------------
|
|
|
|
|
|
2018-02-22 12:30:52 -08:00
|
|
|
// Implementation note:
|
|
|
|
|
// retry logic for upload() comes from the syncer since it is stream based
|
|
|
|
|
// for the other API calls we leave it to the backend to retry. this allows
|
|
|
|
|
// them to tune the concurrency based on failures/rate limits accordingly
|
2016-09-16 12:55:45 +02:00
|
|
|
exports = module.exports = {
|
2022-10-02 16:26:27 +02:00
|
|
|
getBackupRootPath,
|
2022-10-02 17:22:44 +02:00
|
|
|
getBackupProviderStatus,
|
|
|
|
|
getAvailableSize,
|
2020-06-05 13:27:18 +02:00
|
|
|
|
2021-02-18 16:51:43 -08:00
|
|
|
upload,
|
2018-02-22 12:30:52 -08:00
|
|
|
|
2021-02-18 16:51:43 -08:00
|
|
|
exists,
|
2017-09-17 18:50:29 -07:00
|
|
|
|
2021-02-18 16:51:43 -08:00
|
|
|
download,
|
|
|
|
|
copy,
|
2018-07-27 14:29:07 -07:00
|
|
|
|
2021-02-18 16:51:43 -08:00
|
|
|
listDir,
|
2016-10-11 11:36:25 +02:00
|
|
|
|
2021-02-18 16:51:43 -08:00
|
|
|
remove,
|
|
|
|
|
removeDir,
|
|
|
|
|
|
2021-10-11 17:45:35 +02:00
|
|
|
remount,
|
|
|
|
|
|
2021-02-18 16:51:43 -08:00
|
|
|
testConfig,
|
|
|
|
|
removePrivateFields,
|
|
|
|
|
injectPrivateFields
|
2016-09-16 12:55:45 +02:00
|
|
|
};
|
|
|
|
|
|
2022-04-14 07:40:19 -05:00
|
|
|
const assert = require('assert'),
|
2022-10-02 17:22:44 +02:00
|
|
|
BoxError = require('../boxerror.js');
|
2016-09-16 12:55:45 +02:00
|
|
|
|
2019-02-09 18:08:10 -08:00
|
|
|
function removePrivateFields(apiConfig) {
|
2020-05-14 23:01:44 +02:00
|
|
|
// in-place removal of tokens and api keys with constants.SECRET_PLACEHOLDER
|
2019-02-09 18:08:10 -08:00
|
|
|
return apiConfig;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-04 10:21:42 -08:00
|
|
|
// eslint-disable-next-line no-unused-vars
|
2019-02-09 18:08:10 -08:00
|
|
|
function injectPrivateFields(newConfig, currentConfig) {
|
2020-05-14 23:01:44 +02:00
|
|
|
// in-place injection of tokens and api keys which came in with constants.SECRET_PLACEHOLDER
|
2019-02-09 18:08:10 -08:00
|
|
|
}
|
|
|
|
|
|
2022-10-02 16:26:27 +02:00
|
|
|
function getBackupRootPath(apiConfig) {
|
2020-06-05 13:27:18 +02:00
|
|
|
assert.strictEqual(typeof apiConfig, 'object');
|
|
|
|
|
|
|
|
|
|
// Result: path at the backup storage
|
|
|
|
|
return '/';
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-02 17:22:44 +02:00
|
|
|
async function getBackupProviderStatus(apiConfig) {
|
2020-06-08 16:25:00 +02:00
|
|
|
assert.strictEqual(typeof apiConfig, 'object');
|
2022-10-02 17:22:44 +02:00
|
|
|
|
|
|
|
|
return { state: 'active' };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function getAvailableSize(apiConfig) {
|
|
|
|
|
assert.strictEqual(typeof apiConfig, 'object');
|
|
|
|
|
|
|
|
|
|
return Number.POSITIVE_INFINITY;
|
2020-06-08 16:25:00 +02:00
|
|
|
}
|
|
|
|
|
|
2017-09-20 09:57:16 -07:00
|
|
|
function upload(apiConfig, backupFilePath, sourceStream, callback) {
|
2016-09-16 12:55:45 +02:00
|
|
|
assert.strictEqual(typeof apiConfig, 'object');
|
2017-09-19 20:40:38 -07:00
|
|
|
assert.strictEqual(typeof backupFilePath, 'string');
|
2017-09-20 09:57:16 -07:00
|
|
|
assert.strictEqual(typeof sourceStream, 'object');
|
2016-09-16 12:55:45 +02:00
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
2017-04-11 11:00:55 +02:00
|
|
|
// Result: none
|
2018-02-27 19:16:03 -08:00
|
|
|
// sourceStream errors are handled upstream
|
2016-09-16 12:55:45 +02:00
|
|
|
|
2019-12-04 10:21:42 -08:00
|
|
|
callback(new BoxError(BoxError.NOT_IMPLEMENTED, 'upload is not implemented'));
|
2016-09-16 12:55:45 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-14 08:07:03 -05:00
|
|
|
async function exists(apiConfig, backupFilePath) {
|
2021-02-18 16:51:43 -08:00
|
|
|
assert.strictEqual(typeof apiConfig, 'object');
|
|
|
|
|
assert.strictEqual(typeof backupFilePath, 'string');
|
|
|
|
|
|
2022-04-14 08:07:03 -05:00
|
|
|
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'exists is not implemented');
|
2021-02-18 16:51:43 -08:00
|
|
|
}
|
|
|
|
|
|
2017-09-20 09:57:16 -07:00
|
|
|
function download(apiConfig, backupFilePath, callback) {
|
2016-09-16 12:55:45 +02:00
|
|
|
assert.strictEqual(typeof apiConfig, 'object');
|
2017-09-20 09:57:16 -07:00
|
|
|
assert.strictEqual(typeof backupFilePath, 'string');
|
2016-09-16 12:55:45 +02:00
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
2017-09-20 09:57:16 -07:00
|
|
|
// Result: download stream
|
2019-12-04 10:21:42 -08:00
|
|
|
callback(new BoxError(BoxError.NOT_IMPLEMENTED, 'download is not implemented'));
|
2017-04-11 11:00:55 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-30 16:01:42 -07:00
|
|
|
async function copy(apiConfig, oldFilePath, newFilePath, progressCallback) {
|
2017-04-11 11:00:55 +02:00
|
|
|
assert.strictEqual(typeof apiConfig, 'object');
|
2017-09-19 20:40:38 -07:00
|
|
|
assert.strictEqual(typeof oldFilePath, 'string');
|
|
|
|
|
assert.strictEqual(typeof newFilePath, 'string');
|
2022-04-30 16:01:42 -07:00
|
|
|
assert.strictEqual(typeof progressCallback, 'function');
|
2016-09-16 12:55:45 +02:00
|
|
|
|
2022-04-30 16:01:42 -07:00
|
|
|
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'copy is not implemented');
|
2016-09-16 12:55:45 +02:00
|
|
|
}
|
|
|
|
|
|
2018-07-27 14:29:07 -07:00
|
|
|
function listDir(apiConfig, dir, batchSize, iteratorCallback, callback) {
|
|
|
|
|
assert.strictEqual(typeof apiConfig, 'object');
|
|
|
|
|
assert.strictEqual(typeof dir, 'string');
|
|
|
|
|
assert.strictEqual(typeof batchSize, 'number');
|
|
|
|
|
assert.strictEqual(typeof iteratorCallback, 'function');
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
2019-12-04 10:21:42 -08:00
|
|
|
callback(new BoxError(BoxError.NOT_IMPLEMENTED, 'listDir is not implemented'));
|
2018-07-27 14:29:07 -07:00
|
|
|
}
|
|
|
|
|
|
2022-04-14 16:07:01 -05:00
|
|
|
async function remove(apiConfig, filename) {
|
2017-09-27 17:34:49 -07:00
|
|
|
assert.strictEqual(typeof apiConfig, 'object');
|
|
|
|
|
assert.strictEqual(typeof filename, 'string');
|
|
|
|
|
|
2018-02-22 10:58:56 -08:00
|
|
|
// Result: none
|
2022-04-14 16:07:01 -05:00
|
|
|
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'remove is not implemented');
|
2017-09-27 17:34:49 -07:00
|
|
|
}
|
|
|
|
|
|
2022-04-14 16:07:01 -05:00
|
|
|
async function removeDir(apiConfig, pathPrefix, progressCallback) {
|
2016-09-19 15:03:38 +02:00
|
|
|
assert.strictEqual(typeof apiConfig, 'object');
|
2017-09-23 11:09:36 -07:00
|
|
|
assert.strictEqual(typeof pathPrefix, 'string');
|
2022-04-14 16:07:01 -05:00
|
|
|
assert.strictEqual(typeof progressCallback, 'function');
|
2016-09-16 12:55:45 +02:00
|
|
|
|
2018-02-22 10:58:56 -08:00
|
|
|
// Result: none
|
2022-04-14 16:07:01 -05:00
|
|
|
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'removeDir is not implemented');
|
2016-09-16 12:55:45 +02:00
|
|
|
}
|
2016-10-10 15:04:28 +02:00
|
|
|
|
2022-04-14 07:43:43 -05:00
|
|
|
async function remount(apiConfig) {
|
2021-10-11 17:45:35 +02:00
|
|
|
assert.strictEqual(typeof apiConfig, 'object');
|
|
|
|
|
|
|
|
|
|
// Result: none
|
|
|
|
|
|
2022-04-14 07:43:43 -05:00
|
|
|
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'remount is not implemented');
|
2021-10-11 17:45:35 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-14 07:59:50 -05:00
|
|
|
async function testConfig(apiConfig) {
|
2016-10-11 11:36:25 +02:00
|
|
|
assert.strictEqual(typeof apiConfig, 'object');
|
|
|
|
|
|
2017-04-18 14:55:22 +02:00
|
|
|
// Result: none - first callback argument error if config does not pass the test
|
2016-10-11 11:36:25 +02:00
|
|
|
|
2022-04-14 07:59:50 -05:00
|
|
|
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'testConfig is not implemented');
|
2016-10-11 11:36:25 +02:00
|
|
|
}
|