MCPcopy
hub / github.com/transloadit/uppy / constructor

Method constructor

packages/@uppy/core/src/Uppy.ts:439–519  ·  view source on GitHub ↗

* Instantiate Uppy

(opts?: UppyOptionsWithOptionalRestrictions<M, B>)

Source from the content-addressed store, hash-verified

437 * Instantiate Uppy
438 */
439 constructor(opts?: UppyOptionsWithOptionalRestrictions<M, B>) {
440 this.defaultLocale = locale
441
442 const defaultOptions: UppyOptions<Record<string, unknown>, B> = {
443 id: 'uppy',
444 autoProceed: false,
445 allowMultipleUploadBatches: true,
446 debug: false,
447 restrictions: defaultRestrictionOptions,
448 meta: {},
449 onBeforeFileAdded: (file, files) => !Object.hasOwn(files, file.id),
450 onBeforeUpload: (files) => files,
451 store: new DefaultStore(),
452 logger: justErrorsLogger,
453 infoTimeout: 5000,
454 }
455
456 const merged = { ...defaultOptions, ...opts } as Omit<
457 NonNullableUppyOptions<M, B>,
458 'restrictions'
459 >
460 // Merge default options with the ones set by user,
461 // making sure to merge restrictions too
462 this.opts = {
463 ...merged,
464 restrictions: {
465 ...(defaultOptions.restrictions as Restrictions),
466 ...opts?.restrictions,
467 },
468 }
469
470 // Support debug: true for backwards-compatability, unless logger is set in opts
471 // opts instead of this.opts to avoid comparing objects — we set logger: justErrorsLogger in defaultOptions
472 if (opts?.logger && opts.debug) {
473 this.log(
474 'You are using a custom `logger`, but also set `debug: true`, which uses built-in logger to output logs to console. Ignoring `debug: true` and using your custom `logger`.',
475 'warning',
476 )
477 } else if (opts?.debug) {
478 this.opts.logger = debugLogger
479 }
480
481 this.log(`Using Core v${Uppy.VERSION}`)
482
483 this.i18nInit()
484
485 this.store = this.opts.store
486 this.setState({
487 ...defaultUploadState,
488 plugins: {},
489 files: {},
490 currentUploads: {},
491 capabilities: {
492 uploadProgress: supportsUploadProgress(),
493 individualCancellation: true,
494 resumableUploads: false,
495 },
496 meta: { ...this.opts.meta },

Callers

nothing calls this directly

Calls 8

logMethod · 0.95
i18nInitMethod · 0.95
setStateMethod · 0.95
emitMethod · 0.95
updateAllMethod · 0.95
#addListenersMethod · 0.95
supportsUploadProgressFunction · 0.85
subscribeMethod · 0.65

Tested by

no test coverage detected