<commit_before>/* global forge */

forge["file"] = {
    /**
     * Allow the user to select an image and give a file object representing it.
     *
     * @param {Object} props
     * @param {function({uri: string, name: string})=} success
     * @param {function({message: string}=} error
     */
    "getImage": function (props, success, error) {
        if (typeof props === "function") {
            error = success;
            success = props;
            props = {};
        }
        if (!props) {
            props = {};
        }
        props.source = "gallery";
        forge.internal.call("file.getImage", props, success && function (uri) {
            var file = {
                uri: uri,
                name: "Image",
                type: "image"
            };
            if (props.width) {
                file.width = props.width;
            }
            if (props.height) {
                file.height = props.height;
            }
            success(file);
        }, error);
    },

    /**
     * Allow the user to select a video and give a file object representing it.
     *
     * @param {Object} props
     * @param {function({uri: string, name: string})=} success
     * @param {function({message: string}=} error
     */
    "getVideo": function (props, success, error) {
        if (typeof props === "function") {
            error = success;
            success = props;
            props = {};
        }
        if (!props) {
            props = {};
        }
        props.source = "gallery";
        forge.internal.call("file.getVideo", props, success && function (uri) {
            var file = {
                uri: uri,
                name: "Video",
                type: "video"
            };
            success(file);
        }, error);
    },

    /**
     * Get file object for a local file.
     *
     * @param {string} name
     * @param {function(string)=} success
     * @param {function({message: string}=} error
     */
    "getLocal": function (path, success, error) {
        forge.internal.call("file.getLocal", {name: path}, success, error);
    },

    /**
     * Returns file information
     *
     * @param {{uri: string, name: string}} file
     * @param {function(object)=} success
     * @param {function({message: string}=} error
     */
    "info": function (file, success, error) {
        forge.internal.call("file.info", file, success, error);
    },

    /**
     * Get the base64 value for a files contents.
     *
     * @param {{uri: string, name: string}} file
     * @param {function(string)=} success
     * @param {function({message: string}=} error
     */
    "base64": function (file, success, error) {
        forge.internal.call("file.base64", file, success, error);
    },

    /**
     * Get the string value for a files contents.
     *
     * @param {{uri: string, name: string}} file
     * @param {function(string)=} success
     * @param {function({message: string}=} error
     */
    "string": function (file, success, error) {
        forge.internal.call("file.string", file, success, error);
    },

    /**
     * Get the URL an image which is no bigger than the given height and width.
     *
     * URL must be useable in the current scope of the code, may return a base64 data: URI.
     *
     * @param {{uri: string, name: string}} file
     * @param {Object} props
     * @param {function(string)=} success
     * @param {function({message: string}=} error
     */
    "URL": function (file, props, success, error) {
        if (typeof props === "function") {
            error = success;
            success = props;
        }
        // Avoid mutating original file
        var newFile = {};
        for (var prop in file) {
            newFile[prop] = file[prop];
        }
        newFile.height = props.height || file.height || undefined;
        newFile.width = props.width || file.width || undefined;
        if (forge.httpd && forge.config.modules.httpd.config.port) {
            forge.internal.call("file.URL", newFile, function (url) {
                success(forge.httpd.normalize(url));
            }, error);
        } else {
            forge.internal.call("file.URL", newFile, success, error);
        }
    },

    /**
     * Check a file object represents a file which exists.<commit_msg>Support build-in webserver<commit_after>/* global forge */

forge["file"] = {
    /**
     * Allow the user to select an image and give a file object representing it.
     *
     * @param {Object} props
     * @param {function({uri: string, name: string})=} success
     * @param {function({message: string}=} error
     */
    "getImage": function (props, success, error) {
        if (typeof props === "function") {
            error = success;
            success = props;
            props = {};
        }
        if (!props) {
            props = {};
        }
        props.source = "gallery";
        forge.internal.call("file.getImage", props, success && function (uri) {
            var file = {
                uri: uri,
                name: "Image",
                type: "image"
            };
            if (props.width) {
                file.width = props.width;
            }
            if (props.height) {
                file.height = props.height;
            }
            success(file);
        }, error);
    },

    /**
     * Allow the user to select a video and give a file object representing it.
     *
     * @param {Object} props
     * @param {function({uri: string, name: string})=} success
     * @param {function({message: string}=} error
     */
    "getVideo": function (props, success, error) {
        if (typeof props === "function") {
            error = success;
            success = props;
            props = {};
        }
        if (!props) {
            props = {};
        }
        props.source = "gallery";
        forge.internal.call("file.getVideo", props, success && function (uri) {
            var file = {
                uri: uri,
                name: "Video",
                type: "video"
            };
            success(file);
        }, error);
    },

    /**
     * Get file object for a local file.
     *
     * @param {string} name
     * @param {function(string)=} success
     * @param {function({message: string}=} error
     */
    "getLocal": function (path, success, error) {
        forge.internal.call("file.getLocal", {name: path}, success, error);
    },

    /**
     * Returns file information
     *
     * @param {{uri: string, name: string}} file
     * @param {function(object)=} success
     * @param {function({message: string}=} error
     */
    "info": function (file, success, error) {
        forge.internal.call("file.info", file, success, error);
    },

    /**
     * Get the base64 value for a files contents.
     *
     * @param {{uri: string, name: string}} file
     * @param {function(string)=} success
     * @param {function({message: string}=} error
     */
    "base64": function (file, success, error) {
        forge.internal.call("file.base64", file, success, error);
    },

    /**
     * Get the string value for a files contents.
     *
     * @param {{uri: string, name: string}} file
     * @param {function(string)=} success
     * @param {function({message: string}=} error
     */
    "string": function (file, success, error) {
        forge.internal.call("file.string", file, success, error);
    },

    /**
     * Get the URL an image which is no bigger than the given height and width.
     *
     * URL must be useable in the current scope of the code, may return a base64 data: URI.
     *
     * @param {{uri: string, name: string}} file
     * @param {Object} props
     * @param {function(string)=} success
     * @param {function({message: string}=} error
     */
    "URL": function (file, props, success, error) {
        if (typeof props === "function") {
            error = success;
            success = props;
        }
        // Avoid mutating original file
        var newFile = {};
        for (var prop in file) {
            newFile[prop] = file[prop];
        }
        newFile.height = props.height || file.height || undefined;
        newFile.width = props.width || file.width || undefined;
        if (forge.flags.android_disable_httpd === true || forge.flags.ios_disable_httpd === true) {
            forge.internal.call("file.URL", newFile, success, error);
        } else {
            forge.internal.call("file.URL", newFile, function (url) {
                success(forge.httpd.normalize(url));
            }, error);
        }
    },

    /**
     * Check a file object represents a file which exists.
{'fraction_non_alphanumeric': 0.14132441162898016, 'fraction_numerical': 0.0018458698661744347, 'mean_word_length': 1.7892535392535394, 'pattern_counts': {'":': 14, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1752965', 'n_tokens_mistral': 2453, 'n_tokens_neox': 2382, 'n_words': 707}