phirepass-widgets 0.0.116 → 0.0.117
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/README.md +13 -12
- package/dist/cjs/{index-BCgmMoIq.js → index-DehquNXP.js} +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/phirepass-downloader_3.cjs.entry.js +19 -8
- package/dist/cjs/phirepass-rdp.cjs.entry.js +1 -1
- package/dist/cjs/phirepass-terminal.cjs.entry.js +1 -1
- package/dist/cjs/phirepass-widgets.cjs.js +2 -2
- package/dist/collection/collection-manifest.json +1 -1
- package/dist/collection/components/phirepass-downloader/phirepass-downloader.js +18 -7
- package/dist/components/{p-5QoAejYG.js → p-B4kFfbHE.js} +1 -1
- package/dist/components/phirepass-downloader.js +1 -1
- package/dist/components/phirepass-sftp-client.js +1 -1
- package/dist/esm/{index-Dd9o0CbU.js → index-BinptKL7.js} +1 -1
- package/dist/esm/loader.js +2 -2
- package/dist/esm/phirepass-downloader_3.entry.js +19 -8
- package/dist/esm/phirepass-rdp.entry.js +1 -1
- package/dist/esm/phirepass-terminal.entry.js +1 -1
- package/dist/esm/phirepass-widgets.js +3 -3
- package/dist/phirepass-widgets/p-6a192c8d.entry.js +1 -0
- package/dist/phirepass-widgets/{p-c28a9257.entry.js → p-9e6f9220.entry.js} +4 -4
- package/dist/phirepass-widgets/{p-70a67e4d.entry.js → p-fe1ce8da.entry.js} +1 -1
- package/dist/phirepass-widgets/phirepass-widgets.esm.js +1 -1
- package/dist/types/components/phirepass-downloader/phirepass-downloader.d.ts +7 -0
- package/package.json +8 -8
- package/dist/phirepass-widgets/p-ab33f71f.entry.js +0 -1
- /package/dist/phirepass-widgets/{p-Dd9o0CbU.js → p-BinptKL7.js} +0 -0
package/README.md
CHANGED
|
@@ -16,18 +16,19 @@ Every component takes a `channelFactory` (or the downloader an injected `channel
|
|
|
16
16
|
|
|
17
17
|
## Development
|
|
18
18
|
|
|
19
|
-
Node is pinned in `.nvmrc` (`nvm use`).
|
|
19
|
+
Bun is the package manager / script runner (version pinned in `.bun-version`); Node is still the runtime for Stencil/Vitest and is pinned in `.nvmrc` (`nvm use`).
|
|
20
20
|
|
|
21
21
|
```bash
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
bun install # install deps (bun.lock)
|
|
23
|
+
bun start # stencil dev server
|
|
24
|
+
bun run storybook # stencil build, then Storybook on :6006
|
|
25
|
+
bun run test # spec tests (vitest, Stencil environment)
|
|
26
|
+
bun run test:storybook # every story's play function in headless Chromium
|
|
27
|
+
bun run test:all # both
|
|
28
|
+
bun run build # production build
|
|
28
29
|
```
|
|
29
30
|
|
|
30
|
-
`
|
|
31
|
+
`bun run test:storybook` needs Chromium once: `bunx playwright install chromium`.
|
|
31
32
|
|
|
32
33
|
Stories live in `stories/`: one file per existing widget and one per Remote Fetch screen group (`stories/remote-fetch/1-sftp` … `9-notices`). Each screen is its own story, and its `play` function is its test. The mock channel (`src/testing/mock-channel.ts`) and fixtures (`src/testing/fixtures.ts`) are shared by stories and specs.
|
|
33
34
|
|
|
@@ -56,20 +57,20 @@ git remote rm origin
|
|
|
56
57
|
and run:
|
|
57
58
|
|
|
58
59
|
```bash
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
bun install
|
|
61
|
+
bun start
|
|
61
62
|
```
|
|
62
63
|
|
|
63
64
|
To build the component for production, run:
|
|
64
65
|
|
|
65
66
|
```bash
|
|
66
|
-
|
|
67
|
+
bun run build
|
|
67
68
|
```
|
|
68
69
|
|
|
69
70
|
To run the unit tests for the components, run:
|
|
70
71
|
|
|
71
72
|
```bash
|
|
72
|
-
|
|
73
|
+
bun run test
|
|
73
74
|
```
|
|
74
75
|
|
|
75
76
|
Need help? Check out our docs [here](https://stenciljs.com/docs/my-first-component).
|
|
@@ -4,7 +4,7 @@ const NAMESPACE = 'phirepass-widgets';
|
|
|
4
4
|
const BUILD = /* phirepass-widgets */ { hotModuleReplacement: false, hydratedSelectorName: "hydrated", lazyLoad: true, propChangeCallback: true, state: true, updatable: true};
|
|
5
5
|
|
|
6
6
|
/*
|
|
7
|
-
Stencil Client Platform v4.45.
|
|
7
|
+
Stencil Client Platform v4.45.5 | MIT Licensed | https://stenciljs.com
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
|
package/dist/cjs/loader.cjs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var index = require('./index-
|
|
3
|
+
var index = require('./index-DehquNXP.js');
|
|
4
4
|
var protocol = require('./protocol-BjOgJZ9-.js');
|
|
5
5
|
|
|
6
6
|
const DOWNLOAD_METHODS = [
|
|
@@ -1632,6 +1632,15 @@ const PhirepassDownloader = class {
|
|
|
1632
1632
|
this.picker = null;
|
|
1633
1633
|
}
|
|
1634
1634
|
// ---------------------------------------------------------------- render
|
|
1635
|
+
/**
|
|
1636
|
+
* The dialog's state as it is now, not as it was when the dialog last rendered.
|
|
1637
|
+
* Handlers run between a state change and the re-render it schedules (tick a box,
|
|
1638
|
+
* then click confirm before the frame), so reading `c` from the render closure
|
|
1639
|
+
* would act on the stale value.
|
|
1640
|
+
*/
|
|
1641
|
+
latest(c) {
|
|
1642
|
+
return this.confirm?.kind === c.kind ? this.confirm : c;
|
|
1643
|
+
}
|
|
1635
1644
|
renderConfirm() {
|
|
1636
1645
|
const c = this.confirm;
|
|
1637
1646
|
if (!c) {
|
|
@@ -1640,13 +1649,15 @@ const PhirepassDownloader = class {
|
|
|
1640
1649
|
const cancel = () => (this.confirm = null);
|
|
1641
1650
|
switch (c.kind) {
|
|
1642
1651
|
case 'stop':
|
|
1643
|
-
return (index.h(ConfirmStop, { row: c.row, discard: c.discard, onDiscard: discard => (this.confirm = { ...c, discard }), onCancel: cancel, onConfirm: () => {
|
|
1644
|
-
this.
|
|
1652
|
+
return (index.h(ConfirmStop, { row: c.row, discard: c.discard, onDiscard: discard => (this.confirm = { ...this.latest(c), discard }), onCancel: cancel, onConfirm: () => {
|
|
1653
|
+
const cur = this.latest(c);
|
|
1654
|
+
this.sendStop(cur.row, cur.discard);
|
|
1645
1655
|
this.confirm = null;
|
|
1646
1656
|
} }));
|
|
1647
1657
|
case 'delete':
|
|
1648
|
-
return (index.h(ConfirmDelete, { row: c.row, nodeName: this.name, deleteFile: c.deleteFile, onDeleteFile: deleteFile => (this.confirm = { ...c, deleteFile }), onCancel: cancel, onConfirm: () => {
|
|
1649
|
-
this.
|
|
1658
|
+
return (index.h(ConfirmDelete, { row: c.row, nodeName: this.name, deleteFile: c.deleteFile, onDeleteFile: deleteFile => (this.confirm = { ...this.latest(c), deleteFile }), onCancel: cancel, onConfirm: () => {
|
|
1659
|
+
const cur = this.latest(c);
|
|
1660
|
+
this.sendDelete(cur.row, cur.deleteFile);
|
|
1650
1661
|
this.confirm = null;
|
|
1651
1662
|
} }));
|
|
1652
1663
|
case 'fastest':
|
|
@@ -1656,8 +1667,8 @@ const PhirepassDownloader = class {
|
|
|
1656
1667
|
this.confirm = null;
|
|
1657
1668
|
} }));
|
|
1658
1669
|
case 'torrent':
|
|
1659
|
-
return (index.h(ConfirmTorrent, { nodeName: this.name, dontAsk: c.dontAsk, onDontAsk: dontAsk => (this.confirm = { ...c, dontAsk }), onCancel: cancel, onConfirm: () => {
|
|
1660
|
-
if (c.dontAsk) {
|
|
1670
|
+
return (index.h(ConfirmTorrent, { nodeName: this.name, dontAsk: c.dontAsk, onDontAsk: dontAsk => (this.confirm = { ...this.latest(c), dontAsk }), onCancel: cancel, onConfirm: () => {
|
|
1671
|
+
if (this.latest(c).dontAsk) {
|
|
1661
1672
|
writeTorrentAck();
|
|
1662
1673
|
this.torrentAcked = true;
|
|
1663
1674
|
}
|
|
@@ -1736,7 +1747,7 @@ const PhirepassDownloader = class {
|
|
|
1736
1747
|
]));
|
|
1737
1748
|
}
|
|
1738
1749
|
render() {
|
|
1739
|
-
return (index.h(index.Host, { key: '
|
|
1750
|
+
return (index.h(index.Host, { key: 'b7f751d7107ff8f00d791e5c54f4261e2d7cd580', class: { compact: this.compact, standalone: !this.compact } }, this.compact ? this.renderCompact() : this.renderStandalone(), this.renderConfirm(), this.picker && (index.h(FolderPicker, { key: '538f0f433863e0fbd79a8e66c0b7a45c93a8bd28', root: this.caps?.folder ?? '', path: this.picker.path, folders: this.picker.folders, error: this.picker.error, newName: this.picker.newName, onOpen: name => this.listFolders([...this.picker.path, name]), onUp: depth => this.listFolders(this.picker.path.slice(0, depth)), onNewName: newName => (this.picker = { ...this.picker, newName }), onCancel: () => (this.picker = null), onSave: () => this.savePicker() })), this.player && (index.h("div", { key: 'b9d3ade696c6079d6a2e3bc2206c19a6bdd7d640', class: "overlay player" }, index.h("phirepass-media-player", { key: 'c5fa1244ea9766ff37d08478dbc2d096430f2081', src: this.player.src, name: this.player.name, status: this.playerStatus(), ready: this.playerReady(), positionKey: `dl:${this.player.downloadId}`, onPhirepassPlayerClose: () => (this.player = null) }))), index.h(Notices, { key: '34a34a810001815a890a0995aab44f29f34aab61', notices: this.notices, onDismiss: id => this.dismiss(id) })));
|
|
1740
1751
|
}
|
|
1741
1752
|
playerRow() {
|
|
1742
1753
|
return this.player ? this.jobs[this.player.downloadId] : undefined;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var index = require('./index-
|
|
3
|
+
var index = require('./index-DehquNXP.js');
|
|
4
4
|
var appGlobals = require('./app-globals-V2Kpy_OQ.js');
|
|
5
5
|
|
|
6
6
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
7
7
|
/*
|
|
8
|
-
Stencil Client Patch Browser v4.45.
|
|
8
|
+
Stencil Client Patch Browser v4.45.5 | MIT Licensed | https://stenciljs.com
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
var patchBrowser = () => {
|
|
@@ -670,6 +670,15 @@ export class PhirepassDownloader {
|
|
|
670
670
|
this.picker = null;
|
|
671
671
|
}
|
|
672
672
|
// ---------------------------------------------------------------- render
|
|
673
|
+
/**
|
|
674
|
+
* The dialog's state as it is now, not as it was when the dialog last rendered.
|
|
675
|
+
* Handlers run between a state change and the re-render it schedules (tick a box,
|
|
676
|
+
* then click confirm before the frame), so reading `c` from the render closure
|
|
677
|
+
* would act on the stale value.
|
|
678
|
+
*/
|
|
679
|
+
latest(c) {
|
|
680
|
+
return this.confirm?.kind === c.kind ? this.confirm : c;
|
|
681
|
+
}
|
|
673
682
|
renderConfirm() {
|
|
674
683
|
const c = this.confirm;
|
|
675
684
|
if (!c) {
|
|
@@ -678,13 +687,15 @@ export class PhirepassDownloader {
|
|
|
678
687
|
const cancel = () => (this.confirm = null);
|
|
679
688
|
switch (c.kind) {
|
|
680
689
|
case 'stop':
|
|
681
|
-
return (h(ConfirmStop, { row: c.row, discard: c.discard, onDiscard: discard => (this.confirm = { ...c, discard }), onCancel: cancel, onConfirm: () => {
|
|
682
|
-
this.
|
|
690
|
+
return (h(ConfirmStop, { row: c.row, discard: c.discard, onDiscard: discard => (this.confirm = { ...this.latest(c), discard }), onCancel: cancel, onConfirm: () => {
|
|
691
|
+
const cur = this.latest(c);
|
|
692
|
+
this.sendStop(cur.row, cur.discard);
|
|
683
693
|
this.confirm = null;
|
|
684
694
|
} }));
|
|
685
695
|
case 'delete':
|
|
686
|
-
return (h(ConfirmDelete, { row: c.row, nodeName: this.name, deleteFile: c.deleteFile, onDeleteFile: deleteFile => (this.confirm = { ...c, deleteFile }), onCancel: cancel, onConfirm: () => {
|
|
687
|
-
this.
|
|
696
|
+
return (h(ConfirmDelete, { row: c.row, nodeName: this.name, deleteFile: c.deleteFile, onDeleteFile: deleteFile => (this.confirm = { ...this.latest(c), deleteFile }), onCancel: cancel, onConfirm: () => {
|
|
697
|
+
const cur = this.latest(c);
|
|
698
|
+
this.sendDelete(cur.row, cur.deleteFile);
|
|
688
699
|
this.confirm = null;
|
|
689
700
|
} }));
|
|
690
701
|
case 'fastest':
|
|
@@ -694,8 +705,8 @@ export class PhirepassDownloader {
|
|
|
694
705
|
this.confirm = null;
|
|
695
706
|
} }));
|
|
696
707
|
case 'torrent':
|
|
697
|
-
return (h(ConfirmTorrent, { nodeName: this.name, dontAsk: c.dontAsk, onDontAsk: dontAsk => (this.confirm = { ...c, dontAsk }), onCancel: cancel, onConfirm: () => {
|
|
698
|
-
if (c.dontAsk) {
|
|
708
|
+
return (h(ConfirmTorrent, { nodeName: this.name, dontAsk: c.dontAsk, onDontAsk: dontAsk => (this.confirm = { ...this.latest(c), dontAsk }), onCancel: cancel, onConfirm: () => {
|
|
709
|
+
if (this.latest(c).dontAsk) {
|
|
699
710
|
writeTorrentAck();
|
|
700
711
|
this.torrentAcked = true;
|
|
701
712
|
}
|
|
@@ -774,7 +785,7 @@ export class PhirepassDownloader {
|
|
|
774
785
|
]));
|
|
775
786
|
}
|
|
776
787
|
render() {
|
|
777
|
-
return (h(Host, { key: '
|
|
788
|
+
return (h(Host, { key: 'b7f751d7107ff8f00d791e5c54f4261e2d7cd580', class: { compact: this.compact, standalone: !this.compact } }, this.compact ? this.renderCompact() : this.renderStandalone(), this.renderConfirm(), this.picker && (h(FolderPicker, { key: '538f0f433863e0fbd79a8e66c0b7a45c93a8bd28', root: this.caps?.folder ?? '', path: this.picker.path, folders: this.picker.folders, error: this.picker.error, newName: this.picker.newName, onOpen: name => this.listFolders([...this.picker.path, name]), onUp: depth => this.listFolders(this.picker.path.slice(0, depth)), onNewName: newName => (this.picker = { ...this.picker, newName }), onCancel: () => (this.picker = null), onSave: () => this.savePicker() })), this.player && (h("div", { key: 'b9d3ade696c6079d6a2e3bc2206c19a6bdd7d640', class: "overlay player" }, h("phirepass-media-player", { key: 'c5fa1244ea9766ff37d08478dbc2d096430f2081', src: this.player.src, name: this.player.name, status: this.playerStatus(), ready: this.playerReady(), positionKey: `dl:${this.player.downloadId}`, onPhirepassPlayerClose: () => (this.player = null) }))), h(Notices, { key: '34a34a810001815a890a0995aab44f29f34aab61', notices: this.notices, onDismiss: id => this.dismiss(id) })));
|
|
778
789
|
}
|
|
779
790
|
playerRow() {
|
|
780
791
|
return this.player ? this.jobs[this.player.downloadId] : undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{h as e,t,p as n,H as o,c as s,a as i}from"./index.js";import{_ as r,C as a,P as l,E as d}from"./p-BekUePpu.js";import{f as c,a as h,b as p,c as u,e as f,g as b,I as g,p as m,d as w}from"./p-DIf-Ru26.js";const v=["send_download_start","send_download_stop","send_download_resume","send_download_set_order","send_download_delete","send_download_subscribe","send_download_where"];function x(e){return!(!e||"object"!=typeof e)&&v.every((t=>"function"==typeof e[t]))}const y=1073741824,k=new Set(["DownloadProgress","DownloadAccepted","DownloadWhereAnswer","DownloadCaps","DownloadFoldersAnswer"]);function C(e){return k.has(e.type)}const S=new Set(["host","content-length","range","if-range","transfer-encoding","connection","keep-alive","proxy-authenticate","proxy-authorization","te","trailer","upgrade"]);function $(e){const t=e.trim();if(!t)return{kind:"empty"};if(/^magnet:\?/i.test(t)){const e=t.slice(t.indexOf("?")+1),n=new URLSearchParams(e),o=n.getAll("xt").find((e=>/^urn:btih:/i.test(e)));if(!o)return{kind:"invalid"};const s=o.slice(9),i=n.get("dn")?.trim();return{kind:"magnet",uri:t,infoHash:s,...i?{name:i}:{}}}let n;try{n=new URL(t)}catch{return{kind:"invalid"}}if("http:"!==n.protocol&&"https:"!==n.protocol)return{kind:"invalid"};if(!n.hostname)return{kind:"invalid"};if(n.username||n.password)return{kind:"invalid"};const o="https:"===n.protocol?"HTTPS":"HTTP",s=function(e){const t=e.split("/").filter(Boolean),n=t[t.length-1]??"";try{return decodeURIComponent(n)}catch{return n}}(n.pathname)||"download";return{kind:/\.torrent$/i.test(n.pathname)?"torrent-url":"http",url:t,host:n.hostname,name:s,scheme:o}}function D(e){const t=(...e)=>e.some((e=>/[\r\n\0]/.test(e)));switch(e.mode){case"none":return{auth:null};case"basic":return e.username?e.username.includes(":")?{auth:null,error:"A username cannot contain a colon."}:t(e.username,e.password)?{auth:null,error:"A login cannot contain line breaks."}:{auth:{Basic:{username:e.username,password:e.password}}}:{auth:null,error:"Enter a username."};case"bearer":return e.token.trim()?t(e.token)?{auth:null,error:"A login cannot contain line breaks."}:{auth:{Bearer:{token:e.token.trim()}}}:{auth:null,error:"Enter a token."};case"header":{const n=e.headerName.trim();return/^[A-Za-z0-9!#$%&'*+.^_`|~-]+$/.test(n)?S.has(n.toLowerCase())?{auth:null,error:`${n} cannot be set here.`}:t(e.headerValue)?{auth:null,error:"A login cannot contain line breaks."}:{auth:{Header:{name:n,value:e.headerValue}}}:{auth:null,error:"Enter a valid header name."}}}}const z={text:"",saveAs:"",torrent:null,order:null,auth:{mode:"none",username:"",password:"",token:"",headerName:"",headerValue:""},authOpen:!1};function F(e,t,n){const o=e.torrent?{kind:"empty"}:$(e.text),s=!!e.torrent||"magnet"===o.kind,i=s&&!!t&&!t.torrents,r="http"===o.kind||"torrent-url"===o.kind;let a=null;"too-large"===e.torrent?.error?a={tone:"err",title:"Too large",body:"A .torrent file can be up to 2 MB. Use its magnet link instead."}:"not-torrent"===e.torrent?.error?a={tone:"err",title:"Not a .torrent",body:"Choose a file that ends in .torrent."}:"invalid"===o.kind?a={tone:"err",title:"Not a link",body:"Use http://, https:// or magnet:"}:i&&(a={tone:"warn",title:"Torrents are off",body:"This node only allows ordinary links. Its owner can allow torrents in the node's settings."});const l=D(e.auth),d=s&&!i,c=n&&!!t&&(r||"magnet"===o.kind||!!e.torrent&&!e.torrent.error&&!!e.torrent.contents)&&!a&&(!d||null!==e.order)&&(!r||!e.authOpen||!l.error);let h;return r?h=e.saveAs.trim()||o.name:"magnet"===o.kind&&(h=o.name),{detected:o,isTorrent:s,needsOrder:d,showSaveAs:"http"===o.kind,showAuth:r,note:a,canStart:c,askedName:h,authError:r&&e.authOpen&&(e.auth.username||e.auth.token||e.auth.headerName||e.auth.headerValue)?l.error:void 0}}const _=new Set(["Completed","Seeding"]);function P(e){return _.has(e)}const R=new Set(["Queued","Scheduled","Resolving","FetchingMetadata","Downloading","Verifying","Paused","Stopped","Unknown"]);function T(e){return"Stopped"===e.state&&"Torrent"===e.kind&&!!e.seeding_since}function I(e){return["Queued","Scheduled","Resolving","FetchingMetadata","Downloading","Verifying","Paused"].includes(e.state)}function N(e){return("Completed"===e.state||"Cancelled"===e.state)&&!e.deleting}const A={Downloading:0,Verifying:1,FetchingMetadata:2,Resolving:3,Paused:4,Queued:5,Scheduled:6,Retrying:7,Stopped:8,Seeding:9,Completed:10,Cancelled:11,Deleted:12,Unknown:13};function j(e){const t=e.filter(I),n=t.reduce(((e,t)=>e+(t.down_bps||0)),0),o=t.filter((e=>e.total_bytes)),s=o.reduce(((e,t)=>e+t.done_bytes),0),i=o.reduce(((e,t)=>e+(t.total_bytes??0)),0);return{active:t.length,downBps:n,done:s,total:i,percent:i?s/i*100:null}}const O=/\.(mp4|m4v|webm|mkv|mov|mp3|m4a|flac|ogg|oga|opus|wav)$/i;function M(e){return O.test(e)}function B(e){const t=function(e){const t=e.files.filter((e=>e.media||M(e.name)));return t.length?t.reduce(((e,t)=>t.size>e.size?t:e)):!e.files.length&&M(e.name)?{index:0,name:e.name,size:e.total_bytes??0,done_bytes:e.done_bytes,media:!0,ready_from_start:e.in_order?e.done_bytes:0}:null}(e);return!t||e.deleting?{play:!1,file:null,switchToInOrder:!1}:P(e.state)?{play:!0,file:t,switchToInOrder:!1}:["Downloading","Verifying","Paused","Stopped","Retrying"].includes(e.state)&&t.size?e.in_order?{play:!0,file:t,switchToInOrder:!1}:{play:!1,file:null,switchToInOrder:"Torrent"===e.kind&&!T(e)}:{play:!1,file:null,switchToInOrder:!1}}function U(...e){const t=e.filter((e=>!!e)).join("/").replace(/\/{2,}/g,"/");return t.length>1?t.replace(/\/+$/,""):t}function E(e){return U(e.dest_root,e.sub_dir)}function V(e,t,n){return e.agent_supported?"Organisation"===e.lock?{id:"blocked",title:"Blocked",body:`Your organisation does not allow downloads on ${t}.`,secondary:"An owner or admin of the organisation can change this under Organisation → Downloads."}:e.http?"NoFolder"===e.lock?{id:"no-folder",title:"No download folder",body:"The download folder on this node is missing or can't be written.",secondary:"Someone who can configure the node can pick another one.",action:n?"Open node settings":void 0}:null:{id:"off",title:"Downloads are off",body:`Downloads are turned off for ${t}.`,secondary:n?"You can turn them on in the node's settings.":"Ask the node's owner to turn them on.",action:n?"Open node settings":void 0}:{id:"too-old",title:"Too old",body:`${t} runs an agent that cannot download. Update the agent on that machine, then try again.`}}const W=({label:t,onClose:n,wide:o},s)=>e("div",{class:"overlay",onClick:e=>{e.target===e.currentTarget&&n()}},e("div",{class:{modal:!0,wide:!!o},role:"dialog","aria-modal":"true","aria-label":t,tabindex:-1,onKeyDown:e=>{"Escape"===e.key&&(e.stopPropagation(),n())}},s)),q=({cancel:t,confirm:n,danger:o,onCancel:s,onConfirm:i})=>e("div",{class:"dlg-f"},e("button",{type:"button",class:"btn",onClick:s},t),e("button",{type:"button",class:{btn:!0,pri:!o,dng:!!o},onClick:i},n)),L=({row:t,discard:n,onDiscard:o,...s})=>e(W,{label:"Stop this download?",onClose:s.onCancel},e("div",{class:"dlg"},e("h4",null,"Stop this download?"),e("div",{class:"filechip"},e(g,{name:"file",size:20}),e("div",null,e("b",null,t.name),e("span",null,t.total_bytes?`${h(t.done_bytes)} of ${h(t.total_bytes)} downloaded`:`${h(t.done_bytes)} downloaded`))),e("label",{class:"checkline"},e("input",{type:"checkbox",checked:n,onChange:e=>o(e.target.checked)}),e("span",null,"Also delete the part already downloaded",e("span",{class:"hint block"},"Leave this off and Resume continues from here."))),e(q,{cancel:"Keep downloading",confirm:"Stop download",danger:!0,...s}))),Q=({row:t,deleteFile:n,onDeleteFile:o,nodeName:s,...i})=>{const r=P(t.state),a=t.files.length>1?`${t.files.length} files · ${h(t.total_bytes??t.done_bytes)}`:h(t.total_bytes??t.done_bytes);return e(W,{label:"Delete this download?",onClose:i.onCancel},e("div",{class:"dlg"},e("h4",null,"Delete this download?"),e("div",{class:"filechip"},e(g,{name:"file",size:20}),e("div",null,e("b",null,t.name),e("span",null,"Seeding"===t.state?"Seeding · ":"",a," in ",E(t)))),"Seeding"===t.state&&e("p",{class:"dtx"},s," stops sharing it with peers."),r?e("label",{class:"checkline"},e("input",{type:"checkbox",checked:n,onChange:e=>o(e.target.checked)}),e("span",null,"Also delete the files",e("span",{class:"hint block"},"Off: the files stay in ",E(t)," and only the download is removed."))):e("p",{class:"dtx"},"The part already downloaded is deleted."),e(q,{cancel:"Cancel",confirm:"Delete",danger:!0,...i})))},H=({row:t,...n})=>e(W,{label:"Switch to fastest?",onClose:n.onCancel},e("div",{class:"dlg"},e("h4",null,"Switch to fastest?"),e("p",{class:"dtx"},e("b",null,t.name)," is playing. Fastest downloads pieces in any order, so playback stops until it finishes or you switch back."),e(q,{cancel:"Keep in order",confirm:"Switch and stop playback",danger:!0,...n}))),K=({nodeName:t,dontAsk:n,onDontAsk:o,...s})=>e(W,{label:`Start a torrent on ${t}?`,onClose:s.onCancel},e("div",{class:"dlg"},e("h4",null,"Start a torrent on ",t,"?"),e("div",{class:"note warn"},e(g,{name:"warn",size:14}),e("div",null,"The node will connect to public peers. They can see its internet address, and it uploads to them while it downloads.")),e("p",{class:"dtx"},"When it finishes, ",t," keeps sharing it with other peers until you delete it."),e("label",{class:"checkline"},e("input",{type:"checkbox",checked:n,onChange:e=>o(e.target.checked)}),e("span",null,"Do not ask again on this browser")),e(q,{cancel:"Cancel",confirm:"Start torrent",...s}))),Y=({reason:t,onClose:n})=>e(W,{label:"Not enough space",onClose:n},e("div",{class:"dlg"},e("h4",null,"Not enough space"),e("p",{class:"dtx"},t),e("div",{class:"dlg-f"},e("button",{type:"button",class:"btn pri",onClick:n},"OK")))),X=t=>e(W,{label:"Save downloads to",onClose:t.onCancel,wide:!0},e("div",{class:"dlg"},e("h4",null,"Save downloads to"),e("nav",{class:"crumbs","aria-label":"Folder"},e("button",{type:"button",class:"lnk",onClick:()=>t.onUp(0)},t.root),t.path.map(((n,o)=>[e("span",{class:"sep"},"/"),e("button",{type:"button",class:"lnk",onClick:()=>t.onUp(o+1)},n)]))),e("div",{class:"folders",role:"list"},null===t.folders&&e("div",{class:"muted"},"Loading…"),0===t.folders?.length&&e("div",{class:"muted"},"No folders here."),t.folders?.map((n=>e("button",{type:"button",class:"folder-row",role:"listitem",onClick:()=>t.onOpen(n)},e(g,{name:"folder",size:14}),e("span",null,n))))),t.error&&e("div",{class:"note err"},t.error),null!==t.newName&&e("input",{class:"inp",type:"text","aria-label":"New folder name",placeholder:"New folder name",value:t.newName,onInput:e=>t.onNewName(e.target.value)}),e("p",{class:"hint"},"Folders only, and only inside the node's download folder. A new folder is created by the node when the first download lands in it."),e("div",{class:"dlg-f"},e("button",{type:"button",class:"btn left",onClick:()=>t.onNewName(null===t.newName?"":null)},e(g,{name:"plus",size:12})," New folder"),e("button",{type:"button",class:"btn",onClick:t.onCancel},"Cancel"),e("button",{type:"button",class:"btn pri",disabled:null!==t.newName&&!/^[^/\\\0]+$/.test(t.newName.trim()),onClick:t.onSave},"Save here")))),Z=({note:t})=>e("div",{class:`note ${t.tone}`,role:"err"===t.tone?"alert":"status"},e(g,{name:"warn",size:14}),e("div",null,e("b",null,t.title)," ",t.body));function G({model:t}){const n=t.detected;return"http"===n.kind||"torrent-url"===n.kind?e("div",{class:"detect","data-kind":n.kind},e("span",{class:"pill meta"},"torrent-url"===n.kind?".torrent link":n.scheme),e("span",{class:"host"},n.host)):"magnet"===n.kind?e("div",{class:"detect","data-kind":"magnet"},e("span",{class:"pill meta"},"Magnet"),e("span",{class:"host"},n.name??"name arrives with the metadata")):e("div",{class:"detect"})}const J=({auth:t,onChange:n})=>{const o=n,s=(n,s,i="text")=>e("label",{class:"fld"},e("span",null,n),e("input",{class:"inp",type:i,autocomplete:"off",spellcheck:!1,value:t[s],onInput:e=>o({[s]:e.target.value})}));return e("div",{class:"auth"},e("div",{class:"seg",role:"radiogroup","aria-label":"Login for the link"},[["none","No login"],["basic","Username and password"],["bearer","Bearer token"],["header","Custom header"]].map((([n,s])=>e("label",{class:{on:t.mode===n}},e("input",{type:"radio",name:"auth-mode",checked:t.mode===n,onChange:()=>o({mode:n})}),s)))),"basic"===t.mode&&[s("Username","username"),s("Password","password","password")],"bearer"===t.mode&&s("Token","token","password"),"header"===t.mode&&[s("Header name","headerName"),s("Value","headerValue","password")],"none"!==t.mode&&e("p",{class:"hint"},"Sent only to this link's own site, and dropped if it redirects elsewhere. The node seals it and deletes it when the download finishes."))},ee=({order:t,onChange:n})=>e("fieldset",{class:"order"},e("legend",null,"How should it download? (required for torrents)"),e("label",{class:{opt:!0,on:"in"===t}},e("input",{type:"radio",name:"order",value:"in",checked:"in"===t,onChange:()=>n("in")}),e("span",null,e("b",null,"In order")," · watch while it downloads, a little slower")),e("label",{class:{opt:!0,on:"fast"===t}},e("input",{type:"radio",name:"order",value:"fast",checked:"fast"===t,onChange:()=>n("fast")}),e("span",null,e("b",null,"Fastest")," · any order; switch to in order later if you want to watch"))),te=t=>{const{form:n,model:o,caps:s}=t;let i;const r=!!s?.torrents,a="dialog"===t.layout,l=e("input",{type:"file",accept:".torrent,application/x-bittorrent",class:"hidden-input",ref:e=>i=e,onChange:e=>{const n=e.target,o=n.files?.[0];o&&t.onPickTorrent(o),n.value=""}}),d=n.torrent?e("div",{class:{filechip:!0,bad:!!n.torrent.error}},e(g,{name:"torrent",size:20}),e("div",null,e("b",null,n.torrent.name),e("span",null,h(n.torrent.size)," · from this computer")),e("button",{type:"button",class:"ib","aria-label":"Remove the .torrent file",title:"Remove",onClick:()=>t.onChange({torrent:null,order:null})},e(g,{name:"x",size:14}))):e("div",{class:"fld"},e("label",{htmlFor:"fetch-link"},"Link or magnet"),e("div",{class:"inline-row"},e("input",{id:"fetch-link",class:"inp",type:"text",inputMode:"url",autocomplete:"off",autocapitalize:"none",spellcheck:!1,placeholder:"https://… or magnet:?xt=…",value:n.text,disabled:t.starting,onInput:e=>t.onChange({text:e.target.value}),onKeyDown:e=>{"Enter"===e.key&&o.canStart&&(e.preventDefault(),t.onStart())}}),!a&&r&&e("button",{type:"button",class:"btn",onClick:()=>i?.click()},".torrent…"),!a&&e("button",{type:"button",class:"btn pri",disabled:!o.canStart||t.starting,onClick:()=>t.onStart()},t.starting?"Starting…":"Download")),e(G,{model:o}));return e("form",{class:{"fetch-form":!0,[t.layout]:!0},onSubmit:e=>{e.preventDefault(),o.canStart&&t.onStart()},onDragOver:e=>r&&e.preventDefault(),onDrop:e=>r&&(e=>{e.preventDefault();const n=e.dataTransfer?.files?.[0];n&&t.onPickTorrent(n)})(e)},a&&e("div",{class:"dlg-h"},e(g,{name:"fetch"}),e("h4",null,t.title)),l,d,o.note&&e(Z,{note:o.note}),t.refusal&&e(Z,{note:t.refusal}),o.showSaveAs&&e("div",{class:"fld"},e("label",{htmlFor:"fetch-save-as"},"Save as"),e("input",{id:"fetch-save-as",class:"inp",type:"text",autocomplete:"off",spellcheck:!1,placeholder:o.askedName,value:n.saveAs,disabled:t.starting,onInput:e=>t.onChange({saveAs:e.target.value})}),e("span",{class:"hint"},"Taken from the server's filename when it sends one. An existing file is never overwritten; the new one gets “(1)” added.")),o.showAuth&&e("div",{class:"login"},e("button",{type:"button",class:"lnk","aria-expanded":n.authOpen?"true":"false",onClick:()=>t.onChange({authOpen:!n.authOpen})},e(g,{name:n.authOpen?"up":"chevron",size:12})," This link needs a login"),n.authOpen&&e(J,{auth:n.auth,onChange:t.onAuth}),o.authError&&e("span",{class:"hint err",role:"alert"},o.authError)),o.needsOrder&&e(ee,{order:n.order,onChange:e=>t.onChange({order:e})}),("http"===o.detected.kind||"torrent-url"===o.detected.kind)&&e("p",{class:"hint"},"A link always downloads in order, so you can watch while it arrives."),a&&r&&!n.torrent&&[e("div",{class:"or"},"or"),e("button",{type:"button",class:"drop",onClick:()=>i?.click()},e(g,{name:"torrent",size:22}),e("span",null,e("b",null,"Choose a .torrent file")," or drop it here",e("br",null),e("span",{class:"hint"},"Up to 2 MB, read in the browser and sent to the node")))],t.destination&&e("div",{class:"fld"},a&&e("label",null,"Destination"),e("div",{class:"dest-row"},e("div",{class:"dest",title:t.destination.path},e(g,{name:"folder",size:14}),e("span",null,t.destination.path)),t.onChooseFolder&&e("button",{type:"button",class:"btn",onClick:()=>t.onChooseFolder?.()},"Choose folder…")),t.destination.hint&&e("span",{class:"hint where"},t.destination.hint)),a&&e("div",{class:"dlg-f"},e("button",{type:"button",class:"btn",onClick:()=>t.onCancel?.()},"Cancel"),e("button",{type:"submit",class:"btn pri",disabled:!o.canStart||t.starting},t.starting?"Starting…":"Start download")))};function ne(e){return"FetchingMetadata"===e.state||"Resolving"===e.state?"bar indet":"Retrying"===e.state||"Paused"===e.state?"bar moving":"Stopped"===e.state||"Queued"===e.state||"Scheduled"===e.state||e.deleting?"bar paused":"Cancelled"===e.state?"bar fail":"Seeding"===e.state?"bar seed":"bar"}const oe=({icon:t,label:n,onClick:o,primary:s})=>e("button",{type:"button",class:{ib:!0,new:!!s},title:n,"aria-label":n,onClick:o},e(g,{name:t,size:14})),se=({row:t,actions:n,running:o,source:s,compact:i})=>{const{icon:r,tone:a}=function(e){return"Torrent"===e.kind?{icon:e.name.startsWith("magnet:")?"magnet":"torrent",tone:"t"}:"Node"===e.kind?{icon:"node",tone:"n"}:{icon:"globe",tone:"h"}}(t),l=function(e){if(e.deleting)return{text:"Deleting…",tone:"ps"};if(e.waitingForNode)return{text:"Waiting for the node",tone:"q"};switch(e.state){case"Queued":return{text:"Queued",tone:"q"};case"Scheduled":return{text:"Scheduled",tone:"q"};case"Resolving":return{text:"Connecting",tone:"meta"};case"FetchingMetadata":return{text:"Fetching metadata",tone:"meta"};case"Downloading":return{text:"Downloading",tone:"dl"};case"Verifying":return{text:"Checking pieces",tone:"meta"};case"Paused":return{text:"DiskFull"===e.pause_reason?"Paused · disk almost full":"Paused",tone:"mv"};case"Retrying":return{text:"Retrying",tone:"mv"};case"Seeding":return{text:"Seeding",tone:"sd"};case"Completed":return{text:"Completed",tone:"ok"};case"Stopped":return{text:T(e)?"Seeding paused":"Stopped",tone:"ps"};case"Cancelled":return{text:"Cancelled",tone:"err"};default:return{text:e.state,tone:"ps"}}}(t),d=function(e){return"Torrent"===e.kind&&["Downloading","Verifying","Paused"].includes(e.state)?e.in_order?"In order":"Fastest":null}(t),w=B(t),v=function(e,t={}){const n=t.now??Date.now(),o=c(e.done_bytes,e.total_bytes),s=e.total_bytes?`${h(e.done_bytes)} of ${h(e.total_bytes)}`:e.done_bytes?h(e.done_bytes):"",i=[],r=(e,t={})=>e&&i.push({text:e,...t});if(e.deleting)return r("Waiting for the node to confirm"),i;if(e.waitingForNode)return r("Starts when the node reports in"),r("It keeps going after you close this tab"),i;switch(e.state){case"Queued":r("Waiting for a free slot"),t.running&&r(`${t.running} ${1===t.running?"is":"are"} running`);break;case"Scheduled":r("Waits for the download window"),e.next_attempt_at&&e.next_attempt_at>n&&r(`starts in ${p((e.next_attempt_at-n)/1e3)}`);break;case"Resolving":r(t.source?`Contacting ${t.source}`:"Contacting the server");break;case"FetchingMetadata":r("Asking peers for the torrent info"),r(`${e.peers} ${1===e.peers?"peer":"peers"}`),r(b((n-e.started_at)/1e3));break;case"Downloading":r(o,{strong:!0}),r(s),r(u(e.down_bps)),"Torrent"===e.kind&&(r(u(e.up_bps,"↑")),r(`${e.peers} ${1===e.peers?"peer":"peers"}`)),r(f(e.done_bytes,e.total_bytes,e.down_bps)),e.restarted_from_zero&&r("The file changed on the server, so it started over"),t.source&&r(t.source);break;case"Verifying":r(o,{strong:!0}),r("Checking downloaded pieces after a restart"),r(`${h(e.done_bytes)} already on disk`);break;case"Paused":"DiskFull"===e.pause_reason?(r(e.reason??"Free space is below the floor"),r("Resumes by itself when there is room")):(r(o,{strong:!0}),r("Outside the download window"),r("Resumes by itself"));break;case"Retrying":r(e.retry_reason??e.reason??"Something went wrong",{error:!0}),r(`attempt ${e.attempt}`),e.next_attempt_at&&r(e.next_attempt_at>n?`Next try in ${p((e.next_attempt_at-n)/1e3)}`:"Trying again now"),e.done_bytes&&r(`${h(e.done_bytes)} kept`);break;case"Seeding":r(u(e.up_bps,"↑")),r(`${h(e.up_total)} uploaded`),r(`${e.peers} ${1===e.peers?"peer":"peers"}`),e.seeding_since&&r(`seeding for ${p((n-e.seeding_since)/1e3).replace(/ \d+[hm]$/,"")}, until you delete it`);break;case"Completed":if(r("100%",{strong:!0}),r(e.files.length>1?`${e.files.length} files · ${h(e.total_bytes??e.done_bytes)}`:h(e.total_bytes??e.done_bytes)),e.finished_at&&e.started_at){const t=(e.finished_at-e.started_at)/1e3;r(`took ${p(t)}`),t>0&&(e.total_bytes??e.done_bytes)&&r(`avg ${h((e.total_bytes??e.done_bytes)/t)}/s`)}break;case"Stopped":if(T(e)){r(`${h(e.up_total)} uploaded`),r(e.reason??"Seeding paused by you"),r("Resume shares it again");break}r(o,{strong:!0}),r(e.reason??"Stopped by you"),r("Resume continues from here");break;case"Cancelled":r(e.reason??"Stopped and its part deleted",{error:!!e.reason}),r("Resume starts from zero")}return i}(t,{running:o,source:s}),x="Completed"===t.state||"Seeding"===t.state?100:m(t.done_bytes,t.total_bytes),y=[];if(!t.deleting)switch(w.play&&y.push(e(oe,{icon:"play",label:P(t.state)?"Play":"Play while downloading",primary:!0,onClick:()=>n.play(t)})),t.state){case"Downloading":case"Verifying":case"Resolving":case"FetchingMetadata":case"Queued":"Downloading"!==t.state&&"Verifying"!==t.state||y.push(e(oe,{icon:"pause",label:"Pause",onClick:()=>n.pause(t)})),y.push(e(oe,{icon:"x",label:"Stop",onClick:()=>n.stop(t)}));break;case"Scheduled":case"Paused":"Scheduled"!==t.state&&"Window"!==t.pause_reason||y.push(e(oe,{icon:"play",label:"Start now",onClick:()=>n.resume(t,!0)})),y.push(e(oe,{icon:"x",label:"Stop",onClick:()=>n.stop(t)}));break;case"Retrying":y.push(e(oe,{icon:"retry",label:"Try now",onClick:()=>n.resume(t)})),y.push(e(oe,{icon:"x",label:"Stop",onClick:()=>n.stop(t)}));break;case"Stopped":y.push(e(oe,{icon:"play",label:"Resume",onClick:()=>n.resume(t)})),y.push(e(oe,{icon:"trash",label:"Delete",onClick:()=>n.remove(t)}));break;case"Seeding":y.push(e(oe,{icon:"pause",label:"Pause seeding",onClick:()=>n.pause(t)})),y.push(e(oe,{icon:"locate",label:"Show in folder",onClick:()=>n.showInFolder(t)})),y.push(e(oe,{icon:"trash",label:"Delete",onClick:()=>n.remove(t)}));break;case"Completed":y.push(e(oe,{icon:"locate",label:"Show in folder",onClick:()=>n.showInFolder(t)})),y.push(e(oe,{icon:"x",label:"Remove from list",onClick:()=>n.remove(t)}));break;case"Cancelled":y.push(e(oe,{icon:"retry",label:"Start again",onClick:()=>n.resume(t)})),y.push(e(oe,{icon:"x",label:"Remove from list",onClick:()=>n.remove(t)}))}return e("div",{key:t.download_id,class:{job:!0,compact:!!i},"data-state":t.deleting?"Deleting":t.state,"data-id":t.download_id,role:"listitem","aria-label":`${t.name}, ${l.text}`},e("span",{class:`kind ${a}`},e(g,{name:r,size:15})),e("div",{class:"title"},e("span",{class:"nm",title:t.name},t.name),e("span",{class:`pill ${l.tone}`},l.text),d&&e("span",{class:"pill meta"},d)),e("div",{class:"acts"},y),e("div",{class:ne(t),role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(x),"aria-label":`${t.name} progress`},e("i",{style:{width:`${x}%`}})),e("div",{class:"stats"},v.map((t=>t.strong?e("b",null,t.text):e("span",{class:{err:!!t.error}},t.text))),!w.play&&w.switchToInOrder&&e("button",{type:"button",class:"lnk inline",onClick:()=>n.setOrder(t,!0)},"Switch to in order to watch"),w.play&&"Torrent"===t.kind&&t.in_order&&!P(t.state)&&e("button",{type:"button",class:"lnk inline",onClick:()=>n.setOrder(t,!1)},"Switch to fastest")))},ie={started:"fetch",queued:"fetch",stuck:"warn",renamed:"file",completed:"check",error:"warn"},re=({notices:t,onDismiss:n})=>t.length?e("div",{class:"toasts","aria-live":"polite"},t.map((t=>e("div",{class:{toast:!0,bad:"stuck"===t.kind||"error"===t.kind},"data-notice":t.kind,key:t.id},e(g,{name:ie[t.kind],size:18}),e("div",{class:"t"},e("b",null,t.title),e("span",{title:t.detail},t.detail)),t.action&&e("button",{type:"button",class:"btn",onClick:()=>{t.action.run(),n(t.id)}},t.action.label),e("button",{type:"button",class:"ib","aria-label":"Dismiss",onClick:()=>n(t.id)},e(g,{name:"x",size:12})))))):null,ae=({icon:t,title:n,body:o,action:s})=>e("div",{class:"empty",role:"status"},e(g,{name:t,size:28}),e("b",null,n),e("span",null,o),s&&e("button",{type:"button",class:"btn pri",onClick:s.onClick},s.label)),le=()=>e(ae,{icon:"fetch",title:"No downloads yet",body:"Press Fetch and paste a link. Downloads keep running after you close this tab, and they show here when you come back."}),de=({nodeName:t,folder:n})=>e(ae,{icon:"fetch",title:"Nothing downloading",body:`Paste a link above. It downloads onto ${t}${n?`, into ${n}`:""}.`}),ce=({onSignIn:t})=>e(ae,{icon:"lock",title:"Sign in to PhirePass",body:"Your downloads are tied to your account and the nodes you can reach.",action:{label:"Sign in",onClick:t}}),he=({nodeName:t,onRetry:n})=>e(ae,{icon:"signal",title:`Can't reach ${t}`,body:"If the machine is still running, its downloads carry on. They will show here when it reconnects.",action:n?{label:"Try again",onClick:n}:void 0}),pe=()=>e(ae,{icon:"warn",title:"Downloads are not available here",body:"This page's connection library is too old to start downloads. Reload after the site updates."}),ue=()=>e("div",{class:"empty",role:"status"},e("span",{class:"spin","aria-hidden":"true"}),e("span",null,"Loading downloads…")),fe=({blocker:t,onAction:n,onClose:o})=>e("div",{class:"blocker","data-blocker":t.id},e("div",{class:"note "+("off"===t.id?"info":"warn"),role:"status"},e(g,{name:"off"===t.id?"fetch":"warn",size:14}),e("div",null,e("b",null,t.title)," ",t.body)),t.secondary&&e("p",{class:"hint"},t.secondary),(o||t.action&&n)&&e("div",{class:"dlg-f"},o&&e("button",{type:"button",class:"btn",onClick:o},"Close"),t.action&&n&&e("button",{type:"button",class:"btn pri",onClick:n},t.action))),be="phirepass.downloader.torrent-ack",ge=n(class extends o{constructor(e){super(),!1!==e&&this.__registerHost(),this.__attachShadow(),this.fetchCompleted=s(this,"phirepassFetchCompleted"),this.play=s(this,"phirepassPlay"),this.activeCount=s(this,"phirepassActiveCount"),this.showInFolder=s(this,"phirepassShowInFolder"),this.openNodeSettings=s(this,"phirepassOpenNodeSettings"),this.signIn=s(this,"phirepassSignIn")}get el(){return this}ownChannel=!1;msgId=y;noticeId=1;seenNotices=new Set;torrentAcked=function(){try{return"1"===window.localStorage.getItem(be)}catch{return!1}}();noticeTimers=new Map;whereMsgId;nodeId;nodeLabel;token;channel;connected=!1;channelFactory;browsingService;browsingPath;compact=!1;streamBase;canConfigure=!1;inlinePlayer=!0;serverHost="phirepass.com";serverPort=443;serverId;allowInsecure=!1;heartbeatInterval=3e4;fetchCompleted;play;activeCount;showInFolder;openNodeSettings;signIn;connection="connecting";caps=null;jobs={};tab="active";drawerOpen=!1;dialogOpen=!1;unread=0;form=z;where=null;starting=null;refusal=null;confirm=null;notices=[];subDir=null;picker=null;player=null;get name(){return this.nodeLabel||this.nodeId}get ch(){return this.channel??this.ownedChannel}ownedChannel;async componentWillLoad(){this.channel?this.adoptChannel():await this.openOwnChannel()}disconnectedCallback(){this.noticeTimers.forEach((e=>window.clearTimeout(e))),this.noticeTimers.clear(),this.starting?.silence&&window.clearTimeout(this.starting.silence),this.ownChannel&&this.ownedChannel&&(this.ownedChannel.stop_heartbeat(),this.ownedChannel.disconnect())}onChannel(){this.channel&&this.adoptChannel()}onConnected(e,t){this.channel&&(e&&!t?this.subscribe():!e&&t&&(this.connection="unreachable"))}onBrowsing(){this.where=null,this.dialogOpen&&this.askWhere()}onNode(e,t){e!==t&&(this.jobs={},this.caps=null,this.where=null,this.channel?this.connected&&this.subscribe():this.ownedChannel&&(this.ownedChannel.disconnect(),this.openOwnChannel()))}adoptChannel(){this.ownChannel=!1,x(this.channel)?(this.connection="connecting",this.connected&&this.subscribe()):this.connection="unsupported"}endpoint(){return`${this.allowInsecure?"ws":"wss"}://${this.serverHost}${!this.allowInsecure&&443===this.serverPort||this.allowInsecure&&80===this.serverPort?"":`:${this.serverPort}`}/api/web/ws`}defaultStreamBase(){return`${this.allowInsecure?"http":"https"}://${this.serverHost}${!this.allowInsecure&&443===this.serverPort||this.allowInsecure&&80===this.serverPort?"":`:${this.serverPort}`}`}async openOwnChannel(){if(this.ownChannel=!0,!this.token)return void(this.connection="signed-out");if(!this.nodeId)return;this.channelFactory||await r();const e=this.channelFactory?this.channelFactory(this.endpoint(),this.nodeId,this.serverId):this.serverId?new a(this.endpoint(),this.nodeId,this.serverId):new a(this.endpoint(),this.nodeId);this.ownedChannel=e,x(e)?(e.on_connection_open((()=>e.authenticate(this.token,this.nodeId))),e.on_connection_close((()=>{"signed-out"!==this.connection&&(this.connection="unreachable")})),e.on_connection_error((()=>{"signed-out"!==this.connection&&(this.connection="unreachable")})),e.on_connection_message((()=>{})),e.on_protocol_message((e=>this.dispatch(e.data.web))),this.connection="connecting",e.connect()):this.connection="unsupported"}reconnect(){this.ownChannel?(this.ownedChannel?.disconnect(),this.openOwnChannel()):this.connected&&this.subscribe()}async receive(e){this.dispatch(e.data.web)}dispatch(e){if(e.type===l.AuthSuccess)return this.ownedChannel?.start_heartbeat(Math.max(3e4,this.heartbeatInterval)),void this.subscribe();if(e.type!==l.Error){if(C(e))switch(e.type){case"DownloadCaps":e.node_id===this.nodeId&&(this.caps=e.caps,this.connection="ready");break;case"DownloadProgress":e.node_id===this.nodeId&&this.onProgress(e.job);break;case"DownloadAccepted":this.onAccepted(e.msg_id,e.download_id);break;case"DownloadWhereAnswer":e.msg_id===this.whereMsgId&&(this.where={saves_to:e.saves_to,mapped:e.mapped});break;case"DownloadFoldersAnswer":this.picker&&e.msg_id===this.picker.msgId&&(this.picker={...this.picker,folders:[...e.folders].sort(((e,t)=>e.localeCompare(t)))})}}else this.handleError(e)}handleError(e){if(void 0!==e.msg_id&&e.msg_id===this.starting?.msgId)return this.clearStarting(),void(this.refusal={tone:"err",title:"Refused",body:e.message||"The server refused this download."});this.picker&&e.msg_id===this.picker.msgId?this.picker={...this.picker,folders:[],error:e.message}:void 0!==e.msg_id&&e.msg_id>=y?this.notify("error","That did not work",e.message||"The server refused it."):this.ownChannel&&e.kind===d.Authentication&&(this.connection="signed-out")}subscribe(){const e=this.ch;x(e)?(this.jobs={},e.send_download_subscribe({Node:this.nodeId}),this.dialogOpen&&this.askWhere()):this.connection="unsupported"}onProgress(e){const t=this.jobs[e.download_id],{jobs:n,completed:o}=function(e,t){const n=e[t.download_id];if("Deleted"===t.state){if(!n)return{jobs:e,first:!1};const{[t.download_id]:o,...s}=e;return{jobs:s,first:!1}}const o=t.deleting||n?.deleting||void 0;return{jobs:{...e,[t.download_id]:{...t,deleting:o}},completed:n&&!P(n.state)&&P(t.state)?t:void 0,first:!n}}(this.jobs,e);this.jobs=n,this.emitCount(),this.starting?.downloadId!==e.download_id||t||this.onFirstProgress(e),o&&(this.fetchCompleted.emit({download_id:e.download_id,dest_root:e.dest_root,sub_dir:e.sub_dir,name:e.name}),!this.drawerOpen&&this.compact&&this.unread++,this.notify("completed","Download complete",`${e.name} → ${E(e)}`,{label:"Show",run:()=>this.showInFolder.emit({path:E(e),name:e.name})}));const s=this.jobs[e.download_id];s&&function(e,t=3600){return"Retrying"===e.state&&function(e,t=3600){let n=0;for(let o=0;o<e;o++)n+=Math.min(10*2**o,t);return n}(e.attempt,t)>=86400}(s)&&!this.seenNotices.has(`stuck:${e.download_id}`)&&(this.seenNotices.add(`stuck:${e.download_id}`),this.notify("stuck","Still retrying after a day",`${e.name} · ${e.retry_reason??"no answer"}`,{label:"Show",run:()=>this.showRetrying()},!0))}onAccepted(e,t){if(!this.starting||this.starting.msgId!==e)return;if(this.jobs[t])return void this.onFirstProgress(this.jobs[t]);const n=window.setTimeout((()=>this.nodeSilent(t)),8e3);this.starting={...this.starting,downloadId:t,silence:n}}nodeSilent(e){if(this.starting?.downloadId!==e||this.jobs[e])return;const t=this.starting.askedName??"Download",n=Date.now(),o={download_id:e,kind:"Unknown",name:t,dest_root:this.where?.saves_to??this.caps?.folder??"",sub_dir:null,state:"Queued",done_bytes:0,total_bytes:null,down_bps:0,up_bps:0,peers:0,in_order:!0,started_at:n,finished_at:null,reason:null,requested_by:null,files:[],up_total:0,pause_reason:null,seeding_since:null,info_hash:null,retry_reason:null,attempt:0,next_attempt_at:null,restarted_from_zero:!1,waitingForNode:!0};this.jobs={...this.jobs,[e]:o},this.clearStarting(),this.closeDialog(!0),this.notify("queued",`Waiting for ${this.name}`,`${t} starts when the node reports in.`)}onFirstProgress(e){const t=this.starting?.askedName;if(this.clearStarting(),"Cancelled"!==e.state){if(this.closeDialog(!0),"Queued"===e.state){const e=Object.values(this.jobs).filter((e=>"Downloading"===e.state)).length;this.notify("queued","Added to the queue",`${e} ${1===e?"download is":"downloads are"} already running on this node`)}else this.notify("started","Download started",`${e.name} → ${E(e)}`);(function(e,t){return!!e&&e!==t&&/ \(\d+\)(\.[^.]*)?$/.test(t)})(t,e.name)&&this.notify("renamed",`Saved as ${e.name}`,`A file named ${t} was already in ${E(e)}`)}else{const t=e.reason??"The node refused this download.";!function(e){return!!e&&/not enough (disk )?space|disk (is )?full|needs [\d.]+ ?[kmgt]?b\b.*\bfree\b/i.test(e)}(t)?!this.dialogOpen&&this.compact||(this.refusal={tone:"err",title:"Refused",body:t}):this.confirm={kind:"space",reason:t}}}clearStarting(){this.starting?.silence&&window.clearTimeout(this.starting.silence),this.starting=null}emitCount(){this.activeCount.emit({n:Object.values(this.jobs).filter(I).length})}notify(e,t,n,o,s=!1){const i=this.noticeId++;this.notices=[...this.notices.slice(-2),{id:i,kind:e,title:t,detail:n,action:o,sticky:s}],s||this.noticeTimers.set(i,window.setTimeout((()=>this.dismiss(i)),6e3))}dismiss(e){const t=this.noticeTimers.get(e);t&&(window.clearTimeout(t),this.noticeTimers.delete(e)),this.notices=this.notices.filter((t=>t.id!==e))}showRetrying(){this.tab="retrying",this.drawerOpen=!0}async openFetch(e){void 0!==e&&e!==this.browsingPath&&(this.browsingPath=e),this.drawerOpen=!0,this.unread=0,this.dialogOpen=!0,this.refusal=null,this.askWhere()}async toggleDrawer(e){this.drawerOpen=e??!this.drawerOpen,this.drawerOpen&&(this.unread=0)}async jobForPath(e){const t=Object.values(this.jobs).find((t=>!P(t.state)&&"Cancelled"!==t.state&&function(e){return`${U(E(e),e.name)}.phirepass-part`}(t)===e));return t?{download_id:t.download_id,name:t.name}:null}async deleteDownload(e,t=!1){const n=this.jobs[e];n&&this.sendDelete(n,t)}async torrentPathFor(e){const t=this.caps?.folder;if(!t||!this.caps?.torrents||!/\.torrent$/i.test(e)||V(this.caps,this.name,this.canConfigure))return null;const n=t.endsWith("/")?t:`${t}/`;return e.startsWith(n)?e.slice(n.length):null}async startTorrentPath(e,t=!1){const n=await this.torrentPathFor(e),o=this.ch;if(null===n||!x(o))return!1;const s=this.nextMsgId();this.starting={msgId:s,askedName:n.split("/").pop()?.replace(/\.torrent$/i,"")};const i=n.includes("/")?n.slice(0,n.lastIndexOf("/")):null;return o.send_download_start(this.nodeId,{TorrentPath:{path:n}},i,null,t,{source_auth:null,ignore_window:!1},s),this.drawerOpen=!0,!0}nextMsgId(){return this.msgId=this.msgId>=4294967280?y:this.msgId+1,this.msgId}browsing(){return this.compact&&this.browsingService&&this.browsingPath?{service_id:this.browsingService,path:this.browsingPath}:null}askWhere(){const e=this.browsing(),t=this.ch;e&&x(t)&&"ready"===this.connection&&(this.whereMsgId=this.nextMsgId(),t.send_download_where(this.nodeId,e,this.whereMsgId))}destination(){if(this.browsing())return this.where?this.where.mapped?{path:this.where.saves_to}:{path:this.where.saves_to,hint:`This folder is outside ${this.name}'s download folder. The file will be saved to ${this.where.saves_to}.`}:{path:this.browsingPath,hint:"Asking the node where this lands…"};const e=this.caps?.folder;return e?{path:U(e,this.subDir)}:null}formReady(){return!(this.starting||"ready"!==this.connection||this.browsing()&&!this.where)}async pickTorrent(e){const t=function(e){const t=function(e){return/\.torrent$/i.test(e.name)?e.size>2097152?{ok:!1,reason:"too-large"}:{ok:!0}:{ok:!1,reason:"not-torrent"}}(e);return t.ok?{name:e.name,size:e.size}:{name:e.name,size:e.size,error:t.reason}}(e);t.error||(t.contents=new Uint8Array(await e.arrayBuffer())),this.form={...this.form,torrent:t,text:"",order:null},this.refusal=null}start(e=!1){const t=F(this.form,this.caps,this.formReady()),n=function(e){const t={source_auth:null,ignore_window:!1};if(e.torrent)return!e.torrent.contents||e.torrent.error?null:{source:{TorrentFile:{name:e.torrent.name,contents:e.torrent.contents}},inOrder:"in"===e.order,options:t};const n=$(e.text);if("magnet"===n.kind)return{source:{Magnet:{uri:n.uri}},inOrder:"in"===e.order,options:t};if("http"===n.kind||"torrent-url"===n.kind){const o=e.authOpen?D(e.auth):{auth:null};if("error"in o&&o.error)return null;const s=e.saveAs.trim();return{source:{Http:{url:n.url,save_as:s||null}},inOrder:!0,options:{...t,source_auth:o.auth}}}return null}(this.form),o=this.ch;if(!t.canStart||!n||!x(o))return;if(t.isTorrent&&!this.torrentAcked&&!e)return void(this.confirm={kind:"torrent",dontAsk:!1});const s=this.nextMsgId(),i=t.askedName??(this.form.torrent?this.form.torrent.name.replace(/\.torrent$/i,""):"magnet"===t.detected.kind?function(e){const t=/urn:btih:([a-z0-9]+)/i.exec(e);if(!t)return e.length>40?`${e.slice(0,37)}…`:e;const n=t[1];return`magnet:?xt=urn:btih:${n.slice(0,4)}…${n.slice(-4)}`}(t.detected.uri):void 0);this.starting={msgId:s,askedName:i},this.refusal=null;const r=this.browsing();o.send_download_start(this.nodeId,n.source,r?null:this.subDir,r,n.inOrder,n.options,s)}closeDialog(e=!1){this.dialogOpen=!1,this.refusal=null,e&&(this.form=z,this.drawerOpen=!0)}sendStop(e,t){const n=this.ch;x(n)&&n.send_download_stop(e.download_id,t,this.nextMsgId())}sendDelete(e,t){const n=this.ch;x(n)&&(n.send_download_delete(e.download_id,t,this.nextMsgId()),this.jobs={...this.jobs,[e.download_id]:{...e,deleting:!0}})}actions={play:e=>this.playRow(e),pause:e=>this.sendStop(e,!1),resume:(e,t=!1)=>{const n=this.ch;x(n)&&n.send_download_resume(e.download_id,t,this.nextMsgId())},stop:e=>this.confirm={kind:"stop",row:e,discard:!1},remove:e=>{"Completed"===e.state||"Seeding"===e.state||"Stopped"===e.state?this.confirm={kind:"delete",row:e,deleteFile:!1}:this.sendDelete(e,!1)},setOrder:(e,t)=>{t||this.player?.downloadId!==e.download_id?this.sendOrder(e,t):this.confirm={kind:"fastest",row:e}},showInFolder:e=>this.showInFolder.emit({path:E(e),name:e.name})};sendOrder(e,t){const n=this.ch;x(n)&&n.send_download_set_order(e.download_id,t,this.nextMsgId())}playRow(e){const t=B(e);if(!t.play||!t.file)return;const n=(o=this.streamBase||this.defaultStreamBase(),s=this.nodeId,i=e.download_id,r=t.file.index,`${o.replace(/\/+$/,"")}/api/web/stream/${encodeURIComponent(s)}/${encodeURIComponent(i)}/${r}`);var o,s,i,r;!this.play.emit({src:n,name:t.file.name,downloadId:e.download_id}).defaultPrevented&&this.inlinePlayer&&(this.player={src:n,name:t.file.name,downloadId:e.download_id})}clearFinished(){Object.values(this.jobs).filter(N).forEach((e=>this.sendDelete(e,!1)))}canPickFolder(){return!!this.caps?.folder&&"function"==typeof this.ch?.send_download_folders}listFolders(e){const t=this.nextMsgId();this.picker={path:e,folders:null,msgId:t,newName:null},this.ch?.send_download_folders?.(this.nodeId,e.length?e.join("/"):null,t)}savePicker(){if(!this.picker)return;const e=[...this.picker.path],t=this.picker.newName?.trim();t&&e.push(t),this.subDir=e.length?e.join("/"):null,this.picker=null}renderConfirm(){const t=this.confirm;if(!t)return null;const n=()=>this.confirm=null;switch(t.kind){case"stop":return e(L,{row:t.row,discard:t.discard,onDiscard:e=>this.confirm={...t,discard:e},onCancel:n,onConfirm:()=>{this.sendStop(t.row,t.discard),this.confirm=null}});case"delete":return e(Q,{row:t.row,nodeName:this.name,deleteFile:t.deleteFile,onDeleteFile:e=>this.confirm={...t,deleteFile:e},onCancel:n,onConfirm:()=>{this.sendDelete(t.row,t.deleteFile),this.confirm=null}});case"fastest":return e(H,{row:t.row,onCancel:n,onConfirm:()=>{this.player=null,this.sendOrder(t.row,!1),this.confirm=null}});case"torrent":return e(K,{nodeName:this.name,dontAsk:t.dontAsk,onDontAsk:e=>this.confirm={...t,dontAsk:e},onCancel:n,onConfirm:()=>{t.dontAsk&&(function(){try{window.localStorage.setItem(be,"1")}catch{}}(),this.torrentAcked=!0),this.confirm=null,this.start(!0)}});case"space":return e(Y,{reason:t.reason,onClose:n})}}renderForm(t){const n=this.caps?V(this.caps,this.name,this.canConfigure):null,o=()=>this.openNodeSettings.emit({nodeId:this.nodeId});if(n)return"dialog"===t?e("div",{class:"dlg"},e("div",{class:"dlg-h"},e(g,{name:"fetch"}),e("h4",null,"Fetch into this folder")),e(fe,{blocker:n,onAction:o,onClose:()=>this.closeDialog()})):e(fe,{blocker:n,onAction:o});const s=F(this.form,this.caps,this.formReady());return e(te,{form:this.form,model:s,caps:this.caps,layout:t,title:this.browsing()?"Fetch into this folder":"Add download",destination:"dialog"===t||this.browsing()?this.destination():null,starting:!!this.starting,refusal:this.refusal,onChange:e=>{this.form={...this.form,...e},("text"in e||"torrent"in e)&&(this.refusal=null)},onAuth:e=>this.form={...this.form,auth:{...this.form.auth,...e}},onPickTorrent:e=>{this.pickTorrent(e)},onStart:()=>this.start(),onCancel:()=>this.closeDialog()})}renderRows(t){const n=t.filter((e=>"Downloading"===e.state)).length;return e("div",{class:"jobs",role:"list"},function(e){return[...e].sort(((e,t)=>A[e.state]-A[t.state]||(t.finished_at??t.started_at)-(e.finished_at??e.started_at)))}(t).map((t=>e(se,{row:t,actions:this.actions,running:n,compact:this.compact}))))}renderStatus(){switch(this.connection){case"unsupported":return e(pe,null);case"signed-out":return e(ce,{onSignIn:()=>this.signIn.emit()});case"unreachable":return e(he,{nodeName:this.name,onRetry:()=>this.reconnect()});case"connecting":return e(ue,null);default:return null}}renderCompact(){const t=Object.values(this.jobs),n=j(t),o=this.renderStatus();if("unsupported"===this.connection)return null;const s=t.some(N),i=!this.drawerOpen&&(n.active>0||this.unread>0),r=[`${n.active} active`,null===n.percent||this.drawerOpen?"":`${Math.round(n.percent)}%`,u(n.downBps)].filter(Boolean).join(" · ");return[this.drawerOpen&&e("section",{class:"drawer","aria-label":"Transfers"},e("div",{class:"drawer-h"},e("h4",null,"Transfers"),e("span",{class:"sum"},r),e("span",{class:"sp"}),s&&e("button",{type:"button",class:"lnk",onClick:()=>this.clearFinished()},"Clear finished"),e("button",{type:"button",class:"ib","aria-label":"Collapse transfers",title:"Collapse",onClick:()=>this.drawerOpen=!1},e(g,{name:"chevron",size:12}))),e("div",{class:"drawer-b"},o??(t.length?this.renderRows(t):e(le,null)))),i&&e("button",{type:"button",class:"strip","aria-label":"Show transfers",onClick:()=>this.toggleDrawer(!0)},e("h4",null,"Transfers"),e("span",{class:"bar"},e("i",{style:{width:`${n.percent??0}%`}})),e("span",{class:"sum"},this.unread&&!n.active?`${this.unread} finished`:r),e(g,{name:"up",size:12})),this.dialogOpen&&e(W,{label:"Fetch into this folder",onClose:()=>this.closeDialog()},o&&"ready"!==this.connection?e("div",{class:"dlg"},o,e("div",{class:"dlg-f"},e("button",{type:"button",class:"btn",onClick:()=>this.closeDialog()},"Close"))):this.renderForm("dialog"))]}renderStandalone(){const t=this.renderStatus(),n=Object.values(this.jobs),o={active:[],finished:[],retrying:[]};n.forEach((e=>{return o[(t=e,"Retrying"===t.state?"retrying":T(t)?"finished":R.has(t.state)?"active":"finished")].push(e);var t}));const s=j(n),i=o[this.tab],r=this.caps?.folder?U(this.caps.folder,this.subDir):null;return e("section",{class:"standalone"},e("header",{class:"sa-head"},e("div",{class:"sa-title"},e("h3",null,"Downloads"),e("span",{class:"node"},this.name),s.downBps>0&&e("span",{class:"sum"},u(s.downBps))),r&&e("span",{class:"saving"},"saving to ",e("code",null,r),this.caps&&this.caps.folder_free_bytes>0&&e("span",{class:"free"}," · ",h(this.caps.folder_free_bytes)," free"))),t??[e("div",{class:"sa-add"},this.renderForm("inline"),r&&!V(this.caps,this.name,this.canConfigure)&&e("div",{class:"sa-dest"},e("span",{class:"dest"},e(g,{name:"folder",size:14}),e("span",null,r)),this.canPickFolder()&&e("button",{type:"button",class:"btn",onClick:()=>this.listFolders(this.subDir?this.subDir.split("/"):[])},"Choose folder…"))),e("div",{class:"tabs",role:"tablist","aria-label":"Downloads"},[["active","Active"],["finished","Finished"],["retrying","Retrying"]].map((([t,n])=>e("button",{type:"button",role:"tab","aria-selected":this.tab===t?"true":"false",class:{on:this.tab===t},onClick:()=>this.tab=t},n,e("b",null,o[t].length))))),"finished"===this.tab&&o.finished.length>0&&e("div",{class:"tab-h"},e("span",null,o.finished.length," finished"),o.finished.some(N)&&e("button",{type:"button",class:"lnk",onClick:()=>this.clearFinished()},"Clear finished")),i.length?this.renderRows(i):0===n.length?e(de,{nodeName:this.name,folder:r}):e("div",{class:"muted pad"},"retrying"===this.tab?"Nothing is retrying.":"finished"===this.tab?"Nothing has finished yet.":"Nothing is running.")])}render(){return e(i,{key:"6a7316df730c5bc4bc588f7d05e19033d98a9d0a",class:{compact:this.compact,standalone:!this.compact}},this.compact?this.renderCompact():this.renderStandalone(),this.renderConfirm(),this.picker&&e(X,{key:"412dc8107ea30420f022a49f188ea020eabd46f5",root:this.caps?.folder??"",path:this.picker.path,folders:this.picker.folders,error:this.picker.error,newName:this.picker.newName,onOpen:e=>this.listFolders([...this.picker.path,e]),onUp:e=>this.listFolders(this.picker.path.slice(0,e)),onNewName:e=>this.picker={...this.picker,newName:e},onCancel:()=>this.picker=null,onSave:()=>this.savePicker()}),this.player&&e("div",{key:"61bc6c3ab32346d87c0ed02280182fdae234eb71",class:"overlay player"},e("phirepass-media-player",{key:"59d99ac6289a146ba106e9cb8682d5f7b4383e26",src:this.player.src,name:this.player.name,status:this.playerStatus(),ready:this.playerReady(),positionKey:`dl:${this.player.downloadId}`,onPhirepassPlayerClose:()=>this.player=null})),e(re,{key:"fa27f16c8f72435939e51b48d92b6f10b0535d80",notices:this.notices,onDismiss:e=>this.dismiss(e)}))}playerRow(){return this.player?this.jobs[this.player.downloadId]:void 0}playerStatus(){const e=this.playerRow();if(!e)return this.player?"On the node":void 0;if(P(e.state))return"On the node";const t=e.total_bytes?` · ${(e.done_bytes/e.total_bytes*100).toFixed(1)}%`:"";return`${"Downloading"===e.state?"Downloading":e.state}${t}`}playerReady(){const e=this.playerRow();if(!e||P(e.state))return;const t=B(e);return t.file?.ready_from_start}static get watchers(){return{channel:[{onChannel:0}],connected:[{onConnected:0}],browsingPath:[{onBrowsing:0}],browsingService:[{onBrowsing:0}],nodeId:[{onNode:0}]}}static get style(){return":host{--card:220 18% 10%;--bg:216 18% 7%;--border:220 15% 18%;--primary:160 60% 45%;--primary-foreground:220 20% 7%;--destructive:0 70% 50%;--muted:220 15% 13%;--muted-foreground:215 10% 52%;--foreground:210 20% 90%;--amber:38 75% 55%;--blue:206 72% 63%;--radius:0.375rem;display:block;color:hsl(var(--foreground));font-family:ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;font-size:13px;line-height:1.45;container-type:inline-size}:host(.standalone){position:relative;height:100%;background:hsl(var(--card));border:1px solid hsl(var(--border));border-radius:var(--radius);overflow:auto}:host(.compact){flex:none}*{box-sizing:border-box}button{font:inherit;color:inherit;cursor:pointer}button:disabled{cursor:not-allowed}:focus-visible{outline:2px solid hsl(var(--primary));outline-offset:2px}.hidden-input{display:none}.mono,code,.stats,.sum,.inp,.dest,.detect .host{font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace}code{font-size:12px}.muted{color:hsl(var(--muted-foreground))}.pad{padding:18px 14px}.ib{width:28px;height:28px;display:inline-grid;place-items:center;border-radius:4px;border:1px solid transparent;background:transparent;color:hsl(var(--muted-foreground));flex:none;padding:0}.ib:hover:not(:disabled){background:hsl(var(--muted));color:hsl(var(--foreground))}.ib:disabled{opacity:0.4}.ib.new{color:hsl(var(--primary));border-color:hsl(var(--primary) / 0.55);background:hsl(var(--primary) / 0.12)}.btn{border-radius:4px;padding:7px 14px;font-size:12px;font-weight:600;border:1px solid hsl(var(--border));background:hsl(var(--muted));white-space:nowrap;display:inline-flex;align-items:center;gap:6px;text-decoration:none;color:hsl(var(--foreground))}.btn:hover:not(:disabled){border-color:hsl(var(--muted-foreground))}.btn.pri{background:hsl(var(--primary));border-color:hsl(var(--primary));color:hsl(var(--primary-foreground))}.btn.dng{background:hsl(var(--destructive));border-color:hsl(var(--destructive));color:#fff}.btn:disabled{opacity:0.45}.lnk{background:none;border:0;color:hsl(var(--muted-foreground));font-size:11px;padding:2px 4px;display:inline-flex;align-items:center;gap:4px}.lnk:hover{color:hsl(var(--foreground))}.lnk.inline{color:hsl(var(--primary));padding:0}.pill{font-size:10px;font-weight:600;text-transform:uppercase;letter-spacing:0.05em;padding:2px 7px;border-radius:3px;white-space:nowrap;flex:none}.pill.dl{background:hsl(var(--primary) / 0.18);color:hsl(var(--primary))}.pill.meta,.pill.sd{background:hsl(var(--blue) / 0.18);color:hsl(var(--blue))}.pill.mv{background:hsl(var(--amber) / 0.18);color:hsl(var(--amber))}.pill.ok{background:hsl(var(--primary));color:hsl(var(--primary-foreground))}.pill.err{background:hsl(var(--destructive) / 0.2);color:hsl(var(--destructive))}.pill.ps,.pill.q{background:hsl(var(--muted));color:hsl(var(--muted-foreground))}.bar{display:block;height:5px;border-radius:3px;background:hsl(var(--muted));overflow:hidden;position:relative}.bar i{display:block;height:100%;background:hsl(var(--primary));border-radius:3px;transition:width 0.6s linear}.bar.indet i{width:30% !important;animation:slide 1.3s ease-in-out infinite;background:hsl(var(--blue))}.bar.paused i{background:hsl(var(--muted-foreground))}.bar.fail i{background:hsl(var(--destructive))}.bar.moving i{background:hsl(var(--amber))}.bar.seed i{background:hsl(var(--blue))}@keyframes slide{0%{transform:translateX(-100%)}100%{transform:translateX(340%)}}.jobs{display:flex;flex-direction:column}.job{display:grid;grid-template-columns:28px minmax(0, 1fr) auto;gap:4px 10px;padding:10px 12px;border-bottom:1px solid hsl(var(--border) / 0.6);align-items:center}.job:last-child{border-bottom:0}.job .kind{grid-row:span 3;align-self:start;width:28px;height:28px;border-radius:6px;display:grid;place-items:center;background:hsl(var(--muted));color:hsl(var(--muted-foreground))}.job .kind.t{color:hsl(var(--blue))}.job .kind.h{color:hsl(var(--primary))}.job .kind.n{color:hsl(var(--amber))}.job .title{display:flex;gap:8px;align-items:center;min-width:0}.job .title .nm{font-weight:500;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}.job .acts{display:flex;gap:2px;grid-row:1;grid-column:3}.job .bar,.job .stats{grid-column:2 / 4}.stats{display:flex;flex-wrap:wrap;gap:4px 14px;font-size:11px;color:hsl(var(--muted-foreground));font-variant-numeric:tabular-nums}.stats b{color:hsl(var(--foreground));font-weight:500}.stats .err{color:hsl(var(--destructive))}.job[data-state='Deleting']{opacity:0.6}.drawer{border-top:1px solid hsl(var(--border));background:hsl(var(--bg));display:flex;flex-direction:column;max-height:min(46vh, 380px)}.drawer-h{display:flex;align-items:center;gap:10px;padding:6px 12px;border-bottom:1px solid hsl(var(--border));flex:none}.drawer-h h4,.strip h4{margin:0;font-size:12px;font-weight:600;letter-spacing:0.04em;text-transform:uppercase}.sum{color:hsl(var(--muted-foreground));font-size:11px;font-variant-numeric:tabular-nums}.sp{flex:1}.drawer-b{overflow:auto;min-height:0}.strip{display:flex;align-items:center;gap:10px;padding:7px 12px;border:0;border-top:1px solid hsl(var(--border));background:hsl(var(--bg));width:100%;text-align:left}.strip .bar{flex:1 1 120px}.overlay{position:absolute;inset:0;background:rgba(5, 7, 9, 0.6);display:grid;place-items:center;padding:14px;z-index:20}:host(.standalone) .overlay{position:fixed}.modal{width:min(100%, 420px);max-height:100%;overflow:auto;background:hsl(var(--card));border:1px solid hsl(var(--border));border-radius:8px;box-shadow:0 20px 50px -10px rgba(0, 0, 0, 0.7)}.modal.wide{width:min(100%, 480px)}.dlg,.fetch-form.dialog{padding:16px;display:flex;flex-direction:column;gap:14px}.dlg h4,.dlg-h h4{margin:0;font-size:14px;font-weight:600}.dlg-h{display:flex;align-items:center;gap:10px;color:hsl(var(--primary))}.dlg-h h4{color:hsl(var(--foreground))}.dlg-f{display:flex;justify-content:flex-end;gap:8px;flex-wrap:wrap}.dlg-f .left{margin-right:auto}.dtx{margin:0;font-size:13px}.hint{font-size:11px;color:hsl(var(--muted-foreground));margin:0}.hint.block{display:block;margin-top:2px}.hint.err{color:hsl(var(--destructive))}.hint.where{color:hsl(var(--amber))}.fld{display:flex;flex-direction:column;gap:6px;min-width:0}.fld>label,.fld>span:first-child,legend{font-size:11px;text-transform:uppercase;letter-spacing:0.05em;color:hsl(var(--muted-foreground))}.inp{width:100%;min-width:0;background:hsl(var(--muted));border:1px solid hsl(var(--border));border-radius:4px;color:hsl(var(--foreground));padding:8px 10px;font-size:12px}.inp:focus{outline:none;border-color:hsl(var(--primary))}.inline-row{display:flex;gap:8px;align-items:stretch}.detect{display:flex;align-items:center;gap:8px;font-size:12px;color:hsl(var(--muted-foreground));min-height:20px;min-width:0}.detect .host{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.note{display:flex;gap:8px;align-items:flex-start;font-size:12px;line-height:1.45;padding:8px 10px;border-radius:4px;border:1px solid hsl(var(--border));background:hsl(var(--muted))}.note svg{flex:none;margin-top:2px}.note.err{border-color:hsl(var(--destructive) / 0.5)}.note.err svg{color:hsl(var(--destructive))}.note.warn{border-color:hsl(var(--amber) / 0.5)}.note.warn svg{color:hsl(var(--amber))}.note.info svg{color:hsl(var(--primary))}.or{display:flex;align-items:center;gap:10px;color:hsl(var(--muted-foreground));font-size:11px;text-transform:uppercase;letter-spacing:0.06em}.or::before,.or::after{content:'';flex:1;height:1px;background:hsl(var(--border))}.drop{border:1px dashed hsl(var(--border));border-radius:6px;padding:14px;display:flex;align-items:center;gap:12px;color:hsl(var(--muted-foreground));font-size:12px;background:transparent;text-align:left}.drop svg{color:hsl(var(--blue));flex:none}.drop b{color:hsl(var(--foreground));font-weight:500}.filechip{display:flex;gap:10px;align-items:center;padding:10px;border:1px solid hsl(var(--border));border-radius:4px;background:hsl(var(--muted))}.filechip>svg{color:hsl(var(--blue));flex:none}.filechip>div{flex:1;min-width:0}.filechip b{display:block;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.filechip span{color:hsl(var(--muted-foreground));font-size:11px}.filechip.bad{border-color:hsl(var(--destructive) / 0.55)}.filechip.bad>svg{color:hsl(var(--destructive))}.dest-row,.sa-dest{display:flex;gap:8px;align-items:center;flex-wrap:wrap}.dest{display:flex;align-items:center;gap:8px;background:hsl(var(--bg));border:1px solid hsl(var(--border));border-radius:4px;padding:7px 10px;font-size:12px;min-width:0;flex:1 1 200px}.dest span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dest svg{color:hsl(var(--primary));flex:none}fieldset.order{border:0;margin:0;padding:0;display:flex;flex-direction:column;gap:6px}fieldset.order legend{margin-bottom:6px}.opt{display:flex;gap:8px;align-items:flex-start;padding:8px 10px;border:1px solid hsl(var(--border));border-radius:4px;font-size:12px;cursor:pointer}.opt.on{border-color:hsl(var(--primary));background:hsl(var(--primary) / 0.08)}.opt input,.checkline input,.seg input{accent-color:hsl(var(--primary));margin:2px 0 0}.checkline{display:flex;gap:8px;align-items:flex-start;font-size:12px;cursor:pointer}.login{display:flex;flex-direction:column;gap:8px}.login>.lnk{align-self:flex-start;padding-left:0}.auth{display:flex;flex-direction:column;gap:10px;padding:10px;border:1px solid hsl(var(--border));border-radius:4px}.seg{display:flex;flex-wrap:wrap;gap:6px}.seg label{display:flex;gap:6px;align-items:center;font-size:11px;padding:4px 8px;border:1px solid hsl(var(--border));border-radius:999px;cursor:pointer}.seg label.on{border-color:hsl(var(--primary));color:hsl(var(--primary))}.seg input{margin:0}.crumbs{display:flex;flex-wrap:wrap;align-items:center;gap:2px;font-family:ui-monospace, SFMono-Regular, Menlo, monospace}.crumbs .lnk{font-size:12px}.crumbs .sep{color:hsl(var(--muted-foreground))}.folders{display:flex;flex-direction:column;border:1px solid hsl(var(--border));border-radius:4px;max-height:220px;overflow:auto}.folders .muted{padding:10px}.folder-row{display:flex;align-items:center;gap:8px;padding:7px 10px;border:0;border-bottom:1px solid hsl(var(--border) / 0.6);background:transparent;text-align:left;font-family:ui-monospace, SFMono-Regular, Menlo, monospace;font-size:12px}.folder-row:hover{background:hsl(var(--muted))}.folder-row svg{color:hsl(var(--primary))}.blocker{display:flex;flex-direction:column;gap:10px}.empty{display:flex;flex-direction:column;align-items:center;text-align:center;gap:8px;padding:30px 20px}.empty>svg{color:hsl(var(--muted-foreground))}.empty b{font-size:14px;font-weight:600}.empty span{color:hsl(var(--muted-foreground));font-size:12px;max-width:44ch}.spin{width:22px;height:22px;border-radius:50%;border:3px solid hsl(var(--border));border-top-color:hsl(var(--primary));animation:spin 1s linear infinite}@keyframes spin{to{transform:rotate(360deg)}}.standalone{display:flex;flex-direction:column;min-height:100%}.sa-head{padding:14px 16px 10px;display:flex;flex-direction:column;gap:4px}.sa-title{display:flex;align-items:baseline;gap:10px;flex-wrap:wrap}.sa-title h3{margin:0;font-size:16px;font-weight:600}.sa-title .node{color:hsl(var(--muted-foreground))}.saving{font-size:12px;color:hsl(var(--muted-foreground))}.sa-add{padding:0 16px 14px;display:flex;flex-direction:column;gap:10px;border-bottom:1px solid hsl(var(--border))}.fetch-form.inline{display:flex;flex-direction:column;gap:10px}.tabs{display:flex;gap:4px;padding:0 10px;border-bottom:1px solid hsl(var(--border));overflow-x:auto}.tabs button{padding:9px 10px;font-size:12px;color:hsl(var(--muted-foreground));border:0;border-bottom:2px solid transparent;background:none;white-space:nowrap}.tabs button.on{color:hsl(var(--foreground));border-bottom-color:hsl(var(--primary))}.tabs b{font-family:ui-monospace, SFMono-Regular, Menlo, monospace;font-weight:500;color:hsl(var(--muted-foreground));margin-left:6px}.tab-h{display:flex;justify-content:space-between;align-items:center;padding:8px 12px;font-size:12px;color:hsl(var(--muted-foreground));border-bottom:1px solid hsl(var(--border) / 0.6)}.toasts{position:absolute;left:12px;right:12px;bottom:12px;display:flex;flex-direction:column;gap:8px;z-index:30;pointer-events:none;align-items:flex-end}:host(.standalone) .toasts{position:sticky;margin:12px}.toast{pointer-events:auto;display:flex;gap:10px;align-items:center;padding:10px 12px;background:hsl(var(--bg));border:1px solid hsl(var(--primary) / 0.5);border-radius:6px;width:min(100%, 420px);box-shadow:0 12px 30px -12px rgba(0, 0, 0, 0.7)}.toast>svg{color:hsl(var(--primary));flex:none}.toast.bad{border-color:hsl(var(--destructive) / 0.55)}.toast.bad>svg{color:hsl(var(--destructive))}.toast .t{flex:1;min-width:0}.toast .t b{display:block;font-weight:600}.toast .t span{color:hsl(var(--muted-foreground));font-family:ui-monospace, SFMono-Regular, Menlo, monospace;font-size:11px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;display:block}.overlay.player{padding:10px}.overlay.player phirepass-media-player{width:min(100%, 880px)}@container (max-width: 480px){.job{padding:9px 10px}.job .title .pill.meta{display:none}.inline-row{flex-wrap:wrap}.inline-row .inp{flex-basis:100%}.inline-row .btn.pri{flex:1;justify-content:center}.stats{gap:2px 10px}}@media (prefers-reduced-motion: reduce){.bar i{transition:none}.bar.indet i{animation:none;width:100% !important;opacity:0.5}.spin{animation:none}}"}},[513,"phirepass-downloader",{nodeId:[1,"node-id"],nodeLabel:[1,"node-label"],token:[1],channel:[16],connected:[4],channelFactory:[16],browsingService:[1,"browsing-service"],browsingPath:[1025,"browsing-path"],compact:[516],streamBase:[1,"stream-base"],canConfigure:[4,"can-configure"],inlinePlayer:[4,"inline-player"],serverHost:[1,"server-host"],serverPort:[2,"server-port"],serverId:[1,"server-id"],allowInsecure:[4,"allow-insecure"],heartbeatInterval:[2,"heartbeat-interval"],connection:[32],caps:[32],jobs:[32],tab:[32],drawerOpen:[32],dialogOpen:[32],unread:[32],form:[32],where:[32],starting:[32],refusal:[32],confirm:[32],notices:[32],subDir:[32],picker:[32],player:[32],receive:[64],openFetch:[64],toggleDrawer:[64],jobForPath:[64],deleteDownload:[64],torrentPathFor:[64],startTorrentPath:[64]},void 0,{channel:[{onChannel:0}],connected:[{onConnected:0}],browsingPath:[{onBrowsing:0}],browsingService:[{onBrowsing:0}],nodeId:[{onNode:0}]}]);function me(){"undefined"!=typeof customElements&&["phirepass-downloader","phirepass-media-player"].forEach((e=>{switch(e){case"phirepass-downloader":customElements.get(t(e))||customElements.define(t(e),ge);break;case"phirepass-media-player":customElements.get(t(e))||w()}}))}me();export{y as D,ge as P,me as d,C as i,x as s}
|
|
1
|
+
import{h as e,t,p as n,H as o,c as s,a as i}from"./index.js";import{_ as r,C as a,P as l,E as d}from"./p-BekUePpu.js";import{f as h,a as c,b as p,c as u,e as f,g as b,I as g,p as m,d as w}from"./p-DIf-Ru26.js";const v=["send_download_start","send_download_stop","send_download_resume","send_download_set_order","send_download_delete","send_download_subscribe","send_download_where"];function x(e){return!(!e||"object"!=typeof e)&&v.every((t=>"function"==typeof e[t]))}const y=1073741824,k=new Set(["DownloadProgress","DownloadAccepted","DownloadWhereAnswer","DownloadCaps","DownloadFoldersAnswer"]);function C(e){return k.has(e.type)}const S=new Set(["host","content-length","range","if-range","transfer-encoding","connection","keep-alive","proxy-authenticate","proxy-authorization","te","trailer","upgrade"]);function $(e){const t=e.trim();if(!t)return{kind:"empty"};if(/^magnet:\?/i.test(t)){const e=t.slice(t.indexOf("?")+1),n=new URLSearchParams(e),o=n.getAll("xt").find((e=>/^urn:btih:/i.test(e)));if(!o)return{kind:"invalid"};const s=o.slice(9),i=n.get("dn")?.trim();return{kind:"magnet",uri:t,infoHash:s,...i?{name:i}:{}}}let n;try{n=new URL(t)}catch{return{kind:"invalid"}}if("http:"!==n.protocol&&"https:"!==n.protocol)return{kind:"invalid"};if(!n.hostname)return{kind:"invalid"};if(n.username||n.password)return{kind:"invalid"};const o="https:"===n.protocol?"HTTPS":"HTTP",s=function(e){const t=e.split("/").filter(Boolean),n=t[t.length-1]??"";try{return decodeURIComponent(n)}catch{return n}}(n.pathname)||"download";return{kind:/\.torrent$/i.test(n.pathname)?"torrent-url":"http",url:t,host:n.hostname,name:s,scheme:o}}function D(e){const t=(...e)=>e.some((e=>/[\r\n\0]/.test(e)));switch(e.mode){case"none":return{auth:null};case"basic":return e.username?e.username.includes(":")?{auth:null,error:"A username cannot contain a colon."}:t(e.username,e.password)?{auth:null,error:"A login cannot contain line breaks."}:{auth:{Basic:{username:e.username,password:e.password}}}:{auth:null,error:"Enter a username."};case"bearer":return e.token.trim()?t(e.token)?{auth:null,error:"A login cannot contain line breaks."}:{auth:{Bearer:{token:e.token.trim()}}}:{auth:null,error:"Enter a token."};case"header":{const n=e.headerName.trim();return/^[A-Za-z0-9!#$%&'*+.^_`|~-]+$/.test(n)?S.has(n.toLowerCase())?{auth:null,error:`${n} cannot be set here.`}:t(e.headerValue)?{auth:null,error:"A login cannot contain line breaks."}:{auth:{Header:{name:n,value:e.headerValue}}}:{auth:null,error:"Enter a valid header name."}}}}const z={text:"",saveAs:"",torrent:null,order:null,auth:{mode:"none",username:"",password:"",token:"",headerName:"",headerValue:""},authOpen:!1};function F(e,t,n){const o=e.torrent?{kind:"empty"}:$(e.text),s=!!e.torrent||"magnet"===o.kind,i=s&&!!t&&!t.torrents,r="http"===o.kind||"torrent-url"===o.kind;let a=null;"too-large"===e.torrent?.error?a={tone:"err",title:"Too large",body:"A .torrent file can be up to 2 MB. Use its magnet link instead."}:"not-torrent"===e.torrent?.error?a={tone:"err",title:"Not a .torrent",body:"Choose a file that ends in .torrent."}:"invalid"===o.kind?a={tone:"err",title:"Not a link",body:"Use http://, https:// or magnet:"}:i&&(a={tone:"warn",title:"Torrents are off",body:"This node only allows ordinary links. Its owner can allow torrents in the node's settings."});const l=D(e.auth),d=s&&!i,h=n&&!!t&&(r||"magnet"===o.kind||!!e.torrent&&!e.torrent.error&&!!e.torrent.contents)&&!a&&(!d||null!==e.order)&&(!r||!e.authOpen||!l.error);let c;return r?c=e.saveAs.trim()||o.name:"magnet"===o.kind&&(c=o.name),{detected:o,isTorrent:s,needsOrder:d,showSaveAs:"http"===o.kind,showAuth:r,note:a,canStart:h,askedName:c,authError:r&&e.authOpen&&(e.auth.username||e.auth.token||e.auth.headerName||e.auth.headerValue)?l.error:void 0}}const _=new Set(["Completed","Seeding"]);function P(e){return _.has(e)}const R=new Set(["Queued","Scheduled","Resolving","FetchingMetadata","Downloading","Verifying","Paused","Stopped","Unknown"]);function T(e){return"Stopped"===e.state&&"Torrent"===e.kind&&!!e.seeding_since}function I(e){return["Queued","Scheduled","Resolving","FetchingMetadata","Downloading","Verifying","Paused"].includes(e.state)}function N(e){return("Completed"===e.state||"Cancelled"===e.state)&&!e.deleting}const A={Downloading:0,Verifying:1,FetchingMetadata:2,Resolving:3,Paused:4,Queued:5,Scheduled:6,Retrying:7,Stopped:8,Seeding:9,Completed:10,Cancelled:11,Deleted:12,Unknown:13};function j(e){const t=e.filter(I),n=t.reduce(((e,t)=>e+(t.down_bps||0)),0),o=t.filter((e=>e.total_bytes)),s=o.reduce(((e,t)=>e+t.done_bytes),0),i=o.reduce(((e,t)=>e+(t.total_bytes??0)),0);return{active:t.length,downBps:n,done:s,total:i,percent:i?s/i*100:null}}const O=/\.(mp4|m4v|webm|mkv|mov|mp3|m4a|flac|ogg|oga|opus|wav)$/i;function M(e){return O.test(e)}function B(e){const t=function(e){const t=e.files.filter((e=>e.media||M(e.name)));return t.length?t.reduce(((e,t)=>t.size>e.size?t:e)):!e.files.length&&M(e.name)?{index:0,name:e.name,size:e.total_bytes??0,done_bytes:e.done_bytes,media:!0,ready_from_start:e.in_order?e.done_bytes:0}:null}(e);return!t||e.deleting?{play:!1,file:null,switchToInOrder:!1}:P(e.state)?{play:!0,file:t,switchToInOrder:!1}:["Downloading","Verifying","Paused","Stopped","Retrying"].includes(e.state)&&t.size?e.in_order?{play:!0,file:t,switchToInOrder:!1}:{play:!1,file:null,switchToInOrder:"Torrent"===e.kind&&!T(e)}:{play:!1,file:null,switchToInOrder:!1}}function U(...e){const t=e.filter((e=>!!e)).join("/").replace(/\/{2,}/g,"/");return t.length>1?t.replace(/\/+$/,""):t}function E(e){return U(e.dest_root,e.sub_dir)}function V(e,t,n){return e.agent_supported?"Organisation"===e.lock?{id:"blocked",title:"Blocked",body:`Your organisation does not allow downloads on ${t}.`,secondary:"An owner or admin of the organisation can change this under Organisation → Downloads."}:e.http?"NoFolder"===e.lock?{id:"no-folder",title:"No download folder",body:"The download folder on this node is missing or can't be written.",secondary:"Someone who can configure the node can pick another one.",action:n?"Open node settings":void 0}:null:{id:"off",title:"Downloads are off",body:`Downloads are turned off for ${t}.`,secondary:n?"You can turn them on in the node's settings.":"Ask the node's owner to turn them on.",action:n?"Open node settings":void 0}:{id:"too-old",title:"Too old",body:`${t} runs an agent that cannot download. Update the agent on that machine, then try again.`}}const W=({label:t,onClose:n,wide:o},s)=>e("div",{class:"overlay",onClick:e=>{e.target===e.currentTarget&&n()}},e("div",{class:{modal:!0,wide:!!o},role:"dialog","aria-modal":"true","aria-label":t,tabindex:-1,onKeyDown:e=>{"Escape"===e.key&&(e.stopPropagation(),n())}},s)),q=({cancel:t,confirm:n,danger:o,onCancel:s,onConfirm:i})=>e("div",{class:"dlg-f"},e("button",{type:"button",class:"btn",onClick:s},t),e("button",{type:"button",class:{btn:!0,pri:!o,dng:!!o},onClick:i},n)),L=({row:t,discard:n,onDiscard:o,...s})=>e(W,{label:"Stop this download?",onClose:s.onCancel},e("div",{class:"dlg"},e("h4",null,"Stop this download?"),e("div",{class:"filechip"},e(g,{name:"file",size:20}),e("div",null,e("b",null,t.name),e("span",null,t.total_bytes?`${c(t.done_bytes)} of ${c(t.total_bytes)} downloaded`:`${c(t.done_bytes)} downloaded`))),e("label",{class:"checkline"},e("input",{type:"checkbox",checked:n,onChange:e=>o(e.target.checked)}),e("span",null,"Also delete the part already downloaded",e("span",{class:"hint block"},"Leave this off and Resume continues from here."))),e(q,{cancel:"Keep downloading",confirm:"Stop download",danger:!0,...s}))),Q=({row:t,deleteFile:n,onDeleteFile:o,nodeName:s,...i})=>{const r=P(t.state),a=t.files.length>1?`${t.files.length} files · ${c(t.total_bytes??t.done_bytes)}`:c(t.total_bytes??t.done_bytes);return e(W,{label:"Delete this download?",onClose:i.onCancel},e("div",{class:"dlg"},e("h4",null,"Delete this download?"),e("div",{class:"filechip"},e(g,{name:"file",size:20}),e("div",null,e("b",null,t.name),e("span",null,"Seeding"===t.state?"Seeding · ":"",a," in ",E(t)))),"Seeding"===t.state&&e("p",{class:"dtx"},s," stops sharing it with peers."),r?e("label",{class:"checkline"},e("input",{type:"checkbox",checked:n,onChange:e=>o(e.target.checked)}),e("span",null,"Also delete the files",e("span",{class:"hint block"},"Off: the files stay in ",E(t)," and only the download is removed."))):e("p",{class:"dtx"},"The part already downloaded is deleted."),e(q,{cancel:"Cancel",confirm:"Delete",danger:!0,...i})))},H=({row:t,...n})=>e(W,{label:"Switch to fastest?",onClose:n.onCancel},e("div",{class:"dlg"},e("h4",null,"Switch to fastest?"),e("p",{class:"dtx"},e("b",null,t.name)," is playing. Fastest downloads pieces in any order, so playback stops until it finishes or you switch back."),e(q,{cancel:"Keep in order",confirm:"Switch and stop playback",danger:!0,...n}))),K=({nodeName:t,dontAsk:n,onDontAsk:o,...s})=>e(W,{label:`Start a torrent on ${t}?`,onClose:s.onCancel},e("div",{class:"dlg"},e("h4",null,"Start a torrent on ",t,"?"),e("div",{class:"note warn"},e(g,{name:"warn",size:14}),e("div",null,"The node will connect to public peers. They can see its internet address, and it uploads to them while it downloads.")),e("p",{class:"dtx"},"When it finishes, ",t," keeps sharing it with other peers until you delete it."),e("label",{class:"checkline"},e("input",{type:"checkbox",checked:n,onChange:e=>o(e.target.checked)}),e("span",null,"Do not ask again on this browser")),e(q,{cancel:"Cancel",confirm:"Start torrent",...s}))),Y=({reason:t,onClose:n})=>e(W,{label:"Not enough space",onClose:n},e("div",{class:"dlg"},e("h4",null,"Not enough space"),e("p",{class:"dtx"},t),e("div",{class:"dlg-f"},e("button",{type:"button",class:"btn pri",onClick:n},"OK")))),X=t=>e(W,{label:"Save downloads to",onClose:t.onCancel,wide:!0},e("div",{class:"dlg"},e("h4",null,"Save downloads to"),e("nav",{class:"crumbs","aria-label":"Folder"},e("button",{type:"button",class:"lnk",onClick:()=>t.onUp(0)},t.root),t.path.map(((n,o)=>[e("span",{class:"sep"},"/"),e("button",{type:"button",class:"lnk",onClick:()=>t.onUp(o+1)},n)]))),e("div",{class:"folders",role:"list"},null===t.folders&&e("div",{class:"muted"},"Loading…"),0===t.folders?.length&&e("div",{class:"muted"},"No folders here."),t.folders?.map((n=>e("button",{type:"button",class:"folder-row",role:"listitem",onClick:()=>t.onOpen(n)},e(g,{name:"folder",size:14}),e("span",null,n))))),t.error&&e("div",{class:"note err"},t.error),null!==t.newName&&e("input",{class:"inp",type:"text","aria-label":"New folder name",placeholder:"New folder name",value:t.newName,onInput:e=>t.onNewName(e.target.value)}),e("p",{class:"hint"},"Folders only, and only inside the node's download folder. A new folder is created by the node when the first download lands in it."),e("div",{class:"dlg-f"},e("button",{type:"button",class:"btn left",onClick:()=>t.onNewName(null===t.newName?"":null)},e(g,{name:"plus",size:12})," New folder"),e("button",{type:"button",class:"btn",onClick:t.onCancel},"Cancel"),e("button",{type:"button",class:"btn pri",disabled:null!==t.newName&&!/^[^/\\\0]+$/.test(t.newName.trim()),onClick:t.onSave},"Save here")))),Z=({note:t})=>e("div",{class:`note ${t.tone}`,role:"err"===t.tone?"alert":"status"},e(g,{name:"warn",size:14}),e("div",null,e("b",null,t.title)," ",t.body));function G({model:t}){const n=t.detected;return"http"===n.kind||"torrent-url"===n.kind?e("div",{class:"detect","data-kind":n.kind},e("span",{class:"pill meta"},"torrent-url"===n.kind?".torrent link":n.scheme),e("span",{class:"host"},n.host)):"magnet"===n.kind?e("div",{class:"detect","data-kind":"magnet"},e("span",{class:"pill meta"},"Magnet"),e("span",{class:"host"},n.name??"name arrives with the metadata")):e("div",{class:"detect"})}const J=({auth:t,onChange:n})=>{const o=n,s=(n,s,i="text")=>e("label",{class:"fld"},e("span",null,n),e("input",{class:"inp",type:i,autocomplete:"off",spellcheck:!1,value:t[s],onInput:e=>o({[s]:e.target.value})}));return e("div",{class:"auth"},e("div",{class:"seg",role:"radiogroup","aria-label":"Login for the link"},[["none","No login"],["basic","Username and password"],["bearer","Bearer token"],["header","Custom header"]].map((([n,s])=>e("label",{class:{on:t.mode===n}},e("input",{type:"radio",name:"auth-mode",checked:t.mode===n,onChange:()=>o({mode:n})}),s)))),"basic"===t.mode&&[s("Username","username"),s("Password","password","password")],"bearer"===t.mode&&s("Token","token","password"),"header"===t.mode&&[s("Header name","headerName"),s("Value","headerValue","password")],"none"!==t.mode&&e("p",{class:"hint"},"Sent only to this link's own site, and dropped if it redirects elsewhere. The node seals it and deletes it when the download finishes."))},ee=({order:t,onChange:n})=>e("fieldset",{class:"order"},e("legend",null,"How should it download? (required for torrents)"),e("label",{class:{opt:!0,on:"in"===t}},e("input",{type:"radio",name:"order",value:"in",checked:"in"===t,onChange:()=>n("in")}),e("span",null,e("b",null,"In order")," · watch while it downloads, a little slower")),e("label",{class:{opt:!0,on:"fast"===t}},e("input",{type:"radio",name:"order",value:"fast",checked:"fast"===t,onChange:()=>n("fast")}),e("span",null,e("b",null,"Fastest")," · any order; switch to in order later if you want to watch"))),te=t=>{const{form:n,model:o,caps:s}=t;let i;const r=!!s?.torrents,a="dialog"===t.layout,l=e("input",{type:"file",accept:".torrent,application/x-bittorrent",class:"hidden-input",ref:e=>i=e,onChange:e=>{const n=e.target,o=n.files?.[0];o&&t.onPickTorrent(o),n.value=""}}),d=n.torrent?e("div",{class:{filechip:!0,bad:!!n.torrent.error}},e(g,{name:"torrent",size:20}),e("div",null,e("b",null,n.torrent.name),e("span",null,c(n.torrent.size)," · from this computer")),e("button",{type:"button",class:"ib","aria-label":"Remove the .torrent file",title:"Remove",onClick:()=>t.onChange({torrent:null,order:null})},e(g,{name:"x",size:14}))):e("div",{class:"fld"},e("label",{htmlFor:"fetch-link"},"Link or magnet"),e("div",{class:"inline-row"},e("input",{id:"fetch-link",class:"inp",type:"text",inputMode:"url",autocomplete:"off",autocapitalize:"none",spellcheck:!1,placeholder:"https://… or magnet:?xt=…",value:n.text,disabled:t.starting,onInput:e=>t.onChange({text:e.target.value}),onKeyDown:e=>{"Enter"===e.key&&o.canStart&&(e.preventDefault(),t.onStart())}}),!a&&r&&e("button",{type:"button",class:"btn",onClick:()=>i?.click()},".torrent…"),!a&&e("button",{type:"button",class:"btn pri",disabled:!o.canStart||t.starting,onClick:()=>t.onStart()},t.starting?"Starting…":"Download")),e(G,{model:o}));return e("form",{class:{"fetch-form":!0,[t.layout]:!0},onSubmit:e=>{e.preventDefault(),o.canStart&&t.onStart()},onDragOver:e=>r&&e.preventDefault(),onDrop:e=>r&&(e=>{e.preventDefault();const n=e.dataTransfer?.files?.[0];n&&t.onPickTorrent(n)})(e)},a&&e("div",{class:"dlg-h"},e(g,{name:"fetch"}),e("h4",null,t.title)),l,d,o.note&&e(Z,{note:o.note}),t.refusal&&e(Z,{note:t.refusal}),o.showSaveAs&&e("div",{class:"fld"},e("label",{htmlFor:"fetch-save-as"},"Save as"),e("input",{id:"fetch-save-as",class:"inp",type:"text",autocomplete:"off",spellcheck:!1,placeholder:o.askedName,value:n.saveAs,disabled:t.starting,onInput:e=>t.onChange({saveAs:e.target.value})}),e("span",{class:"hint"},"Taken from the server's filename when it sends one. An existing file is never overwritten; the new one gets “(1)” added.")),o.showAuth&&e("div",{class:"login"},e("button",{type:"button",class:"lnk","aria-expanded":n.authOpen?"true":"false",onClick:()=>t.onChange({authOpen:!n.authOpen})},e(g,{name:n.authOpen?"up":"chevron",size:12})," This link needs a login"),n.authOpen&&e(J,{auth:n.auth,onChange:t.onAuth}),o.authError&&e("span",{class:"hint err",role:"alert"},o.authError)),o.needsOrder&&e(ee,{order:n.order,onChange:e=>t.onChange({order:e})}),("http"===o.detected.kind||"torrent-url"===o.detected.kind)&&e("p",{class:"hint"},"A link always downloads in order, so you can watch while it arrives."),a&&r&&!n.torrent&&[e("div",{class:"or"},"or"),e("button",{type:"button",class:"drop",onClick:()=>i?.click()},e(g,{name:"torrent",size:22}),e("span",null,e("b",null,"Choose a .torrent file")," or drop it here",e("br",null),e("span",{class:"hint"},"Up to 2 MB, read in the browser and sent to the node")))],t.destination&&e("div",{class:"fld"},a&&e("label",null,"Destination"),e("div",{class:"dest-row"},e("div",{class:"dest",title:t.destination.path},e(g,{name:"folder",size:14}),e("span",null,t.destination.path)),t.onChooseFolder&&e("button",{type:"button",class:"btn",onClick:()=>t.onChooseFolder?.()},"Choose folder…")),t.destination.hint&&e("span",{class:"hint where"},t.destination.hint)),a&&e("div",{class:"dlg-f"},e("button",{type:"button",class:"btn",onClick:()=>t.onCancel?.()},"Cancel"),e("button",{type:"submit",class:"btn pri",disabled:!o.canStart||t.starting},t.starting?"Starting…":"Start download")))};function ne(e){return"FetchingMetadata"===e.state||"Resolving"===e.state?"bar indet":"Retrying"===e.state||"Paused"===e.state?"bar moving":"Stopped"===e.state||"Queued"===e.state||"Scheduled"===e.state||e.deleting?"bar paused":"Cancelled"===e.state?"bar fail":"Seeding"===e.state?"bar seed":"bar"}const oe=({icon:t,label:n,onClick:o,primary:s})=>e("button",{type:"button",class:{ib:!0,new:!!s},title:n,"aria-label":n,onClick:o},e(g,{name:t,size:14})),se=({row:t,actions:n,running:o,source:s,compact:i})=>{const{icon:r,tone:a}=function(e){return"Torrent"===e.kind?{icon:e.name.startsWith("magnet:")?"magnet":"torrent",tone:"t"}:"Node"===e.kind?{icon:"node",tone:"n"}:{icon:"globe",tone:"h"}}(t),l=function(e){if(e.deleting)return{text:"Deleting…",tone:"ps"};if(e.waitingForNode)return{text:"Waiting for the node",tone:"q"};switch(e.state){case"Queued":return{text:"Queued",tone:"q"};case"Scheduled":return{text:"Scheduled",tone:"q"};case"Resolving":return{text:"Connecting",tone:"meta"};case"FetchingMetadata":return{text:"Fetching metadata",tone:"meta"};case"Downloading":return{text:"Downloading",tone:"dl"};case"Verifying":return{text:"Checking pieces",tone:"meta"};case"Paused":return{text:"DiskFull"===e.pause_reason?"Paused · disk almost full":"Paused",tone:"mv"};case"Retrying":return{text:"Retrying",tone:"mv"};case"Seeding":return{text:"Seeding",tone:"sd"};case"Completed":return{text:"Completed",tone:"ok"};case"Stopped":return{text:T(e)?"Seeding paused":"Stopped",tone:"ps"};case"Cancelled":return{text:"Cancelled",tone:"err"};default:return{text:e.state,tone:"ps"}}}(t),d=function(e){return"Torrent"===e.kind&&["Downloading","Verifying","Paused"].includes(e.state)?e.in_order?"In order":"Fastest":null}(t),w=B(t),v=function(e,t={}){const n=t.now??Date.now(),o=h(e.done_bytes,e.total_bytes),s=e.total_bytes?`${c(e.done_bytes)} of ${c(e.total_bytes)}`:e.done_bytes?c(e.done_bytes):"",i=[],r=(e,t={})=>e&&i.push({text:e,...t});if(e.deleting)return r("Waiting for the node to confirm"),i;if(e.waitingForNode)return r("Starts when the node reports in"),r("It keeps going after you close this tab"),i;switch(e.state){case"Queued":r("Waiting for a free slot"),t.running&&r(`${t.running} ${1===t.running?"is":"are"} running`);break;case"Scheduled":r("Waits for the download window"),e.next_attempt_at&&e.next_attempt_at>n&&r(`starts in ${p((e.next_attempt_at-n)/1e3)}`);break;case"Resolving":r(t.source?`Contacting ${t.source}`:"Contacting the server");break;case"FetchingMetadata":r("Asking peers for the torrent info"),r(`${e.peers} ${1===e.peers?"peer":"peers"}`),r(b((n-e.started_at)/1e3));break;case"Downloading":r(o,{strong:!0}),r(s),r(u(e.down_bps)),"Torrent"===e.kind&&(r(u(e.up_bps,"↑")),r(`${e.peers} ${1===e.peers?"peer":"peers"}`)),r(f(e.done_bytes,e.total_bytes,e.down_bps)),e.restarted_from_zero&&r("The file changed on the server, so it started over"),t.source&&r(t.source);break;case"Verifying":r(o,{strong:!0}),r("Checking downloaded pieces after a restart"),r(`${c(e.done_bytes)} already on disk`);break;case"Paused":"DiskFull"===e.pause_reason?(r(e.reason??"Free space is below the floor"),r("Resumes by itself when there is room")):(r(o,{strong:!0}),r("Outside the download window"),r("Resumes by itself"));break;case"Retrying":r(e.retry_reason??e.reason??"Something went wrong",{error:!0}),r(`attempt ${e.attempt}`),e.next_attempt_at&&r(e.next_attempt_at>n?`Next try in ${p((e.next_attempt_at-n)/1e3)}`:"Trying again now"),e.done_bytes&&r(`${c(e.done_bytes)} kept`);break;case"Seeding":r(u(e.up_bps,"↑")),r(`${c(e.up_total)} uploaded`),r(`${e.peers} ${1===e.peers?"peer":"peers"}`),e.seeding_since&&r(`seeding for ${p((n-e.seeding_since)/1e3).replace(/ \d+[hm]$/,"")}, until you delete it`);break;case"Completed":if(r("100%",{strong:!0}),r(e.files.length>1?`${e.files.length} files · ${c(e.total_bytes??e.done_bytes)}`:c(e.total_bytes??e.done_bytes)),e.finished_at&&e.started_at){const t=(e.finished_at-e.started_at)/1e3;r(`took ${p(t)}`),t>0&&(e.total_bytes??e.done_bytes)&&r(`avg ${c((e.total_bytes??e.done_bytes)/t)}/s`)}break;case"Stopped":if(T(e)){r(`${c(e.up_total)} uploaded`),r(e.reason??"Seeding paused by you"),r("Resume shares it again");break}r(o,{strong:!0}),r(e.reason??"Stopped by you"),r("Resume continues from here");break;case"Cancelled":r(e.reason??"Stopped and its part deleted",{error:!!e.reason}),r("Resume starts from zero")}return i}(t,{running:o,source:s}),x="Completed"===t.state||"Seeding"===t.state?100:m(t.done_bytes,t.total_bytes),y=[];if(!t.deleting)switch(w.play&&y.push(e(oe,{icon:"play",label:P(t.state)?"Play":"Play while downloading",primary:!0,onClick:()=>n.play(t)})),t.state){case"Downloading":case"Verifying":case"Resolving":case"FetchingMetadata":case"Queued":"Downloading"!==t.state&&"Verifying"!==t.state||y.push(e(oe,{icon:"pause",label:"Pause",onClick:()=>n.pause(t)})),y.push(e(oe,{icon:"x",label:"Stop",onClick:()=>n.stop(t)}));break;case"Scheduled":case"Paused":"Scheduled"!==t.state&&"Window"!==t.pause_reason||y.push(e(oe,{icon:"play",label:"Start now",onClick:()=>n.resume(t,!0)})),y.push(e(oe,{icon:"x",label:"Stop",onClick:()=>n.stop(t)}));break;case"Retrying":y.push(e(oe,{icon:"retry",label:"Try now",onClick:()=>n.resume(t)})),y.push(e(oe,{icon:"x",label:"Stop",onClick:()=>n.stop(t)}));break;case"Stopped":y.push(e(oe,{icon:"play",label:"Resume",onClick:()=>n.resume(t)})),y.push(e(oe,{icon:"trash",label:"Delete",onClick:()=>n.remove(t)}));break;case"Seeding":y.push(e(oe,{icon:"pause",label:"Pause seeding",onClick:()=>n.pause(t)})),y.push(e(oe,{icon:"locate",label:"Show in folder",onClick:()=>n.showInFolder(t)})),y.push(e(oe,{icon:"trash",label:"Delete",onClick:()=>n.remove(t)}));break;case"Completed":y.push(e(oe,{icon:"locate",label:"Show in folder",onClick:()=>n.showInFolder(t)})),y.push(e(oe,{icon:"x",label:"Remove from list",onClick:()=>n.remove(t)}));break;case"Cancelled":y.push(e(oe,{icon:"retry",label:"Start again",onClick:()=>n.resume(t)})),y.push(e(oe,{icon:"x",label:"Remove from list",onClick:()=>n.remove(t)}))}return e("div",{key:t.download_id,class:{job:!0,compact:!!i},"data-state":t.deleting?"Deleting":t.state,"data-id":t.download_id,role:"listitem","aria-label":`${t.name}, ${l.text}`},e("span",{class:`kind ${a}`},e(g,{name:r,size:15})),e("div",{class:"title"},e("span",{class:"nm",title:t.name},t.name),e("span",{class:`pill ${l.tone}`},l.text),d&&e("span",{class:"pill meta"},d)),e("div",{class:"acts"},y),e("div",{class:ne(t),role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(x),"aria-label":`${t.name} progress`},e("i",{style:{width:`${x}%`}})),e("div",{class:"stats"},v.map((t=>t.strong?e("b",null,t.text):e("span",{class:{err:!!t.error}},t.text))),!w.play&&w.switchToInOrder&&e("button",{type:"button",class:"lnk inline",onClick:()=>n.setOrder(t,!0)},"Switch to in order to watch"),w.play&&"Torrent"===t.kind&&t.in_order&&!P(t.state)&&e("button",{type:"button",class:"lnk inline",onClick:()=>n.setOrder(t,!1)},"Switch to fastest")))},ie={started:"fetch",queued:"fetch",stuck:"warn",renamed:"file",completed:"check",error:"warn"},re=({notices:t,onDismiss:n})=>t.length?e("div",{class:"toasts","aria-live":"polite"},t.map((t=>e("div",{class:{toast:!0,bad:"stuck"===t.kind||"error"===t.kind},"data-notice":t.kind,key:t.id},e(g,{name:ie[t.kind],size:18}),e("div",{class:"t"},e("b",null,t.title),e("span",{title:t.detail},t.detail)),t.action&&e("button",{type:"button",class:"btn",onClick:()=>{t.action.run(),n(t.id)}},t.action.label),e("button",{type:"button",class:"ib","aria-label":"Dismiss",onClick:()=>n(t.id)},e(g,{name:"x",size:12})))))):null,ae=({icon:t,title:n,body:o,action:s})=>e("div",{class:"empty",role:"status"},e(g,{name:t,size:28}),e("b",null,n),e("span",null,o),s&&e("button",{type:"button",class:"btn pri",onClick:s.onClick},s.label)),le=()=>e(ae,{icon:"fetch",title:"No downloads yet",body:"Press Fetch and paste a link. Downloads keep running after you close this tab, and they show here when you come back."}),de=({nodeName:t,folder:n})=>e(ae,{icon:"fetch",title:"Nothing downloading",body:`Paste a link above. It downloads onto ${t}${n?`, into ${n}`:""}.`}),he=({onSignIn:t})=>e(ae,{icon:"lock",title:"Sign in to PhirePass",body:"Your downloads are tied to your account and the nodes you can reach.",action:{label:"Sign in",onClick:t}}),ce=({nodeName:t,onRetry:n})=>e(ae,{icon:"signal",title:`Can't reach ${t}`,body:"If the machine is still running, its downloads carry on. They will show here when it reconnects.",action:n?{label:"Try again",onClick:n}:void 0}),pe=()=>e(ae,{icon:"warn",title:"Downloads are not available here",body:"This page's connection library is too old to start downloads. Reload after the site updates."}),ue=()=>e("div",{class:"empty",role:"status"},e("span",{class:"spin","aria-hidden":"true"}),e("span",null,"Loading downloads…")),fe=({blocker:t,onAction:n,onClose:o})=>e("div",{class:"blocker","data-blocker":t.id},e("div",{class:"note "+("off"===t.id?"info":"warn"),role:"status"},e(g,{name:"off"===t.id?"fetch":"warn",size:14}),e("div",null,e("b",null,t.title)," ",t.body)),t.secondary&&e("p",{class:"hint"},t.secondary),(o||t.action&&n)&&e("div",{class:"dlg-f"},o&&e("button",{type:"button",class:"btn",onClick:o},"Close"),t.action&&n&&e("button",{type:"button",class:"btn pri",onClick:n},t.action))),be="phirepass.downloader.torrent-ack",ge=n(class extends o{constructor(e){super(),!1!==e&&this.__registerHost(),this.__attachShadow(),this.fetchCompleted=s(this,"phirepassFetchCompleted"),this.play=s(this,"phirepassPlay"),this.activeCount=s(this,"phirepassActiveCount"),this.showInFolder=s(this,"phirepassShowInFolder"),this.openNodeSettings=s(this,"phirepassOpenNodeSettings"),this.signIn=s(this,"phirepassSignIn")}get el(){return this}ownChannel=!1;msgId=y;noticeId=1;seenNotices=new Set;torrentAcked=function(){try{return"1"===window.localStorage.getItem(be)}catch{return!1}}();noticeTimers=new Map;whereMsgId;nodeId;nodeLabel;token;channel;connected=!1;channelFactory;browsingService;browsingPath;compact=!1;streamBase;canConfigure=!1;inlinePlayer=!0;serverHost="phirepass.com";serverPort=443;serverId;allowInsecure=!1;heartbeatInterval=3e4;fetchCompleted;play;activeCount;showInFolder;openNodeSettings;signIn;connection="connecting";caps=null;jobs={};tab="active";drawerOpen=!1;dialogOpen=!1;unread=0;form=z;where=null;starting=null;refusal=null;confirm=null;notices=[];subDir=null;picker=null;player=null;get name(){return this.nodeLabel||this.nodeId}get ch(){return this.channel??this.ownedChannel}ownedChannel;async componentWillLoad(){this.channel?this.adoptChannel():await this.openOwnChannel()}disconnectedCallback(){this.noticeTimers.forEach((e=>window.clearTimeout(e))),this.noticeTimers.clear(),this.starting?.silence&&window.clearTimeout(this.starting.silence),this.ownChannel&&this.ownedChannel&&(this.ownedChannel.stop_heartbeat(),this.ownedChannel.disconnect())}onChannel(){this.channel&&this.adoptChannel()}onConnected(e,t){this.channel&&(e&&!t?this.subscribe():!e&&t&&(this.connection="unreachable"))}onBrowsing(){this.where=null,this.dialogOpen&&this.askWhere()}onNode(e,t){e!==t&&(this.jobs={},this.caps=null,this.where=null,this.channel?this.connected&&this.subscribe():this.ownedChannel&&(this.ownedChannel.disconnect(),this.openOwnChannel()))}adoptChannel(){this.ownChannel=!1,x(this.channel)?(this.connection="connecting",this.connected&&this.subscribe()):this.connection="unsupported"}endpoint(){return`${this.allowInsecure?"ws":"wss"}://${this.serverHost}${!this.allowInsecure&&443===this.serverPort||this.allowInsecure&&80===this.serverPort?"":`:${this.serverPort}`}/api/web/ws`}defaultStreamBase(){return`${this.allowInsecure?"http":"https"}://${this.serverHost}${!this.allowInsecure&&443===this.serverPort||this.allowInsecure&&80===this.serverPort?"":`:${this.serverPort}`}`}async openOwnChannel(){if(this.ownChannel=!0,!this.token)return void(this.connection="signed-out");if(!this.nodeId)return;this.channelFactory||await r();const e=this.channelFactory?this.channelFactory(this.endpoint(),this.nodeId,this.serverId):this.serverId?new a(this.endpoint(),this.nodeId,this.serverId):new a(this.endpoint(),this.nodeId);this.ownedChannel=e,x(e)?(e.on_connection_open((()=>e.authenticate(this.token,this.nodeId))),e.on_connection_close((()=>{"signed-out"!==this.connection&&(this.connection="unreachable")})),e.on_connection_error((()=>{"signed-out"!==this.connection&&(this.connection="unreachable")})),e.on_connection_message((()=>{})),e.on_protocol_message((e=>this.dispatch(e.data.web))),this.connection="connecting",e.connect()):this.connection="unsupported"}reconnect(){this.ownChannel?(this.ownedChannel?.disconnect(),this.openOwnChannel()):this.connected&&this.subscribe()}async receive(e){this.dispatch(e.data.web)}dispatch(e){if(e.type===l.AuthSuccess)return this.ownedChannel?.start_heartbeat(Math.max(3e4,this.heartbeatInterval)),void this.subscribe();if(e.type!==l.Error){if(C(e))switch(e.type){case"DownloadCaps":e.node_id===this.nodeId&&(this.caps=e.caps,this.connection="ready");break;case"DownloadProgress":e.node_id===this.nodeId&&this.onProgress(e.job);break;case"DownloadAccepted":this.onAccepted(e.msg_id,e.download_id);break;case"DownloadWhereAnswer":e.msg_id===this.whereMsgId&&(this.where={saves_to:e.saves_to,mapped:e.mapped});break;case"DownloadFoldersAnswer":this.picker&&e.msg_id===this.picker.msgId&&(this.picker={...this.picker,folders:[...e.folders].sort(((e,t)=>e.localeCompare(t)))})}}else this.handleError(e)}handleError(e){if(void 0!==e.msg_id&&e.msg_id===this.starting?.msgId)return this.clearStarting(),void(this.refusal={tone:"err",title:"Refused",body:e.message||"The server refused this download."});this.picker&&e.msg_id===this.picker.msgId?this.picker={...this.picker,folders:[],error:e.message}:void 0!==e.msg_id&&e.msg_id>=y?this.notify("error","That did not work",e.message||"The server refused it."):this.ownChannel&&e.kind===d.Authentication&&(this.connection="signed-out")}subscribe(){const e=this.ch;x(e)?(this.jobs={},e.send_download_subscribe({Node:this.nodeId}),this.dialogOpen&&this.askWhere()):this.connection="unsupported"}onProgress(e){const t=this.jobs[e.download_id],{jobs:n,completed:o}=function(e,t){const n=e[t.download_id];if("Deleted"===t.state){if(!n)return{jobs:e,first:!1};const{[t.download_id]:o,...s}=e;return{jobs:s,first:!1}}const o=t.deleting||n?.deleting||void 0;return{jobs:{...e,[t.download_id]:{...t,deleting:o}},completed:n&&!P(n.state)&&P(t.state)?t:void 0,first:!n}}(this.jobs,e);this.jobs=n,this.emitCount(),this.starting?.downloadId!==e.download_id||t||this.onFirstProgress(e),o&&(this.fetchCompleted.emit({download_id:e.download_id,dest_root:e.dest_root,sub_dir:e.sub_dir,name:e.name}),!this.drawerOpen&&this.compact&&this.unread++,this.notify("completed","Download complete",`${e.name} → ${E(e)}`,{label:"Show",run:()=>this.showInFolder.emit({path:E(e),name:e.name})}));const s=this.jobs[e.download_id];s&&function(e,t=3600){return"Retrying"===e.state&&function(e,t=3600){let n=0;for(let o=0;o<e;o++)n+=Math.min(10*2**o,t);return n}(e.attempt,t)>=86400}(s)&&!this.seenNotices.has(`stuck:${e.download_id}`)&&(this.seenNotices.add(`stuck:${e.download_id}`),this.notify("stuck","Still retrying after a day",`${e.name} · ${e.retry_reason??"no answer"}`,{label:"Show",run:()=>this.showRetrying()},!0))}onAccepted(e,t){if(!this.starting||this.starting.msgId!==e)return;if(this.jobs[t])return void this.onFirstProgress(this.jobs[t]);const n=window.setTimeout((()=>this.nodeSilent(t)),8e3);this.starting={...this.starting,downloadId:t,silence:n}}nodeSilent(e){if(this.starting?.downloadId!==e||this.jobs[e])return;const t=this.starting.askedName??"Download",n=Date.now(),o={download_id:e,kind:"Unknown",name:t,dest_root:this.where?.saves_to??this.caps?.folder??"",sub_dir:null,state:"Queued",done_bytes:0,total_bytes:null,down_bps:0,up_bps:0,peers:0,in_order:!0,started_at:n,finished_at:null,reason:null,requested_by:null,files:[],up_total:0,pause_reason:null,seeding_since:null,info_hash:null,retry_reason:null,attempt:0,next_attempt_at:null,restarted_from_zero:!1,waitingForNode:!0};this.jobs={...this.jobs,[e]:o},this.clearStarting(),this.closeDialog(!0),this.notify("queued",`Waiting for ${this.name}`,`${t} starts when the node reports in.`)}onFirstProgress(e){const t=this.starting?.askedName;if(this.clearStarting(),"Cancelled"!==e.state){if(this.closeDialog(!0),"Queued"===e.state){const e=Object.values(this.jobs).filter((e=>"Downloading"===e.state)).length;this.notify("queued","Added to the queue",`${e} ${1===e?"download is":"downloads are"} already running on this node`)}else this.notify("started","Download started",`${e.name} → ${E(e)}`);(function(e,t){return!!e&&e!==t&&/ \(\d+\)(\.[^.]*)?$/.test(t)})(t,e.name)&&this.notify("renamed",`Saved as ${e.name}`,`A file named ${t} was already in ${E(e)}`)}else{const t=e.reason??"The node refused this download.";!function(e){return!!e&&/not enough (disk )?space|disk (is )?full|needs [\d.]+ ?[kmgt]?b\b.*\bfree\b/i.test(e)}(t)?!this.dialogOpen&&this.compact||(this.refusal={tone:"err",title:"Refused",body:t}):this.confirm={kind:"space",reason:t}}}clearStarting(){this.starting?.silence&&window.clearTimeout(this.starting.silence),this.starting=null}emitCount(){this.activeCount.emit({n:Object.values(this.jobs).filter(I).length})}notify(e,t,n,o,s=!1){const i=this.noticeId++;this.notices=[...this.notices.slice(-2),{id:i,kind:e,title:t,detail:n,action:o,sticky:s}],s||this.noticeTimers.set(i,window.setTimeout((()=>this.dismiss(i)),6e3))}dismiss(e){const t=this.noticeTimers.get(e);t&&(window.clearTimeout(t),this.noticeTimers.delete(e)),this.notices=this.notices.filter((t=>t.id!==e))}showRetrying(){this.tab="retrying",this.drawerOpen=!0}async openFetch(e){void 0!==e&&e!==this.browsingPath&&(this.browsingPath=e),this.drawerOpen=!0,this.unread=0,this.dialogOpen=!0,this.refusal=null,this.askWhere()}async toggleDrawer(e){this.drawerOpen=e??!this.drawerOpen,this.drawerOpen&&(this.unread=0)}async jobForPath(e){const t=Object.values(this.jobs).find((t=>!P(t.state)&&"Cancelled"!==t.state&&function(e){return`${U(E(e),e.name)}.phirepass-part`}(t)===e));return t?{download_id:t.download_id,name:t.name}:null}async deleteDownload(e,t=!1){const n=this.jobs[e];n&&this.sendDelete(n,t)}async torrentPathFor(e){const t=this.caps?.folder;if(!t||!this.caps?.torrents||!/\.torrent$/i.test(e)||V(this.caps,this.name,this.canConfigure))return null;const n=t.endsWith("/")?t:`${t}/`;return e.startsWith(n)?e.slice(n.length):null}async startTorrentPath(e,t=!1){const n=await this.torrentPathFor(e),o=this.ch;if(null===n||!x(o))return!1;const s=this.nextMsgId();this.starting={msgId:s,askedName:n.split("/").pop()?.replace(/\.torrent$/i,"")};const i=n.includes("/")?n.slice(0,n.lastIndexOf("/")):null;return o.send_download_start(this.nodeId,{TorrentPath:{path:n}},i,null,t,{source_auth:null,ignore_window:!1},s),this.drawerOpen=!0,!0}nextMsgId(){return this.msgId=this.msgId>=4294967280?y:this.msgId+1,this.msgId}browsing(){return this.compact&&this.browsingService&&this.browsingPath?{service_id:this.browsingService,path:this.browsingPath}:null}askWhere(){const e=this.browsing(),t=this.ch;e&&x(t)&&"ready"===this.connection&&(this.whereMsgId=this.nextMsgId(),t.send_download_where(this.nodeId,e,this.whereMsgId))}destination(){if(this.browsing())return this.where?this.where.mapped?{path:this.where.saves_to}:{path:this.where.saves_to,hint:`This folder is outside ${this.name}'s download folder. The file will be saved to ${this.where.saves_to}.`}:{path:this.browsingPath,hint:"Asking the node where this lands…"};const e=this.caps?.folder;return e?{path:U(e,this.subDir)}:null}formReady(){return!(this.starting||"ready"!==this.connection||this.browsing()&&!this.where)}async pickTorrent(e){const t=function(e){const t=function(e){return/\.torrent$/i.test(e.name)?e.size>2097152?{ok:!1,reason:"too-large"}:{ok:!0}:{ok:!1,reason:"not-torrent"}}(e);return t.ok?{name:e.name,size:e.size}:{name:e.name,size:e.size,error:t.reason}}(e);t.error||(t.contents=new Uint8Array(await e.arrayBuffer())),this.form={...this.form,torrent:t,text:"",order:null},this.refusal=null}start(e=!1){const t=F(this.form,this.caps,this.formReady()),n=function(e){const t={source_auth:null,ignore_window:!1};if(e.torrent)return!e.torrent.contents||e.torrent.error?null:{source:{TorrentFile:{name:e.torrent.name,contents:e.torrent.contents}},inOrder:"in"===e.order,options:t};const n=$(e.text);if("magnet"===n.kind)return{source:{Magnet:{uri:n.uri}},inOrder:"in"===e.order,options:t};if("http"===n.kind||"torrent-url"===n.kind){const o=e.authOpen?D(e.auth):{auth:null};if("error"in o&&o.error)return null;const s=e.saveAs.trim();return{source:{Http:{url:n.url,save_as:s||null}},inOrder:!0,options:{...t,source_auth:o.auth}}}return null}(this.form),o=this.ch;if(!t.canStart||!n||!x(o))return;if(t.isTorrent&&!this.torrentAcked&&!e)return void(this.confirm={kind:"torrent",dontAsk:!1});const s=this.nextMsgId(),i=t.askedName??(this.form.torrent?this.form.torrent.name.replace(/\.torrent$/i,""):"magnet"===t.detected.kind?function(e){const t=/urn:btih:([a-z0-9]+)/i.exec(e);if(!t)return e.length>40?`${e.slice(0,37)}…`:e;const n=t[1];return`magnet:?xt=urn:btih:${n.slice(0,4)}…${n.slice(-4)}`}(t.detected.uri):void 0);this.starting={msgId:s,askedName:i},this.refusal=null;const r=this.browsing();o.send_download_start(this.nodeId,n.source,r?null:this.subDir,r,n.inOrder,n.options,s)}closeDialog(e=!1){this.dialogOpen=!1,this.refusal=null,e&&(this.form=z,this.drawerOpen=!0)}sendStop(e,t){const n=this.ch;x(n)&&n.send_download_stop(e.download_id,t,this.nextMsgId())}sendDelete(e,t){const n=this.ch;x(n)&&(n.send_download_delete(e.download_id,t,this.nextMsgId()),this.jobs={...this.jobs,[e.download_id]:{...e,deleting:!0}})}actions={play:e=>this.playRow(e),pause:e=>this.sendStop(e,!1),resume:(e,t=!1)=>{const n=this.ch;x(n)&&n.send_download_resume(e.download_id,t,this.nextMsgId())},stop:e=>this.confirm={kind:"stop",row:e,discard:!1},remove:e=>{"Completed"===e.state||"Seeding"===e.state||"Stopped"===e.state?this.confirm={kind:"delete",row:e,deleteFile:!1}:this.sendDelete(e,!1)},setOrder:(e,t)=>{t||this.player?.downloadId!==e.download_id?this.sendOrder(e,t):this.confirm={kind:"fastest",row:e}},showInFolder:e=>this.showInFolder.emit({path:E(e),name:e.name})};sendOrder(e,t){const n=this.ch;x(n)&&n.send_download_set_order(e.download_id,t,this.nextMsgId())}playRow(e){const t=B(e);if(!t.play||!t.file)return;const n=(o=this.streamBase||this.defaultStreamBase(),s=this.nodeId,i=e.download_id,r=t.file.index,`${o.replace(/\/+$/,"")}/api/web/stream/${encodeURIComponent(s)}/${encodeURIComponent(i)}/${r}`);var o,s,i,r;!this.play.emit({src:n,name:t.file.name,downloadId:e.download_id}).defaultPrevented&&this.inlinePlayer&&(this.player={src:n,name:t.file.name,downloadId:e.download_id})}clearFinished(){Object.values(this.jobs).filter(N).forEach((e=>this.sendDelete(e,!1)))}canPickFolder(){return!!this.caps?.folder&&"function"==typeof this.ch?.send_download_folders}listFolders(e){const t=this.nextMsgId();this.picker={path:e,folders:null,msgId:t,newName:null},this.ch?.send_download_folders?.(this.nodeId,e.length?e.join("/"):null,t)}savePicker(){if(!this.picker)return;const e=[...this.picker.path],t=this.picker.newName?.trim();t&&e.push(t),this.subDir=e.length?e.join("/"):null,this.picker=null}latest(e){return this.confirm?.kind===e.kind?this.confirm:e}renderConfirm(){const t=this.confirm;if(!t)return null;const n=()=>this.confirm=null;switch(t.kind){case"stop":return e(L,{row:t.row,discard:t.discard,onDiscard:e=>this.confirm={...this.latest(t),discard:e},onCancel:n,onConfirm:()=>{const e=this.latest(t);this.sendStop(e.row,e.discard),this.confirm=null}});case"delete":return e(Q,{row:t.row,nodeName:this.name,deleteFile:t.deleteFile,onDeleteFile:e=>this.confirm={...this.latest(t),deleteFile:e},onCancel:n,onConfirm:()=>{const e=this.latest(t);this.sendDelete(e.row,e.deleteFile),this.confirm=null}});case"fastest":return e(H,{row:t.row,onCancel:n,onConfirm:()=>{this.player=null,this.sendOrder(t.row,!1),this.confirm=null}});case"torrent":return e(K,{nodeName:this.name,dontAsk:t.dontAsk,onDontAsk:e=>this.confirm={...this.latest(t),dontAsk:e},onCancel:n,onConfirm:()=>{this.latest(t).dontAsk&&(function(){try{window.localStorage.setItem(be,"1")}catch{}}(),this.torrentAcked=!0),this.confirm=null,this.start(!0)}});case"space":return e(Y,{reason:t.reason,onClose:n})}}renderForm(t){const n=this.caps?V(this.caps,this.name,this.canConfigure):null,o=()=>this.openNodeSettings.emit({nodeId:this.nodeId});if(n)return"dialog"===t?e("div",{class:"dlg"},e("div",{class:"dlg-h"},e(g,{name:"fetch"}),e("h4",null,"Fetch into this folder")),e(fe,{blocker:n,onAction:o,onClose:()=>this.closeDialog()})):e(fe,{blocker:n,onAction:o});const s=F(this.form,this.caps,this.formReady());return e(te,{form:this.form,model:s,caps:this.caps,layout:t,title:this.browsing()?"Fetch into this folder":"Add download",destination:"dialog"===t||this.browsing()?this.destination():null,starting:!!this.starting,refusal:this.refusal,onChange:e=>{this.form={...this.form,...e},("text"in e||"torrent"in e)&&(this.refusal=null)},onAuth:e=>this.form={...this.form,auth:{...this.form.auth,...e}},onPickTorrent:e=>{this.pickTorrent(e)},onStart:()=>this.start(),onCancel:()=>this.closeDialog()})}renderRows(t){const n=t.filter((e=>"Downloading"===e.state)).length;return e("div",{class:"jobs",role:"list"},function(e){return[...e].sort(((e,t)=>A[e.state]-A[t.state]||(t.finished_at??t.started_at)-(e.finished_at??e.started_at)))}(t).map((t=>e(se,{row:t,actions:this.actions,running:n,compact:this.compact}))))}renderStatus(){switch(this.connection){case"unsupported":return e(pe,null);case"signed-out":return e(he,{onSignIn:()=>this.signIn.emit()});case"unreachable":return e(ce,{nodeName:this.name,onRetry:()=>this.reconnect()});case"connecting":return e(ue,null);default:return null}}renderCompact(){const t=Object.values(this.jobs),n=j(t),o=this.renderStatus();if("unsupported"===this.connection)return null;const s=t.some(N),i=!this.drawerOpen&&(n.active>0||this.unread>0),r=[`${n.active} active`,null===n.percent||this.drawerOpen?"":`${Math.round(n.percent)}%`,u(n.downBps)].filter(Boolean).join(" · ");return[this.drawerOpen&&e("section",{class:"drawer","aria-label":"Transfers"},e("div",{class:"drawer-h"},e("h4",null,"Transfers"),e("span",{class:"sum"},r),e("span",{class:"sp"}),s&&e("button",{type:"button",class:"lnk",onClick:()=>this.clearFinished()},"Clear finished"),e("button",{type:"button",class:"ib","aria-label":"Collapse transfers",title:"Collapse",onClick:()=>this.drawerOpen=!1},e(g,{name:"chevron",size:12}))),e("div",{class:"drawer-b"},o??(t.length?this.renderRows(t):e(le,null)))),i&&e("button",{type:"button",class:"strip","aria-label":"Show transfers",onClick:()=>this.toggleDrawer(!0)},e("h4",null,"Transfers"),e("span",{class:"bar"},e("i",{style:{width:`${n.percent??0}%`}})),e("span",{class:"sum"},this.unread&&!n.active?`${this.unread} finished`:r),e(g,{name:"up",size:12})),this.dialogOpen&&e(W,{label:"Fetch into this folder",onClose:()=>this.closeDialog()},o&&"ready"!==this.connection?e("div",{class:"dlg"},o,e("div",{class:"dlg-f"},e("button",{type:"button",class:"btn",onClick:()=>this.closeDialog()},"Close"))):this.renderForm("dialog"))]}renderStandalone(){const t=this.renderStatus(),n=Object.values(this.jobs),o={active:[],finished:[],retrying:[]};n.forEach((e=>{return o[(t=e,"Retrying"===t.state?"retrying":T(t)?"finished":R.has(t.state)?"active":"finished")].push(e);var t}));const s=j(n),i=o[this.tab],r=this.caps?.folder?U(this.caps.folder,this.subDir):null;return e("section",{class:"standalone"},e("header",{class:"sa-head"},e("div",{class:"sa-title"},e("h3",null,"Downloads"),e("span",{class:"node"},this.name),s.downBps>0&&e("span",{class:"sum"},u(s.downBps))),r&&e("span",{class:"saving"},"saving to ",e("code",null,r),this.caps&&this.caps.folder_free_bytes>0&&e("span",{class:"free"}," · ",c(this.caps.folder_free_bytes)," free"))),t??[e("div",{class:"sa-add"},this.renderForm("inline"),r&&!V(this.caps,this.name,this.canConfigure)&&e("div",{class:"sa-dest"},e("span",{class:"dest"},e(g,{name:"folder",size:14}),e("span",null,r)),this.canPickFolder()&&e("button",{type:"button",class:"btn",onClick:()=>this.listFolders(this.subDir?this.subDir.split("/"):[])},"Choose folder…"))),e("div",{class:"tabs",role:"tablist","aria-label":"Downloads"},[["active","Active"],["finished","Finished"],["retrying","Retrying"]].map((([t,n])=>e("button",{type:"button",role:"tab","aria-selected":this.tab===t?"true":"false",class:{on:this.tab===t},onClick:()=>this.tab=t},n,e("b",null,o[t].length))))),"finished"===this.tab&&o.finished.length>0&&e("div",{class:"tab-h"},e("span",null,o.finished.length," finished"),o.finished.some(N)&&e("button",{type:"button",class:"lnk",onClick:()=>this.clearFinished()},"Clear finished")),i.length?this.renderRows(i):0===n.length?e(de,{nodeName:this.name,folder:r}):e("div",{class:"muted pad"},"retrying"===this.tab?"Nothing is retrying.":"finished"===this.tab?"Nothing has finished yet.":"Nothing is running.")])}render(){return e(i,{key:"b7f751d7107ff8f00d791e5c54f4261e2d7cd580",class:{compact:this.compact,standalone:!this.compact}},this.compact?this.renderCompact():this.renderStandalone(),this.renderConfirm(),this.picker&&e(X,{key:"538f0f433863e0fbd79a8e66c0b7a45c93a8bd28",root:this.caps?.folder??"",path:this.picker.path,folders:this.picker.folders,error:this.picker.error,newName:this.picker.newName,onOpen:e=>this.listFolders([...this.picker.path,e]),onUp:e=>this.listFolders(this.picker.path.slice(0,e)),onNewName:e=>this.picker={...this.picker,newName:e},onCancel:()=>this.picker=null,onSave:()=>this.savePicker()}),this.player&&e("div",{key:"b9d3ade696c6079d6a2e3bc2206c19a6bdd7d640",class:"overlay player"},e("phirepass-media-player",{key:"c5fa1244ea9766ff37d08478dbc2d096430f2081",src:this.player.src,name:this.player.name,status:this.playerStatus(),ready:this.playerReady(),positionKey:`dl:${this.player.downloadId}`,onPhirepassPlayerClose:()=>this.player=null})),e(re,{key:"34a34a810001815a890a0995aab44f29f34aab61",notices:this.notices,onDismiss:e=>this.dismiss(e)}))}playerRow(){return this.player?this.jobs[this.player.downloadId]:void 0}playerStatus(){const e=this.playerRow();if(!e)return this.player?"On the node":void 0;if(P(e.state))return"On the node";const t=e.total_bytes?` · ${(e.done_bytes/e.total_bytes*100).toFixed(1)}%`:"";return`${"Downloading"===e.state?"Downloading":e.state}${t}`}playerReady(){const e=this.playerRow();if(!e||P(e.state))return;const t=B(e);return t.file?.ready_from_start}static get watchers(){return{channel:[{onChannel:0}],connected:[{onConnected:0}],browsingPath:[{onBrowsing:0}],browsingService:[{onBrowsing:0}],nodeId:[{onNode:0}]}}static get style(){return":host{--card:220 18% 10%;--bg:216 18% 7%;--border:220 15% 18%;--primary:160 60% 45%;--primary-foreground:220 20% 7%;--destructive:0 70% 50%;--muted:220 15% 13%;--muted-foreground:215 10% 52%;--foreground:210 20% 90%;--amber:38 75% 55%;--blue:206 72% 63%;--radius:0.375rem;display:block;color:hsl(var(--foreground));font-family:ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;font-size:13px;line-height:1.45;container-type:inline-size}:host(.standalone){position:relative;height:100%;background:hsl(var(--card));border:1px solid hsl(var(--border));border-radius:var(--radius);overflow:auto}:host(.compact){flex:none}*{box-sizing:border-box}button{font:inherit;color:inherit;cursor:pointer}button:disabled{cursor:not-allowed}:focus-visible{outline:2px solid hsl(var(--primary));outline-offset:2px}.hidden-input{display:none}.mono,code,.stats,.sum,.inp,.dest,.detect .host{font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace}code{font-size:12px}.muted{color:hsl(var(--muted-foreground))}.pad{padding:18px 14px}.ib{width:28px;height:28px;display:inline-grid;place-items:center;border-radius:4px;border:1px solid transparent;background:transparent;color:hsl(var(--muted-foreground));flex:none;padding:0}.ib:hover:not(:disabled){background:hsl(var(--muted));color:hsl(var(--foreground))}.ib:disabled{opacity:0.4}.ib.new{color:hsl(var(--primary));border-color:hsl(var(--primary) / 0.55);background:hsl(var(--primary) / 0.12)}.btn{border-radius:4px;padding:7px 14px;font-size:12px;font-weight:600;border:1px solid hsl(var(--border));background:hsl(var(--muted));white-space:nowrap;display:inline-flex;align-items:center;gap:6px;text-decoration:none;color:hsl(var(--foreground))}.btn:hover:not(:disabled){border-color:hsl(var(--muted-foreground))}.btn.pri{background:hsl(var(--primary));border-color:hsl(var(--primary));color:hsl(var(--primary-foreground))}.btn.dng{background:hsl(var(--destructive));border-color:hsl(var(--destructive));color:#fff}.btn:disabled{opacity:0.45}.lnk{background:none;border:0;color:hsl(var(--muted-foreground));font-size:11px;padding:2px 4px;display:inline-flex;align-items:center;gap:4px}.lnk:hover{color:hsl(var(--foreground))}.lnk.inline{color:hsl(var(--primary));padding:0}.pill{font-size:10px;font-weight:600;text-transform:uppercase;letter-spacing:0.05em;padding:2px 7px;border-radius:3px;white-space:nowrap;flex:none}.pill.dl{background:hsl(var(--primary) / 0.18);color:hsl(var(--primary))}.pill.meta,.pill.sd{background:hsl(var(--blue) / 0.18);color:hsl(var(--blue))}.pill.mv{background:hsl(var(--amber) / 0.18);color:hsl(var(--amber))}.pill.ok{background:hsl(var(--primary));color:hsl(var(--primary-foreground))}.pill.err{background:hsl(var(--destructive) / 0.2);color:hsl(var(--destructive))}.pill.ps,.pill.q{background:hsl(var(--muted));color:hsl(var(--muted-foreground))}.bar{display:block;height:5px;border-radius:3px;background:hsl(var(--muted));overflow:hidden;position:relative}.bar i{display:block;height:100%;background:hsl(var(--primary));border-radius:3px;transition:width 0.6s linear}.bar.indet i{width:30% !important;animation:slide 1.3s ease-in-out infinite;background:hsl(var(--blue))}.bar.paused i{background:hsl(var(--muted-foreground))}.bar.fail i{background:hsl(var(--destructive))}.bar.moving i{background:hsl(var(--amber))}.bar.seed i{background:hsl(var(--blue))}@keyframes slide{0%{transform:translateX(-100%)}100%{transform:translateX(340%)}}.jobs{display:flex;flex-direction:column}.job{display:grid;grid-template-columns:28px minmax(0, 1fr) auto;gap:4px 10px;padding:10px 12px;border-bottom:1px solid hsl(var(--border) / 0.6);align-items:center}.job:last-child{border-bottom:0}.job .kind{grid-row:span 3;align-self:start;width:28px;height:28px;border-radius:6px;display:grid;place-items:center;background:hsl(var(--muted));color:hsl(var(--muted-foreground))}.job .kind.t{color:hsl(var(--blue))}.job .kind.h{color:hsl(var(--primary))}.job .kind.n{color:hsl(var(--amber))}.job .title{display:flex;gap:8px;align-items:center;min-width:0}.job .title .nm{font-weight:500;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}.job .acts{display:flex;gap:2px;grid-row:1;grid-column:3}.job .bar,.job .stats{grid-column:2 / 4}.stats{display:flex;flex-wrap:wrap;gap:4px 14px;font-size:11px;color:hsl(var(--muted-foreground));font-variant-numeric:tabular-nums}.stats b{color:hsl(var(--foreground));font-weight:500}.stats .err{color:hsl(var(--destructive))}.job[data-state='Deleting']{opacity:0.6}.drawer{border-top:1px solid hsl(var(--border));background:hsl(var(--bg));display:flex;flex-direction:column;max-height:min(46vh, 380px)}.drawer-h{display:flex;align-items:center;gap:10px;padding:6px 12px;border-bottom:1px solid hsl(var(--border));flex:none}.drawer-h h4,.strip h4{margin:0;font-size:12px;font-weight:600;letter-spacing:0.04em;text-transform:uppercase}.sum{color:hsl(var(--muted-foreground));font-size:11px;font-variant-numeric:tabular-nums}.sp{flex:1}.drawer-b{overflow:auto;min-height:0}.strip{display:flex;align-items:center;gap:10px;padding:7px 12px;border:0;border-top:1px solid hsl(var(--border));background:hsl(var(--bg));width:100%;text-align:left}.strip .bar{flex:1 1 120px}.overlay{position:absolute;inset:0;background:rgba(5, 7, 9, 0.6);display:grid;place-items:center;padding:14px;z-index:20}:host(.standalone) .overlay{position:fixed}.modal{width:min(100%, 420px);max-height:100%;overflow:auto;background:hsl(var(--card));border:1px solid hsl(var(--border));border-radius:8px;box-shadow:0 20px 50px -10px rgba(0, 0, 0, 0.7)}.modal.wide{width:min(100%, 480px)}.dlg,.fetch-form.dialog{padding:16px;display:flex;flex-direction:column;gap:14px}.dlg h4,.dlg-h h4{margin:0;font-size:14px;font-weight:600}.dlg-h{display:flex;align-items:center;gap:10px;color:hsl(var(--primary))}.dlg-h h4{color:hsl(var(--foreground))}.dlg-f{display:flex;justify-content:flex-end;gap:8px;flex-wrap:wrap}.dlg-f .left{margin-right:auto}.dtx{margin:0;font-size:13px}.hint{font-size:11px;color:hsl(var(--muted-foreground));margin:0}.hint.block{display:block;margin-top:2px}.hint.err{color:hsl(var(--destructive))}.hint.where{color:hsl(var(--amber))}.fld{display:flex;flex-direction:column;gap:6px;min-width:0}.fld>label,.fld>span:first-child,legend{font-size:11px;text-transform:uppercase;letter-spacing:0.05em;color:hsl(var(--muted-foreground))}.inp{width:100%;min-width:0;background:hsl(var(--muted));border:1px solid hsl(var(--border));border-radius:4px;color:hsl(var(--foreground));padding:8px 10px;font-size:12px}.inp:focus{outline:none;border-color:hsl(var(--primary))}.inline-row{display:flex;gap:8px;align-items:stretch}.detect{display:flex;align-items:center;gap:8px;font-size:12px;color:hsl(var(--muted-foreground));min-height:20px;min-width:0}.detect .host{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.note{display:flex;gap:8px;align-items:flex-start;font-size:12px;line-height:1.45;padding:8px 10px;border-radius:4px;border:1px solid hsl(var(--border));background:hsl(var(--muted))}.note svg{flex:none;margin-top:2px}.note.err{border-color:hsl(var(--destructive) / 0.5)}.note.err svg{color:hsl(var(--destructive))}.note.warn{border-color:hsl(var(--amber) / 0.5)}.note.warn svg{color:hsl(var(--amber))}.note.info svg{color:hsl(var(--primary))}.or{display:flex;align-items:center;gap:10px;color:hsl(var(--muted-foreground));font-size:11px;text-transform:uppercase;letter-spacing:0.06em}.or::before,.or::after{content:'';flex:1;height:1px;background:hsl(var(--border))}.drop{border:1px dashed hsl(var(--border));border-radius:6px;padding:14px;display:flex;align-items:center;gap:12px;color:hsl(var(--muted-foreground));font-size:12px;background:transparent;text-align:left}.drop svg{color:hsl(var(--blue));flex:none}.drop b{color:hsl(var(--foreground));font-weight:500}.filechip{display:flex;gap:10px;align-items:center;padding:10px;border:1px solid hsl(var(--border));border-radius:4px;background:hsl(var(--muted))}.filechip>svg{color:hsl(var(--blue));flex:none}.filechip>div{flex:1;min-width:0}.filechip b{display:block;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.filechip span{color:hsl(var(--muted-foreground));font-size:11px}.filechip.bad{border-color:hsl(var(--destructive) / 0.55)}.filechip.bad>svg{color:hsl(var(--destructive))}.dest-row,.sa-dest{display:flex;gap:8px;align-items:center;flex-wrap:wrap}.dest{display:flex;align-items:center;gap:8px;background:hsl(var(--bg));border:1px solid hsl(var(--border));border-radius:4px;padding:7px 10px;font-size:12px;min-width:0;flex:1 1 200px}.dest span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dest svg{color:hsl(var(--primary));flex:none}fieldset.order{border:0;margin:0;padding:0;display:flex;flex-direction:column;gap:6px}fieldset.order legend{margin-bottom:6px}.opt{display:flex;gap:8px;align-items:flex-start;padding:8px 10px;border:1px solid hsl(var(--border));border-radius:4px;font-size:12px;cursor:pointer}.opt.on{border-color:hsl(var(--primary));background:hsl(var(--primary) / 0.08)}.opt input,.checkline input,.seg input{accent-color:hsl(var(--primary));margin:2px 0 0}.checkline{display:flex;gap:8px;align-items:flex-start;font-size:12px;cursor:pointer}.login{display:flex;flex-direction:column;gap:8px}.login>.lnk{align-self:flex-start;padding-left:0}.auth{display:flex;flex-direction:column;gap:10px;padding:10px;border:1px solid hsl(var(--border));border-radius:4px}.seg{display:flex;flex-wrap:wrap;gap:6px}.seg label{display:flex;gap:6px;align-items:center;font-size:11px;padding:4px 8px;border:1px solid hsl(var(--border));border-radius:999px;cursor:pointer}.seg label.on{border-color:hsl(var(--primary));color:hsl(var(--primary))}.seg input{margin:0}.crumbs{display:flex;flex-wrap:wrap;align-items:center;gap:2px;font-family:ui-monospace, SFMono-Regular, Menlo, monospace}.crumbs .lnk{font-size:12px}.crumbs .sep{color:hsl(var(--muted-foreground))}.folders{display:flex;flex-direction:column;border:1px solid hsl(var(--border));border-radius:4px;max-height:220px;overflow:auto}.folders .muted{padding:10px}.folder-row{display:flex;align-items:center;gap:8px;padding:7px 10px;border:0;border-bottom:1px solid hsl(var(--border) / 0.6);background:transparent;text-align:left;font-family:ui-monospace, SFMono-Regular, Menlo, monospace;font-size:12px}.folder-row:hover{background:hsl(var(--muted))}.folder-row svg{color:hsl(var(--primary))}.blocker{display:flex;flex-direction:column;gap:10px}.empty{display:flex;flex-direction:column;align-items:center;text-align:center;gap:8px;padding:30px 20px}.empty>svg{color:hsl(var(--muted-foreground))}.empty b{font-size:14px;font-weight:600}.empty span{color:hsl(var(--muted-foreground));font-size:12px;max-width:44ch}.spin{width:22px;height:22px;border-radius:50%;border:3px solid hsl(var(--border));border-top-color:hsl(var(--primary));animation:spin 1s linear infinite}@keyframes spin{to{transform:rotate(360deg)}}.standalone{display:flex;flex-direction:column;min-height:100%}.sa-head{padding:14px 16px 10px;display:flex;flex-direction:column;gap:4px}.sa-title{display:flex;align-items:baseline;gap:10px;flex-wrap:wrap}.sa-title h3{margin:0;font-size:16px;font-weight:600}.sa-title .node{color:hsl(var(--muted-foreground))}.saving{font-size:12px;color:hsl(var(--muted-foreground))}.sa-add{padding:0 16px 14px;display:flex;flex-direction:column;gap:10px;border-bottom:1px solid hsl(var(--border))}.fetch-form.inline{display:flex;flex-direction:column;gap:10px}.tabs{display:flex;gap:4px;padding:0 10px;border-bottom:1px solid hsl(var(--border));overflow-x:auto}.tabs button{padding:9px 10px;font-size:12px;color:hsl(var(--muted-foreground));border:0;border-bottom:2px solid transparent;background:none;white-space:nowrap}.tabs button.on{color:hsl(var(--foreground));border-bottom-color:hsl(var(--primary))}.tabs b{font-family:ui-monospace, SFMono-Regular, Menlo, monospace;font-weight:500;color:hsl(var(--muted-foreground));margin-left:6px}.tab-h{display:flex;justify-content:space-between;align-items:center;padding:8px 12px;font-size:12px;color:hsl(var(--muted-foreground));border-bottom:1px solid hsl(var(--border) / 0.6)}.toasts{position:absolute;left:12px;right:12px;bottom:12px;display:flex;flex-direction:column;gap:8px;z-index:30;pointer-events:none;align-items:flex-end}:host(.standalone) .toasts{position:sticky;margin:12px}.toast{pointer-events:auto;display:flex;gap:10px;align-items:center;padding:10px 12px;background:hsl(var(--bg));border:1px solid hsl(var(--primary) / 0.5);border-radius:6px;width:min(100%, 420px);box-shadow:0 12px 30px -12px rgba(0, 0, 0, 0.7)}.toast>svg{color:hsl(var(--primary));flex:none}.toast.bad{border-color:hsl(var(--destructive) / 0.55)}.toast.bad>svg{color:hsl(var(--destructive))}.toast .t{flex:1;min-width:0}.toast .t b{display:block;font-weight:600}.toast .t span{color:hsl(var(--muted-foreground));font-family:ui-monospace, SFMono-Regular, Menlo, monospace;font-size:11px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;display:block}.overlay.player{padding:10px}.overlay.player phirepass-media-player{width:min(100%, 880px)}@container (max-width: 480px){.job{padding:9px 10px}.job .title .pill.meta{display:none}.inline-row{flex-wrap:wrap}.inline-row .inp{flex-basis:100%}.inline-row .btn.pri{flex:1;justify-content:center}.stats{gap:2px 10px}}@media (prefers-reduced-motion: reduce){.bar i{transition:none}.bar.indet i{animation:none;width:100% !important;opacity:0.5}.spin{animation:none}}"}},[513,"phirepass-downloader",{nodeId:[1,"node-id"],nodeLabel:[1,"node-label"],token:[1],channel:[16],connected:[4],channelFactory:[16],browsingService:[1,"browsing-service"],browsingPath:[1025,"browsing-path"],compact:[516],streamBase:[1,"stream-base"],canConfigure:[4,"can-configure"],inlinePlayer:[4,"inline-player"],serverHost:[1,"server-host"],serverPort:[2,"server-port"],serverId:[1,"server-id"],allowInsecure:[4,"allow-insecure"],heartbeatInterval:[2,"heartbeat-interval"],connection:[32],caps:[32],jobs:[32],tab:[32],drawerOpen:[32],dialogOpen:[32],unread:[32],form:[32],where:[32],starting:[32],refusal:[32],confirm:[32],notices:[32],subDir:[32],picker:[32],player:[32],receive:[64],openFetch:[64],toggleDrawer:[64],jobForPath:[64],deleteDownload:[64],torrentPathFor:[64],startTorrentPath:[64]},void 0,{channel:[{onChannel:0}],connected:[{onConnected:0}],browsingPath:[{onBrowsing:0}],browsingService:[{onBrowsing:0}],nodeId:[{onNode:0}]}]);function me(){"undefined"!=typeof customElements&&["phirepass-downloader","phirepass-media-player"].forEach((e=>{switch(e){case"phirepass-downloader":customElements.get(t(e))||customElements.define(t(e),ge);break;case"phirepass-media-player":customElements.get(t(e))||w()}}))}me();export{y as D,ge as P,me as d,C as i,x as s}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{P as o,d as s}from"./p-
|
|
1
|
+
import{P as o,d as s}from"./p-B4kFfbHE.js";const p=o,r=s;export{p as PhirepassDownloader,r as defineCustomElement}
|