textfile-streaming fixes;

* give up on disconnect
* block scrapers from tailing
* prism throws on window-resize if riced object has poofed
* fix prism-init race
This commit is contained in:
ed 2025-06-19 17:07:06 +00:00
parent 77df17d191
commit a1c7a095ee
4 changed files with 24 additions and 9 deletions

View file

@ -1600,7 +1600,6 @@ def run_argparse(
add_db_metadata(ap) add_db_metadata(ap)
add_thumbnail(ap) add_thumbnail(ap)
add_transcoding(ap) add_transcoding(ap)
add_tail(ap)
add_rss(ap) add_rss(ap)
add_ftp(ap) add_ftp(ap)
add_webdav(ap) add_webdav(ap)
@ -1615,6 +1614,7 @@ def run_argparse(
add_hooks(ap) add_hooks(ap)
add_stats(ap) add_stats(ap)
add_txt(ap) add_txt(ap)
add_tail(ap)
add_og(ap) add_og(ap)
add_ui(ap, retry) add_ui(ap, retry)
add_admin(ap) add_admin(ap)

View file

@ -3815,6 +3815,10 @@ class HttpCli(object):
return txt return txt
def _can_tail(self, volflags: dict[str, Any]) -> bool: def _can_tail(self, volflags: dict[str, Any]) -> bool:
zp = self.args.ua_nodoc
if zp and zp.search(self.ua):
t = "this URL contains no valuable information for bots/crawlers"
raise Pebkac(403, t)
lvl = volflags["tail_who"] lvl = volflags["tail_who"]
if "notail" in volflags or not lvl: if "notail" in volflags or not lvl:
raise Pebkac(400, "tail is disabled in server config") raise Pebkac(400, "tail is disabled in server config")

View file

@ -5817,7 +5817,9 @@ var fileman = (function () {
var showfile = (function () { var showfile = (function () {
var r = {}; var r = {
'nrend': 0,
};
r.map = { r.map = {
'.ahk': 'autohotkey', '.ahk': 'autohotkey',
'.bas': 'basic', '.bas': 'basic',
@ -5956,10 +5958,10 @@ var showfile = (function () {
ro.read().then(function(v) { ro.read().then(function(v) {
if (r.tail_id != me) if (r.tail_id != me)
return; return;
v = v.value; var vt = v.done ? '\n*** lost connection to copyparty ***' : v.value;
if (v == '\x00') if (vt == '\x00')
return rf(); return rf();
txt += v; txt += vt;
var ofs = txt.length - r.tailnb; var ofs = txt.length - r.tailnb;
if (ofs > 0) { if (ofs > 0) {
var ofs2 = txt.indexOf('\n', ofs); var ofs2 = txt.indexOf('\n', ofs);
@ -5973,7 +5975,8 @@ var showfile = (function () {
edoc.innerHTML = html; edoc.innerHTML = html;
if (r.tail2end) if (r.tail2end)
window.scrollTo(0, wfp.offsetTop - window.innerHeight); window.scrollTo(0, wfp.offsetTop - window.innerHeight);
rf(); if (!v.done)
rf();
}); });
}; };
if (r.tail_id == me) if (r.tail_id == me)
@ -6036,6 +6039,7 @@ var showfile = (function () {
function render(doc, no_push) { function render(doc, no_push) {
r.q = null; r.q = null;
r.nrend++;
var url = r.url = doc[0], var url = r.url = doc[0],
lnh = doc[1], lnh = doc[1],
txt = doc[2], txt = doc[2],
@ -6050,9 +6054,13 @@ var showfile = (function () {
ebi('editdoc').style.display = (has(perms, 'write') && (is_md || has(perms, 'delete'))) ? '' : 'none'; ebi('editdoc').style.display = (has(perms, 'write') && (is_md || has(perms, 'delete'))) ? '' : 'none';
var wr = ebi('bdoc'), var wr = ebi('bdoc'),
nrend = r.nrend,
defer = !Prism.highlightElement; defer = !Prism.highlightElement;
var fun = function (el) { var fun = function (el) {
if (r.nrend != nrend)
return;
try { try {
if (lnh.slice(0, 5) == '#doc.') if (lnh.slice(0, 5) == '#doc.')
sethash(lnh.slice(1)); sethash(lnh.slice(1));
@ -6065,8 +6073,11 @@ var showfile = (function () {
catch (ex) { } catch (ex) { }
} }
if (!txt || txt.length > 1024 * 256) var skip_prism = !txt || txt.length > 1024 * 256;
if (skip_prism) {
fun = function (el) { }; fun = function (el) { };
is_md = false;
}
qsr('#doc'); qsr('#doc');
var el = mknod('pre', 'doc'); var el = mknod('pre', 'doc');
@ -6078,7 +6089,7 @@ var showfile = (function () {
else { else {
el.textContent = txt; el.textContent = txt;
el.innerHTML = '<code>' + el.innerHTML + '</code>'; el.innerHTML = '<code>' + el.innerHTML + '</code>';
if (!window.no_prism) { if (!window.no_prism && !skip_prism) {
if ((lang == 'conf' || lang == 'cfg') && ('\n' + txt).indexOf('\n# -*- mode: yaml -*-') + 1) if ((lang == 'conf' || lang == 'cfg') && ('\n' + txt).indexOf('\n# -*- mode: yaml -*-') + 1)
lang = 'yaml'; lang = 'yaml';

View file

@ -183,7 +183,7 @@ function vis_exh(msg, url, lineNo, columnNo, error) {
if (url.indexOf(' > eval') + 1 && !evalex_fatal) if (url.indexOf(' > eval') + 1 && !evalex_fatal)
return; // md timer return; // md timer
if (IE && url.indexOf('prism.js') + 1) if (url.indexOf('prism.js') + 1)
return; return;
if (url.indexOf('easymde.js') + 1) if (url.indexOf('easymde.js') + 1)