Repository: toeverything/AFFiNE
File: blocksuite/affine/block-attachment/src/embed.ts (TypeScript)

Code before:
    return this.std.store.get(FileSizeLimitService).maxFileSize;
  }

  get keys() {
    return this.configs.keys();
  }

  get values() {
    return this.configs.values();
  }

  get configs(): Map<string, AttachmentEmbedConfig> {
    return this.std.get(AttachmentEmbedConfigMapIdentifier);
  }

  constructor(private readonly std: BlockStdScope) {
    super();
  }

  static override setup(di: Container) {
    di.addImpl(AttachmentEmbedConfigMapIdentifier, provider =>
      provider.getAll(AttachmentEmbedConfigIdentifier)
    );
    di.addImpl(
      AttachmentEmbedProvider,
      new AttachmentEmbedService(di.provider().get(StdIdentifier))
    );
  }

  // Converts to embed view.
  convertTo(model: AttachmentBlockModel, maxFileSize = this._maxFileSize) {
    const config = this.values.find(config => config.check(model, maxFileSize));
    if (!config || !config.action) {
      model.doc.updateBlock(model, { embed: true });
      return;
    }
    config.action(model)?.catch(console.error);
  }

  embedded(model: AttachmentBlockModel, maxFileSize = this._maxFileSize) {
    return this.values.some(config => config.check(model, maxFileSize));
  }

  render(
    model: AttachmentBlockModel,
    blobUrl?: string,
    maxFileSize = this._maxFileSize
  ) {
    if (!model.embed || !blobUrl) return;

    const config = this.values.find(config => config.check(model, maxFileSize));

Review comment (suggestion):
This is not right, why don't use
```ts
di.addImpl(
    AttachmentEmbedProvider,
    AttachmentEmbedService,
    [StdIdentifier]
)
```

Your implementation will throw error if this extension is registered before stdIdentifier.

Code after:
    return this.std.store.get(FileSizeLimitService).maxFileSize;
  }

  get keys() {
    return this.configs.keys();
  }

  get values() {
    return this.configs.values();
  }

  get configs(): Map<string, AttachmentEmbedConfig> {
    return this.std.get(AttachmentEmbedConfigMapIdentifier);
  }

  constructor(private readonly std: BlockStdScope) {
    super();
  }

  static override setup(di: Container) {
    di.addImpl(AttachmentEmbedConfigMapIdentifier, provider =>
      provider.getAll(AttachmentEmbedConfigIdentifier)
    );
    di.addImpl(AttachmentEmbedProvider, this, [StdIdentifier]);
  }

  // Converts to embed view.
  convertTo(model: AttachmentBlockModel, maxFileSize = this._maxFileSize) {
    const config = this.values.find(config => config.check(model, maxFileSize));
    if (!config || !config.action) {
      model.doc.updateBlock(model, { embed: true });
      return;
    }
    config.action(model)?.catch(console.error);
  }

  embedded(model: AttachmentBlockModel, maxFileSize = this._maxFileSize) {
    return this.values.some(config => config.check(model, maxFileSize));
  }

  render(
    model: AttachmentBlockModel,
    blobUrl?: string,
    maxFileSize = this._maxFileSize
  ) {
    if (!model.embed || !blobUrl) return;

    const config = this.values.find(config => config.check(model, maxFileSize));
    if (!config || !config.template) {
      console.error('No embed view template found!', model, model.type);
      return;