Skip to content

Commit

Permalink
Merge pull request #675 from uploadcare/feat/remove-deprecated-api
Browse files Browse the repository at this point in the history
Remove deprecated APIs
  • Loading branch information
nd0ut authored Jun 23, 2024
2 parents b760e23 + 51f094f commit e163ef7
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 55 deletions.
1 change: 0 additions & 1 deletion abstract/CTX.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const uploaderBlockCtx = (fnCtx) => ({
'*commonProgress': 0,
'*uploadList': [],
'*focusedEntry': null,
'*uploadMetadata': null,
'*uploadQueue': new Queue(1),
'*uploadCollection': null,
/** @type {ReturnType<import('../types').OutputErrorCollection>[]} */
Expand Down
55 changes: 1 addition & 54 deletions abstract/UploaderBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { customUserAgent } from '../blocks/utils/userAgent.js';
import { createCdnUrl, createCdnUrlModifiers } from '../utils/cdn-utils.js';
import { IMAGE_ACCEPT_LIST, fileIsImage, mergeFileTypes } from '../utils/fileTypes.js';
import { stringToArray } from '../utils/stringToArray.js';
import { warnOnce } from '../utils/warnOnce.js';
import { uploaderBlockCtx } from './CTX.js';
import { TypedCollection } from './TypedCollection.js';
import { buildOutputCollectionState } from './buildOutputCollectionState.js';
Expand All @@ -28,32 +27,6 @@ export class UploaderBlock extends ActivityBlock {

init$ = uploaderBlockCtx(this);

/** @private */
__initialUploadMetadata = null;

/**
* This is Public JS API method. Could be called before block initialization, so we need to delay state interactions
* until block init.
*
* TODO: If we add more public methods, it is better to use the single queue instead of tons of private fields per
* each method. See https://github.com/uploadcare/blocks/pull/162/
*
* @deprecated Use `metadata` instance property on `lr-config` block instead.
* @param {import('@uploadcare/upload-client').Metadata} metadata
* @public
*/
setUploadMetadata(metadata) {
warnOnce(
'setUploadMetadata is deprecated. Use `metadata` instance property on `lr-config` block instead. See migration guide: https://uploadcare.com/docs/file-uploader/migration-to-0.25.0/',
);
if (!this.connectedOnce) {
// @ts-ignore TODO: fix this
this.__initialUploadMetadata = metadata;
} else {
this.$['*uploadMetadata'] = metadata;
}
}

get hasCtxOwner() {
return this.hasBlockInCtx((block) => {
if (block instanceof UploaderBlock) {
Expand Down Expand Up @@ -112,10 +85,6 @@ export class UploaderBlock extends ActivityBlock {
this.$['*uploadQueue'].concurrency = Number(value) || 1;
});

if (this.__initialUploadMetadata) {
this.$['*uploadMetadata'] = this.__initialUploadMetadata;
}

if (!this.$['*secureUploadsManager']) {
this.$['*secureUploadsManager'] = new SecureUploadsManager(this);
}
Expand Down Expand Up @@ -193,28 +162,6 @@ export class UploaderBlock extends ActivityBlock {
return this.getOutputItem(internalId);
}

/**
* @deprecated Will be removed in the near future. Please use `addFileFromObject`, `addFileFromUrl` or
* `addFileFromUuid` instead.
* @param {File[]} files
* @returns {import('../types').OutputFileEntry<'idle'>[]}
*/
addFiles(files) {
console.warn(
'`addFiles` method is deprecated. Please use `addFileFromObject`, `addFileFromUrl` or `addFileFromUuid` instead.',
);
return files.map((/** @type {File} */ file) => {
const internalId = this.uploadCollection.add({
file,
isImage: fileIsImage(file),
mimeType: file.type,
fileName: file.name,
fileSize: file.size,
});
return this.getOutputItem(internalId);
});
}

/** @param {string} internalId */
removeFileByInternalId(internalId) {
if (!this.uploadCollection.read(internalId)) {
Expand Down Expand Up @@ -584,7 +531,7 @@ export class UploaderBlock extends ActivityBlock {
* @protected
*/
async getMetadataFor(entryId) {
const configValue = this.cfg.metadata ?? /** @type {import('../types').Metadata} */ (this.$['*uploadMetadata']);
const configValue = this.cfg.metadata || undefined;
if (typeof configValue === 'function') {
const outputFileEntry = this.getOutputItem(entryId);
const metadata = await configValue(outputFileEntry);
Expand Down

0 comments on commit e163ef7

Please sign in to comment.