sliftutils 1.4.7 → 1.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sliftutils",
3
- "version": "1.4.7",
3
+ "version": "1.4.9",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -86,14 +86,30 @@ type RemoteConfig = { url: string; password: string };
86
86
  function remoteConfigKey() { return getFileAPIKey() + ":remote"; }
87
87
  function loadRemoteConfig(): RemoteConfig | undefined {
88
88
  try {
89
- const s = localStorage.getItem(remoteConfigKey());
89
+ const key = remoteConfigKey();
90
+ const s = localStorage.getItem(key);
91
+ console.log("[remotecfg] load", JSON.stringify(key), "->", s);
90
92
  if (!s) return undefined;
91
93
  const c = JSON.parse(s);
92
94
  if (c && typeof c.url === "string" && typeof c.password === "string") return c;
93
- } catch { /* ignore */ }
95
+ } catch (e) { console.warn("[remotecfg] load error", e); }
94
96
  return undefined;
95
97
  }
96
- function saveRemoteConfig(c: RemoteConfig) { localStorage.setItem(remoteConfigKey(), JSON.stringify(c)); }
98
+ function saveRemoteConfig(c: RemoteConfig) {
99
+ const key = remoteConfigKey();
100
+ localStorage.setItem(key, JSON.stringify(c));
101
+ console.log("[remotecfg] saved", JSON.stringify(key), "readback ->", localStorage.getItem(key));
102
+ }
103
+
104
+ // The server is always HTTPS on the filehoster's default port, so the user only needs to type the host
105
+ // (e.g. "65.109.93.113"). We strip any scheme/path they include and default the port if omitted.
106
+ const DEFAULT_REMOTE_PORT = 8787; // matches remoteFileServer.js's default
107
+ function normalizeServerUrl(raw: string): string {
108
+ let s = raw.trim().replace(/^\w+:\/\//, "").replace(/\/.*$/, "");
109
+ if (!s) return "";
110
+ if (!/:\d+$/.test(s)) s += ":" + DEFAULT_REMOTE_PORT;
111
+ return "https://" + s;
112
+ }
97
113
 
98
114
  // One shared factory (and therefore one shared range cache) per remote config.
99
115
  let remoteFactory: { key: string; factory: ReturnType<typeof getRemoteFileStorage> } | undefined;
@@ -129,7 +145,7 @@ class DirectoryPrompter extends preact.Component {
129
145
  @observer
130
146
  class ServerConnectForm extends preact.Component {
131
147
  private obs = observable({ expanded: false, url: "", password: "", error: "", connecting: false, needsCert: false, showPassword: false });
132
- private cleanUrl() { return this.obs.url.trim().replace(/\/+$/, ""); }
148
+ private cleanUrl() { return normalizeServerUrl(this.obs.url); }
133
149
  private connect = async () => {
134
150
  const s = this.obs;
135
151
  s.error = "";
@@ -166,7 +182,7 @@ class ServerConnectForm extends preact.Component {
166
182
  }
167
183
  return (
168
184
  <div className={css.vbox(16).center}>
169
- <input className={inputCss} placeholder="https://host:8787" value={s.url}
185
+ <input className={inputCss} placeholder="server address (e.g. 65.109.93.113, or host:port)" value={s.url}
170
186
  onInput={e => s.url = (e.target as HTMLInputElement).value} />
171
187
  <div className={css.hbox(10).center}>
172
188
  <input className={inputCss} type={s.showPassword ? "text" : "password"} placeholder="password (six words)" value={s.password}
@@ -427,14 +427,18 @@ export async function runFileHoster(): Promise<void> {
427
427
  let externalIP: string | undefined;
428
428
  try { externalIP = (await getExternalIP()).trim(); } catch { /* offline / unreachable */ }
429
429
 
430
+ // What the user types into the app: just the host, plus ":port" only if it's not the default. No
431
+ // scheme — the app always uses https.
432
+ const host = externalIP || "localhost";
433
+ const appAddress = host + (info.port === 8787 ? "" : ":" + info.port);
434
+ const certUrl = "https://" + host + ":" + info.port;
430
435
  console.log("");
431
436
  console.log(" Serving: " + path.resolve(root));
432
437
  console.log(" Password: " + info.password);
433
- console.log(" Local: " + info.url);
434
- if (externalIP) console.log(" Public: https://" + externalIP + ":" + info.port + " (once port-forwarding succeeds)");
438
+ console.log(" Address: " + appAddress + " <- in the app, choose \"Connect to a server\" and enter this");
435
439
  console.log("");
436
- console.log(" In the app, choose \"Connect to a server\" and enter the URL + password.");
437
- console.log(" (Self-signed cert: open the URL once in your browser and accept it first.)");
440
+ console.log(" First time only: open " + certUrl + " in a browser once and accept the");
441
+ console.log(" self-signed certificate warning, then connect from the app.");
438
442
  console.log("");
439
443
 
440
444
  // Keep the UPnP port mapping alive — leases expire ~hourly, so refresh well within that. No-op on