Skip to content

Commit

Permalink
feat: added types and handler fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
egordidenko committed Sep 2, 2024
1 parent e13e3b8 commit f928e6a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 18 deletions.
19 changes: 3 additions & 16 deletions abstract/UploaderBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { TypedCollection } from './TypedCollection.js';
import { UploaderPublicApi } from './UploaderPublicApi.js';
import { ValidationManager } from './ValidationManager.js';
import { uploadEntrySchema } from './uploadEntrySchema.js';
import { ExternalUploadSource, UploadSource } from '../blocks/utils/UploadSource.js';

export class UploaderBlock extends ActivityBlock {
/** @protected */
Expand Down Expand Up @@ -426,27 +427,13 @@ export class UploaderBlock extends ActivityBlock {
* @enum {String}
*/
UploaderBlock.extSrcList = Object.freeze({
FACEBOOK: 'facebook',
DROPBOX: 'dropbox',
GDRIVE: 'gdrive',
GPHOTOS: 'gphotos',
INSTAGRAM: 'instagram',
FLICKR: 'flickr',
VK: 'vk',
EVERNOTE: 'evernote',
BOX: 'box',
ONEDRIVE: 'onedrive',
HUDDLE: 'huddle',
...ExternalUploadSource,
});

/**
* @deprecated Use list sources UploadSource from from blocks/utils/UploadSource.js
* @enum {String}
*/
UploaderBlock.sourceTypes = Object.freeze({
LOCAL: 'local',
URL: 'url',
CAMERA: 'camera',
DRAW: 'draw',
...UploaderBlock.extSrcList,
...UploadSource,
});
2 changes: 1 addition & 1 deletion blocks/FileItem/FileItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ export class FileItem extends UploaderBlock {
cdnUrl: entry.getValue('cdnUrl') ?? fileInfo.cdnUrl,
cdnUrlModifiers: entry.getValue('cdnUrlModifiers') ?? '',
uploadProgress: 100,
source: entry.getValue('source') ?? '',
source: entry.getValue('source') ?? null,
});

if (entry === this._entry) {
Expand Down
2 changes: 1 addition & 1 deletion blocks/utils/UploadSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ export const UploadSource = Object.freeze({
...ExternalUploadSource,
});

/** @typedef {typeof UploadSource} SourceTypes */
/** @typedef {(typeof UploadSource)[keyof typeof UploadSource]} SourceTypes */
3 changes: 3 additions & 0 deletions types/exported.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import type { FuncFileValidator, FuncCollectionValidator } from '../abstract/Val
export type { FuncFileValidator, FuncCollectionValidator } from '../abstract/ValidationManager';
export type { UploaderPublicApi } from '../abstract/UploaderPublicApi';

export type { SourceTypes } from '../blocks/utils/UploadSource'

export type UploadError = import('@uploadcare/upload-client').UploadError;
export type UploadcareFile = import('@uploadcare/upload-client').UploadcareFile;
export type NetworkError = import('@uploadcare/upload-client').NetworkError;
Expand Down Expand Up @@ -168,6 +170,7 @@ export type OutputFileEntry<TStatus extends OutputFileStatus = OutputFileStatus>
externalUrl: string | null;
uploadProgress: number;
fullPath: string | null;
source: SourceTypes;
} & (
| {
status: 'success';
Expand Down

0 comments on commit f928e6a

Please sign in to comment.