vfs: node.hide
Massimo Melina committed
Dec 14, 2021 at 23:22 UTC
e7c0b86101cbd47120a70b430fd198093d403462
5 files changed
+27
-4
dev-notes.md
-1
@@ -9,7 +9,6 @@
9
10
# To do
11
- vfs: rename file in source folder
12
-- vfs: hide file in source folder
12
- fix: crash if vfs is not loadable
13
- vfs: serve an html for a folder?
14
- "default" property for vfsNode?
src/apis.ts
+4
-3
@@ -1,7 +1,7 @@
1
import glob from 'fast-glob'
2
import Koa from 'koa'
3
import { vfs, VfsNode } from './vfs'
4
-import { enforceFinal } from './misc'
4
+import { enforceFinal, wantArray } from './misc'
5
import { Stats } from 'fs'
6
import { stat } from 'fs/promises'
7
import _ from 'lodash'
@@ -36,12 +36,13 @@ export const frontEndApis: ApiHandlers = {
36
let path = node.source
37
if (path) {
38
// using / because trying path.join broke glob() on my Windows machine
39
- path = enforceFinal('/', glob.escapePath(path)) + '*'
40
- const res = await glob(path, {
39
+ path = enforceFinal('/', glob.escapePath(path))
40
+ const res = await glob(path + '*', {
41
stats: true,
42
dot: true,
43
markDirectories: true,
44
onlyFiles: false,
45
+ ignore: wantArray(node.hide).map(x => path+x),
46
})
47
list.push( ...res.map(x => statToFile(x.name, x.stats!)) )
48
}
src/misc.ts
+4
@@ -1,3 +1,7 @@
1
export function enforceFinal(sub:string, s:string) {
2
return s.endsWith(sub) ? s : s+sub
3
+}
4
+
5
+export function wantArray(x:any) {
6
+ return x == null ? [] : Array.isArray(x) ? x : [x]
7
}
\ No newline at end of file
tests/test.js
new
+18
@@ -0,0 +1,18 @@
1
+"use strict";
2
+const axios = require('axios');
3
+describe('file', () => {
4
+ itHttp('md', '/NOTES.md', '##');
5
+ itHttp('frontend', '/', '<body>');
6
+ itHttp('api.list', '/~/api/file_list', data => Array.isArray(data.list));
7
+});
8
+function itHttp(name, uri, test) {
9
+ it(name, () => axios.get(uri).then((res) => {
10
+ if (typeof test === 'string') {
11
+ if (!res.data.includes(test))
12
+ throw 'bad content: ' + res.data;
13
+ }
14
+ else if (typeof test === 'function')
15
+ if (!test(res.data))
16
+ throw 'test failed: ' + JSON.stringify(res.data);
17
+ }));
18
+}
vfs.yaml
+1
@@ -1,3 +1,4 @@
1
source: .
2
children:
3
- source: /music
4
+ hide: mix*