Files
cloudron-box/src/storage/interface.js
T

158 lines
4.8 KiB
JavaScript
Raw Normal View History

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 = {
getAvailableSize,
2025-08-04 10:47:00 +02:00
getStatus,
upload,
2018-02-22 12:30:52 -08:00
exists,
2017-09-17 18:50:29 -07:00
download,
copy,
2018-07-27 14:29:07 -07:00
listDir,
2016-10-11 11:36:25 +02:00
remove,
removeDir,
2025-08-01 14:54:32 +02:00
setup,
teardown,
cleanup,
verifyConfig,
removePrivateFields,
injectPrivateFields
2016-09-16 12:55:45 +02:00
};
2025-08-14 11:17:38 +05:30
const assert = require('node:assert'),
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
}
async function getAvailableSize(apiConfig) {
assert.strictEqual(typeof apiConfig, 'object');
return Number.POSITIVE_INFINITY;
2020-06-08 16:25:00 +02:00
}
2025-08-04 10:47:00 +02:00
async function getStatus(apiConfig) {
assert.strictEqual(typeof apiConfig, 'object');
// Result: { state, message } . state is 'active' or 'inactive'
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'getStatus is not implemented');
}
2024-07-05 17:53:35 +02:00
async function upload(apiConfig, backupFilePath) {
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');
2016-09-16 12:55:45 +02:00
2024-07-05 17:53:35 +02:00
// Result: { stream, finish() callback }
throw 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) {
assert.strictEqual(typeof apiConfig, 'object');
assert.strictEqual(typeof backupFilePath, 'string');
2024-07-05 17:53:35 +02:00
// Result: boolean if exists or not
2022-04-14 08:07:03 -05:00
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'exists is not implemented');
}
async function download(apiConfig, backupFilePath) {
2016-09-16 12:55:45 +02:00
assert.strictEqual(typeof apiConfig, 'object');
assert.strictEqual(typeof backupFilePath, 'string');
2016-09-16 12:55:45 +02:00
// Result: download stream
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'download is not implemented');
}
2022-04-30 16:01:42 -07:00
async function copy(apiConfig, oldFilePath, newFilePath, progressCallback) {
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
}
async function listDir(apiConfig, dir, batchSize, marker) {
2018-07-27 14:29:07 -07:00
assert.strictEqual(typeof apiConfig, 'object');
assert.strictEqual(typeof dir, 'string');
assert.strictEqual(typeof batchSize, 'number');
assert(typeof marker !== 'undefined');
2018-07-27 14:29:07 -07:00
// Result: array of { path, size }
// path is relative to the prefix/root and not the _dir_ being listed
throw 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');
// 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) {
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
// 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
async function cleanup(apiConfig, progressCallback) {
assert.strictEqual(typeof apiConfig, 'object');
assert.strictEqual(typeof progressCallback, 'function');
// Result: none
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'cleanup is not implemented');
}
async function verifyConfig({ id, provider, config }) {
assert.strictEqual(typeof id, 'string');
assert.strictEqual(typeof provider, 'string');
assert.strictEqual(typeof config, 'object');
2016-10-11 11:36:25 +02:00
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
}
2025-08-01 14:54:32 +02:00
async function setup(apiConfig) {
assert.strictEqual(typeof apiConfig, 'object');
// Result: none - first callback argument error if config does not pass the test
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'setup is not implemented');
}
async function teardown(apiConfig) {
assert.strictEqual(typeof apiConfig, 'object');
// Result: none - first callback argument error if config does not pass the test
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'teardown is not implemented');
}