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

Remove deprecated APIs #675

Merged
merged 2 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading