browse relocation, system class improvements, safe_delete improvements, auto expire, utf-8, ...

git-svn-id: file:///root/webif/svn/humax/pkg/src/webif/trunk@1420 2a923420-c742-0410-a762-8d5b09965624
This commit is contained in:
hummypkg 2013-02-25 22:31:54 +00:00
parent 39d7dab2a9
commit 22320536ee
70 changed files with 291 additions and 115 deletions

View File

@ -1,9 +1,9 @@
Package: webif
Priority: optional
Section: web
Version: 0.12.0-3
Version: 0.12.1
Architecture: mipsel
Maintainer: af123@hummypkg.org.uk
Depends: webif-channelicons(>=1.0.4-1),mongoose(>=3.0-7),jim(>=0.73-1),jim-oo,jim-sqlite3(>=0.73-1),jim-cgi(>=0.7),jim-binary,service-control(>=1.2),busybox(>=1.20.2-1),lsof,epg(>=1.0.10),hmt(>=1.1.12),ssmtp,anacron,trm(>=1.1),openssl-command,nicesplice,id3v2,file,rsvsync(>=1.0.2),webif-charts(>=1.2),stripts(>=1.1.2),smartmontools,tmenu(>=1.05)
Depends: webif-channelicons(>=1.0.4-1),mongoose(>=3.0-7),jim(>=0.73-1),jim-oo,jim-sqlite3(>=0.73-1),jim-cgi(>=0.7),jim-binary,service-control(>=1.2),busybox(>=1.20.2-1),lsof,epg(>=1.0.10),hmt(>=1.1.13),ssmtp,anacron,trm(>=1.1),openssl-command,nicesplice,id3v2,file,rsvsync(>=1.0.2),webif-charts(>=1.2),stripts(>=1.1.2),smartmontools,tmenu(>=1.05)
Suggests: ffmpeg
Description: An evolving web interface for the Humax.

View File

@ -0,0 +1,24 @@
#!/mod/bin/jimsh
package require cgi
source /mod/webif/lib/setup
httpheader
# dir=%2Fmedia%2FMy+Video%2FWeatherview
# aexpiry_days=13
set dir [cgi_get dir "-"]
set days [cgi_get aexpiry_days 7]
if {$dir eq "-"} exit
if {![file isdirectory $dir]} {
puts "Not a directory."
exit
}
set fd [open "$dir/.autoexpire" w]
puts $fd $days
$fd close
puts "Ok."

View File

@ -68,6 +68,7 @@ if $flatten {
}
puts {
<li class=clock><a href=#expire>Auto-Expire</a></li>
<li class=mpg><a href=#mpg>Auto-MPG Extract</a></li>
</ul>
@ -232,6 +233,32 @@ puts {
</form>
</div>
<div id=aexpiry title="Auto-Expiry" style="display: none">
<form id=aexpiry_form>
<input type=hidden name="dir" id="aexpiry_ldir" value="">
}
puts {
<table border=0>
<tr>
<th>
<label for="aexpiry_days">
<b>Expire after</b>
<span class=blood>(in days)</span>
</label>
</th>
<td>
<input type=text name="aexpiry_days" id="aexpiry_days"
type=number value=0 size=5 maxlength=3
class="text ui-widget-content ui-corner-all">
</td>
</tr>
</table>
<div id=aexpiry_working class=hidden>
<img src=/img/loading.gif> Applying auto-expiry...
</div>
</form>
</div>
<div id=dialogue></div>
<div id=confirm title="Confirmation Required"></div>
<div id=pwdialogue style="display: none">

View File

@ -15,7 +15,7 @@ $(document).ready(function() {
$('#progressbar').reportprogress(0);
$('#back').button().click(function() {
window.location = '/cgi-bin/browse.jim?dir=' + $('#params').attr('dir');
window.location = '../index.jim?dir=' + $('#params').attr('dir');
});
$('#audioit').button().click(function() {

View File

@ -69,7 +69,7 @@ $('#back').button().click(function(e) {
e.preventDefault();
var dir = $(this).attr('dir');
window.location = '/cgi-bin/browse.jim?dir=' + dir;
window.location = '../index.jim?dir=' + dir;
});
});

View File

@ -17,7 +17,7 @@ $(document).ready(function() {
$('#progressbar').reportprogress(0);
$('#back').button().click(function() {
window.location = '/cgi-bin/browse.jim?dir=' + $('#params').attr('dir');
window.location = '../index.jim?dir=' + $('#params').attr('dir');
});
$('#cropit').button().click(function() {

View File

@ -15,7 +15,7 @@ $(document).ready(function() {
$('#progressbar').reportprogress(0);
$('#back').button().click(function() {
window.location = '/cgi-bin/browse.jim?dir=' + $('#params').attr('dir');
window.location = '../index.jim?dir=' + $('#params').attr('dir');
});
$('#decryptit').button().click(function() {

View File

@ -146,7 +146,7 @@ puts "
</table>
"
set url "/cgi-bin/browse/ffmpeg.jim?file=[cgi_quote_url $file]"
set url "/bin/browse/ffmpeg.jim?file=[cgi_quote_url $file]"
puts { <script type="text/javascript"> }
puts "var url = \"$url\";"
puts {

View File

@ -202,8 +202,8 @@ proc entry {file} {{i 0}} {
icon "/img/compress.png" "Shrunk" \
"id=\"sp_$tbfile\"" "va hidden"
# Timeshifted (shown when necessary via Ajax)
icon "/img/clock.png" "Time-shifted Recording" \
"id=\"tsr_$tbfile\"" "va hidden"
# icon "/img/clock.png" "Time-shifted Recording" \
# "id=\"tsr_$tbfile\"" "va hidden"
set bx [$ts get bookmarks]
}
@ -234,11 +234,11 @@ puts {
<link href=/css/jquery.bar.css rel=stylesheet type=text/css />
<script type=text/javascript src=/js/jquery.bar.js></script>
<script type=text/javascript src=/js/enadis.js></script>
<script type=text/javascript src=/cgi-bin/browse/browse.js></script>
<link type=text/css rel=stylesheet href=/cgi-bin/browse/style.css />
<script type=text/javascript src=script.js></script>
<link type=text/css rel=stylesheet href=style.css />
}
source browse/assets.jim
source assets.jim
puts "
<span style=\"display:none\" id=dir>$dir</span>

View File

@ -22,7 +22,7 @@ $(document).ready(function() {
$('#progressbar').reportprogress(0);
$('#back').button().click(function() {
window.location = '/cgi-bin/browse.jim?dir=' + $(this).attr('dir');
window.location = '../index.jim?dir=' + $(this).attr('dir');
});
$('#filelist').sortable().disableSelection();

View File

@ -15,7 +15,7 @@ $(document).ready(function() {
$('#progressbar').reportprogress(0);
$('#back').button().click(function() {
window.location = '/cgi-bin/browse.jim?dir=' + $('#params').attr('dir');
window.location = '../index.jim?dir=' + $('#params').attr('dir');
});
$('#mpgit').button().click(function() {

View File

@ -26,7 +26,7 @@ function reloadclipboard()
$('#clipboard')
.empty()
.html('<img src=/img/loading.gif> <i>Loading...</i>')
.load('/cgi-bin/browse/clipboard.jim', function() {
.load('/browse/clipboard.jim', function() {
// Start Clipboard post-load actions
@ -42,13 +42,13 @@ else
}
$('#clipclear').button().click(function() {
$.get('/cgi-bin/browse/clipboard.jim?act=clear', function() {
$.get('/browse/clipboard.jim?act=clear', function() {
reloadclipboard();
});
});
$('a.clipdel').click(function() {
$.get('/cgi-bin/browse/clipboard.jim?act=remove&path=' +
$.get('/browse/clipboard.jim?act=remove&path=' +
$(this).attr('path'), function() {
reloadclipboard();
});
@ -59,7 +59,7 @@ $('#paste').button()
disableall();
pastedialogue();
$('#pwfeedback').load(
'/cgi-bin/browse/clipboard.jim?act=paste&dir='
'/browse/clipboard.jim?act=paste&dir='
+ encodeURIComponent(dir), function() {
$('#pwdialogue').dialog('close');
window.location.reload(true);
@ -150,7 +150,7 @@ function delete_callback(file, dir, id)
$(results)
.html('<img src=/img/loading.gif>Deleting, please wait...')
.slideDown('slow')
.load('/cgi-bin/browse/delete.jim', {
.load('/browse/delete.jim', {
'dir': dir,
'files': [decodeURIComponent(file)]
}, function() {
@ -162,40 +162,48 @@ function delete_callback(file, dir, id)
function lock_callback(file, type, id)
{
var url = '/cgi-bin/browse/lock.jim?file=' + file;
var url = '/browse/lock.jim?file=' + file;
$.get(url, function() { window.location.reload(true); });
}
function enc_callback(file, type, id)
{
var url = '/cgi-bin/browse/enc.jim?file=' + file;
var url = '/browse/enc.jim?file=' + file;
$.get(url, function() { window.location.reload(true); });
}
function new_callback(file, type, id)
{
var url = '/cgi-bin/browse/new.jim?file=' + file;
var url = '/browse/new.jim?file=' + file;
$.get(url, function() { window.location.reload(true); });
}
function rename_submit()
{
var s = $('#renameform_form').serialize();
$.post('/cgi-bin/browse/rename.jim', s,
$.post('/browse/rename.jim', s,
function() { window.location.reload(true); });
}
function drename_submit()
{
var s = $('#drenameform_form').serialize();
$.get('/cgi-bin/browse/rename.jim?' + s,
$.get('/browse/rename.jim?' + s,
function() { window.location.reload(true); });
}
function aexpiry_submit()
{
$('#aexpiry_working').slideDown('slow');
var s = $('#aexpiry_form').serialize();
$.get('/browse/aexpiry.jim?' + s,
function() { window.location.reload(true); });
}
function newdir_submit()
{
var s = $('#newdirform_form').serialize();
$.get('/cgi-bin/browse/mknewdir.jim?' + s,
$.get('/browse/mknewdir.jim?' + s,
function() { window.location.reload(true); });
}
@ -204,7 +212,7 @@ function savestream_submit()
var s = $('#savestream_form').serialize();
var sf = $('#save_stream').attr('file');
$('#savestream_spin').show();
$.get('/cgi-bin/browse/savestream.jim?sfile=' +
$.get('/browse/savestream.jim?sfile=' +
encodeURIComponent(sf) + '&' + s,
function() {
window.location.reload(true);
@ -249,12 +257,7 @@ function preparemenu(el, menu)
else
$(menu).disableContextMenuItems('#crop');
/*
if (el.attr('def') == 'HD')
$(menu).disableContextMenuItems('#strip');
else
*/
$(menu).enableContextMenuItems('#strip');
$(menu).enableContextMenuItems('#strip');
if (el.attr('rsize') > 4294967296)
$(menu).enableContextMenuItems('#chunk');
@ -355,6 +358,7 @@ function preparedmenu(el, menu)
fixdmenu(el, menu, 'autodedup', '#dedup', 'Auto-dedup', 0);
fixdmenu(el, menu, 'autodecrypt', '#decrypt', 'Auto-decrypt', 1);
fixdmenu(el, menu, 'autompg', '#mpg', 'Auto-mpg', 0);
fixdmenu(el, menu, 'autoexpire', '#expire', 'Auto-expire', 0);
}
$(document).ready(function() {
@ -380,7 +384,7 @@ var menuclick = function(action, el, pos)
break;
// Fallthrough
case 'cut':
$.get('/cgi-bin/browse/clipboard.jim?act=add&mode=' + action +
$.get('/browse/clipboard.jim?act=add&mode=' + action +
'&path=' + file, function() {
reloadclipboard();
});
@ -412,7 +416,7 @@ var menuclick = function(action, el, pos)
if (type == 'ts')
{
$.getJSON('/cgi-bin/browse/epgtitle.jim?file=' +
$.getJSON('/browse/epgtitle.jim?file=' +
file, epginfo_callback);
}
@ -420,38 +424,38 @@ var menuclick = function(action, el, pos)
break;
case 'download':
window.location.href = '/cgi-bin/browse/download.jim?file=' +
window.location.href = '/browse/download.jim?file=' +
file + '&base=' +
encodeURIComponent(document.URL.match(/:\/\/(.[^/]+)/)[1]);
break;
case 'crop':
window.location.href = '/cgi-bin/browse/crop/crop.jim?file=' +
window.location.href = '/browse/crop/crop.jim?file=' +
file;
break;
case 'strip':
window.location.href = '/cgi-bin/browse/strip/strip.jim?file=' +
window.location.href = '/browse/strip/strip.jim?file=' +
file;
break;
case 'chunk':
window.location.href = '/cgi-bin/browse/chunk/chunk.jim?file=' +
window.location.href = '/browse/chunk/chunk.jim?file=' +
file;
break;
case 'decrypt':
window.location.href =
'/cgi-bin/browse/decrypt/decrypt.jim?file=' + file;
'/browse/decrypt/decrypt.jim?file=' + file;
break;
case 'audio':
window.location.href = '/cgi-bin/browse/audio/audio.jim?file=' +
window.location.href = '/browse/audio/audio.jim?file=' +
file;
break;
case 'mpg':
window.location.href = '/cgi-bin/browse/mpg/mpg.jim?file=' +
window.location.href = '/browse/mpg/mpg.jim?file=' +
file;
break;
@ -463,14 +467,14 @@ var menuclick = function(action, el, pos)
function flagdir(file, flag, iconset, output, options)
{
var url = '/cgi-bin/browse/flagdir.jim?dir=' + file +
var url = '/browse/flagdir.jim?dir=' + file +
'&flag=' + flag;
$(output).load(url, function() {
$(iconset)
.empty()
.html('<img src=/img/loading.gif> Updating...')
.load('/cgi-bin/browse/iconset.jim?file=' + file);
.load('/browse/iconset.jim?file=' + file);
if ($(options).attr(flag) == '1')
$(options).attr(flag, 0);
else
@ -492,7 +496,7 @@ var dmenuclick = function(action, el, pos)
case 'paste':
pastedialogue();
$('#pwfeedback').load(
'/cgi-bin/browse/clipboard.jim?act=paste&dir=' +
'/browse/clipboard.jim?act=paste&dir=' +
file, function() {
$('#pwdialogue').dialog('close');
reloadclipboard();
@ -509,7 +513,7 @@ var dmenuclick = function(action, el, pos)
.html('<img src=/img/loading.gif>' +
'Deleting, please wait...')
.slideDown('slow')
.load('/cgi-bin/browse/delete.jim', {
.load('/browse/delete.jim', {
'dir': dir,
'files': [decodeURIComponent(file)]
}, function() {
@ -525,7 +529,7 @@ var dmenuclick = function(action, el, pos)
break;
// Fallthrough
case 'cut':
$.get('/cgi-bin/browse/clipboard.jim?act=add&mode=' + action +
$.get('/browse/clipboard.jim?act=add&mode=' + action +
'&path=' + file, function() {
reloadclipboard();
});
@ -537,6 +541,22 @@ var dmenuclick = function(action, el, pos)
$('#drenameform').dialog('open');
break;
case 'expire':
if ($(el).attr('autoexpire') == 1)
flagdir(file, 'autoexpire', iconset, results, el);
else
{
$('#aexpiry_ldir').val(decodeURIComponent(file));
if ($(el).attr('autoexpiredays') > 0)
$('#aexpiry_days')
.val($(el).attr('autoexpiredays'));
else
$('#aexpiry_days').val(7);
$('#aexpiry_working').hide('fast');
$('#aexpiry').dialog('open');
}
break;
case 'flat':
flagdir(file, 'noflatten', iconset, results, el);
break;
@ -566,7 +586,7 @@ var dmenuclick = function(action, el, pos)
break;
case 'resetnew':
var url = '/cgi-bin/browse/resetnew.jim?dir=' + file;
var url = '/browse/resetnew.jim?dir=' + file;
$.get(url, function() { window.location.reload(true); });
break;
@ -647,7 +667,7 @@ var dmenuclick = function(action, el, pos)
var type = $(this).attr('type');
var opt = $(this).nextAll('a').find('img.opt');
var url = '/cgi-bin/browse/file.jim?file=' + file
var url = '/browse/file.jim?file=' + file
+ '&type=' + type;
$dialog.load(url);
@ -688,6 +708,19 @@ var dmenuclick = function(action, el, pos)
close: function() { $('#drename').val(''); }
});
$('#aexpiry').dialog({
autoOpen: false,
height: 'auto', width: 'auto',
modal: true,
buttons: {
"Update": aexpiry_submit,
"Close": function() {
$(this).dialog('close');
}
},
close: function() { $('#aexpiry_days').val('0'); }
});
$('#savestreamform').dialog({
autoOpen: false,
height: 'auto', width: 'auto',
@ -710,15 +743,15 @@ var dmenuclick = function(action, el, pos)
});
// Load folder sizes
$.getJSON('/cgi-bin/browse/sizes.jim?dir=' + encodeURIComponent(dir),
$.getJSON('/browse/sizes.jim?dir=' + encodeURIComponent(dir),
folder_size_callback);
// Flag shrunk recordings
$.getJSON('/cgi-bin/browse/shrunk.jim?dir=' + encodeURIComponent(dir),
$.getJSON('/browse/shrunk.jim?dir=' + encodeURIComponent(dir),
shrunk_callback);
// Flag folders with unwatched items
$.getJSON('/cgi-bin/browse/newdir.jim?dir=' + encodeURIComponent(dir),
$.getJSON('/browse/newdir.jim?dir=' + encodeURIComponent(dir),
new_folder_callback);
// Load clipboard
@ -738,7 +771,7 @@ var dmenuclick = function(action, el, pos)
$('#savestream_spin').hide();
$('#savestreamform').dialog('open');
$('#savestream_detail').load(
'/cgi-bin/browse/ffmpeg.jim?file=' +
'/browse/ffmpeg.jim?file=' +
encodeURIComponent($('#save_stream').attr('file')));
});
@ -758,7 +791,7 @@ var dmenuclick = function(action, el, pos)
files.push($(this).attr('file'));
});
//console.log("%o", files);
window.location.href = '/cgi-bin/browse/join/join.jim?files=' +
window.location.href = '/browse/join/join.jim?files=' +
files.join();
});
@ -790,7 +823,7 @@ var dmenuclick = function(action, el, pos)
}
});
$('#pwfeedback').load(
'/cgi-bin/browse/delete.jim', {
'/browse/delete.jim', {
'dir': dir,
'files': files
}, function() {
@ -812,7 +845,7 @@ var dmenuclick = function(action, el, pos)
'Copying recordings can take a very long time!'))
return;
$.post('/cgi-bin/browse/clipboard.jim', {
$.post('/browse/clipboard.jim', {
'act': 'add',
'dir': dir,
'mode': action,
@ -857,7 +890,7 @@ var dmenuclick = function(action, el, pos)
function checkstream()
{
$.get('/cgi-bin/streamsize.jim', function(size) {
$.get('/browse/streamsize.jim', function(size) {
//console.log('Stream size: %o', size);
var mb = size / (1024 * 1024);
mb = mb|0;

View File

@ -27,7 +27,7 @@ $('#analysis').load('analyse.jim?file=' + $('#params').attr('file'),
$('#progressbar').reportprogress(0);
$('#back').button().click(function() {
window.location = '/cgi-bin/browse.jim?dir=' + $('#params').attr('dir');
window.location = '../index.jim?dir=' + $('#params').attr('dir');
});
$('#stripit').button().click(function() {

View File

@ -70,5 +70,6 @@
.contextMenu LI.decrypt A { background-image: url(/img/context/decrypt.png); }
.contextMenu LI.decryptr A { background-image: url(/img/context/decryptr.png); }
.contextMenu LI.mpg A { background-image: url(/img/context/mpg.png); }
.contextMenu LI.clock A { background-image: url(/img/context/clock.png); }

View File

@ -73,6 +73,7 @@ foreach dir $dirs {
# Dooooo, it.
$ts settitle $syn
ts renamegroup $file $fn
$ts set_deduped
}
}
}

View File

@ -4,6 +4,12 @@ require system.class
proc dedupprocess {file} {{seen {}}} {
set ts [ts fetch $file 1]
if {[$ts flag "Deduped"]} {
lappend seen [file rootname [file tail $file]]
return [list nothing $ts "" ""]
}
set dir [file dirname $file]
set base [file tail [file rootname $file]]
set syn [dedupnormalise [$ts get synopsis] [$ts get title]]
@ -12,7 +18,7 @@ proc dedupprocess {file} {{seen {}}} {
regsub -all -- {[?]} $fn "" fn
set stat ok
if {[system inuse [file rootname $file]]} {
if {[$ts inuse]} {
set stat inuse
} elseif {$fn in $seen} {
set stat dup
@ -20,6 +26,7 @@ proc dedupprocess {file} {{seen {}}} {
set stat error
} elseif {$base eq $fn} {
set stat nothing
$ts set_deduped
} elseif {[file exists "$dir/$fn.ts"]} {
set stat preserve
}

View File

@ -2,7 +2,7 @@
$(function() {
$('#browse').button().click(function() {
window.location = '/cgi-bin/browse.jim?dir=' +
window.location = '/browse/index.jim?dir=' +
encodeURIComponent($('#dir').text());
});

View File

@ -4,6 +4,7 @@ puts {
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>
}
source /mod/webif/include/model.jim

View File

@ -112,15 +112,15 @@ $(document).delegate('#browsepage', 'pageinit', function() {
//console.log('DIR: %O', dir);
// Load folder sizes
$.getJSON('/cgi-bin/browse/sizes.jim?dir=' + encodeURIComponent(dir),
$.getJSON('/browse/sizes.jim?dir=' + encodeURIComponent(dir),
folder_size_callback);
// Flag folders with unwatched items
$.getJSON('/cgi-bin/browse/newdir.jim?dir=' + encodeURIComponent(dir),
$.getJSON('/browse/newdir.jim?dir=' + encodeURIComponent(dir),
new_folder_callback);
// Flag shrunk recordings
$.getJSON('/cgi-bin/browse/shrunk.jim?dir=' + encodeURIComponent(dir),
$.getJSON('/browse/shrunk.jim?dir=' + encodeURIComponent(dir),
shrunk_callback);
});

View File

@ -38,7 +38,7 @@ if {[[settings] epg_style] eq "grid"} {
puts {<div style="clear: both">}
menuitem "Browse Media Files" "/images/323_1_10_Menu_Video.png" \
/cgi-bin/browse.jim 217 228
/browse/index.jim 217 228
menuitem "Scheduled Events" "/images/321_1_00_Menu_CHList.png" \
/sched/sched.jim 217 228
menuitem "EPG" "/images/328_1_26_Menu_TV_Guide.png" \

View File

@ -38,7 +38,7 @@ puts {
if {[file exists "/mod/bin/ir"]} {
tb "/img/remote.png" "Remote" "/plugin/ir/remote.jim"
}
tb "/images/323_1_10_Menu_Video.png" "Browse" "/cgi-bin/browse.jim"
tb "/images/323_1_10_Menu_Video.png" "Browse" "/browse/index.jim"
tb "/images/321_1_00_Menu_CHList.png" "Schedule" "/sched/sched.jim"
tb "/images/328_1_26_Menu_TV_Guide.png" "EPG" $epglink
tb "/img/spanner.png" "Services" "/services.shtml"

View File

@ -1,7 +1,7 @@
#!/mod/bin/jimsh
source /mod/webif/lib/setup
require lock system.class ts.class tdelete pretty_size
require lock system.class ts.class tdelete pretty_size browse.class safe_delete
set debug 0
@ -95,17 +95,9 @@ if {[system pkginst undelete]} {
log "Dustbin: $dustbin"
proc bindir {file binroot} {
set dir [file dirname $file]
regsub "^[system mediaroot]" $dir $binroot ndir
if {$dir eq $ndir} { set ndir $binroot }
system mkdir_p $ndir
return $ndir
}
proc dedup {dir} {
log "DEDUP: \[$dir]"
loop i 0 2 {
loop i 0 1 {
foreach line [split \
[exec /mod/webif/html/dedup/dedup -yes -auto $dir] "\n"] {
log $line 1
@ -113,9 +105,34 @@ proc dedup {dir} {
}
}
proc do_expire {ts} {
global ax_days
set file [$ts get file]
# Calculate the age of the file in days.
set age $(([clock seconds] - [$ts get start]) / 86400.0)
log " EXPIRE: $file (age = $age)"
if {$age > $ax_days} {
log " EXPIRE: $file ($age > $ax_days)" 1
if {[$ts inuse]} {
log " In use." 1
return
}
if {[safe_delete $file]} {
log " Deleted." 1
}
}
}
proc do_shrink {ts} {
global tmp dustbin tsgroup
if {[$ts flag "Shrunk"]} {
log " Already shrunk."
return
}
set file [file rootname [$ts get file]]
if {[catch {
set perc [exec /mod/bin/stripts -aq $file]
@ -131,6 +148,11 @@ proc do_shrink {ts} {
if {$perc == 0} {
log " Already shrunk."
$ts set_shrunk
return
}
if {[$ts inuse]} {
log " In use." 1
return
}
set size [$ts size]
@ -161,18 +183,8 @@ proc do_shrink {ts} {
file rename $f "${file}_shrunk${ext}"
}
# Move the old recording to the bin if undelete is installed.
if {$dustbin ne ""} {
$ts move [bindir $file "$dustbin/webif_autoshrink"] 1 1
} else {
# Delete otherwise.
if {[$ts delete]} {
log "Successfully deleted $file."
} else {
log "Problem deleting $file, [$ts get error]" 1
return
}
}
# Remove the old recording (-> bin if undelete is installed)
safe_delete [$ts get file] "webif_autoshrink"
# Finally, rename the shrunken recording again.
foreach ext $tsgroup {
@ -181,6 +193,7 @@ proc do_shrink {ts} {
file rename $f "${file}.$ext"
}
}
$ts set_shrunk
log "Done... [endclock $size]" 1
}
@ -208,6 +221,10 @@ proc do_decrypt {ts} {
return
}
if {[$ts inuse]} {
log " In use." 1
return
}
set size [$ts size]
dsc $size
startclock
@ -230,7 +247,7 @@ proc do_decrypt {ts} {
log " Removing/binning old copy."
# Move the old recording to the bin if undelete is installed.
if {$dustbin ne ""} {
set bin [bindir $file "$dustbin/webif_autodecrypt"]
set bin [_del_bindir $file "webif_autodecrypt"]
set tail [file tail $rfile]
file rename "$rfile.encrypted" "$bin/$tail.ts"
foreach ext {nts hmt thm} {
@ -269,6 +286,10 @@ proc do_mpg {ts} {
return
}
if {[$ts inuse]} {
log " In use." 1
return
}
dsc [$ts size]
log " MPG: $file" 1
@ -295,11 +316,6 @@ proc entries {dir callback} {
if {![string match {*.ts} $entry} continue
if {[catch {set ts [ts fetch "$dir/$entry"]}]} continue
if {$ts == 0} continue
if {[system inuse [file rootname "$dir/$entry"]]} {
log "$entry - in use\n" 1
continue
}
#dsc [file size "$dir/$entry"]
$callback $ts
}
}
@ -319,6 +335,14 @@ proc mpg {dir} {
entries $dir do_mpg
}
proc expire {dir} {
global ax_days
log "EXPIRE: \[$dir]"
set ax_days [{dir expiry} $dir]
entries $dir do_expire
}
proc scan {dir attr {force 0}} {{indent 0}} {
global dustbin
@ -369,10 +393,10 @@ set rootdev $rootstat(dev)
#log "Root device: $rootdev" 1
if {[llength $argv] > 0} {
if {[lindex $argv 0] eq "test"} { set debug 1 }
set debug 1
foreach arg $argv { scan $root $arg }
} else {
foreach arg {dedup decrypt shrink mpg} {
foreach arg {dedup decrypt shrink mpg expire} {
set st [clock milliseconds]
scan $root $arg
log "$arg scan completed in [elapsed $st] seconds." 1

View File

@ -15,6 +15,16 @@ proc _addicon {img {hover ""} {class va}} {
return $icon
}
proc {dir expiry} {dir} {
if {[catch {
set fd [open "$dir/.autoexpire"]
set days $([read $fd] + 0)
$fd close
}]} { set days 0 }
if {!$days} { set days 7 }
return $days
}
proc {dir iconset} {dir} {
set icons {}
set attrs {}
@ -73,6 +83,15 @@ proc {dir iconset} {dir} {
lappend attrs "autompg=1"
}
set autoexpire 0
if {[file exists "$dir/.autoexpire"]} {
set days [{dir expiry} $dir]
set autoexpire 1
lappend icons [_addicon "/img/clock.png" \
"Auto-Expire ($days day$($days == 1 ? "" : "s"))"]
lappend attrs "autoexpire=1" "autoexpiredays=$days"
}
return [list $icons $attrs]
}

View File

@ -10,11 +10,13 @@ if {![exists -proc _del_bindir]} {
set _del_dustbin ""
}
proc _del_bindir {file} {
proc _del_bindir {file {prefix ""}} {
global _del_dustbin
set lbin $_del_dustbin
if {$prefix ne ""} { append lbin "/$prefix" }
set dir [file dirname $file]
regsub "^[system mediaroot]" $dir $_del_dustbin ndir
if {$dir eq $ndir} { set ndir $_del_dustbin }
regsub "^[system mediaroot]" $dir $lbin ndir
if {$dir eq $ndir} { set ndir $lbin }
system mkdir_p $ndir
return $ndir
}
@ -23,23 +25,23 @@ if {![exists -proc _del_bindir]} {
exec /mod/bin/busybox/touch $file
}
proc safe_delete {file} {
proc safe_delete {file {px ""}} {
global _del_dustbin
# Check if the file is already in the dustbin
if {$_del_dustbin ne "" && [\
# Check if undelete is installed and that the file being
# deleted is not already in the dustbin.
set dustbin 1
if {$_del_dustbin eq "" || [\
string first $_del_dustbin $file] > -1} {
set dustbin ""
} else {
set dustbin $_del_dustbin
set dustbin 0
}
# Directory
if {[file isdirectory $file]} {
if {$dustbin ne ""} {
set ndir "[_del_bindir $file]/[file tail $file]"
if {$dustbin} {
set ndir "[_del_bindir $file $px]/[\
file tail $file]"
while {[file isdirectory $ndir]} {
append ndir "_"
}
@ -56,8 +58,8 @@ if {![exists -proc _del_bindir]} {
# Check TS validity
if {![catch {$ts get file}]} {
if {$dustbin ne ""} {
$ts move [_del_bindir $file] 1 1
if {$dustbin} {
$ts move [_del_bindir $file $px] 1 1
} else {
if {[$ts delete]} {
return 1
@ -71,8 +73,8 @@ if {![exists -proc _del_bindir]} {
# otherwise treat as normal file.
if {$dustbin ne ""} {
set nfile "[_del_bindir $file]/[file tail $file]"
if {$dustbin} {
set nfile "[_del_bindir $file $px]/[file tail $file]"
file rename $file $nfile
_del_touch $nfile
} else {

View File

@ -12,12 +12,12 @@ if {![exists -proc require]} {
proc httpheader {{type "text/html"} {cache 0} {extra ""}} {{done 0}} {
if {$done} return
if {!$cache} {
puts -nonewline "Content-Type: $type; no-cache\r\n"
puts -nonewline "Content-Type: $type; charset=\"UTF-8\"; no-cache\r\n"
puts -nonewline "Expires: -1\r\n"
puts -nonewline "Pragma: no-cache\r\n"
puts -nonewline "Cache-Control: no-cache\r\n"
} else {
puts "Content-Type: $type\r\n"
puts "Content-Type: $type; charset=\"UTF-8\"\r\n"
}
puts -nonewline $extra
puts -nonewline "\r\n"

View File

@ -69,9 +69,29 @@ proc {system pkgver} {{pkg webif}} {
return [lrange [split [exec opkg list-installed $pkg] " "] 2 end]
}
proc {system pkginst} {pkg} {
if {[exec opkg list-installed $pkg] ne ""} {
return 1 } else { return 0 }
proc {system pkginst} {pkg} {{cache {}} {ncache {}}} {
if {$pkg in $cache} { return 1 }
if {$pkg in $ncache} { return 0 }
# It may not be possible to get an opkg lock immediately so
# try several times and throw an error if not.
set status unknown
loop i 0 5 {
if {[catch {set status [exec opkg list-installed $pkg]}]} {
sleep 1
} else break
}
if {$status eq "unknown"} {
puts "Could not get opkg lock after 5 seconds."
exit
}
if {$status ne ""} {
lappend $cache $pkg
return 1
}
lappend $ncache $pkg
return 0
}
proc {system mediaroot} {} {

View File

@ -48,6 +48,11 @@ ts method _parse {line} {
set flags [split [string range $flags_list 0 end-1] ,]
}
ts method inuse {} {
if {[system inuse [file rootname $file]]} { return 1 }
return 0
}
ts method bookmarks {} {
return [exec /mod/bin/hmt -bookmarks $file]
}
@ -68,6 +73,18 @@ ts method lock {} {
return 1
}
ts method set_shrunk {} {
set cmd [list /mod/bin/hmt +shrunk $file]
exec {*}$cmd
return 1
}
ts method set_deduped {} {
set cmd [list /mod/bin/hmt +dedup $file]
exec {*}$cmd
return 1
}
ts method unenc {} {
set cmd [list /mod/bin/hmt -protect $file]
exec {*}$cmd