<commit_before>'use strict';

var BaseController = require('./Base'),
    portfolioService = new (require('../service/PortfolioService'))(),
    sessionService = new (require('../service/SessionService'))(),
    path = require('path'),
    fs = require('fs'),
    _ = require('underscore'),
    ejs = require('ejs');

function PortfolioController() {
    if (!(this instanceof PortfolioController)) {
        return new PortfolioController();
    }
}

PortfolioController.prototype = new BaseController('PortfolioController');

PortfolioController.prototype.getUserPortfolio = function (req, res, next) {
    var params = {};
    var content = {};
    var isOwner = false;
    var filePath;
    var addedScript, portfolioFile;

    params.userName = req.params.name;

    if (sessionService.hasSession(req) && sessionService.hasUserAuthorityByName(req, params.userName)) {
        isOwner = true;
    }

    portfolioService.getUserPortfolioData(params, function (err, result) {
        if (err) {
            res.render('404.ejs', err);
            return;
        }

        if (!result || result.length === 0) {
            res.redirect('/');
            return;
        }

        content.isOwner = isOwner;  // isOwner: 유저 자신의 페이지인지 확인
        content.portfolioId = result[0].PORTFOLIO_ID;   // portfolioId: 포트폴리오 ID 설정

        portfolioFile = result[0].PORTFOLIO_ID + '.ejs';
        filePath = path.join(__dirname, '../views/portfolio/', portfolioFile);
        fs.readFile(filePath, 'utf-8', function (err, portfolioData) {
            if (err) {
               res.render('404.ejs', err);
               return;
            }
            addedScript = "<script>var g_isOwner = '<%= isOwner %>'</script>";
            portfolioData = addedScript + portfolioData;
            res.end(ejs.render(portfolioData, content));
        });
    });
};

PortfolioController.prototype.makeUserPortfolio = function (req, res) {
    var params = {};<commit_msg>Update Portfolio.js<commit_after>'use strict';

var BaseController = require('./Base'),
    portfolioService = new (require('../service/PortfolioService'))(),
    sessionService = new (require('../service/SessionService'))(),
    path = require('path'),
    fs = require('fs'),
    _ = require('underscore'),
    ejs = require('ejs');

function PortfolioController() {
    if (!(this instanceof PortfolioController)) {
        return new PortfolioController();
    }
}

PortfolioController.prototype = new BaseController('PortfolioController');

PortfolioController.prototype.getUserPortfolio = function (req, res, next) {
    var params = {};
    var content = {};
    var isOwner = false;
    var filePath;
    var addedScript, portfolioFile;

    params.userName = req.params.name;

    if (sessionService.hasSession(req) && sessionService.hasUserAuthorityByName(req, params.userName)) {
        isOwner = true;
    }

    portfolioService.getUserPortfolioData(params, function (err, result) {
        if (err) {
            res.render('404.ejs', err);
            return;
        }

        if (!result || result.length === 0) {
            res.redirect('/');
            return;
        }
    
        portfolioFile = result[0].PORTFOLIO_ID + '.ejs';
        filePath = path.join(__dirname, '../views/portfolio/', portfolioFile);
        
        content.isOwner = isOwner;  // isOwner: 유저 자신의 페이지인지 확인
        content.portfolioId = result[0].PORTFOLIO_ID;   // portfolioId: 포트폴리오 ID 설정
        content.filename = filePath;
        
        fs.readFile(filePath, 'utf-8', function (err, portfolioData) {
            if (err) {
               res.render('404.ejs', err);
               return;
            }
            addedScript = "<script>var g_isOwner = '<%= isOwner %>'</script>";
            portfolioData = addedScript + portfolioData;
            res.end(ejs.render(portfolioData, content));
        });
    });
};

PortfolioController.prototype.makeUserPortfolio = function (req, res) {
    var params = {};
{'fraction_non_alphanumeric': 0.14027149321266968, 'fraction_numerical': 0.005027652086475616, 'mean_word_length': 2.5526785714285714, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '1340871', 'n_tokens_mistral': 1172, 'n_tokens_neox': 1185, 'n_words': 235}