Fix ESlint problems / typescript for cvat-core (#5027)
* typescripted some files * typescripted cloud storage * reverted api-implementation, fixed minor errors * updated changelog * fixed jest test * updated file: to link: Co-authored-by: Boris Sekachev <boris.sekachev@yandex.ru>main
parent
e7c16064c4
commit
f719f58df4
@ -1,511 +1,393 @@
|
|||||||
// Copyright (C) 2021-2022 Intel Corporation
|
// Copyright (C) 2021-2022 Intel Corporation
|
||||||
|
// Copyright (C) 2022 CVAT.ai Corporation
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
(() => {
|
import { isBrowser, isNode } from 'browser-or-node';
|
||||||
const PluginRegistry = require('./plugins').default;
|
import PluginRegistry from './plugins';
|
||||||
const serverProxy = require('./server-proxy').default;
|
import serverProxy from './server-proxy';
|
||||||
const { isBrowser, isNode } = require('browser-or-node');
|
import { ArgumentError } from './exceptions';
|
||||||
const { ArgumentError } = require('./exceptions');
|
import { CloudStorageCredentialsType, CloudStorageProviderType, CloudStorageStatus } from './enums';
|
||||||
const { CloudStorageCredentialsType, CloudStorageProviderType } = require('./enums');
|
import User from './user';
|
||||||
|
|
||||||
function validateNotEmptyString(value) {
|
function validateNotEmptyString(value: string): void {
|
||||||
if (typeof value !== 'string') {
|
if (typeof value !== 'string') {
|
||||||
throw new ArgumentError(`Value must be a string. ${typeof value} was found`);
|
throw new ArgumentError(`Value must be a string. ${typeof value} was found`);
|
||||||
} else if (!value.trim().length) {
|
} else if (!value.trim().length) {
|
||||||
throw new ArgumentError('Value mustn\'t be empty string');
|
throw new ArgumentError('Value mustn\'t be empty string');
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
interface RawCloudStorageData {
|
||||||
* Class representing a cloud storage
|
id?: number;
|
||||||
* @memberof module:API.cvat.classes
|
display_name?: string;
|
||||||
*/
|
description?: string,
|
||||||
class CloudStorage {
|
credentials_type?: CloudStorageCredentialsType,
|
||||||
constructor(initialData) {
|
provider_type?: CloudStorageProviderType,
|
||||||
const data = {
|
resource?: string,
|
||||||
id: undefined,
|
account_name?: string,
|
||||||
display_name: undefined,
|
key?: string,
|
||||||
description: undefined,
|
secret_key?: string,
|
||||||
credentials_type: undefined,
|
session_token?: string,
|
||||||
provider_type: undefined,
|
key_file?: File,
|
||||||
resource: undefined,
|
specific_attributes?: string,
|
||||||
account_name: undefined,
|
owner?: any,
|
||||||
key: undefined,
|
created_date?: string,
|
||||||
secret_key: undefined,
|
updated_date?: string,
|
||||||
session_token: undefined,
|
manifest_path?: string,
|
||||||
key_file: undefined,
|
manifests?: string[],
|
||||||
specific_attributes: undefined,
|
}
|
||||||
owner: undefined,
|
|
||||||
created_date: undefined,
|
|
||||||
updated_date: undefined,
|
|
||||||
manifest_path: undefined,
|
|
||||||
manifests: undefined,
|
|
||||||
};
|
|
||||||
|
|
||||||
for (const property in data) {
|
export default class CloudStorage {
|
||||||
if (Object.prototype.hasOwnProperty.call(data, property) && property in initialData) {
|
public readonly id: number;
|
||||||
data[property] = initialData[property];
|
public displayName: string;
|
||||||
}
|
public description: string;
|
||||||
|
public accountName: string;
|
||||||
|
public accessKey: string;
|
||||||
|
public secretKey: string;
|
||||||
|
public token: string;
|
||||||
|
public keyFile: File;
|
||||||
|
public resource: string;
|
||||||
|
public manifestPath: string;
|
||||||
|
public provider_type: CloudStorageProviderType;
|
||||||
|
public credentials_type: CloudStorageCredentialsType;
|
||||||
|
public specificAttributes: string;
|
||||||
|
public manifests: string[];
|
||||||
|
public readonly owner: User;
|
||||||
|
public readonly createdDate: string;
|
||||||
|
public readonly updatedDate: string;
|
||||||
|
|
||||||
|
constructor(initialData: RawCloudStorageData) {
|
||||||
|
const data: RawCloudStorageData = {
|
||||||
|
id: undefined,
|
||||||
|
display_name: undefined,
|
||||||
|
description: undefined,
|
||||||
|
credentials_type: undefined,
|
||||||
|
provider_type: undefined,
|
||||||
|
resource: undefined,
|
||||||
|
account_name: undefined,
|
||||||
|
key: undefined,
|
||||||
|
secret_key: undefined,
|
||||||
|
session_token: undefined,
|
||||||
|
key_file: undefined,
|
||||||
|
specific_attributes: undefined,
|
||||||
|
owner: undefined,
|
||||||
|
created_date: undefined,
|
||||||
|
updated_date: undefined,
|
||||||
|
manifest_path: undefined,
|
||||||
|
manifests: undefined,
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const property in data) {
|
||||||
|
if (Object.prototype.hasOwnProperty.call(data, property) && property in initialData) {
|
||||||
|
data[property] = initialData[property];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Object.defineProperties(
|
Object.defineProperties(
|
||||||
this,
|
this,
|
||||||
Object.freeze({
|
Object.freeze({
|
||||||
/**
|
id: {
|
||||||
* @name id
|
get: () => data.id,
|
||||||
* @type {number}
|
},
|
||||||
* @memberof module:API.cvat.classes.CloudStorage
|
displayName: {
|
||||||
* @readonly
|
get: () => data.display_name,
|
||||||
* @instance
|
set: (value) => {
|
||||||
*/
|
validateNotEmptyString(value);
|
||||||
id: {
|
data.display_name = value;
|
||||||
get: () => data.id,
|
|
||||||
},
|
},
|
||||||
/**
|
},
|
||||||
* Storage name
|
description: {
|
||||||
* @name displayName
|
get: () => data.description,
|
||||||
* @type {string}
|
set: (value) => {
|
||||||
* @memberof module:API.cvat.classes.CloudStorage
|
if (typeof value !== 'string') {
|
||||||
* @instance
|
throw new ArgumentError('Value must be string');
|
||||||
* @throws {module:API.cvat.exceptions.ArgumentError}
|
}
|
||||||
*/
|
data.description = value;
|
||||||
displayName: {
|
|
||||||
get: () => data.display_name,
|
|
||||||
set: (value) => {
|
|
||||||
validateNotEmptyString(value);
|
|
||||||
data.display_name = value;
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
/**
|
},
|
||||||
* Storage description
|
accountName: {
|
||||||
* @name description
|
get: () => data.account_name,
|
||||||
* @type {string}
|
set: (value) => {
|
||||||
* @memberof module:API.cvat.classes.CloudStorage
|
validateNotEmptyString(value);
|
||||||
* @instance
|
data.account_name = value;
|
||||||
* @throws {module:API.cvat.exceptions.ArgumentError}
|
|
||||||
*/
|
|
||||||
description: {
|
|
||||||
get: () => data.description,
|
|
||||||
set: (value) => {
|
|
||||||
if (typeof value !== 'string') {
|
|
||||||
throw new ArgumentError('Value must be string');
|
|
||||||
}
|
|
||||||
data.description = value;
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
/**
|
},
|
||||||
* Azure account name
|
accessKey: {
|
||||||
* @name accountName
|
get: () => data.key,
|
||||||
* @type {string}
|
set: (value) => {
|
||||||
* @memberof module:API.cvat.classes.CloudStorage
|
validateNotEmptyString(value);
|
||||||
* @instance
|
data.key = value;
|
||||||
* @throws {module:API.cvat.exceptions.ArgumentError}
|
|
||||||
*/
|
|
||||||
accountName: {
|
|
||||||
get: () => data.account_name,
|
|
||||||
set: (value) => {
|
|
||||||
validateNotEmptyString(value);
|
|
||||||
data.account_name = value;
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
/**
|
},
|
||||||
* AWS access key id
|
secretKey: {
|
||||||
* @name accessKey
|
get: () => data.secret_key,
|
||||||
* @type {string}
|
set: (value) => {
|
||||||
* @memberof module:API.cvat.classes.CloudStorage
|
validateNotEmptyString(value);
|
||||||
* @instance
|
data.secret_key = value;
|
||||||
* @throws {module:API.cvat.exceptions.ArgumentError}
|
|
||||||
*/
|
|
||||||
accessKey: {
|
|
||||||
get: () => data.key,
|
|
||||||
set: (value) => {
|
|
||||||
validateNotEmptyString(value);
|
|
||||||
data.key = value;
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
/**
|
},
|
||||||
* AWS secret key
|
token: {
|
||||||
* @name secretKey
|
get: () => data.session_token,
|
||||||
* @type {string}
|
set: (value) => {
|
||||||
* @memberof module:API.cvat.classes.CloudStorage
|
validateNotEmptyString(value);
|
||||||
* @instance
|
data.session_token = value;
|
||||||
* @throws {module:API.cvat.exceptions.ArgumentError}
|
|
||||||
*/
|
|
||||||
secretKey: {
|
|
||||||
get: () => data.secret_key,
|
|
||||||
set: (value) => {
|
|
||||||
validateNotEmptyString(value);
|
|
||||||
data.secret_key = value;
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
/**
|
},
|
||||||
* Session token
|
keyFile: {
|
||||||
* @name token
|
get: () => data.key_file,
|
||||||
* @type {string}
|
set: (file) => {
|
||||||
* @memberof module:API.cvat.classes.CloudStorage
|
if (file instanceof File) {
|
||||||
* @instance
|
data.key_file = file;
|
||||||
* @throws {module:API.cvat.exceptions.ArgumentError}
|
} else {
|
||||||
*/
|
throw new ArgumentError(`Should be a file. ${typeof file} was found`);
|
||||||
token: {
|
}
|
||||||
get: () => data.session_token,
|
|
||||||
set: (value) => {
|
|
||||||
validateNotEmptyString(value);
|
|
||||||
data.session_token = value;
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
/**
|
},
|
||||||
* Key file
|
resource: {
|
||||||
* @name keyFile
|
get: () => data.resource,
|
||||||
* @type {File}
|
set: (value) => {
|
||||||
* @memberof module:API.cvat.classes.CloudStorage
|
validateNotEmptyString(value);
|
||||||
* @instance
|
data.resource = value;
|
||||||
* @throws {module:API.cvat.exceptions.ArgumentError}
|
|
||||||
*/
|
|
||||||
keyFile: {
|
|
||||||
get: () => data.key_file,
|
|
||||||
set: (file) => {
|
|
||||||
if (file instanceof File) {
|
|
||||||
data.key_file = file;
|
|
||||||
} else {
|
|
||||||
throw new ArgumentError(`Should be a file. ${typeof file} was found`);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
/**
|
},
|
||||||
* Unique resource name
|
manifestPath: {
|
||||||
* @name resource
|
get: () => data.manifest_path,
|
||||||
* @type {string}
|
set: (value) => {
|
||||||
* @memberof module:API.cvat.classes.CloudStorage
|
validateNotEmptyString(value);
|
||||||
* @instance
|
data.manifest_path = value;
|
||||||
* @throws {module:API.cvat.exceptions.ArgumentError}
|
|
||||||
*/
|
|
||||||
resource: {
|
|
||||||
get: () => data.resource,
|
|
||||||
set: (value) => {
|
|
||||||
validateNotEmptyString(value);
|
|
||||||
data.resource = value;
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
/**
|
},
|
||||||
* @name manifestPath
|
providerType: {
|
||||||
* @type {string}
|
get: () => data.provider_type,
|
||||||
* @memberof module:API.cvat.classes.CloudStorage
|
set: (key) => {
|
||||||
* @instance
|
if (key !== undefined && !!CloudStorageProviderType[key]) {
|
||||||
* @throws {module:API.cvat.exceptions.ArgumentError}
|
data.provider_type = CloudStorageProviderType[key];
|
||||||
*/
|
} else {
|
||||||
manifestPath: {
|
throw new ArgumentError('Value must be one CloudStorageProviderType keys');
|
||||||
get: () => data.manifest_path,
|
}
|
||||||
set: (value) => {
|
|
||||||
validateNotEmptyString(value);
|
|
||||||
data.manifest_path = value;
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
/**
|
},
|
||||||
* @name providerType
|
credentialsType: {
|
||||||
* @type {module:API.cvat.enums.ProviderType}
|
get: () => data.credentials_type,
|
||||||
* @memberof module:API.cvat.classes.CloudStorage
|
set: (key) => {
|
||||||
* @instance
|
if (key !== undefined && !!CloudStorageCredentialsType[key]) {
|
||||||
* @throws {module:API.cvat.exceptions.ArgumentError}
|
data.credentials_type = CloudStorageCredentialsType[key];
|
||||||
*/
|
} else {
|
||||||
providerType: {
|
throw new ArgumentError('Value must be one CloudStorageCredentialsType keys');
|
||||||
get: () => data.provider_type,
|
}
|
||||||
set: (key) => {
|
|
||||||
if (key !== undefined && !!CloudStorageProviderType[key]) {
|
|
||||||
data.provider_type = CloudStorageProviderType[key];
|
|
||||||
} else {
|
|
||||||
throw new ArgumentError('Value must be one CloudStorageProviderType keys');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
/**
|
},
|
||||||
* @name credentialsType
|
specificAttributes: {
|
||||||
* @type {module:API.cvat.enums.CloudStorageCredentialsType}
|
get: () => data.specific_attributes,
|
||||||
* @memberof module:API.cvat.classes.CloudStorage
|
set: (attributesValue) => {
|
||||||
* @instance
|
if (typeof attributesValue === 'string') {
|
||||||
* @throws {module:API.cvat.exceptions.ArgumentError}
|
const attrValues = new URLSearchParams(
|
||||||
*/
|
Array.from(new URLSearchParams(attributesValue).entries()).filter(
|
||||||
credentialsType: {
|
([key, value]) => !!key && !!value,
|
||||||
get: () => data.credentials_type,
|
),
|
||||||
set: (key) => {
|
).toString();
|
||||||
if (key !== undefined && !!CloudStorageCredentialsType[key]) {
|
if (!attrValues) {
|
||||||
data.credentials_type = CloudStorageCredentialsType[key];
|
throw new ArgumentError('Value must match the key1=value1&key2=value2');
|
||||||
} else {
|
|
||||||
throw new ArgumentError('Value must be one CloudStorageCredentialsType keys');
|
|
||||||
}
|
}
|
||||||
},
|
data.specific_attributes = attributesValue;
|
||||||
|
} else {
|
||||||
|
throw new ArgumentError('Value must be a string');
|
||||||
|
}
|
||||||
},
|
},
|
||||||
/**
|
},
|
||||||
* @name specificAttributes
|
owner: {
|
||||||
* @type {string}
|
get: () => data.owner,
|
||||||
* @memberof module:API.cvat.classes.CloudStorage
|
},
|
||||||
* @instance
|
createdDate: {
|
||||||
* @throws {module:API.cvat.exceptions.ArgumentError}
|
get: () => data.created_date,
|
||||||
*/
|
},
|
||||||
specificAttributes: {
|
updatedDate: {
|
||||||
get: () => data.specific_attributes,
|
get: () => data.updated_date,
|
||||||
set: (attributesValue) => {
|
},
|
||||||
if (typeof attributesValue === 'string') {
|
manifests: {
|
||||||
const attrValues = new URLSearchParams(
|
get: () => data.manifests,
|
||||||
Array.from(new URLSearchParams(attributesValue).entries()).filter(
|
set: (manifests) => {
|
||||||
([key, value]) => !!key && !!value,
|
if (Array.isArray(manifests)) {
|
||||||
),
|
for (const elem of manifests) {
|
||||||
).toString();
|
if (typeof elem !== 'string') {
|
||||||
if (!attrValues) {
|
throw new ArgumentError('Each element of the manifests array must be a string');
|
||||||
throw new ArgumentError('Value must match the key1=value1&key2=value2');
|
|
||||||
}
|
}
|
||||||
data.specific_attributes = attributesValue;
|
|
||||||
} else {
|
|
||||||
throw new ArgumentError('Value must be a string');
|
|
||||||
}
|
}
|
||||||
},
|
data.manifests = manifests;
|
||||||
|
} else {
|
||||||
|
throw new ArgumentError('Value must be an array');
|
||||||
|
}
|
||||||
},
|
},
|
||||||
/**
|
},
|
||||||
* Instance of a user who has created the cloud storage
|
}),
|
||||||
* @name owner
|
);
|
||||||
* @type {module:API.cvat.classes.User}
|
}
|
||||||
* @memberof module:API.cvat.classes.CloudStorage
|
|
||||||
* @readonly
|
|
||||||
* @instance
|
|
||||||
*/
|
|
||||||
owner: {
|
|
||||||
get: () => data.owner,
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* @name createdDate
|
|
||||||
* @type {string}
|
|
||||||
* @memberof module:API.cvat.classes.CloudStorage
|
|
||||||
* @readonly
|
|
||||||
* @instance
|
|
||||||
*/
|
|
||||||
createdDate: {
|
|
||||||
get: () => data.created_date,
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* @name updatedDate
|
|
||||||
* @type {string}
|
|
||||||
* @memberof module:API.cvat.classes.CloudStorage
|
|
||||||
* @readonly
|
|
||||||
* @instance
|
|
||||||
*/
|
|
||||||
updatedDate: {
|
|
||||||
get: () => data.updated_date,
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* @name manifests
|
|
||||||
* @type {string[]}
|
|
||||||
* @memberof module:API.cvat.classes.CloudStorage
|
|
||||||
* @instance
|
|
||||||
* @throws {module:API.cvat.exceptions.ArgumentError}
|
|
||||||
*/
|
|
||||||
manifests: {
|
|
||||||
get: () => data.manifests,
|
|
||||||
set: (manifests) => {
|
|
||||||
if (Array.isArray(manifests)) {
|
|
||||||
for (const elem of manifests) {
|
|
||||||
if (typeof elem !== 'string') {
|
|
||||||
throw new ArgumentError('Each element of the manifests array must be a string');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
data.manifests = manifests;
|
|
||||||
} else {
|
|
||||||
throw new ArgumentError('Value must be an array');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// Method updates data of a created cloud storage or creates new cloud storage
|
||||||
* Method updates data of a created cloud storage or creates new cloud storage
|
public async save(): Promise<CloudStorage> {
|
||||||
* @method save
|
const result = await PluginRegistry.apiWrapper.call(this, CloudStorage.prototype.save);
|
||||||
* @returns {module:API.cvat.classes.CloudStorage}
|
return result;
|
||||||
* @memberof module:API.cvat.classes.CloudStorage
|
}
|
||||||
* @readonly
|
|
||||||
* @instance
|
|
||||||
* @async
|
|
||||||
* @throws {module:API.cvat.exceptions.ServerError}
|
|
||||||
* @throws {module:API.cvat.exceptions.PluginError}
|
|
||||||
*/
|
|
||||||
async save() {
|
|
||||||
const result = await PluginRegistry.apiWrapper.call(this, CloudStorage.prototype.save);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public async delete(): Promise<void> {
|
||||||
* Method deletes a cloud storage from a server
|
const result = await PluginRegistry.apiWrapper.call(this, CloudStorage.prototype.delete);
|
||||||
* @method delete
|
return result;
|
||||||
* @memberof module:API.cvat.classes.CloudStorage
|
}
|
||||||
* @readonly
|
|
||||||
* @instance
|
|
||||||
* @async
|
|
||||||
* @throws {module:API.cvat.exceptions.ServerError}
|
|
||||||
* @throws {module:API.cvat.exceptions.PluginError}
|
|
||||||
*/
|
|
||||||
async delete() {
|
|
||||||
const result = await PluginRegistry.apiWrapper.call(this, CloudStorage.prototype.delete);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public async getContent(): Promise<any> {
|
||||||
* Method returns cloud storage content
|
const result = await PluginRegistry.apiWrapper.call(this, CloudStorage.prototype.getContent);
|
||||||
* @method getContent
|
return result;
|
||||||
* @memberof module:API.cvat.classes.CloudStorage
|
}
|
||||||
* @readonly
|
|
||||||
* @instance
|
|
||||||
* @async
|
|
||||||
* @throws {module:API.cvat.exceptions.ServerError}
|
|
||||||
* @throws {module:API.cvat.exceptions.PluginError}
|
|
||||||
*/
|
|
||||||
async getContent() {
|
|
||||||
const result = await PluginRegistry.apiWrapper.call(this, CloudStorage.prototype.getContent);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public async getPreview(): Promise<string | ArrayBuffer> {
|
||||||
* Method returns the cloud storage preview
|
const result = await PluginRegistry.apiWrapper.call(this, CloudStorage.prototype.getPreview);
|
||||||
* @method getPreview
|
return result;
|
||||||
* @memberof module:API.cvat.classes.CloudStorage
|
}
|
||||||
* @readonly
|
|
||||||
* @instance
|
|
||||||
* @async
|
|
||||||
* @throws {module:API.cvat.exceptions.ServerError}
|
|
||||||
* @throws {module:API.cvat.exceptions.PluginError}
|
|
||||||
*/
|
|
||||||
async getPreview() {
|
|
||||||
const result = await PluginRegistry.apiWrapper.call(this, CloudStorage.prototype.getPreview);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public async getStatus(): Promise<CloudStorageStatus> {
|
||||||
* Method returns cloud storage status
|
const result = await PluginRegistry.apiWrapper.call(this, CloudStorage.prototype.getStatus);
|
||||||
* @method getStatus
|
return result;
|
||||||
* @memberof module:API.cvat.classes.CloudStorage
|
|
||||||
* @readonly
|
|
||||||
* @instance
|
|
||||||
* @async
|
|
||||||
* @throws {module:API.cvat.exceptions.ServerError}
|
|
||||||
* @throws {module:API.cvat.exceptions.PluginError}
|
|
||||||
*/
|
|
||||||
async getStatus() {
|
|
||||||
const result = await PluginRegistry.apiWrapper.call(this, CloudStorage.prototype.getStatus);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CloudStorage.prototype.save.implementation = async function () {
|
Object.defineProperties(CloudStorage.prototype.save, {
|
||||||
function prepareOptionalFields(cloudStorageInstance) {
|
implementation: {
|
||||||
const data = {};
|
writable: false,
|
||||||
if (cloudStorageInstance.description !== undefined) {
|
enumerable: false,
|
||||||
data.description = cloudStorageInstance.description;
|
value: async function implementation(): Promise<CloudStorage> {
|
||||||
}
|
function prepareOptionalFields(cloudStorageInstance: CloudStorage): RawCloudStorageData {
|
||||||
|
const data: RawCloudStorageData = {};
|
||||||
|
if (cloudStorageInstance.description !== undefined) {
|
||||||
|
data.description = cloudStorageInstance.description;
|
||||||
|
}
|
||||||
|
|
||||||
if (cloudStorageInstance.accountName) {
|
if (cloudStorageInstance.accountName) {
|
||||||
data.account_name = cloudStorageInstance.accountName;
|
data.account_name = cloudStorageInstance.accountName;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cloudStorageInstance.accessKey) {
|
if (cloudStorageInstance.accessKey) {
|
||||||
data.key = cloudStorageInstance.accessKey;
|
data.key = cloudStorageInstance.accessKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cloudStorageInstance.secretKey) {
|
if (cloudStorageInstance.secretKey) {
|
||||||
data.secret_key = cloudStorageInstance.secretKey;
|
data.secret_key = cloudStorageInstance.secretKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cloudStorageInstance.token) {
|
if (cloudStorageInstance.token) {
|
||||||
data.session_token = cloudStorageInstance.token;
|
data.session_token = cloudStorageInstance.token;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cloudStorageInstance.keyFile) {
|
if (cloudStorageInstance.keyFile) {
|
||||||
data.key_file = cloudStorageInstance.keyFile;
|
data.key_file = cloudStorageInstance.keyFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cloudStorageInstance.specificAttributes !== undefined) {
|
if (cloudStorageInstance.specificAttributes !== undefined) {
|
||||||
data.specific_attributes = cloudStorageInstance.specificAttributes;
|
data.specific_attributes = cloudStorageInstance.specificAttributes;
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
|
||||||
// update
|
|
||||||
if (typeof this.id !== 'undefined') {
|
|
||||||
// provider_type and recource should not change;
|
|
||||||
// send to the server only the values that have changed
|
|
||||||
const initialData = {};
|
|
||||||
if (this.displayName) {
|
|
||||||
initialData.display_name = this.displayName;
|
|
||||||
}
|
|
||||||
if (this.credentialsType) {
|
|
||||||
initialData.credentials_type = this.credentialsType;
|
|
||||||
}
|
}
|
||||||
|
// update
|
||||||
|
if (typeof this.id !== 'undefined') {
|
||||||
|
// provider_type and recource should not change;
|
||||||
|
// send to the server only the values that have changed
|
||||||
|
const initialData: RawCloudStorageData = {};
|
||||||
|
if (this.displayName) {
|
||||||
|
initialData.display_name = this.displayName;
|
||||||
|
}
|
||||||
|
if (this.credentialsType) {
|
||||||
|
initialData.credentials_type = this.credentialsType;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.manifests) {
|
if (this.manifests) {
|
||||||
initialData.manifests = this.manifests;
|
initialData.manifests = this.manifests;
|
||||||
|
}
|
||||||
|
|
||||||
|
const cloudStorageData = {
|
||||||
|
...initialData,
|
||||||
|
...prepareOptionalFields(this),
|
||||||
|
};
|
||||||
|
|
||||||
|
await serverProxy.cloudStorages.update(this.id, cloudStorageData);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// create
|
||||||
|
const initialData: RawCloudStorageData = {
|
||||||
|
display_name: this.displayName,
|
||||||
|
credentials_type: this.credentialsType,
|
||||||
|
provider_type: this.providerType,
|
||||||
|
resource: this.resource,
|
||||||
|
manifests: this.manifests,
|
||||||
|
};
|
||||||
|
|
||||||
const cloudStorageData = {
|
const cloudStorageData = {
|
||||||
...initialData,
|
...initialData,
|
||||||
...prepareOptionalFields(this),
|
...prepareOptionalFields(this),
|
||||||
};
|
};
|
||||||
|
|
||||||
await serverProxy.cloudStorages.update(this.id, cloudStorageData);
|
const cloudStorage = await serverProxy.cloudStorages.create(cloudStorageData);
|
||||||
return this;
|
return new CloudStorage(cloudStorage);
|
||||||
}
|
},
|
||||||
|
},
|
||||||
// create
|
});
|
||||||
const initialData = {
|
|
||||||
display_name: this.displayName,
|
|
||||||
credentials_type: this.credentialsType,
|
|
||||||
provider_type: this.providerType,
|
|
||||||
resource: this.resource,
|
|
||||||
manifests: this.manifests,
|
|
||||||
};
|
|
||||||
|
|
||||||
const cloudStorageData = {
|
|
||||||
...initialData,
|
|
||||||
...prepareOptionalFields(this),
|
|
||||||
};
|
|
||||||
|
|
||||||
const cloudStorage = await serverProxy.cloudStorages.create(cloudStorageData);
|
|
||||||
return new CloudStorage(cloudStorage);
|
|
||||||
};
|
|
||||||
|
|
||||||
CloudStorage.prototype.delete.implementation = async function () {
|
Object.defineProperties(CloudStorage.prototype.delete, {
|
||||||
const result = await serverProxy.cloudStorages.delete(this.id);
|
implementation: {
|
||||||
return result;
|
writable: false,
|
||||||
};
|
enumerable: false,
|
||||||
|
value: async function implementation(): Promise<void> {
|
||||||
CloudStorage.prototype.getContent.implementation = async function () {
|
const result = await serverProxy.cloudStorages.delete(this.id);
|
||||||
const result = await serverProxy.cloudStorages.getContent(this.id, this.manifestPath);
|
return result;
|
||||||
return result;
|
},
|
||||||
};
|
},
|
||||||
|
});
|
||||||
|
|
||||||
CloudStorage.prototype.getPreview.implementation = async function getPreview() {
|
Object.defineProperties(CloudStorage.prototype.getContent, {
|
||||||
return new Promise((resolve, reject) => {
|
implementation: {
|
||||||
serverProxy.cloudStorages
|
writable: false,
|
||||||
.getPreview(this.id)
|
enumerable: false,
|
||||||
.then((result) => {
|
value: async function implementation(): Promise<any> {
|
||||||
if (isNode) {
|
const result = await serverProxy.cloudStorages.getContent(this.id, this.manifestPath);
|
||||||
resolve(global.Buffer.from(result, 'binary').toString('base64'));
|
return result;
|
||||||
} else if (isBrowser) {
|
},
|
||||||
const reader = new FileReader();
|
},
|
||||||
reader.onload = () => {
|
});
|
||||||
resolve(reader.result);
|
|
||||||
};
|
|
||||||
reader.readAsDataURL(result);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
CloudStorage.prototype.getStatus.implementation = async function () {
|
Object.defineProperties(CloudStorage.prototype.getPreview, {
|
||||||
const result = await serverProxy.cloudStorages.getStatus(this.id);
|
implementation: {
|
||||||
return result;
|
writable: false,
|
||||||
};
|
enumerable: false,
|
||||||
|
value: async function implementation(): Promise<string | ArrayBuffer> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
serverProxy.cloudStorages
|
||||||
|
.getPreview(this.id)
|
||||||
|
.then((result) => {
|
||||||
|
if (isNode) {
|
||||||
|
resolve(global.Buffer.from(result, 'binary').toString('base64'));
|
||||||
|
} else if (isBrowser) {
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onload = () => {
|
||||||
|
resolve(reader.result);
|
||||||
|
};
|
||||||
|
reader.readAsDataURL(result);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
module.exports = {
|
Object.defineProperties(CloudStorage.prototype.getStatus, {
|
||||||
CloudStorage,
|
implementation: {
|
||||||
};
|
writable: false,
|
||||||
})();
|
enumerable: false,
|
||||||
|
value: async function implementation(): Promise<CloudStorageStatus> {
|
||||||
|
const result = await serverProxy.cloudStorages.getStatus(this.id);
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
// Copyright (C) 2020-2022 Intel Corporation
|
// Copyright (C) 2020-2022 Intel Corporation
|
||||||
|
// Copyright (C) 2022 CVAT.ai Corporation
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
import 'redux-thunk/extend-redux';
|
||||||
|
|
||||||
declare module '*.svg';
|
declare module '*.svg';
|
||||||
declare module 'cvat-core/src/api';
|
declare module 'cvat-core/src/api';
|
||||||
|
|||||||
Loading…
Reference in New Issue