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

how to set allowed_extensions? #5

Open
c2h2 opened this issue Dec 2, 2020 · 3 comments
Open

how to set allowed_extensions? #5

c2h2 opened this issue Dec 2, 2020 · 3 comments

Comments

@c2h2
Copy link

c2h2 commented Dec 2, 2020

Hi, Great project.

Can you tell us how to sepcify allowed_extensions in a flask app?

@sujeetkv
Copy link
Owner

sujeetkv commented Dec 4, 2020

Currently this is not possible filter file types but this feature is in backlog and will be added in future development.

@eduardomsec
Copy link

Looking forward to this new release. I need to edit files with 'conf' type extensions.

@WillianBR
Copy link

WillianBR commented Jul 3, 2023

How to get rid of "This file type is not allowed to open..."

I digged into the source code and just found out a function called flaskcode.validResource() into file flaskcode.js,
It's the core of file type validation.

This function try to find a syntax handler. If it can't, just raise the error. But it would be a lot more easy if it just handle it as plain/text ascii.

flaskcode.validResource = function (filename) {
    var ext = flaskcode.getExt(filename);
    var lang = ext ? flaskcode.getLanguageByExtension(ext) : null;
    return lang ? flaskcode.allowedLangIds.indexOf(lang.id) > -1 : false;
};

You can see at line #18 the default handler!

flaskcode.languages = [];
flaskcode.defaultExt = 'txt';
flaskcode.defaultLangId = 'plaintext';
flaskcode.defaultLang = null;
flaskcode.fallbackLang = null;

The return of flaskcode.getLanguageByExtension(ext) is something like this:

{
    "id": "python",
    "extensions": [
        ".py",
        ".rpy",
        ".pyw",
        ".cpy",
        ".gyp",
        ".gypi"
    ],
    "aliases": [
        "Python",
        "py"
    ],
    "firstLine": "^#!/.*\\bpython[0-9.-]*\\b"
}

This is my validResource() version:
⭐⭐ ⭐ ⭐ ⭐

flaskcode.validResource = function (filename) {
    var ext = flaskcode.getExt(filename);
    var lang = ext ? flaskcode.getLanguageByExtension(ext) : null;
    
    /* fallback to plaintext */
    if(!lang){ /* if not found try text file */
        lang = flaskcode.getLanguageByExtension('txt')
        //alert(JSON.stringify(lang, null, 4));
        if(lang){ /* Just to be sure! */
            if(ext) /* add ext to array */
               lang.extensions.push("."+ext);
            /* return the struct */
            return lang
        }
    }
    return lang ? flaskcode.allowedLangIds.indexOf(lang.id) > -1 : false;
};

💡💡💡 Also a good trick would be ignore all '.git' and '.env' folder! It can slow down the editor! 💡💡💡

💣💣 💣 Be carefull! If you try to open a binary file, things can get messy! 💣💣 💣

That's all Folks!!!

2023-07-03 17_57_29-FlaskCode - flaskcode 2023-07-03 17_57_44-FlaskCode - flaskcode

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

4 participants