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

When Adding a Custom Firebase plugin using BasePlugin, Getting a plugin.update not found error #4443

Closed
2 tasks done
George-field opened this issue May 6, 2023 · 2 comments
Labels
Types Issues relating to the Typescript definition files

Comments

@George-field
Copy link

Initial checklist

  • I understand this is a bug report and questions should be posted in the Community Forum
  • I searched issues and couldn’t find anything (or linked relevant results below)

Link to runnable example

No response

Steps to reproduce

Getting an issue with a custom plugin, I have checked the BasePlugin interface and there is no property there called update

import { v4 } from 'uuid';
import { FirebaseStorage, getDownloadURL, ref, uploadBytesResumable } from "firebase/storage";
import { storage } from '@/lib/firebase';


export default class FirebaseCloudStoragePlugin extends BasePlugin {
  type: string;
  id: string;
  title: string;
  storageRef: FirebaseStorage;

  // @ts-ignore
  constructor(uppy: Uppy, opts) {
    // @ts-ignore
    super(uppy, opts);
    this.type = "uploader";
    this.id = "FirebaseCloudStorage";
    this.title = "Firebase Cloud Storage";
    this.storageRef = storage;
    this.uploadFile = this.uploadFile.bind(this);

  }

  async uploadFile(fileIds: string[]) {
    await Promise.all(
      fileIds.map((id: string) => {
        return new Promise<void>(async (resolve, reject) => {
          const file = this.getFile(id);
          const refId = v4();
          const fileRef = ref(this.storageRef, refId);
          
          const metaData = {
            contentType: file.type
          };


          this.emit("upload-started", file);
          const uploadTask = uploadBytesResumable(fileRef, file.data, metaData);
          uploadTask.on(
            "state_changed",
            snapshot => {
              const progressInfo = {
                uploader: this,
                bytesUploaded: snapshot.bytesTransferred,
                bytesTotal: snapshot.totalBytes
              };
              this.emit("upload-progress", file, progressInfo);
            },
            error => {
              this.emit("upload-error", file, error);
              reject(error);
            },
            () => {
              getDownloadURL(fileRef).then((downloadUrl: string) => {
                const file = this.getFile(id);
                this.emit(
                  "upload-success",
                  { ...file, downloadUrl },
                  uploadTask.snapshot,
                  downloadUrl
                );
                resolve();
              });
            }
          );
        });
      })
    );
  }

  install() {
    this.addUploader(this.uploadFile);
  }

  uninstall() {
    this.removeUploader(this.uploadFile);
  }

}

### Expected behavior

I believe that it should render fine. The issue I am finding though is that the error makes sense, if you check the BasePlugin interface, there is no update function there. 

This is the code that is causing the bug:

updateAll(state) {
this.iteratePlugins(plugin => {
plugin.update(state);
});
}


Can be found in `@uppy/core/lib/Uppy.js` line 261.

I assume that I need to add an update function to the class I have created but type defs won't allow it because the BasePlugin interface hasn't got it defined. 

### Actual behavior

Should Either let me create my own function or ignore the update?
@arturi
Copy link
Contributor

arturi commented May 7, 2023

plugin.update exists in BasePlugin here:

So when your plugin extends BasePlugin, empty update is inherited and all should be fine.

So am I understanding correctly that the issue is types, and we should add update here

export class BasePlugin<TOptions extends PluginOptions = DefaultPluginOptions> {
id: string
// eslint-disable-next-line no-use-before-define
uppy: Uppy
type: string
// eslint-disable-next-line no-use-before-define
constructor(uppy: Uppy, opts?: TOptions)
setOptions(update: Partial<TOptions>): void
getPluginState(): Record<string, unknown>
setPluginState(update: IndexedObject<any>): Record<string, unknown>
install(): void
uninstall(): void
}
? If so, could you PR this please?

@Murderlon
Copy link
Member

Core has been redone in TS and is properly typed. The new types are not yet released but will be soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Types Issues relating to the Typescript definition files
Projects
None yet
Development

No branches or pull requests

3 participants