<commit_before>package CoGe::Services::Data::IRODS;
use Mojo::Base 'Mojolicious::Controller';
use Mojo::JSON;
use CoGeX;
use CoGe::Accessory::IRODS;
use CoGe::Accessory::Utils qw(get_unique_id);
use CoGe::Core::Storage qw(get_irods_path get_irods_file);
use CoGe::Services::Auth;
use Data::Dumper;

sub list {
    my $self = shift;
    my $path = $self->stash('path');
    #print STDERR "IRODS::list ", $path, "\n";

    # Authenticate user and connect to the database
    my ($db, $user, $conf) = CoGe::Services::Auth::init($self);
    unless ($user) {
        $self->render(json => { error => { Error => 'Access denied' } });
        return;
    }

    # Fetch directory listing
    #my $result = CoGe::Accessory::IRODS::irods_ils($path);
    my $result = get_irods_path($path, $user->name);
    unless ($result) {
        $self->render(json => { error => { IRODS => 'Access denied' } });
        return;
    }
    
    # Setup path
    #TODO set path to home if not specified
    #my $username = $user->name;
    #my $basepath = $conf->{IRODSDIR};
    #$basepath =~ s/\<USER\>/$username/;
    #$path = $basepath unless $path;
    $path = '/' . $path;

    # Fetch directory listing
    my $result = CoGe::Accessory::IRODS::irods_ils($path);
    my $error  = $result->{error};
    if ($error) {
        $self->render(json => { error => { IRODS => $error } });
        return;
    }

    $self->render(json => { path => $path, items => $result->{items} });
}

sub fetch {
    my $self = shift;
    my $path = $self->stash('path');<commit_msg>Restricted irods access to home and shared<commit_after>package CoGe::Services::Data::IRODS;
use Mojo::Base 'Mojolicious::Controller';
use Mojo::JSON;
use CoGeX;
use CoGe::Accessory::IRODS;
use CoGe::Accessory::Utils qw(get_unique_id);
use CoGe::Core::Storage qw(get_irods_path get_irods_file);
use CoGe::Services::Auth;
use Data::Dumper;

sub list {
    my $self = shift;
    my $path = $self->stash('path');
    #print STDERR "IRODS::list ", $path, "\n";

    # Authenticate user and connect to the database
    my ($db, $user, $conf) = CoGe::Services::Auth::init($self);
    unless ($user) {
        $self->render(json => { error => { Error => 'Access denied' } });
        return;
    }

    # Setup path
    #TODO set path to home if not specified
    #my $username = $user->name;
    #my $basepath = $conf->{IRODSDIR};
    #$basepath =~ s/\<USER\>/$username/;
    #$path = $basepath unless $path;
    $path = '/' . $path;

    # Fetch directory listing
    #my $result = CoGe::Accessory::IRODS::irods_ils($path);
    my $result = get_irods_path($path, $user->name);
    unless ($result) {
        $self->render(json => { error => { IRODS => 'Access denied' } });
        return;
    }
    
    my $error  = $result->{error};
    if ($error) {
        $self->render(json => { error => { IRODS => $error } });
        return;
    }

    $self->render(json => { path => $path, items => $result->{items} });
}

sub fetch {
    my $self = shift;
    my $path = $self->stash('path');
{'fraction_non_alphanumeric': 0.18737607402511566, 'fraction_numerical': 0.0, 'mean_word_length': 3.1636863823933976, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, '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': '6881367', 'n_tokens_mistral': 1077, 'n_tokens_neox': 1065, 'n_words': 251}