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

Note: mime.lookup renamed to mime.getExtension #16

Open
pongraczi opened this issue Aug 28, 2019 · 1 comment
Open

Note: mime.lookup renamed to mime.getExtension #16

pongraczi opened this issue Aug 28, 2019 · 1 comment

Comments

@pongraczi
Copy link

Background

The mime package changed from 1.x to 2.x and mime.lookup renamed to mime.getExtension.
Codepad use it, but expect 1.x and does not prepared for 2.x

Result

Using codepad, etherpad-lite will crash, you will be frustrated.

How to fix it

  • First, be sure, the reason is really the mime problem.
    • Check the CHANGELOG.md in node_modules/mime/ path, you should see version numbers something similar: ### [2.4.4](https://github.com/broofa/node-mime/compare/v2.4.3...v2.4.4) (2019-06-07)
    • Alternatively you can start etherpad-lite manually and read the output when it crashes, you should see the following: blahblahblah mime.lookup() blahblahblah filestatic.js blahblahblah
  • Now go tonode_modules/ep_codepad and search all files contains mime.lookup (you should find the fileview.js and filestatic.js)
  • Replace the mime.lookup with mime.getExtension in these files. Example:
     if (exists) {                                                                                                                                                                                   
-      if (!ext.getBrush(path) && mime.lookup(path) !== 'application/octet-stream') {
+      if (!ext.getBrush(path) && mime.getExtension(path) !== 'application/octet-stream') { 
     fs.readFile(path, function(err, data) {                                                                                                                                                 
     if (err) throw err;      
  • Save them and restart etherpad-lite.

Now you will be happy, it will work as expected.

@ProdigyView
Copy link

ProdigyView commented Jun 3, 2021

@pongraczi would it be easier to have lookup call get extension?

mime.lookup(path) {
    return mime.getExtension(path);
}

Or in etherpad-lite/node_modules/mime/Mime.js

function Mime() {
  this._types = Object.create(null);
  this._extensions = Object.create(null);

  for (let i = 0; i < arguments.length; i++) {
    this.define(arguments[i]);
  }

  this.define = this.define.bind(this);
  this.getType = this.getType.bind(this);
  this.getExtension = this.getExtension.bind(this);
  this.lookup = this.getExtension;
}

Or something to that effect? (I havent gotten this working yet as my updates are not in the build)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants