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

Update Leap in CI to 15.6 #474

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion assets/assetpack.def
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@
< https://code.jquery.com/jquery-3.3.1.js
< https://cdn.datatables.net/1.10.16/js/jquery.dataTables.js
< https://cdn.datatables.net/1.10.16/js/dataTables.bootstrap4.js
< http://timeago.yarp.com/jquery.timeago.js
< https://timeago.yarp.com/jquery.timeago.js
< https://cdn.jsdelivr.net/npm/dayjs@1/dayjs.min.js
< https://cdn.jsdelivr.net/npm/dayjs@1/plugin/relativeTime.js
< javascripts/mirrorcache.js
< javascripts/browse.js
< javascripts/mirrorlist.js
Expand Down
53 changes: 53 additions & 0 deletions assets/javascripts/mirrorcache.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,56 @@ function deleteAndRedirect(btn, redir) {
error: handleAjaxError,
});
}

function sendPost(url, path) {
$.ajax({
url: url,
method: 'POST',
data: { path: path },
dataType: 'json',
success: function(data) {
id = data.job_id;
if (id) {
location.href = '/minion/jobs?id='.concat(id);
}
},
error: handleAjaxError,
});
}

function fromNow(date) {
const SECOND = 1000;
const MINUTE = 60 * SECOND;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const WEEK = 7 * DAY;
const YEAR = 365 * DAY;
const MONTH = YEAR / 12;
const units = [
{ max: 30 * SECOND, divisor: 1, past1: 'just now', pastN: 'just now', future1: 'just now', futureN: 'just now' },
{ max: MINUTE, divisor: SECOND, past1: 'a second ago', pastN: '# seconds ago', future1: 'in a second', futureN: 'in # seconds' },
{ max: HOUR, divisor: MINUTE, past1: 'a minute ago', pastN: '# minutes ago', future1: 'in a minute', futureN: 'in # minutes' },
{ max: DAY, divisor: HOUR, past1: 'an hour ago', pastN: '# hours ago', future1: 'in an hour', futureN: 'in # hours' },
{ max: WEEK, divisor: DAY, past1: 'yesterday', pastN: '# days ago', future1: 'tomorrow', futureN: 'in # days' },
{ max: 4 * WEEK, divisor: WEEK, past1: 'last week', pastN: '# weeks ago', future1: 'in a week', futureN: 'in # weeks' },
{ max: YEAR, divisor: MONTH, past1: 'last month', pastN: '# months ago', future1: 'in a month', futureN: 'in # months' },
{ max: 100 * YEAR, divisor: YEAR, past1: 'last year', pastN: '# years ago', future1: 'in a year', futureN: 'in # years' },
{ max: 1000 * YEAR, divisor: 100 * YEAR, past1: 'last century', pastN: '# centuries ago', future1: 'in a century', futureN: 'in # centuries' },
{ max: Infinity, divisor: 1000 * YEAR, past1: 'last millennium', pastN: '# millennia ago', future1: 'in a millennium', futureN: 'in # millennia' },
];
// ensure date is an object to safely use its functions
date = (typeof date === 'object' ? date : new Date(date));
// convert from utc time like this
date = new Date(date.getTime() - date.getTimezoneOffset()*60*1000);

const diff = Date.now() - date.getTime();
const diffAbs = Math.abs(diff);
for (const unit of units) {
if (diffAbs < unit.max) {
const isFuture = diff < 0;
const x = Math.round(Math.abs(diff) / unit.divisor);
if (x <= 1) return isFuture ? unit.future1 : unit.past1;
return (isFuture ? unit.futureN : unit.pastN).replace('#', x);
}
}
};
9 changes: 6 additions & 3 deletions assets/javascripts/reportdownloadtable.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ function setupReportDownloadTable(column) {
columns.push({
data: 'dt',
defaultContent: "",
render: function (data) {
var date = new Date(data);
return date.toLocaleDateString();
render: function (data, type, row, meta) {
if(type === 'display') {
var date = new Date(data);
return date.toLocaleDateString();
}
return data;
}
});
columns.push({
Expand Down
5 changes: 3 additions & 2 deletions dist/rpm/MirrorCache-tmpfilesd.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Type Path Mode UID GID Age Argument
d /var/lib/mirrorcache 0750 mirrorcache mirrorcache - -
d /run/mirrorcache 0750 mirrorcache mirrorcache - -
d! /var/lib/mirrorcache 0750 mirrorcache mirrorcache - -
d! /run/mirrorcache 0750 mirrorcache mirrorcache - -
r /tmp/mojo.tmp.* - mirrorcache mirrorcache 8h
1 change: 1 addition & 0 deletions dist/systemd/mirrorcache-subtree.service
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Group=mirrorcache
EnvironmentFile=-/etc/mirrorcache/conf.env
EnvironmentFile=/etc/mirrorcache/conf-subtree.env
ExecStart=/usr/share/mirrorcache/script/mirrorcache-daemon
WorkingDirectory=/var/lib/mirrorcache

[Install]
WantedBy=multi-user.target
23 changes: 23 additions & 0 deletions lib/Directory/Scanner/OBSMediaVersion.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package Directory::Scanner::OBSMediaVersion;

use Mojo::Base -base, -signatures;
use Mojo::File;

sub parse_version($filename) {
return undef unless $filename;
my $f = Mojo::File->new($filename);
$f = $f->basename;

if ($filename =~ /.*(Build|Snapshot)((\d)+(\.\d+)?).*/) {
return $2
}

if ($filename =~ /.*-(\d+\.?\d*\.?\d*\.?\d*)-(\d*\.?\d*)?.*(\.d?rpm)?$/) {
return $1;
}

return undef unless $filename =~ /.*_(\d+\.?\d*\.?\d*\.?\d*)-(\d*\.?\d*)?.*(\.deb)?$/;
return $1
}

1;
5 changes: 3 additions & 2 deletions lib/MirrorCache/Config.pm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2022,2023 SUSE LLC
# Copyright (C) 2022-2024 SUSE LLC
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -33,6 +33,7 @@ has dbdb => $ENV{MIRRORCACHE_DB} // 'mirrorcache';
has dsn => $ENV{MIRRORCACHE_DSN};
has redirect => $ENV{MIRRORCACHE_REDIRECT};
has redirect_vpn => $ENV{MIRRORCACHE_REDIRECT_VPN};
has vpn_prefix => $ENV{MIRRORCACHE_VPN_PREFIX};

has 'offline_redirect'; # list of url to fallback if there was an error while serving from DB
has 'offline_redirect_https'; # the same as above, just with https
Expand Down Expand Up @@ -64,7 +65,7 @@ sub init($self, $cfgfile) {
my $cfg;
$cfg = Config::IniFiles->new(-file => $cfgfile, -fallback => 'default') if $cfgfile;
if ($cfg) {
for my $k (qw/root root_nfs redirect redirect_huge huge_file_size small_file_size city_mmdb ip2location top_folders regions mirror_provider browser_agent_mask custom_footer_message country_image_dir/) {
for my $k (qw/root root_nfs redirect redirect_huge huge_file_size small_file_size city_mmdb ip2location top_folders regions mirror_provider browser_agent_mask custom_footer_message country_image_dir vpn_prefix/) {
if (my $v = $cfg->val('default', $k)) {
$self->$k($v);
}
Expand Down
134 changes: 79 additions & 55 deletions lib/MirrorCache/Datamodule.pm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2021,2022 SUSE LLC
# Copyright (C) 2021-2024 SUSE LLC
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -23,6 +23,8 @@ use Digest::SHA qw(sha1_hex);
use Mojolicious::Types;
use MirrorCache::Utils 'region_for_country';

use Directory::Scanner::OBSMediaVersion;

my $MCDEBUG = $ENV{MCDEBUG_DATAMODULE} // $ENV{MCDEBUG_ALL} // 0;

has c => undef, weak => 1;
Expand All @@ -31,6 +33,7 @@ my @ROUTES = ( '/browse', '/download' );
has [ '_route', '_route_len' ]; # this is '/download' or '/browse'
has [ 'route', 'route_len' ]; # this may be '/download' or '/browse' or empty if one of TOP_FOLDERS present
has [ 'metalink', 'meta4', 'zsync', 'accept_all', 'accept_metalink', 'accept_meta4', 'accept_zsync' ];
has 'xtra';
has metalink_limit => 10; # maximum mirrors to search for metalink
has [ '_ip', '_country', '_region', '_lat', '_lng', '_vpn' ];
has [ '_avoid_countries' ];
Expand All @@ -48,7 +51,9 @@ has [ '_is_secure', '_is_ipv4', '_ipvstrict', '_is_head' ];
has 'mirrorlist';
has [ 'torrent', 'magnet', 'btih' ];
has [ 'json', 'jsontable' ];
has [ 'folder_id', 'file_id', 'file_age', 'folder_sync_last', 'folder_scan_last' ]; # shortcut to requested folder and file, if known
has [ 'folder_id', 'file_id', 'file_age', 'folder_sync_last', 'folder_scan_last', 'folder_sync_requested' ]; # shortcut to requested folder and file, if known
has [ 'file_size', 'file_mtime' ];
has [ 'media_version' ];
has [ 'real_folder_id' ];

has root_country => ($ENV{MIRRORCACHE_ROOT_COUNTRY} ? lc($ENV{MIRRORCACHE_ROOT_COUNTRY}) : "");
Expand All @@ -71,6 +76,11 @@ sub elapsed($self) {
}

sub app($self, $app) {
eval {
if (my $prefix = $app->mcconfig->vpn_prefix) {
$self->vpn_prefix($prefix);
}
};
$self->_root_region(region_for_country($self->root_country) || '');
}

Expand All @@ -96,6 +106,12 @@ sub reset($self, $c, $top_folder = undef) {
$self->torrent(undef);
$self->magnet(undef);
$self->btih(undef);
$self->xtra(undef);
$self->file_id(undef);
$self->file_size(undef);
$self->file_mtime(undef);
$self->file_age(undef);
$self->media_version(undef);
}

sub ip_sha1($self) {
Expand All @@ -113,12 +129,16 @@ sub vpn($self) {
return $self->_vpn_var if defined $self->_vpn_var;

unless (defined $self->_vpn) {
my $ip = $self->ip;
$ip =~ s/^::ffff://;
if ($self->vpn_prefix && (rindex($ip, $self->vpn_prefix, 0) == 0)) {
$self->_vpn(1);
} else {
unless ($self->vpn_prefix) {
$self->_vpn(0);
} else {
my $ip = $self->ip;
$ip =~ s/^::ffff://;
my $match = 0;
for my $pref (split /[\s]+/, $self->vpn_prefix) {
$match = 1 if (rindex($ip, $pref, 0) == 0);
}
$self->_vpn($match);
}
}
return $self->_vpn;
Expand Down Expand Up @@ -339,6 +359,9 @@ sub redirect($self, $url, $skip_xtra = undef) {
$xtra = substr($xtra, 1);
$param->append($xtra => 1);
}
if (my $version = Directory::Scanner::OBSMediaVersion::parse_version($url)) {
$c->res->headers->add('X-MEDIA-VERSION' => $version);
}
return $c->redirect_to($url) unless $param->to_hash;
return $c->redirect_to($url . '?' . $param->to_string);
}
Expand Down Expand Up @@ -389,14 +412,17 @@ sub _init_headers($self) {
$self->c->log->error($self->c->dumper("DATAMODULE HEADERS ACCEPT", $headers->accept)) if $MCDEBUG;
return unless $headers->accept;

$self->metalink(1) if $headers->accept =~ m/\bapplication\/metalink/i;
$self->meta4(1) if $headers->accept =~ m/\bapplication\/metalink4/i;
$self->zsync(1) if $headers->accept =~ m/\bapplication\/x-zsync/i;

$self->accept_metalink(1) if $headers->accept =~ m/\bapplication\/metalink/i;
$self->accept_meta4(1) if $headers->accept =~ m/\bapplication\/metalink4/i;
$self->accept_zsync(1) if $headers->accept =~ m/\bapplication\/x-zsync/i;

for my $xtra (qw(metalink meta4 zsync)) {
my $x = $xtra;
$x = 'x-zsync' if $x eq 'zsync';
$x = 'metalink4' if $x eq 'meta4';
if ($headers->accept =~ m/\bapplication\/$x/i) {
my $method = "accept_$xtra";
$self->$method(1);
$self->$xtra(1);
$self->xtra($xtra);
}
}
$self->accept_all(1) if scalar($headers->accept =~ m/\*\/\*/) && scalar($headers->accept ne '*/*');
}

Expand Down Expand Up @@ -557,48 +583,19 @@ sub _init_path($self) {
push @c_new, $component;
}
$path = '/'.join('/', reverse @c_new);
if(!$trailing_slash && ((my $pos = length($path)-length('.metalink')) > 1)) {
if ('.metalink' eq substr($path,$pos)) {
$self->metalink(1);
$path = substr($path,0,$pos);
}
}
if(!$trailing_slash && ((my $pos = length($path)-length('.meta4')) > 1)) {
if ('.meta4' eq substr($path,$pos)) {
$self->meta4(1);
$path = substr($path,0,$pos);
}
}
if (!$trailing_slash && ((my $pos = length($path) - length('.mirrorlist')) > 1)) {
if ('.mirrorlist' eq substr($path, $pos)) {
$self->mirrorlist(1);
$path = substr($path, 0, $pos);
}
}
if (!$trailing_slash && ((my $pos = length($path) - length('.zsync')) > 1)) {
if ('.zsync' eq substr($path, $pos)) {
$self->zsync(1);
$path = substr($path, 0, $pos);
}
}
if (!$trailing_slash && ((my $pos = length($path) - length('.torrent')) > 1)) {
if ('.torrent' eq substr($path, $pos)) {
$self->torrent(1);
$path = substr($path, 0, $pos);
}
}
if (!$trailing_slash && ((my $pos = length($path) - length('.magnet')) > 1)) {
if ('.magnet' eq substr($path, $pos)) {
$self->magnet(1);
$path = substr($path, 0, $pos);
}
}
if (!$trailing_slash && ((my $pos = length($path) - length('.btih')) > 1)) {
if ('.btih' eq substr($path, $pos)) {
$self->btih(1);
$path = substr($path, 0, $pos);
unless ($trailing_slash || $self->extra) {
my @ext = qw(metalink meta4 mirrorlist zsync torrent magnet btih);
for my $ext (@ext) {
if((my $pos = length($path)-length(".$ext")) > 1) {
if (".$ext" eq substr($path,$pos)) {
$self->$ext(1);
$path = substr($path,0,$pos);
last;
}
}
}
}

$pedantic = $ENV{'MIRRORCACHE_PEDANTIC'} unless defined $pedantic;
if (!defined $pedantic) {
if ( $path =~ m/.*\/([^\/]*-Current[^\/]*)$/ ) {
Expand Down Expand Up @@ -639,6 +636,7 @@ sub root_is_hit($self) {
sub root_is_better($self, $region, $lng) {
if ($self->_root_region && $region && $self->lng && $self->_root_longitude && $region eq $self->_root_region) {
# simly check if root is closer to the client by longitude
return 1 unless defined $lng;
return 1 if abs( $self->_root_longitude - $self->lng ) < abs( $lng - $self->lng );
}
return 0;
Expand All @@ -662,4 +660,30 @@ sub scan_last_ago($self) {
return time() - $scan_last->epoch;
}

sub set_file_stats($self, $id, $size, $mtime, $age, $name) {
$self->file_id($id);
$self->file_size($size);
$self->file_mtime($mtime);
$self->file_age($age);

return unless $name;
if (my $version = Directory::Scanner::OBSMediaVersion::parse_version($name)) {
$self->media_version($version);
}
}

sub etag($self) {
my $size = sprintf('%X', $self->file_size // 0);
my $mtime = sprintf('%X', $self->file_mtime // 0);
my $res = "$mtime-$size";
my $xtra;
if ($self->_original_path =~ m/\.(metalink|meta4|zsync|mirrorlist|torrent|magnet|btih)$/) {
$xtra = $1;
} else {
$xtra = $self->xtra;
}
$res = "$res-$xtra" if $xtra;
return $res;
}

1;
17 changes: 16 additions & 1 deletion lib/MirrorCache/Schema/ResultSet/Project.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,22 @@ use strict;
use warnings;

use base 'DBIx::Class::ResultSet';
use Mojo::File qw(path);

sub mark_scheduled {
my ($self, $project_id) = @_;

my $rsource = $self->result_source;
my $schema = $rsource->schema;
my $dbh = $schema->storage->dbh;

my $sql = << "END_SQL";
update project
set db_sync_last = CURRENT_TIMESTAMP(3)
where id = ?
END_SQL
my $prep = $dbh->prepare($sql);
$prep->execute($project_id);
}


1;
Loading
Loading