Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cvat-core] support cloud storage #3313

Merged
merged 21 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion cvat-core/src/api-implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
camelToSnake,
} = require('./common');

const { TaskStatus, TaskMode, DimensionType } = require('./enums');
const {
TaskStatus, TaskMode, DimensionType, ProviderType,
} = require('./enums');

const User = require('./user');
const { AnnotationFormats } = require('./annotation-formats');
const { ArgumentError } = require('./exceptions');
const { Task } = require('./session');
const { Project } = require('./project');
const { CloudStorage } = require('./cloud-storage');

function implementAPI(cvat) {
cvat.plugins.list.implementation = PluginRegistry.list;
Expand Down Expand Up @@ -250,6 +253,34 @@

cvat.projects.searchNames.implementation = async (search, limit) => serverProxy.projects.searchNames(search, limit);

cvat.cloudStorages.get.implementation = async (filter) => {
checkFilter(filter, {
page: isInteger,
displayName: isString,
resourceName: isString,
id: isInteger,
owner: isString,
search: isString,
provider: isEnum.bind(ProviderType),
});

checkExclusiveFields(filter, ['id', 'search'], ['page']);

const searchParams = new URLSearchParams();
for (const field of ['displayName', 'resourceName', 'owner', 'search', 'provider', 'id', 'page']) {
if (Object.prototype.hasOwnProperty.call(filter, field)) {
searchParams.set(field, filter[field]);
}
}

const cloudStoragesData = await serverProxy.cloudStoarges.getCloudStorages(searchParams.toString());
const cloudStorages = cloudStoragesData.map((cloudStorage) => new CloudStorage(cloudStorage));

cloudStorages.count = cloudStoragesData.count;

return cloudStorages;
};

return cvat;
}

Expand Down
38 changes: 38 additions & 0 deletions cvat-core/src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function build() {
const { Project } = require('./project');
const { Attribute, Label } = require('./labels');
const MLModel = require('./ml-model');
const { CloudStorage } = require('./cloud-storage');

const enums = require('./enums');

Expand Down Expand Up @@ -746,6 +747,41 @@ function build() {
PluginError,
ServerError,
},
/**
* Namespace is used for getting cloud storages
* @namespace cloudStorages
* @memberof module:API.cvat
*/
cloudStorages: {
/**
* @typedef {Object} CloudStorageFilter
* @property {string} displayName Check if displayName contains this value
* @property {string} resourceName Check if resourceName contains this value
* @property {module:API.cvat.enums.ProviderType} provider Check if provider contains this value
bsekachev marked this conversation as resolved.
Show resolved Hide resolved
* @property {integer} id Check if id equals this value
* @property {integer} page Get specific page
* (default REST API returns 20 clouds storages per request.
* In order to get more, it is need to specify next page)
* @property {string} owner Check if owner user contains this value
bsekachev marked this conversation as resolved.
Show resolved Hide resolved
* @property {string} search Combined search of contains among all fields
bsekachev marked this conversation as resolved.
Show resolved Hide resolved
* @global
*/

/**
* Method returns list of cloud storages corresponding to a filter
bsekachev marked this conversation as resolved.
Show resolved Hide resolved
* @method get
* @async
* @memberof module:API.cvat.cloudStorages
* @param {CloudStorageFilter} [filter={}] cloud storage filter
* @returns {module:API.cvat.classes.CloudStorage[]}
* @throws {module:API.cvat.exceptions.PluginError}
* @throws {module:API.cvat.exceptions.ServerError}
*/
async get(filter = {}) {
const result = await PluginRegistry.apiWrapper(cvat.cloudStorages.get, filter);
return result;
},
},
/**
* Namespace is used for access to classes
* @namespace classes
Expand All @@ -765,6 +801,7 @@ function build() {
Comment,
Issue,
Review,
CloudStorage,
},
};

Expand All @@ -777,6 +814,7 @@ function build() {
cvat.lambda = Object.freeze(cvat.lambda);
cvat.client = Object.freeze(cvat.client);
cvat.enums = Object.freeze(cvat.enums);
cvat.cloudStorages = Object.freeze(cvat.cloudStorages);

const implementAPI = require('./api-implementation');

Expand Down
Loading