hfs 0.49.0-alpha1 → 0.49.0-alpha2
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 +1 -1
- package/admin/assets/index-6afd4b06.js +542 -0
- package/{frontend/assets/sha512-82ed8772.js → admin/assets/sha512-f5f12dc1.js} +1 -1
- package/admin/index.html +1 -1
- package/central.json +30 -8
- package/frontend/assets/index-3a379840.js +94 -0
- package/frontend/assets/index-db5f0e4b.css +1 -0
- package/{admin/assets/sha512-ae917116.js → frontend/assets/sha512-3392c31f.js} +1 -1
- package/frontend/index.html +2 -2
- package/package.json +1 -2
- package/src/api.auth.js +6 -6
- package/src/api.file_list.js +10 -27
- package/src/api.net.js +59 -58
- package/src/api.plugins.js +14 -25
- package/src/api.vfs.js +9 -12
- package/src/block.js +14 -1
- package/src/comments.js +49 -0
- package/src/const.js +3 -2
- package/src/cross.js +29 -1
- package/src/debounceAsync.js +17 -1
- package/src/frontEndApis.js +28 -6
- package/src/github.js +24 -30
- package/src/langs/hfs-lang-it.json +5 -3
- package/src/langs/hfs-lang-ru.json +6 -4
- package/src/listen.js +3 -2
- package/src/middlewares.js +3 -1
- package/src/misc.js +4 -4
- package/src/perm.js +19 -12
- package/src/plugins.js +33 -12
- package/src/serveFile.js +2 -3
- package/src/upload.js +5 -1
- package/src/util-http.js +8 -6
- package/src/vfs.js +24 -32
- package/src/watchLoad.js +5 -12
- package/src/zip.js +4 -4
- package/admin/assets/index-b34ac7b4.js +0 -536
- package/frontend/assets/index-4cbc2ffc.js +0 -94
- package/frontend/assets/index-cbe043ee.css +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@charset "UTF-8";:root{height:100dvh;--bg: #fff;--text: #555;--ghost-contrast: #8882;--ghost-contrast-alt: #eee;--faint-contrast: #8884;--mild-contrast: #8886;--good-contrast: #000a;--button-bg: #6080aa;--button-text: #eaeaea;--focus-color: #468;--separator: " – "}:root .highlightedText,:root .file-menu a:hover{color:#0006;text-shadow:0 0 3px rgba(0,0,0,.4)}:root .theme-dark{--bg: #000;--text: #999;--ghost-contrast-alt: #181818;--good-contrast: #fffa;--button-bg: #345;--button-text: #999;color-scheme:dark}:root .theme-dark .highlightedText,:root .theme-dark .file-menu a:hover,:root .file-menu .theme-dark a:hover{color:#fff;text-shadow:0 0 3px #fff}:root .theme-dark a{color:#8ac}:root .theme-dark .dialog-closer{background:#633}:root .theme-dark .dialog-icon{color:#ccc}:root .theme-dark .dialog-icon .icon{color:#aaa}:root .theme-dark .dialog-backdrop{background:rgba(51,51,51,.7333333333)}:root .theme-dark .error-msg{color:#b88;background-color:#623}:root .theme-dark button.toggled{color:#eee}body{background-color:var(--bg);margin:0;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}body,button,select,input{font-size:12pt}#root>div{max-width:54em;margin:auto;min-height:100vh;display:flex;flex-direction:column}body,input{color:var(--text)}code{font-family:source-code-pro,Menlo,Monaco,Consolas,Courier New,monospace}input:not([type=checkbox],[type=range]),select,textarea{padding:.3em .4em;border-radius:.5em;background:var(--bg);border-color:var(--mild-contrast);color:var(--good-contrast);max-width:100%;box-sizing:border-box;width:100%}input[type=range]{width:calc(100% - 1px)}input[type=checkbox]{transform:scale(1.7);accent-color:var(--button-bg)}textarea{font-size:14pt}label input[type=checkbox]{margin-right:.8em}select{text-align:center}.hidden{display:none!important}[class^=fa-]:before,[class*=" fa-"]:before{margin:0}.icon{font-size:1.2em;height:1.2em;width:1.4em;display:inline-block;text-align:center}img.file-icon{height:1em}.file-icon{background-size:contain;background-repeat:no-repeat;background-position:center;vertical-align:text-bottom}.icon.mirror:before{transform:scaleX(-1)}a{text-decoration:none;color:var(--button-bg)}button{background-color:var(--button-bg);color:var(--button-text);padding:.5em 1em;border:transparent;text-decoration:none;border-radius:.3em;vertical-align:middle;cursor:pointer;transition:background-color .5s}button:hover{outline:1px solid var(--mild-contrast)}button[disabled]{background-color:var(--faint-contrast)}button.toggled{color:#fff;text-shadow:0 0 3px #fff}button:focus-visible,.breadcrumb:focus-visible{outline:3px solid var(--focus-color)}a>button{width:100%}input:focus-visible,select:focus-visible,ul a:focus-visible{border-radius:.3em;border-color:transparent;outline:2px solid var(--focus-color)}.icon-button,ul.dir li .entry-panel .file-menu-button{font-size:.7em;padding:.2em .4em;margin-left:.4em;vertical-align:bottom}.error-msg{background-color:#faa;color:#833;padding:.5em 1em}.hide-back,.upload-toolbar,header{background-color:var(--bg)}header{position:sticky;top:0;padding:.2em .1em;z-index:3}kbd{background-color:#eee;border-radius:3px;border:1px solid #b4b4b4;box-shadow:0 1px 1px #0003,0 2px #ffffffb3 inset;color:#333;display:inline-block;font-size:.85em;font-weight:700;line-height:1;padding:2px 4px;white-space:nowrap;margin-right:.5em}.before-sliding{width:0!important;flex:0!important;margin:0!important;height:0!important;padding:0!important;overflow:hidden!important;transition:flex .5s}.show-sliding{transition:flex .5s;overflow:clip;flex:1;white-space:nowrap}.ani-working{animation:1s blink infinite}@keyframes blink{0%{opacity:1}50%{opacity:.2}}@keyframes spin{to{transform:rotate(360deg)}}@keyframes fade-in{0%{opacity:0}to{opacity:1}}.spinner,.icon.spinner:before{animation:1.5s spin infinite linear;display:inline-flex;justify-content:center;align-items:center;width:min-content}.breadcrumb{padding:.1em .6em .2em;line-height:1.8em;border-radius:.7em;background-color:var(--button-bg);color:var(--button-text);border-top:1px solid #666;margin-right:-.1em}.breadcrumb:nth-child(-n+3) .icon{padding:0 .2em}#folder-stats,#filter-bar>span{font-size:90%}#folder-stats{margin:.5em 0 0 .5em;float:right}#folder-stats .icon{margin-right:.3em}#filter{flex:1;box-sizing:border-box}#filter-bar{display:flex;align-items:center;gap:.8em;margin:.2em 0 0;padding:2px 0 1px 3px;height:1.8em}#filter-bar input[type=checkbox]{margin-top:.3em}#filter-bar span:empty{display:none}ul.dir{flex:1;padding:0;margin:0;clear:both}ul.dir>p{text-align:center}ul.dir li{display:block;list-style-type:none;padding:.3em .3em .4em;border-bottom:1px solid var(--faint-contrast)}ul.dir li:nth-of-type(odd){background-color:var(--ghost-contrast)}ul.dir li input[type=checkbox]{margin-right:1em}@media (hover: none){ul.dir li .link-wrapper .popup-menu-button{display:none}}@media (hover: hover){ul.dir li .link-wrapper:not(:hover) .popup-menu-button{display:none}ul.dir li .link-wrapper:hover{padding:1em;margin:-1em}}ul.dir li .link-wrapper a:last-of-type{word-break:break-word;padding-right:.3em}ul.dir li .link-wrapper a .icon{margin-right:.5em;vertical-align:text-bottom;display:inline-block;text-align:center}ul.dir li .link-wrapper a:hover{text-decoration:underline}ul.dir li .entry-panel{float:right;padding-top:.3em;display:flex;align-items:center}ul.dir li .entry-panel .file-menu-button{margin:-3px 0 -3px .4em}ul.dir li .entry-panel .entry-details{font-size:90%;margin-left:4px;font-variant-numeric:tabular-nums}ul.dir li .entry-panel .entry-details .entry-size-unit{margin-left:.3em}ul.dir li>div:last-of-type{clear:both}ul.dir li.page-separator{margin-top:1em;position:relative}ul.dir li.page-separator:before{content:attr(label);position:absolute;top:-1.8em;font-size:smaller;margin-left:calc(50% - 1em);opacity:.9}.entry-comment{display:inline;white-space:pre-wrap;word-break:break-word}.entry-comment:before,.entry-comment:after{font-size:1.5em;font-family:serif;line-height:1px;position:relative}.entry-comment:before{content:"“";margin-left:.5em;margin-right:.1em;top:.2em}.entry-comment:after{content:"„";top:-.1em;margin-left:.1em}#menu-bar{display:flex;justify-content:space-evenly;flex-wrap:wrap}#menu-bar>*{flex:1;margin:.1em}#menu-bar>*:first-child{margin-left:0}#menu-bar>*:last-child{margin-right:0}#menu-bar button{padding:min(1vh,.5em) 0}#searched{margin:.2em}#user-panel{display:flex;flex-direction:column;gap:1em}#user-panel a>button{width:100%}button label{cursor:inherit;margin-left:.4em}.dialog-backdrop.working{font-size:5em;animation:1s fade-in}.dialog-content{padding:.2em}.dialog-alert .dialog-content{text-align:center}.dialog-alert .dialog-content p{text-align:left;display:inline-block}.dialog{min-width:11em;--color: var(--button-bg)}.dialog-icon .icon{margin-left:-1px;font-size:95%;margin-top:.4em;border-radius:.6em 0}#paging{position:sticky;bottom:0;display:flex;gap:.1em;background-color:var(--bg);padding:0 .2em .2em}#paging>button{z-index:1}#paging button{box-shadow:0 0 .3em .3em #0003}#paging #paging-middle{padding:0 .5em;margin:0 -.3em;display:flex;gap:.5em;flex:1;overflow-x:auto}#paging #paging-middle>button{flex:1;padding-top:0;padding-bottom:0}#paging button{background:var(--button-bg);text-align:center;white-space:nowrap;padding:.5em}.upload-toolbar{position:sticky;top:-4px}.upload-progress:before{content:var(--separator)}.entry-size:after{content:var(--separator)}.upload-progress{min-width:4em;display:inline-block;margin-left:.5em}.upload-list{margin-top:1em}.upload-list td:nth-child(1){width:0}.upload-list td:nth-child(2){text-align:right;width:0;white-space:nowrap;padding-left:.5em}.upload-list td:nth-child(3){padding:.2em .5em;word-break:break-word}.nowrap{white-space:nowrap}.dialog-login form{display:flex;flex-direction:column;gap:1.2em}.dialog-login label{display:block;margin-bottom:.5em;margin-left:.1em}.miss-perm{margin:.3em}.popup-menu-button{font-size:.8em;padding:.2em .3em;position:absolute;opacity:.8;white-space:nowrap}.popup-menu-button:hover{opacity:1}.file-dialog .dialog{min-width:13em}.file-dialog-properties{word-break:break-word;line-height:1.5em;margin:0}.file-dialog-properties dt{font-weight:700}.file-dialog-properties dd{margin-left:1.5em}.file-menu{margin-top:1em;padding-top:1em;border-top:1px solid var(--faint-contrast);display:flex;flex-direction:column;gap:1em}.file-menu a{display:flex;align-items:flex-start}.file-menu a label{margin-top:.1em}.file-menu a label small{display:block}.file-menu a .icon{margin-right:.5em}#root>.tiles-mode{max-width:none;margin:0 1em;--tiles-size: 5;--name-lines: 3;--name-height: calc(4.7em + var(--tiles-size) * .4em + 1.2em * var(--name-lines));--tile-width: calc(5em + 1em * var(--tiles-size))}#root>.tiles-mode ul.dir{display:grid;grid-template-columns:repeat(auto-fill,minmax(var(--tile-width),1fr));grid-auto-rows:calc(var(--name-height) + 1.3em);gap:0 20px}#root>.tiles-mode ul.dir li{text-align:center;position:relative;display:flex;flex-direction:column;border-bottom:none;overflow-x:clip;padding:.5em 0 0}#root>.tiles-mode ul.dir li .link-wrapper:not(:hover){max-height:var(--name-height);display:block;display:-webkit-box;overflow:hidden;-webkit-line-clamp:calc(var(--name-lines) + 1);-webkit-box-orient:vertical}#root>.tiles-mode ul.dir li .link-wrapper a:last-of-type{padding:0}#root>.tiles-mode ul.dir li .link-wrapper a span{display:block}#root>.tiles-mode ul.dir li .link-wrapper a .icon.icon{font-size:calc(1.2rem + .6rem * var(--tiles-size))}#root>.tiles-mode ul.dir li .link-wrapper a img.icon{width:auto;height:1em;padding:.1em 0}#root>.tiles-mode ul.dir li .link-wrapper a .icon{font-size:4rem;display:block;margin:auto}#root>.tiles-mode ul.dir li .link-wrapper:hover{overflow:visible;display:block;z-index:1}#root>.tiles-mode ul.dir li .link-wrapper:hover .icon:before{text-decoration:none}#root>.tiles-mode ul.dir li .link-wrapper:hover{padding:0;margin:0}#root>.tiles-mode ul.dir li:nth-of-type(odd){background-color:var(--bg)}#root>.tiles-mode ul.dir li .entry-panel{justify-content:center;font-size:10pt}#root>.tiles-mode ul.dir li .entry-details{font-size:80%}#root>.tiles-mode ul.dir li.page-separator:before{content:""}#root>.tiles-mode ul.dir li input[type=checkbox]{margin:0;position:absolute;top:.3em;right:1em}#root>.tiles-mode ul.dir li .link-wrapper a{display:inline}#root>.tiles-mode ul.dir li:hover{--bg: var(--ghost-contrast-alt);background:var(--bg)}#root>.tiles-mode ul.dir li:hover .link-wrapper,#root>.tiles-mode ul.dir li:hover .entry-panel{z-index:1;background:var(--bg)}#root>.tiles-mode ul.dir li:hover input[type=checkbox]{z-index:2}#root>.tiles-mode ul.dir li:hover .entry-panel{padding-bottom:.3em}#root>.tiles-mode .entry-size:after{content:none}#root>.tiles-mode .entry-ts{display:none}#root>.tiles-mode .popup-menu-button{position:absolute;top:0;left:0}#root>.tiles-mode #filter-bar{margin-bottom:1em}#root>.tiles-mode #paging{z-index:1}#root .file-show{--nav-size: min(25vh, 25vw)}#root .file-show>div{height:100%;width:100%}#root .file-show .showing-container{width:100%;height:100%;display:flex;justify-content:center;align-items:center}#root .file-show .showing{max-width:calc(100% - var(--nav-size) * 2);max-height:100%}#root .file-show img.showing{max-width:100%}#root .file-show .main{flex:1;position:relative;max-height:100%;overflow:hidden}#root .file-show .freeY .main,#root .file-show .fullWidth .main{overflow-y:auto}#root .file-show .freeY .showing,#root .file-show .fullWidth .showing{max-height:initial;margin:auto}#root .file-show .freeY .showing-container,#root .file-show .fullWidth .showing-container{overflow:auto;align-items:flex-start}#root .file-show .fullWidth .showing-container,#root .file-show .fullWidth .showing{width:100%}#root .file-show .nav{position:absolute;margin:-.4em;font-size:var(--nav-size);cursor:pointer;opacity:.3;-webkit-text-stroke:2px black;user-select:none;transition:opacity .3s}#root .file-show .nav:hover{opacity:.7}#root .file-show .nav.nav-hidden{opacity:0}#root .file-show .bar{padding:.5em 1em;background:var(--bg);opacity:.8;display:flex;flex-wrap:wrap;align-items:center;justify-content:flex-end;gap:.5em 1.5em}#root .file-show .bar .entry-details{font-size:smaller}#root .file-show .bar .entry-ts{display:inherit}#root .file-show .bar .entry-size:after{display:none}.file-show-help kbd{margin:.5em}.file-show-help kbd:first-of-type{margin-top:1em}@media (min-width: 42em){body{scrollbar-width:thin;scrollbar-color:var(--button-bg) var(--ghost-contrast)}body::-webkit-scrollbar{width:12px}body::-webkit-scrollbar-track{background:var(--ghost-contrast)}body::-webkit-scrollbar-thumb{background-color:var(--button-bg);border-radius:20px;border:1px solid var(--ghost-contrast)}}@media (max-width: 42em){:root{--ghost-contrast: #8883}body,button,select{font-size:14pt}#menu-bar button label,#filter-bar button label{display:none}#filter-bar{margin-top:.4em}#filter-bar button{width:17.6vw;height:2.3em}.breadcrumb{word-break:break-all}.breadcrumb .icon{font-size:24px}#root>.tiles-mode{margin:0}}@media (max-height: 600px){.file-dialog .dialog-content{display:flex;gap:3em;margin:1em}.file-dialog .dialog-content .file-menu{margin-top:0;padding-top:0;border-top:none;margin-left:2em;padding-left:2em;border-left:1px solid var(--faint-contrast)}}@media (pointer: coarse){#root>.tiles-mode .file-menu-button{font-size:1em;margin-top:.3em}}.dialog-backdrop{position:fixed;inset:0;background:#8886;backdrop-filter:blur(2px);display:flex;justify-content:center;align-items:center;z-index:1000}.dialog{background:#fff;background:var(--bg);padding:max(.5em,1vw,2vh);padding-top:0;border-radius:1em;position:relative;margin:0 3vw;overflow:hidden;max-height:calc(100vh - 2em);display:flex;flex-direction:column;justify-content:center}.dialog-icon{color:#fff;background-color:var(--color);position:absolute;top:0;width:2em;height:1.8em;text-align:center;border-radius:.8em 0}.dialog-icon-text{display:flex;align-items:center;justify-content:center}.dialog-title{font-size:120%;margin:.3em 0;padding:0 .5em;min-height:1.2em}.dialog-closer~.dialog-title{margin-right:2em}.dialog-type~.dialog-title{margin-left:2em}.dialog-icon~.dialog-title{text-align:center}.dialog-closer{border-radius:0 .8em;right:0;padding:0;background-color:#c88}.dialog-icon~.dialog-content{margin-top:1em}.dialog-type{left:0;top:0;overflow:hidden;opacity:.7}.dialog-content{overflow:auto;max-height:calc(100vh - 4.5em)}.dialog-content p{white-space:pre-wrap;margin:.5em 0}.dialog-confirm .dialog-content button{margin-top:1em}.dialog-alert-info{--color: #282 }.dialog-alert-warning{--color: #c91 }.dialog-alert-error{--color: #822}@media (max-width: 42em){.dialog-icon{font-size:120%}.dialog-icon~.dialog-content{margin-top:1.5em}}.dialog-prompt label{display:block;margin:.5em .1em}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{g as OF,c as UF}from"./index-
|
|
1
|
+
import{g as OF,c as UF}from"./index-3a379840.js";function gF(sF,hF){for(var eF=0;eF<hF.length;eF++){const tF=hF[eF];if(typeof tF!="string"&&!Array.isArray(tF)){for(const w in tF)if(w!=="default"&&!(w in sF)){const lF=Object.getOwnPropertyDescriptor(tF,w);lF&&Object.defineProperty(sF,w,lF.get?lF:{enumerable:!0,get:()=>tF[w]})}}}return Object.freeze(Object.defineProperty(sF,Symbol.toStringTag,{value:"Module"}))}var dF={exports:{}};/*
|
|
2
2
|
* [js-sha512]{@link https://github.com/emn178/js-sha512}
|
|
3
3
|
*
|
|
4
4
|
* @version 0.8.0
|
package/frontend/index.html
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=0" />
|
|
6
6
|
<link href="/fontello.css" rel="stylesheet" />
|
|
7
7
|
|
|
8
|
-
<script type="module" crossorigin src="/assets/index-
|
|
9
|
-
<link rel="stylesheet" href="/assets/index-
|
|
8
|
+
<script type="module" crossorigin src="/assets/index-3a379840.js"></script>
|
|
9
|
+
<link rel="stylesheet" href="/assets/index-db5f0e4b.css">
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|
|
12
12
|
<noscript>You need to enable JavaScript to run this app.</noscript>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hfs",
|
|
3
|
-
"version": "0.49.0-
|
|
3
|
+
"version": "0.49.0-alpha2",
|
|
4
4
|
"description": "HTTP File Server",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"file server",
|
|
@@ -79,7 +79,6 @@
|
|
|
79
79
|
"lodash": "^4.17.21",
|
|
80
80
|
"minimist": "^1.2.6",
|
|
81
81
|
"nat-upnp-ts": "^2.0.1",
|
|
82
|
-
"node-html-parser": "^6.1.5",
|
|
83
82
|
"open": "^8.4.0",
|
|
84
83
|
"tssrp6a": "^3.0.0",
|
|
85
84
|
"unzip-stream": "^0.3.1",
|
package/src/api.auth.js
CHANGED
|
@@ -33,17 +33,17 @@ function makeExp() {
|
|
|
33
33
|
const login = async ({ username, password }, ctx) => {
|
|
34
34
|
if (!username || !password) // some validation
|
|
35
35
|
return new apiMiddleware_1.ApiError(const_1.HTTP_BAD_REQUEST);
|
|
36
|
-
const
|
|
37
|
-
if (!
|
|
36
|
+
const account = (0, perm_1.getAccount)(username);
|
|
37
|
+
if (!account || !(0, perm_1.accountCanLogin)(account))
|
|
38
38
|
return new apiMiddleware_1.ApiError(const_1.HTTP_UNAUTHORIZED);
|
|
39
|
-
if (!
|
|
39
|
+
if (!account.hashed_password)
|
|
40
40
|
return new apiMiddleware_1.ApiError(const_1.HTTP_NOT_ACCEPTABLE);
|
|
41
|
-
if (!await (0, crypt_1.verifyPassword)(
|
|
41
|
+
if (!await (0, crypt_1.verifyPassword)(account.hashed_password, password))
|
|
42
42
|
return new apiMiddleware_1.ApiError(const_1.HTTP_UNAUTHORIZED);
|
|
43
43
|
if (!ctx.session)
|
|
44
44
|
return new apiMiddleware_1.ApiError(const_1.HTTP_SERVER_ERROR);
|
|
45
45
|
await loggedIn(ctx, username);
|
|
46
|
-
return { ...makeExp(), redirect:
|
|
46
|
+
return { ...makeExp(), redirect: account.redirect };
|
|
47
47
|
};
|
|
48
48
|
exports.login = login;
|
|
49
49
|
const loginSrp1 = async ({ username }, ctx) => {
|
|
@@ -52,7 +52,7 @@ const loginSrp1 = async ({ username }, ctx) => {
|
|
|
52
52
|
const account = (0, perm_1.getAccount)(username);
|
|
53
53
|
if (!ctx.session)
|
|
54
54
|
return new apiMiddleware_1.ApiError(const_1.HTTP_SERVER_ERROR);
|
|
55
|
-
if (!account) // TODO simulate fake account to prevent knowing valid usernames
|
|
55
|
+
if (!account || !(0, perm_1.accountCanLogin)(account)) // TODO simulate fake account to prevent knowing valid usernames
|
|
56
56
|
return new apiMiddleware_1.ApiError(const_1.HTTP_UNAUTHORIZED);
|
|
57
57
|
try {
|
|
58
58
|
const { step1, ...rest } = await srpStep1(account);
|
package/src/api.file_list.js
CHANGED
|
@@ -12,10 +12,8 @@ const plugins_1 = require("./plugins");
|
|
|
12
12
|
const misc_1 = require("./misc");
|
|
13
13
|
const lodash_1 = __importDefault(require("lodash"));
|
|
14
14
|
const const_1 = require("./const");
|
|
15
|
-
const
|
|
15
|
+
const comments_1 = require("./comments");
|
|
16
16
|
const path_1 = require("path");
|
|
17
|
-
const DESCRIPT_ION = 'descript.ion';
|
|
18
|
-
const descriptIon = (0, config_1.defineConfig)('descript_ion', true);
|
|
19
17
|
const get_file_list = async ({ uri, offset, limit, search, c }, ctx) => {
|
|
20
18
|
var _a;
|
|
21
19
|
const node = await (0, vfs_1.urlToNode)(uri || '/', ctx);
|
|
@@ -40,12 +38,12 @@ const get_file_list = async ({ uri, offset, limit, search, c }, ctx) => {
|
|
|
40
38
|
const can_upload = (0, vfs_1.hasPermission)(node, 'can_upload', ctx);
|
|
41
39
|
const fakeChild = (0, vfs_1.applyParentToChild)({}, node); // we want to know if we want to delete children
|
|
42
40
|
const can_delete = (0, vfs_1.hasPermission)(fakeChild, 'can_delete', ctx);
|
|
43
|
-
const
|
|
41
|
+
const can_archive = (0, vfs_1.hasPermission)(fakeChild, 'can_archive', ctx);
|
|
42
|
+
const props = { can_archive, can_upload, can_delete, accept: node.accept };
|
|
44
43
|
if (!list)
|
|
45
44
|
return { ...props, list: await (0, misc_1.asyncGeneratorToArray)(produceEntries()) };
|
|
46
45
|
setTimeout(async () => {
|
|
47
|
-
|
|
48
|
-
list.props(props);
|
|
46
|
+
list.props(props);
|
|
49
47
|
for await (const entry of produceEntries())
|
|
50
48
|
list.add(entry);
|
|
51
49
|
list.close();
|
|
@@ -61,15 +59,14 @@ const get_file_list = async ({ uri, offset, limit, search, c }, ctx) => {
|
|
|
61
59
|
for await (const sub of walker) {
|
|
62
60
|
if (ctx.aborted)
|
|
63
61
|
break;
|
|
64
|
-
const name = (0, vfs_1.getNodeName)(sub);
|
|
65
|
-
if (descriptIon.get() && name === DESCRIPT_ION)
|
|
62
|
+
const name = (0, path_1.basename)((0, vfs_1.getNodeName)(sub));
|
|
63
|
+
if (comments_1.descriptIon.get() && name === comments_1.DESCRIPT_ION)
|
|
66
64
|
continue;
|
|
67
65
|
if (!filter(name))
|
|
68
66
|
continue;
|
|
69
67
|
const entry = await nodeToDirEntry(ctx, sub);
|
|
70
68
|
if (!entry)
|
|
71
69
|
continue;
|
|
72
|
-
entry.comment = await getCommentFor(sub.source);
|
|
73
70
|
const cbParams = { entry, ctx, listUri: uri, node: sub };
|
|
74
71
|
try {
|
|
75
72
|
const res = await Promise.all(onDirEntryHandlers.map(cb => cb(cbParams)));
|
|
@@ -105,11 +102,11 @@ const get_file_list = async ({ uri, offset, limit, search, c }, ctx) => {
|
|
|
105
102
|
const st = await (0, promises_1.stat)(source);
|
|
106
103
|
const folder = st.isDirectory();
|
|
107
104
|
const { ctime, mtime } = st;
|
|
108
|
-
const pl = node.can_list ===
|
|
105
|
+
const pl = node.can_list === misc_1.WHO_NO_ONE ? 'l'
|
|
109
106
|
: !(0, vfs_1.hasPermission)(node, 'can_list', ctx) ? 'L'
|
|
110
107
|
: '';
|
|
111
108
|
// no download here, but maybe inside?
|
|
112
|
-
const pr = node.can_read ===
|
|
109
|
+
const pr = node.can_read === misc_1.WHO_NO_ONE && !(folder && filesInsideCould()) ? 'r'
|
|
113
110
|
: !(0, vfs_1.hasPermission)(node, 'can_read', ctx) ? 'R'
|
|
114
111
|
: '';
|
|
115
112
|
const pd = !can_delete && (0, vfs_1.hasPermission)(node, 'can_delete', ctx) ? 'd' : '';
|
|
@@ -118,7 +115,8 @@ const get_file_list = async ({ uri, offset, limit, search, c }, ctx) => {
|
|
|
118
115
|
c: ctime,
|
|
119
116
|
m: Math.abs(+mtime - +ctime) < 1000 ? undefined : mtime,
|
|
120
117
|
s: folder ? undefined : st.size,
|
|
121
|
-
p: (pr + pl + pd) || undefined
|
|
118
|
+
p: (pr + pl + pd) || undefined,
|
|
119
|
+
comment: await (0, comments_1.getCommentFor)(source),
|
|
122
120
|
};
|
|
123
121
|
}
|
|
124
122
|
catch (_a) {
|
|
@@ -132,18 +130,3 @@ const get_file_list = async ({ uri, offset, limit, search, c }, ctx) => {
|
|
|
132
130
|
}
|
|
133
131
|
};
|
|
134
132
|
exports.get_file_list = get_file_list;
|
|
135
|
-
async function getCommentFor(path) {
|
|
136
|
-
return !path || !descriptIon.get() ? undefined
|
|
137
|
-
: readDescription((0, path_1.dirname)(path)).then(x => x.get((0, misc_1.basename)(path)), () => undefined);
|
|
138
|
-
}
|
|
139
|
-
function readDescription(path) {
|
|
140
|
-
return (0, misc_1.parseFile)((0, path_1.join)(path, DESCRIPT_ION), txt => new Map(txt.split('\n').map(line => {
|
|
141
|
-
const quoted = line[0] === '"' ? 1 : 0;
|
|
142
|
-
const i = quoted ? line.indexOf('"', 2) : line.indexOf(' ');
|
|
143
|
-
const fn = line.slice(quoted, i - quoted);
|
|
144
|
-
let comment = line.slice(i + 1);
|
|
145
|
-
if (comment.endsWith('\x04\xc2'))
|
|
146
|
-
comment = comment.slice(0, -2).replaceAll('\\n', '\n');
|
|
147
|
-
return [fn, comment];
|
|
148
|
-
})));
|
|
149
|
-
}
|
package/src/api.net.js
CHANGED
|
@@ -8,8 +8,6 @@ exports.makeCert = exports.acme_email = exports.acme_domain = exports.acmeMiddle
|
|
|
8
8
|
const apiMiddleware_1 = require("./apiMiddleware");
|
|
9
9
|
const nat_upnp_ts_1 = require("nat-upnp-ts");
|
|
10
10
|
const const_1 = require("./const");
|
|
11
|
-
const axios_1 = __importDefault(require("axios"));
|
|
12
|
-
const node_html_parser_1 = require("node-html-parser");
|
|
13
11
|
const lodash_1 = __importDefault(require("lodash"));
|
|
14
12
|
const listen_1 = require("./listen");
|
|
15
13
|
const github_1 = require("./github");
|
|
@@ -22,53 +20,57 @@ const http_1 = require("http");
|
|
|
22
20
|
const promises_2 = require("dns/promises");
|
|
23
21
|
const config_1 = require("./config");
|
|
24
22
|
const events_1 = __importDefault(require("./events"));
|
|
23
|
+
const net_1 = require("net");
|
|
25
24
|
const upnpClient = new nat_upnp_ts_1.Client({ timeout: 4000 });
|
|
26
25
|
const originalMethod = upnpClient.getGateway;
|
|
27
26
|
// other client methods call getGateway too, so this will ensure they reuse this same result
|
|
28
27
|
upnpClient.getGateway = (0, misc_1.debounceAsync)(() => originalMethod.apply(upnpClient), 0, { retain: misc_1.HOUR, retainFailure: 30000 });
|
|
29
28
|
upnpClient.getGateway().catch(() => { });
|
|
30
|
-
exports.externalIp =
|
|
31
|
-
(0, misc_1.repeat)(10 * misc_1.MINUTE, () =>
|
|
32
|
-
const was = exports.externalIp;
|
|
33
|
-
exports.externalIp = upnpClient.getPublicIp().catch(() => was); //fallback to previous value
|
|
34
|
-
});
|
|
29
|
+
exports.externalIp = ''; // poll external ip
|
|
30
|
+
(0, misc_1.repeat)(10 * misc_1.MINUTE, () => upnpClient.getPublicIp().then(v => exports.externalIp = v));
|
|
35
31
|
const getNatInfo = (0, misc_1.debounceAsync)(async () => {
|
|
36
32
|
var _a, _b;
|
|
37
|
-
const
|
|
33
|
+
const gettingIps = getPublicIps(); // don't wait, do it in parallel
|
|
38
34
|
const res = await upnpClient.getGateway().catch(() => null);
|
|
39
35
|
const status = await (0, listen_1.getServerStatus)();
|
|
40
36
|
const mappings = res && await (0, misc_1.haveTimeout)(5000, upnpClient.getMappings()).catch(() => null);
|
|
41
|
-
console.debug('mappings found', mappings);
|
|
42
|
-
const gatewayIp = res ? new URL(res.gateway.description).hostname : await findGateway().catch(() =>
|
|
37
|
+
console.debug('mappings found', mappings === null || mappings === void 0 ? void 0 : mappings.map(x => x.description));
|
|
38
|
+
const gatewayIp = res ? new URL(res.gateway.description).hostname : await findGateway().catch(() => undefined);
|
|
43
39
|
const localIp = (res === null || res === void 0 ? void 0 : res.address) || (await (0, listen_1.getIps)())[0];
|
|
44
|
-
const internalPort = ((_a = status === null || status === void 0 ? void 0 : status.https) === null || _a === void 0 ? void 0 : _a.listening) && status.https.port || ((_b = status === null || status === void 0 ? void 0 : status.http) === null || _b === void 0 ? void 0 : _b.listening) && status.http.port;
|
|
40
|
+
const internalPort = ((_a = status === null || status === void 0 ? void 0 : status.https) === null || _a === void 0 ? void 0 : _a.listening) && status.https.port || ((_b = status === null || status === void 0 ? void 0 : status.http) === null || _b === void 0 ? void 0 : _b.listening) && status.http.port || undefined;
|
|
45
41
|
const mapped = lodash_1.default.find(mappings, x => x.private.host === localIp && x.private.port === internalPort);
|
|
46
42
|
return {
|
|
47
43
|
upnp: Boolean(res),
|
|
48
44
|
localIp,
|
|
49
45
|
gatewayIp,
|
|
50
|
-
|
|
51
|
-
externalIp:
|
|
46
|
+
publicIps: await gettingIps,
|
|
47
|
+
externalIp: exports.externalIp,
|
|
52
48
|
mapped,
|
|
53
49
|
internalPort,
|
|
54
50
|
externalPort: mapped === null || mapped === void 0 ? void 0 : mapped.public.port,
|
|
55
51
|
};
|
|
56
52
|
});
|
|
57
|
-
async function
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
53
|
+
async function getPublicIps() {
|
|
54
|
+
const res = await (0, github_1.getProjectInfo)();
|
|
55
|
+
const groupedByVersion = Object.values(lodash_1.default.groupBy(res.publicIpServices, x => { var _a; return (_a = x.v) !== null && _a !== void 0 ? _a : 4; }));
|
|
56
|
+
const ips = await (0, misc_1.promiseBestEffort)(groupedByVersion.map(singleVersion => Promise.any(singleVersion.map(async (svc) => {
|
|
57
|
+
if (typeof svc === 'string')
|
|
58
|
+
svc = { type: 'http', url: svc };
|
|
59
|
+
console.debug("trying ip service", svc.url || svc.name);
|
|
60
|
+
if (svc.type === 'http')
|
|
61
|
+
return (0, util_http_1.httpString)(svc.url);
|
|
62
|
+
if (svc.type !== 'dns')
|
|
63
|
+
throw "unsupported";
|
|
64
|
+
const resolver = new promises_2.Resolver({ timeout: 2000 });
|
|
65
|
+
resolver.setServers(svc.ips);
|
|
66
|
+
return resolver.resolve(svc.name, svc.dnsRecord);
|
|
67
|
+
}).map(async (ret) => {
|
|
68
|
+
const validIps = (0, misc_1.wantArray)(await ret).map(x => x.trim()).filter(net_1.isIP);
|
|
69
|
+
if (!validIps.length)
|
|
70
|
+
throw "no good";
|
|
71
|
+
return validIps;
|
|
72
|
+
}))));
|
|
73
|
+
return lodash_1.default.uniq(ips.flat());
|
|
72
74
|
}
|
|
73
75
|
function findGateway() {
|
|
74
76
|
return new Promise((resolve, reject) => (0, child_process_1.exec)(const_1.IS_WINDOWS || const_1.IS_MAC ? 'netstat -rn' : 'route -n', (err, out) => {
|
|
@@ -107,12 +109,16 @@ async function checkDomain(domain) {
|
|
|
107
109
|
(0, promises_2.lookup)(domain).then(x => [x.address]),
|
|
108
110
|
]);
|
|
109
111
|
// merge all results
|
|
110
|
-
const
|
|
111
|
-
if (!
|
|
112
|
+
const domainIps = lodash_1.default.uniq((0, misc_1.onlyTruthy)(settled.map(x => x.status === 'fulfilled' && x.value)).flat());
|
|
113
|
+
if (!domainIps.length)
|
|
112
114
|
throw new apiMiddleware_1.ApiError(const_1.HTTP_FAILED_DEPENDENCY, "domain not working");
|
|
113
|
-
const {
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
const { publicIps } = await getNatInfo(); // do this before stopping the server
|
|
116
|
+
for (const v6 of [false, true]) {
|
|
117
|
+
const domainIpsThisVersion = domainIps.filter(x => (0, net_1.isIPv6)(x) === v6);
|
|
118
|
+
const ipsThisVersion = publicIps.filter(x => (0, net_1.isIPv6)(x) === v6);
|
|
119
|
+
if (domainIpsThisVersion.length && ipsThisVersion.length && !lodash_1.default.intersection(domainIpsThisVersion, ipsThisVersion).length)
|
|
120
|
+
throw new apiMiddleware_1.ApiError(const_1.HTTP_FAILED_DEPENDENCY, `configure your domain to point to ${ipsThisVersion} (currently on ${domainIpsThisVersion[0]}) – a change can take hours to be effective`);
|
|
121
|
+
}
|
|
116
122
|
}
|
|
117
123
|
async function generateSSLCert(domain, email) {
|
|
118
124
|
await checkDomain(domain);
|
|
@@ -168,28 +174,26 @@ async function generateSSLCert(domain, email) {
|
|
|
168
174
|
}
|
|
169
175
|
async function checkPort(ip, port) {
|
|
170
176
|
const prjInfo = await (0, github_1.getProjectInfo)();
|
|
177
|
+
console.log(`checking server ${ip}:${port}`);
|
|
171
178
|
for (const services of lodash_1.default.chunk(lodash_1.default.shuffle(prjInfo.checkServerServices), 2)) {
|
|
172
179
|
try {
|
|
173
|
-
return Promise.any(services.map(async (
|
|
174
|
-
|
|
175
|
-
const service = new URL(svc.url).hostname;
|
|
180
|
+
return Promise.any(services.map(async ({ url, body, selector, regexpSuccess, regexpFailure, ...rest }) => {
|
|
181
|
+
const service = new URL(url).hostname;
|
|
176
182
|
console.log('trying service', service);
|
|
177
|
-
const
|
|
178
|
-
const
|
|
179
|
-
const
|
|
180
|
-
const parsed = (_b = (0, node_html_parser_1.parse)(res.data).querySelector(svc.selector)) === null || _b === void 0 ? void 0 : _b.innerText;
|
|
181
|
-
if (!parsed)
|
|
182
|
-
throw console.debug('empty:' + service);
|
|
183
|
-
const success = new RegExp(svc.regexpSuccess).test(parsed);
|
|
184
|
-
const failure = new RegExp(svc.regexpFailure).test(parsed);
|
|
183
|
+
const res = await (0, util_http_1.httpString)(applySymbols(url), { family: (0, net_1.isIPv6)(ip) ? 6 : 4, body: applySymbols(body), ...rest });
|
|
184
|
+
const success = new RegExp(regexpSuccess).test(res);
|
|
185
|
+
const failure = new RegExp(regexpFailure).test(res);
|
|
185
186
|
if (success === failure)
|
|
186
187
|
throw console.debug('inconsistent:' + service); // this result cannot be trusted
|
|
187
188
|
console.debug(service, 'responded', success);
|
|
188
|
-
return { success, service };
|
|
189
|
+
return { success, service, ip, port };
|
|
189
190
|
}));
|
|
190
191
|
}
|
|
191
192
|
catch (_a) { }
|
|
192
193
|
}
|
|
194
|
+
function applySymbols(s) {
|
|
195
|
+
return s === null || s === void 0 ? void 0 : s.replace('$IP', ip).replace('$PORT', String(port));
|
|
196
|
+
}
|
|
193
197
|
}
|
|
194
198
|
const apis = {
|
|
195
199
|
get_nat: getNatInfo,
|
|
@@ -215,15 +219,14 @@ const apis = {
|
|
|
215
219
|
return {};
|
|
216
220
|
},
|
|
217
221
|
async check_server({ port }) {
|
|
218
|
-
const {
|
|
219
|
-
if (!
|
|
220
|
-
return new apiMiddleware_1.ApiError(const_1.
|
|
222
|
+
const { publicIps, internalPort, externalPort } = await getNatInfo();
|
|
223
|
+
if (!publicIps.length)
|
|
224
|
+
return new apiMiddleware_1.ApiError(const_1.HTTP_FAILED_DEPENDENCY, 'cannot detect public ip');
|
|
221
225
|
if (!internalPort)
|
|
222
226
|
return new apiMiddleware_1.ApiError(const_1.HTTP_FAILED_DEPENDENCY, 'no internal port');
|
|
223
227
|
port || (port = externalPort || internalPort);
|
|
224
|
-
|
|
225
|
-
return
|
|
226
|
-
|| new apiMiddleware_1.ApiError(const_1.HTTP_SERVICE_UNAVAILABLE);
|
|
228
|
+
const res = await (0, misc_1.promiseBestEffort)(publicIps.map(ip => checkPort(ip, port)));
|
|
229
|
+
return res.length ? res : new apiMiddleware_1.ApiError(const_1.HTTP_SERVICE_UNAVAILABLE);
|
|
227
230
|
},
|
|
228
231
|
async make_cert({ domain, email }) {
|
|
229
232
|
await (0, exports.makeCert)(domain, email);
|
|
@@ -250,17 +253,15 @@ exports.makeCert = (0, misc_1.debounceAsync)(async (domain, email) => {
|
|
|
250
253
|
events_1.default.once('https ready', () => (0, misc_1.repeat)(misc_1.HOUR, renewCert));
|
|
251
254
|
// checks if the cert is near expiration date, and if so renews it
|
|
252
255
|
const renewCert = (0, misc_1.debounceAsync)(async () => {
|
|
253
|
-
const acmeLog = (...args) => console.log('[acme-renew]:', ...args);
|
|
254
|
-
const now = new Date();
|
|
255
256
|
const cert = (0, listen_1.getCertObject)();
|
|
256
257
|
if (!cert)
|
|
257
258
|
return;
|
|
259
|
+
const now = new Date();
|
|
258
260
|
const validTo = new Date(cert.validTo);
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
return acmeLog("certificate is good");
|
|
261
|
+
// not expiring in a month
|
|
262
|
+
if (now > new Date(cert.validFrom) && now < validTo && validTo.getTime() - now.getTime() >= 30 * misc_1.DAY)
|
|
263
|
+
return console.log("certificate still good");
|
|
263
264
|
await (0, exports.makeCert)(exports.acme_domain.get(), exports.acme_email.get())
|
|
264
|
-
.catch(e =>
|
|
265
|
+
.catch(e => console.log("error renewing certificate: ", String(e)));
|
|
265
266
|
}, 0, { retain: misc_1.DAY, retainFailure: misc_1.HOUR });
|
|
266
267
|
exports.default = apis;
|
package/src/api.plugins.js
CHANGED
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.checkDependencies = void 0;
|
|
7
8
|
const plugins_1 = require("./plugins");
|
|
8
9
|
const lodash_1 = __importDefault(require("lodash"));
|
|
9
10
|
const assert_1 = __importDefault(require("assert"));
|
|
@@ -28,7 +29,8 @@ const apis = {
|
|
|
28
29
|
async get_plugin_updates() {
|
|
29
30
|
return new apiMiddleware_1.SendListReadable({
|
|
30
31
|
async doAtStart(list) {
|
|
31
|
-
const errs =
|
|
32
|
+
const errs = [];
|
|
33
|
+
await Promise.allSettled(lodash_1.default.map((0, github_1.getFolder2repo)(), async (repo, folder) => {
|
|
32
34
|
try {
|
|
33
35
|
if (!repo)
|
|
34
36
|
return;
|
|
@@ -46,12 +48,11 @@ const apis = {
|
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
50
|
catch (err) {
|
|
49
|
-
if (err.message
|
|
50
|
-
|
|
51
|
-
return err.code || err.message;
|
|
51
|
+
if (err.message !== '404') // the plugin is declaring a wrong repo
|
|
52
|
+
errs.push(err.code || err.message);
|
|
52
53
|
}
|
|
53
54
|
}));
|
|
54
|
-
for (const x of lodash_1.default.uniq(
|
|
55
|
+
for (const x of lodash_1.default.uniq(errs))
|
|
55
56
|
list.error(x);
|
|
56
57
|
list.close();
|
|
57
58
|
}
|
|
@@ -124,18 +125,16 @@ const apis = {
|
|
|
124
125
|
});
|
|
125
126
|
},
|
|
126
127
|
async download_plugin({ id, branch }) {
|
|
127
|
-
await checkDependencies(id, branch);
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
return res;
|
|
131
|
-
return (await (0, misc_1.waitFor)(() => (0, plugins_1.getPluginInfo)(res), { timeout: 5000 }))
|
|
128
|
+
await checkDependencies(await (0, github_1.readOnlinePlugin)(id, branch));
|
|
129
|
+
const folder = await (0, github_1.downloadPlugin)(id, { branch });
|
|
130
|
+
return (await (0, misc_1.waitFor)(() => (0, plugins_1.getPluginInfo)(folder), { timeout: 5000 }))
|
|
132
131
|
|| new apiMiddleware_1.ApiError(const_1.HTTP_SERVER_ERROR);
|
|
133
132
|
},
|
|
134
133
|
async update_plugin({ id }) {
|
|
135
134
|
const found = (0, plugins_1.getPluginInfo)(id);
|
|
136
135
|
if (!found)
|
|
137
136
|
return new apiMiddleware_1.ApiError(const_1.HTTP_NOT_FOUND);
|
|
138
|
-
await checkDependencies(found
|
|
137
|
+
await checkDependencies(found);
|
|
139
138
|
const enabled = (0, plugins_1.isPluginEnabled)(id);
|
|
140
139
|
await (0, plugins_1.stopPlugin)(id);
|
|
141
140
|
await (0, github_1.downloadPlugin)(found.repo, { overwrite: true });
|
|
@@ -157,19 +156,9 @@ function serialize(p) {
|
|
|
157
156
|
o.repo = o.repo.web;
|
|
158
157
|
return lodash_1.default.defaults(o, { started: null, badApi: null }); // nulls should be used to be sure to overwrite previous values,
|
|
159
158
|
}
|
|
160
|
-
async function checkDependencies(
|
|
161
|
-
const
|
|
162
|
-
if (
|
|
163
|
-
return;
|
|
164
|
-
const miss = rec.depend && rec.depend.map((dep) => {
|
|
165
|
-
const res = (0, plugins_1.findPluginByRepo)(dep.repo);
|
|
166
|
-
const error = !res ? 'missing'
|
|
167
|
-
: (res.version || 0) < dep.version ? 'version'
|
|
168
|
-
: !(0, plugins_1.isPluginEnabled)(res.id) ? 'disabled'
|
|
169
|
-
: !(0, plugins_1.isPluginRunning)(res.id) ? 'stopped'
|
|
170
|
-
: '';
|
|
171
|
-
return error && { repo: dep.repo, error, id: res === null || res === void 0 ? void 0 : res.id };
|
|
172
|
-
}).filter(Boolean);
|
|
173
|
-
if (miss === null || miss === void 0 ? void 0 : miss.length)
|
|
159
|
+
async function checkDependencies(plugin) {
|
|
160
|
+
const miss = await (0, plugins_1.getMissingDependencies)(plugin);
|
|
161
|
+
if (miss.length)
|
|
174
162
|
throw new apiMiddleware_1.ApiError(const_1.HTTP_FAILED_DEPENDENCY, miss);
|
|
175
163
|
}
|
|
164
|
+
exports.checkDependencies = checkDependencies;
|
package/src/api.vfs.js
CHANGED
|
@@ -19,10 +19,7 @@ async function urlToNodeOriginal(uri) {
|
|
|
19
19
|
}
|
|
20
20
|
const apis = {
|
|
21
21
|
async get_vfs() {
|
|
22
|
-
return {
|
|
23
|
-
root: await recur(),
|
|
24
|
-
defaultPerms: vfs_1.defaultPerms,
|
|
25
|
-
};
|
|
22
|
+
return { root: await recur() };
|
|
26
23
|
async function recur(node = vfs_1.vfs) {
|
|
27
24
|
var _a;
|
|
28
25
|
const { source } = node;
|
|
@@ -32,19 +29,19 @@ const apis = {
|
|
|
32
29
|
: { size: source ? -1 : undefined };
|
|
33
30
|
if (copyStats.mtime && Number(copyStats.mtime) === Number(copyStats.ctime))
|
|
34
31
|
delete copyStats.mtime;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
&&
|
|
38
|
-
|
|
39
|
-
byMasks = undefined;
|
|
32
|
+
const inherited = node.parent && (0, vfs_1.permsFromParent)(node.parent, node.original || node);
|
|
33
|
+
const byMasks = node.original && lodash_1.default.pickBy(node, (v, k) => v !== node.original[k] // something is changing me...
|
|
34
|
+
&& !(inherited && k in inherited) // ...and it's not inheritance...
|
|
35
|
+
&& misc_1.PERM_KEYS.includes(k)); // ...must be masks. Please limit this to perms
|
|
40
36
|
return {
|
|
41
37
|
...copyStats,
|
|
42
38
|
...node.original || node,
|
|
43
|
-
|
|
39
|
+
inherited,
|
|
40
|
+
byMasks: lodash_1.default.isEmpty(byMasks) ? undefined : byMasks,
|
|
44
41
|
website: Boolean((_a = node.children) === null || _a === void 0 ? void 0 : _a.find((0, vfs_1.isSameFilenameAs)('index.html')))
|
|
45
42
|
|| isDir && source && await (0, promises_1.stat)((0, path_1.join)(source, 'index.html')).then(() => true, () => undefined)
|
|
46
43
|
|| undefined,
|
|
47
|
-
name: node === vfs_1.vfs ?
|
|
44
|
+
name: node === vfs_1.vfs ? '' : (0, vfs_1.getNodeName)(node),
|
|
48
45
|
type: isDir ? 'folder' : undefined,
|
|
49
46
|
children: node.children && await Promise.all(node.children.map(child => recur((0, vfs_1.applyParentToChild)(child, node))))
|
|
50
47
|
};
|
|
@@ -78,7 +75,7 @@ const apis = {
|
|
|
78
75
|
const n = await urlToNodeOriginal(uri);
|
|
79
76
|
if (!n)
|
|
80
77
|
return new apiMiddleware_1.ApiError(const_1.HTTP_NOT_FOUND, 'path not found');
|
|
81
|
-
props = pickProps(props, ['name', 'source', 'masks', 'default', 'accept', ...
|
|
78
|
+
props = pickProps(props, ['name', 'source', 'masks', 'default', 'accept', ...misc_1.PERM_KEYS]); // sanitize
|
|
82
79
|
if (props.name && props.name !== (0, vfs_1.getNodeName)(n)) {
|
|
83
80
|
const parent = await urlToNodeOriginal((0, path_1.dirname)(uri));
|
|
84
81
|
if ((_a = parent === null || parent === void 0 ? void 0 : parent.children) === null || _a === void 0 ? void 0 : _a.find(x => (0, vfs_1.getNodeName)(x) === props.name))
|
package/src/block.js
CHANGED
|
@@ -6,8 +6,12 @@ const config_1 = require("./config");
|
|
|
6
6
|
const connections_1 = require("./connections");
|
|
7
7
|
const misc_1 = require("./misc");
|
|
8
8
|
const block = (0, config_1.defineConfig)('block', [], rules => {
|
|
9
|
+
const now = new Date();
|
|
9
10
|
const ret = !Array.isArray(rules) ? []
|
|
10
|
-
: (0, misc_1.onlyTruthy)(rules.map(rule =>
|
|
11
|
+
: (0, misc_1.onlyTruthy)(rules.map(rule => {
|
|
12
|
+
rule.expire && (rule.expire = new Date(rule.expire));
|
|
13
|
+
return !(rule.expire > now) && (0, misc_1.makeNetMatcher)(rule.ip, true);
|
|
14
|
+
}));
|
|
11
15
|
// reapply new block to existing connections
|
|
12
16
|
for (const { socket, ip } of (0, connections_1.getConnections)())
|
|
13
17
|
applyBlock(socket, ip);
|
|
@@ -18,3 +22,12 @@ function applyBlock(socket, ip = (0, connections_1.normalizeIp)(socket.remoteAdd
|
|
|
18
22
|
return socket.destroy();
|
|
19
23
|
}
|
|
20
24
|
exports.applyBlock = applyBlock;
|
|
25
|
+
setInterval(() => {
|
|
26
|
+
const now = new Date();
|
|
27
|
+
const next = block.get().filter(x => !x.expire || x.expire > now);
|
|
28
|
+
const n = block.get().length - next.length;
|
|
29
|
+
if (!n)
|
|
30
|
+
return;
|
|
31
|
+
console.log("blocking rules:", n, "expired");
|
|
32
|
+
block.set(next);
|
|
33
|
+
}, misc_1.MINUTE / 2);
|
package/src/comments.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.setCommentFor = exports.getCommentFor = exports.descriptIon = exports.DESCRIPT_ION = void 0;
|
|
7
|
+
const config_1 = require("./config");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const cross_1 = require("./cross");
|
|
10
|
+
const util_files_1 = require("./util-files");
|
|
11
|
+
const promises_1 = require("fs/promises");
|
|
12
|
+
const misc_1 = require("./misc");
|
|
13
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
14
|
+
exports.DESCRIPT_ION = 'descript.ion';
|
|
15
|
+
exports.descriptIon = (0, config_1.defineConfig)('descript_ion', true);
|
|
16
|
+
async function getCommentFor(path) {
|
|
17
|
+
return !path || !exports.descriptIon.get() ? undefined
|
|
18
|
+
: readDescription((0, path_1.dirname)(path)).then(x => x.get((0, cross_1.basename)(path)), () => undefined);
|
|
19
|
+
}
|
|
20
|
+
exports.getCommentFor = getCommentFor;
|
|
21
|
+
exports.setCommentFor = (0, misc_1.singleFromBatch)(async (jobs) => {
|
|
22
|
+
const byFolder = lodash_1.default.groupBy(jobs, job => (0, path_1.dirname)(job[0]));
|
|
23
|
+
return Promise.allSettled(lodash_1.default.map(byFolder, async (jobs, folder) => {
|
|
24
|
+
const comments = await readDescription(folder).catch(() => new Map());
|
|
25
|
+
for (const [path, comment] of jobs) {
|
|
26
|
+
const file = path.slice(folder.length + 1);
|
|
27
|
+
if (!comment)
|
|
28
|
+
comments.delete(file);
|
|
29
|
+
else
|
|
30
|
+
comments.set(file, comment);
|
|
31
|
+
}
|
|
32
|
+
// encode comments in descript.ion format
|
|
33
|
+
let txt = '';
|
|
34
|
+
comments.forEach((c, f) => txt += (f.includes(' ') ? `"${f}"` : f) + ' ' + (c.includes('\n') ? c.replaceAll('\n', '\\n') + MULTILINE_SUFFIX : c) + '\n');
|
|
35
|
+
await (0, promises_1.writeFile)((0, path_1.join)(folder, exports.DESCRIPT_ION), txt);
|
|
36
|
+
}));
|
|
37
|
+
});
|
|
38
|
+
const MULTILINE_SUFFIX = '\x04\xc2';
|
|
39
|
+
function readDescription(path) {
|
|
40
|
+
return (0, util_files_1.parseFile)((0, path_1.join)(path, exports.DESCRIPT_ION), txt => new Map(txt.split('\n').map(line => {
|
|
41
|
+
const quoted = line[0] === '"' ? 1 : 0;
|
|
42
|
+
const i = quoted ? line.indexOf('"', 2) + 1 : line.indexOf(' ');
|
|
43
|
+
const fn = line.slice(quoted, i - quoted);
|
|
44
|
+
let comment = line.slice(i + 1);
|
|
45
|
+
if (comment.endsWith(MULTILINE_SUFFIX))
|
|
46
|
+
comment = comment.slice(0, -2).replaceAll('\\n', '\n');
|
|
47
|
+
return [fn, comment];
|
|
48
|
+
})));
|
|
49
|
+
}
|
package/src/const.js
CHANGED
|
@@ -27,7 +27,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
28
|
};
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.APP_PATH = exports.IS_BINARY = exports.IS_MAC = exports.IS_WINDOWS = exports.HTTP_SERVICE_UNAVAILABLE = exports.HTTP_SERVER_ERROR = exports.HTTP_FAILED_DEPENDENCY = exports.HTTP_FOOL = exports.HTTP_RANGE_NOT_SATISFIABLE = exports.HTTP_PAYLOAD_TOO_LARGE = exports.HTTP_CONFLICT = exports.HTTP_NOT_ACCEPTABLE = exports.HTTP_METHOD_NOT_ALLOWED = exports.HTTP_NOT_FOUND = exports.HTTP_FORBIDDEN = exports.HTTP_UNAUTHORIZED = exports.HTTP_BAD_REQUEST = exports.HTTP_NOT_MODIFIED = exports.HTTP_TEMPORARY_REDIRECT = exports.HTTP_PARTIAL_CONTENT = exports.HTTP_NO_CONTENT = exports.HTTP_OK = exports.PLUGINS_PUB_URI = exports.API_URI = exports.ADMIN_URI = exports.FRONTEND_URI = exports.SPECIAL_URI = exports.HFS_REPO_BRANCH = exports.HFS_REPO = exports.COMPATIBLE_API_VERSION = exports.API_VERSION = exports.RUNNING_BETA = exports.VERSION = exports.BUILD_TIMESTAMP = exports.HFS_STARTED = exports.ORIGINAL_CWD = exports.DEV = exports.argv = void 0;
|
|
30
|
+
exports.APP_PATH = exports.IS_BINARY = exports.IS_MAC = exports.IS_WINDOWS = exports.HTTP_SERVICE_UNAVAILABLE = exports.HTTP_SERVER_ERROR = exports.HTTP_FAILED_DEPENDENCY = exports.HTTP_FOOL = exports.HTTP_RANGE_NOT_SATISFIABLE = exports.HTTP_PAYLOAD_TOO_LARGE = exports.HTTP_CONFLICT = exports.HTTP_NOT_ACCEPTABLE = exports.HTTP_METHOD_NOT_ALLOWED = exports.HTTP_NOT_FOUND = exports.HTTP_FORBIDDEN = exports.HTTP_UNAUTHORIZED = exports.HTTP_BAD_REQUEST = exports.HTTP_NOT_MODIFIED = exports.HTTP_TEMPORARY_REDIRECT = exports.HTTP_MOVED_PERMANENTLY = exports.HTTP_PARTIAL_CONTENT = exports.HTTP_NO_CONTENT = exports.HTTP_OK = exports.PLUGINS_PUB_URI = exports.API_URI = exports.ADMIN_URI = exports.FRONTEND_URI = exports.SPECIAL_URI = exports.HFS_REPO_BRANCH = exports.HFS_REPO = exports.COMPATIBLE_API_VERSION = exports.API_VERSION = exports.RUNNING_BETA = exports.VERSION = exports.BUILD_TIMESTAMP = exports.HFS_STARTED = exports.ORIGINAL_CWD = exports.DEV = exports.argv = void 0;
|
|
31
31
|
const minimist_1 = __importDefault(require("minimist"));
|
|
32
32
|
const fs = __importStar(require("fs"));
|
|
33
33
|
const os_1 = require("os");
|
|
@@ -38,7 +38,7 @@ exports.DEV = process.env.DEV || exports.argv.dev ? 'DEV' : '';
|
|
|
38
38
|
exports.ORIGINAL_CWD = process.cwd();
|
|
39
39
|
exports.HFS_STARTED = new Date();
|
|
40
40
|
const PKG_PATH = (0, path_1.join)(__dirname, '..', 'package.json');
|
|
41
|
-
exports.BUILD_TIMESTAMP = "2023-
|
|
41
|
+
exports.BUILD_TIMESTAMP = "2023-10-04T19:41:32.601Z";
|
|
42
42
|
const pkg = JSON.parse(fs.readFileSync(PKG_PATH, 'utf8'));
|
|
43
43
|
exports.VERSION = pkg.version;
|
|
44
44
|
exports.RUNNING_BETA = exports.VERSION.includes('-');
|
|
@@ -54,6 +54,7 @@ exports.PLUGINS_PUB_URI = exports.SPECIAL_URI + 'plugins/';
|
|
|
54
54
|
exports.HTTP_OK = 200;
|
|
55
55
|
exports.HTTP_NO_CONTENT = 204;
|
|
56
56
|
exports.HTTP_PARTIAL_CONTENT = 206;
|
|
57
|
+
exports.HTTP_MOVED_PERMANENTLY = 301;
|
|
57
58
|
exports.HTTP_TEMPORARY_REDIRECT = 302;
|
|
58
59
|
exports.HTTP_NOT_MODIFIED = 304;
|
|
59
60
|
exports.HTTP_BAD_REQUEST = 400;
|