]> lifelog.hopto.org Git - LifeLog.git/commitdiff
Implemented compression for service.
authorWill Budic <redacted>
Wed, 6 Dec 2023 21:09:14 +0000 (08:09 +1100)
committerWill Budic <redacted>
Wed, 6 Dec 2023 21:09:14 +0000 (08:09 +1100)
htdocs/cgi-bin/CNFServices.cgi
htdocs/cgi-bin/rss_feeds_setup.cnf [new file with mode: 0644]
htdocs/cgi-bin/system/modules/CNFParser.pm
htdocs/cgi-bin/system/modules/RSSFeedsPlugin.pm
htdocs/cgi-bin/wsrc/feeds.js

index 4b719784b78669cfef7b31d2548c1200b1cba797..351392722773f762e3d21887b6301e16eeac7189 100755 (executable)
@@ -17,6 +17,7 @@ use feature qw(signatures);
 # system requirments or/and unexpected perl compiler errors.
 ##
 use CGI::Carp qw(fatalsToBrowser set_message);
+use Gzip::Faster;
 
 use lib "system/modules";
 #use lib::relative "system/modules";
@@ -25,11 +26,16 @@ require CNFNode;
 
 our $GLOB_HTML_SERVE = "'{}/*.cgi' '{}/*.htm' '{}/*.html' '{}/*.md' '{}/*.txt'";
 our $script_path = $0; $script_path =~ s/\w+.cgi$//;
+
+use constant VERSION => '1.1';
+
+
 use constant LOG_Settings => q(
 <<@<%LOG>
     file      = web_server.log
-    # Should it mirror to console too?
-    console   = 1
+    # Should it mirror to console too, in productation this must be zero,
+    # otherwise it will not output client.
+    console   = 0
     # Disable/enable output to file at all?
     enabled   = 1
     # Tail size cut, set to 0 if no tail cutting is desired.
@@ -51,6 +57,7 @@ cgi {
         }
      );
 
+
     #  my $p = $cgi->_body_params->{keyed};
     #  $p->{'service'} = ['contacts'];
     #  $p->{'action'} = ['form'];
@@ -60,6 +67,7 @@ cgi {
     #   $p->{'service'} = ['feeds'];
     #   $p->{'action'} = ['read'];
     #   $p->{'feed'} = ['Life Hacker'];
+    #   $p->{'setup'} = ['htdocs/cgi-bin/rss_feeds_setup.cnf'];
 
 
     ##
@@ -70,12 +78,22 @@ cgi {
 
 
 sub CNFHTMLService($cgi) {
-    my  $cnf = CNFParser -> new (undef,{ DO_ENABLED => 1, HAS_EXTENSIONS=>1, ANONS_ARE_PUBLIC => 1, CGI=>$cgi });
+
+    my  $setup = $cgi->param('setup');
+    my  $cnf   = CNFParser -> new ($setup,{ DO_ENABLED => 1, HAS_EXTENSIONS=>1, ANONS_ARE_PUBLIC => 1, CGI=>$cgi });
         $cnf -> parse(undef,_getServiceScript($cgi));
     my  $ptr = $cnf->data();
         $ptr = $ptr->{'PAGE'};
-    #say $$ptr if $ptr;
-    $cgi -> render(text=>$$ptr);
+        $cgi-> add_response_header('Expires', '1s');
+        $cgi-> add_response_header('Cache-Control', 'no-cache');
+
+        if( $ENV{'HTTP_ACCEPT_ENCODING'} =~ m/gzip/ ){
+            $cgi-> add_response_header('Content-Encoding', 'gzip');
+            $cgi-> add_response_header('Accept-Encoding','Vary');
+            $cgi-> render(data=>gzip($$ptr));
+        }else{
+            $cgi-> render(text=>$$ptr);
+        }
     return 0
 }
 
@@ -149,10 +167,12 @@ of the Perl programming language through open discussion, collaboration, design,
 The Perl Weekly ( http://perlweekly.com/ ) is a newsletter including links to blog posts and other news items
  related to the Perl programming language.~
 #`The Cipher Brief RSS Feed`https://www.thecipherbrief.com/feed` `The Cipher Brief is the go-to digital platform for the latest security news and high-level analysis. Each day, we offer multiple expert perspectives, engaging the private sector to find solutions and foster dialogue on what events mean for businesses and organizations around the world. More than just reporting on the news, The Cipher Brief helps readers understand what the news means to you.~
+
 #`Viral Now`https://viralnow.uk/feed/`3 business days`ViralNow is a dynamic online platform at the forefront of curating and delivering trending and viral content. ViralNow brings you the latest and most engaging stories, videos, and articles from around the world.~
 
 #`The Sydney Morning Herald - World RSS Feed`http://www.smh.com.au/rssheadlines/world/article/rss.xml`1 business days`
 The Sydney Morning Herald is Australia's leading news source. The Sydney Morning Herald sets the standard for journalistic excellence for Sydney, Australia, and the rest of the world. From breaking news, to travel and fashion, The Sydney Morning Herald continues to transform the way Australians get their news.~
+
 #`Life Hacker`https://lifehacker.com/feed/rss`3 business days`Lifehacker's is an award-winning daily blog that features tips, shortcuts, and downloads that help you work and live smarter and more efficiently.`~
 
 #`Politico`http://www.politico.com/rss/politicopicks.xml`3 business days`POLITICO strives to be the dominant source for news on politics and policy in power centers across every continent where access to reliable information, nonpartisan journ.lism and real-time tools create, inform and engage a global citizenry.~
diff --git a/htdocs/cgi-bin/rss_feeds_setup.cnf b/htdocs/cgi-bin/rss_feeds_setup.cnf
new file mode 100644 (file)
index 0000000..4d702d1
--- /dev/null
@@ -0,0 +1,14 @@
+!CNF3.0
+<<    RSS_FEEDS     <DATA> __CONST____
+
+ID`Name`URL`Expires`Description~
+
+#`The Sydney Morning Herald - World RSS Feed`http://www.smh.com.au/rssheadlines/world/article/rss.xml`
+    1 business days`
+The Sydney Morning Herald is Australia's leading news source. The Sydney Morning Herald sets the standard for journalistic excellence for Sydney, Australia, and the rest of the world. From breaking news, to travel and fashion, The Sydney Morning Herald continues to transform the way Australians get their news.~
+
+#`Life Hacker`https://lifehacker.com/feed/rss`
+    13 business days`
+Lifehacker's is an award-winning daily blog that features tips, shortcuts, and downloads that help you work and live smarter and more efficiently.`~
+
+>>
\ No newline at end of file
index 61c7c0fb24e276cb0813aee8b27142dc86f775af..7e47b96e37c24775eda21fdf7bea4f9b11962eb8 100644 (file)
@@ -619,6 +619,7 @@ sub loadDataFile {  my ($self,$e,$path,$v,$i)=@_;
 sub doDataInstruction_{ my ($self,$e,$v,$t,$d)=@_;
         my $add_as_SQLTable = $v =~ s/${meta('SQL_TABLE')}/""/sexi;
         my $isPostgreSQL    = $v =~ s/${meta('SQL_PostgreSQL')}/""/sexi;
+        my $isConstant      = $v =~ s/$meta_const//se;
         my $isHeader        = 0;
         $v=~ s/^\s*//gm;
         foreach my $row(split(/~\s/,$v)){
@@ -664,11 +665,17 @@ sub doDataInstruction_{ my ($self,$e,$v,$t,$d)=@_;
 
             my $existing = $self->{'__DATA__'}{$e};
             if(defined $existing){
+                if($isConstant){
+                    return; #Not allowed META const protected to overwrite.
+                }
                 if($isHeader){$isHeader=0;next}
                 my @rows = @$existing;
                 push @rows, [@a] if scalar @a >0;
                 $self->{'__DATA__'}{$e} = \@rows
             }else{
+                if($isConstant){
+                   $isConstant = 0; #These are constant to be made brand new entries.
+                }
                 my @rows; push @rows, [@a];
                 $self->{'__DATA__'}{$e} = \@rows if scalar @a >0;
             }
@@ -1345,8 +1352,8 @@ sub log {
                                 my $fh = File::ReadBackwards->new($logfile) or die $!;
                                 my @buffer; $buffer[@buffer] = $fh->readline() for (1..$tail_cnt);
                                    open (my $fhTemp, ">", "/tmp/$logfile") or die $!;
-                                    print $fhTemp $_ foreach (reverse @buffer);
-                                    close $fhTemp;
+                                   foreach my $ln(reverse @buffer){ print $fhTemp $ln if $ln}
+                                   close $fhTemp;
                                    move("/tmp/$logfile",$logfile)
                                 }
                            }
index 3911c4a673a9be275244aa69dfe59b8534f0a795..1a223df80afe61ba8c49ee11d450ede0322de328 100644 (file)
@@ -16,7 +16,7 @@ use LWP::Simple;
 
 use Benchmark;
 
-use constant VERSION => '1.0';
+use constant VERSION => '1.1';
 
 # require CNFNode;
 # require CNFDateTime;
@@ -49,10 +49,10 @@ sub process ($self, $parser, $property) {
         $data[$idx]=\@col;
     }
     if($cgi&&$cgi->param('action') eq 'list'){
-       my $page = '<div class="feed"><h2>List Of Feeds</h2><ol>';
+       my $page = _css().'<div class="feed"><h2>List Of Feeds</h2><ol>';
        for my $idx (1 .. $#data){
            my @col = @{$data[$idx]};
-           $page .= qq|<li><span style="border: 1px solid black; padding: 5px; padding-bottom: 0px;">
+           $page .= qq|<li><span class="feeds_list_span">
            <a onclick="return fetchFeed('$col[1]')" style="cursor: pointer;"> <b>$col[1]</b> </a></span>
             &nbsp;&nbsp;[ $col[4] ]<dt style="padding:10px;">$col[3]</dt></li>\n|;
        }
@@ -64,6 +64,20 @@ sub process ($self, $parser, $property) {
     $parser->data()->{$property} = \@data
 }
 
+sub _css{
+<<__CSS;
+<style>
+.feeds_list_span{
+    border: 1px solid black; padding: 5px; padding-bottom: 0px;
+}
+.feeds_list_span:hover{
+    border-color:red;
+  background:#94cde7;;
+}
+</style>
+__CSS
+}
+
 sub collectFeeds($self, $parser) {
   my $property = $self->{property};
   my %hdr;
index e3bf89b53a939458e2e774f798f6ee61ef5eb123..2dc1afe238c8637cccbff7c097d0f39c00f2d6d7 100644 (file)
@@ -28,7 +28,7 @@ function fetchFeed(feed) {
     $.post('CNFServices.cgi', {service:'feeds', action:'read', feed:feed}, displayFeeds).fail(
         function(response) {
             pnl.html(response.responseText);
-            pnl.fadeOut(30000);
+            // pnl.fadeOut(30000);
         }
     );
 }