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

170 lines
5.2 KiB
JavaScript
Raw Normal View History

import assert from 'node:assert';
import BoxError from '../boxerror.js';
2016-09-16 12:55:45 +02:00
// -------------------------------------------
// 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
2025-11-14 13:03:14 +01:00
function removePrivateFields(config) {
2025-10-08 15:44:58 +02:00
// in-place removal of tokens and api keys
2025-11-14 13:03:14 +01:00
return config;
2019-02-09 18:08:10 -08:00
}
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) {
2025-10-08 15:44:58 +02:00
// in-place injection of tokens and api keys
2019-02-09 18:08:10 -08:00
}
2025-11-14 13:03:14 +01:00
async function getAvailableSize(config) {
assert.strictEqual(typeof config, 'object');
return Number.POSITIVE_INFINITY;
2020-06-08 16:25:00 +02:00
}
2025-11-14 13:03:14 +01:00
async function getStatus(config) {
assert.strictEqual(typeof config, 'object');
2025-08-04 10:47:00 +02:00
// Result: { state, message } . state is 'active' or 'inactive'
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'getStatus is not implemented');
}
2025-11-14 13:18:21 +01:00
async function upload(config, limits, backupFilePath) {
2025-11-14 13:03:14 +01:00
assert.strictEqual(typeof config, 'object');
2025-11-14 13:18:21 +01:00
assert.strictEqual(typeof limits, 'object');
2017-09-19 20:40:38 -07:00
assert.strictEqual(typeof backupFilePath, 'string');
2016-09-16 12:55:45 +02:00
// Result: { createStream(), finish() callback }
2024-07-05 17:53:35 +02:00
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'upload is not implemented');
2016-09-16 12:55:45 +02:00
}
2025-11-14 13:03:14 +01:00
async function exists(config, backupFilePath) {
assert.strictEqual(typeof config, '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');
}
2025-11-14 13:03:14 +01:00
async function download(config, backupFilePath) {
assert.strictEqual(typeof config, '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');
}
2025-11-14 13:03:14 +01:00
async function copy(config, oldFilePath, newFilePath, progressCallback) {
assert.strictEqual(typeof config, '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
}
2025-11-14 13:18:21 +01:00
async function copyDir(config, limits, oldFilePath, newFilePath, progressCallback) {
2025-11-14 13:03:14 +01:00
assert.strictEqual(typeof config, 'object');
2025-11-14 13:18:21 +01:00
assert.strictEqual(typeof limits, 'object');
2025-08-25 23:45:14 +02:00
assert.strictEqual(typeof oldFilePath, 'string');
assert.strictEqual(typeof newFilePath, 'string');
assert.strictEqual(typeof progressCallback, 'function');
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'copy is not implemented');
}
2025-11-14 13:03:14 +01:00
async function listDir(config, dir, batchSize, marker) {
assert.strictEqual(typeof config, 'object');
2018-07-27 14:29:07 -07:00
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
}
2025-11-14 13:03:14 +01:00
async function remove(config, filename) {
assert.strictEqual(typeof config, 'object');
2017-09-27 17:34:49 -07:00
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
}
2025-11-14 13:18:21 +01:00
async function removeDir(config, limits, pathPrefix, progressCallback) {
2025-11-14 13:03:14 +01:00
assert.strictEqual(typeof config, 'object');
2025-11-14 13:18:21 +01:00
assert.strictEqual(typeof limits, '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
2025-11-14 13:03:14 +01:00
async function cleanup(config, progressCallback) {
assert.strictEqual(typeof config, '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
2025-11-14 13:03:14 +01:00
async function setup(config) {
assert.strictEqual(typeof config, 'object');
2025-08-01 14:54:32 +02:00
// Result: none - first callback argument error if config does not pass the test
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'setup is not implemented');
}
2025-11-14 13:03:14 +01:00
async function teardown(config) {
assert.strictEqual(typeof config, 'object');
2025-08-01 14:54:32 +02:00
// Result: none - first callback argument error if config does not pass the test
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'teardown is not implemented');
}
2026-02-14 15:43:24 +01:00
export default {
getAvailableSize,
getStatus,
upload,
exists,
download,
copy,
copyDir,
listDir,
remove,
removeDir,
setup,
teardown,
cleanup,
verifyConfig,
removePrivateFields,
injectPrivateFields
};