<commit_before>angular.module('materialscommons').directive("displayFileContents", displayFileContentsDirective);
function displayFileContentsDirective() {
    return {
        restrict: "E",
        controller: DisplayFileContentsDirectiveController,
        controllerAs: 'view',
        bindToController: true,
        scope: {
            file: '=file'
        },
        templateUrl: 'app/project/components/display-file-contents.html'
    };
}

/*@ngInject*/
function DisplayFileContentsDirectiveController(mcfile, mcmodal, isImage) {
    const ctrl = this;
    ctrl.fileSrc = mcfile.src(ctrl.file.id);
    ctrl.showImage = showImage;
    ctrl.downloadSrc = downloadSrc;

    let officeTypes = [
        {name: "application/vnd.ms-excel"},
        {name: "application/vnd.ms-powerpoint"},
        {name: "application/msword"},
        {name: "application/vnd.openxmlformats-officedocument.presentationml.presentation"},
        {name: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"},
        {name: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"}
    ];

    let officeTypesMap = _.indexBy(officeTypes, 'name');

    ctrl.fileType = determineFileType(ctrl.file.mediatype);

    //////////////

    function determineFileType(mediatype) {
        if (isImage(mediatype.mime)) {
            return "image";
        }
        if (isOfficeFile(mediatype.mime)) {
            return "office";
        }
        switch (mediatype.mime) {
            case "application/pdf":
                return "pdf";
            case "application/vnd.ms-excel":
                return "office";
            case "":
                return "office";
            case "application/octet-stream":
                return "binary";
            default:
                return mediatype.mime;
        }
    }

    function isOfficeFile(mime) {
        return (mime in officeTypesMap);
    }

    function showImage(file) {
        mcmodal.viewImage(file);
    }

    function downloadSrc() {<commit_msg>Clean up check for file type<commit_after>angular.module('materialscommons').directive("displayFileContents", displayFileContentsDirective);
function displayFileContentsDirective() {
    return {
        restrict: "E",
        controller: DisplayFileContentsDirectiveController,
        controllerAs: 'view',
        bindToController: true,
        scope: {
            file: '=file'
        },
        templateUrl: 'app/project/components/display-file-contents.html'
    };
}

/*@ngInject*/
function DisplayFileContentsDirectiveController(mcfile, mcmodal, isImage) {
    const ctrl = this;
    ctrl.fileSrc = mcfile.src(ctrl.file.id);
    ctrl.showImage = showImage;
    ctrl.downloadSrc = downloadSrc;

    let officeTypes = [
        {name: "application/vnd.ms-excel"},
        {name: "application/vnd.ms-powerpoint"},
        {name: "application/msword"},
        {name: "application/vnd.openxmlformats-officedocument.presentationml.presentation"},
        {name: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"},
        {name: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"}
    ];

    let officeTypesMap = _.indexBy(officeTypes, 'name');

    ctrl.fileType = determineFileType(ctrl.file.mediatype);

    //////////////

    function determineFileType(mediatype) {
        if (isImage(mediatype.mime)) {
            return "image";
        }
        if (isOfficeFile(mediatype.mime)) {
            return "office";
        }
        switch (mediatype.mime) {
            case "application/pdf":
                return "pdf";
            case "application/octet-stream":
                return "binary";
            default:
                return mediatype.mime;
        }
    }

    function isOfficeFile(mime) {
        return (mime in officeTypesMap);
    }

    function showImage(file) {
        mcmodal.viewImage(file);
    }

    function downloadSrc() {
{'fraction_non_alphanumeric': 0.12135799341271852, 'fraction_numerical': 0.0, 'mean_word_length': 2.377245508982036, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7593877', 'n_tokens_mistral': 1143, 'n_tokens_neox': 1075, 'n_words': 184}