Skip to content

Make videos on the computer you already own. FreeVideo runs MiniMax H3 in as little as 8 GB of VRAM and 16 GB of RAM, and adapts its acceleration path to your hardware.

Editor: name the cause of a failed save and accept an https page behind a TLS-terminating proxy

Bowen Xue6ee3826c8e54
diff --git a/freevideo_engine/access_proxy.py b/freevideo_engine/access_proxy.py
index 1040bf6..1e64547 100644
--- a/freevideo_engine/access_proxy.py
+++ b/freevideo_engine/access_proxy.py
@@ -23,6 +23,7 @@ from urllib.parse import urlencode, urlsplit
from aiohttp import ClientSession, ClientTimeout, DummyCookieJar, TCPConnector, WSMsgType, client_exceptions, web
from yarl import URL
from . import proxy_identity, lan_password
+from .origin_scheme import effective_scheme
from .lan_auth import PasswordAuth, DEVICE_COOKIE, REMEMBER_SECONDS, LOGIN_DELAY
PHONE_WEB = Path(__file__).resolve().parents[1] / 'web'
@@ -81,17 +82,18 @@ def same_origin(request):
try:
if len(request.headers.getall('Host', [])) != 1 or len(request.headers.getall('Origin', [])) != 1:
return False
- host = urlsplit(request.scheme + '://' + request.host)
origin = urlsplit(request.headers['Origin'])
+ scheme = effective_scheme(request, origin.scheme)
+ host = urlsplit(scheme + '://' + request.host)
socket = request.transport.get_extra_info('sockname')
allowed = {socket[0].split('%')[0]}
if ipaddress.ip_address(socket[0].split('%')[0]).is_loopback:
allowed.update(('localhost', '127.0.0.1', '::1'))
- own_port = host.port or (443 if request.scheme == 'https' else 80)
+ own_port = host.port or (443 if scheme == 'https' else 80)
return (host.hostname in allowed and own_port == socket[1] and origin.hostname == host.hostname
and (origin.port or (443 if origin.scheme == 'https' else 80)) == own_port
- and origin.scheme == request.scheme and not any((origin.path, origin.query, origin.fragment,
- origin.username, origin.password)))
+ and origin.scheme == scheme and not any((origin.path, origin.query, origin.fragment,
+ origin.username, origin.password)))
except (ValueError, TypeError, IndexError, KeyError):
return False
diff --git a/freevideo_engine/agent/access.py b/freevideo_engine/agent/access.py
index 2c5f9e0..a46a3d0 100644
--- a/freevideo_engine/agent/access.py
+++ b/freevideo_engine/agent/access.py
@@ -4,6 +4,7 @@ from urllib.parse import urlsplit
from .jobs import JobError
from .. import proxy_identity
+from ..origin_scheme import effective_scheme
def peer_address(request):
@@ -63,8 +64,9 @@ def check(request, *, local=False, lan=False):
if origin is not None:
parsed = urlsplit(origin)
port = parsed.port or (443 if parsed.scheme == 'https' else 80)
- own_port = host.port or (443 if scheme == 'https' else 80)
- if (parsed.scheme != scheme or parsed.hostname != host.hostname or port != own_port
+ wanted = scheme if proxied else effective_scheme(request, parsed.scheme)
+ own_port = host.port or (443 if wanted == 'https' else 80)
+ if (parsed.scheme != wanted or parsed.hostname != host.hostname or port != own_port
or parsed.path or parsed.query or parsed.fragment or parsed.username or parsed.password):
raise ValueError
except (ValueError, TypeError, IndexError):
diff --git a/freevideo_engine/comfy_editor.py b/freevideo_engine/comfy_editor.py
index 281fc84..3c6b199 100644
--- a/freevideo_engine/comfy_editor.py
+++ b/freevideo_engine/comfy_editor.py
@@ -23,6 +23,7 @@ from fractions import Fraction
from pathlib import Path, PurePosixPath, PureWindowsPath
from urllib.parse import unquote, urlencode, urlsplit
+from .origin_scheme import effective_scheme
from .comfy_library import _ID, _plain, _video
from .system import windows
from .editor_frames import frame_not_after, last_frame_end
@@ -1198,10 +1199,11 @@ def _local_page(request):
try:
parsed = urlsplit(origin)
host = urlsplit('//' + request.host)
- return (parsed.scheme in ('http', 'https') and parsed.scheme == request.scheme and not parsed.username
+ scheme = effective_scheme(request, parsed.scheme)
+ return (parsed.scheme in ('http', 'https') and parsed.scheme == scheme and not parsed.username
and not parsed.password and not parsed.path and not parsed.query and not parsed.fragment
and parsed.hostname == host.hostname
- and (parsed.port or (443 if parsed.scheme == 'https' else 80)) == (host.port or (443 if request.scheme == 'https' else 80)))
+ and (parsed.port or (443 if parsed.scheme == 'https' else 80)) == (host.port or (443 if scheme == 'https' else 80)))
except ValueError:
return False
@@ -1215,7 +1217,7 @@ def _same_origin_audio(request):
if referer:
try:
page = urlsplit(referer)
- origin = urlsplit(request.scheme + '://' + request.host)
+ origin = urlsplit(effective_scheme(request, page.scheme) + '://' + request.host)
return (page.scheme == origin.scheme and page.hostname == origin.hostname
and (page.port or (443 if page.scheme == 'https' else 80)) ==
(origin.port or (443 if origin.scheme == 'https' else 80))
diff --git a/freevideo_engine/origin_scheme.py b/freevideo_engine/origin_scheme.py
new file mode 100644
index 0000000..6ec5f84
--- /dev/null
+++ b/freevideo_engine/origin_scheme.py
@@ -0,0 +1,16 @@
+"""The one rule for comparing a page's Origin protocol with the protocol the server saw."""
+
+
+def effective_scheme(request, origin_scheme):
+ """The protocol to compare an Origin with.
+
+ A TLS-terminating proxy turns https into http before the request arrives. Only when the request carries a single
+ X-Forwarded-Proto equal to the Origin's own protocol is that difference accepted; host and port are still compared
+ by the caller, and no other forwarding header is read.
+ """
+ headers = request.headers
+ forwarded = headers.getall('X-Forwarded-Proto', []) if hasattr(headers, 'getall') else [headers['X-Forwarded-Proto']] if 'X-Forwarded-Proto' in headers else []
+ if (origin_scheme in ('http', 'https') and len(forwarded) == 1
+ and forwarded[0].strip().lower() == origin_scheme):
+ return origin_scheme
+ return request.scheme
diff --git a/web/editor.js b/web/editor.js
index ddf8e52..1c55f65 100644
--- a/web/editor.js
+++ b/web/editor.js
@@ -91,9 +91,15 @@ function exportErrorText(value, t) {
}
// The save route's own messages are internal English, so only a full disk is named.
function saveErrorText(value, t) {
+ if (isNetworkTypeError(value)) return connectionLostText(t);
return value?.reason === 'disk_full' ? t('Saving changes failed: the disk is full. Free some space, then export again.', '保存改动时出错:磁盘空间不够,空出空间后再导出。')
: t('Saving changes failed. Please export again.', '保存改动时出错,请再导出一次。');
}
+// Names the failed save for the report: the server's reason, else the HTTP status, a lost connection, or no failure recorded yet.
+function saveReason(failure) {
+ if (!failure) return 'unsaved';
+ return failure.reason || (failure.status ? 'http_' + failure.status : isNetworkTypeError(failure) ? 'network' : undefined);
+}
function restoreGeneration(record, before, prepared) {
const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
const entries = value => new Map(value.tracks.flatMap(track => track.clips.map(clip => [clip.id, {track: track.id, clip}])));
@@ -491,7 +497,7 @@ export function openEditor({api, app, from = null, panel = {}, components: given
await queue.flush();
}
if (disposed || closing || epoch !== projectEpoch) return false;
- if (queue.dirty) { notify(saveErrorText(queue.failure, t), EDITOR_ISSUE, failureKind('save', {reason: queue.failure?.reason})); return false; }
+ if (queue.dirty) { notify(saveErrorText(queue.failure, t), EDITOR_ISSUE, failureKind('save', {reason: saveReason(queue.failure)})); return false; }
return !!state.record.id;
}
function updateTop() {
@@ -708,7 +714,7 @@ export function openEditor({api, app, from = null, panel = {}, components: given
const words = deleteEditText(t);
if (jobActive()) throw {reason: 'generation_active'};
await queue.flush(); releaseStamp();
- if (queue.dirty) { notify(saveErrorText(queue.failure, t), EDITOR_ISSUE, failureKind('save', {reason: queue.failure?.reason})); return; }
+ if (queue.dirty) { notify(saveErrorText(queue.failure, t), EDITOR_ISSUE, failureKind('save', {reason: saveReason(queue.failure)})); return; }
// Load the replacement before deleting, so a read failure keeps the edit open.
const rows = (await store.projects()).filter(row => row.id !== state.record.id);
// Most recently used: the order the edits were opened, then the last save.