dev: nicer api, no initial slash
Massimo Melina committed
Aug 23, 2023 at 10:02 UTC
893045eb8260b4e2890001e1d3c0d0fc6c04d006
3 files changed
+18
-19
admin/src/HomePage.ts
+1
-2
@@ -115,8 +115,7 @@ export default function HomePage() {
115
: h(Flex, { vert: true },
116
updates.map((x: any) =>
117
h(Flex, { key: x.name, alignItems: 'flex-start', flexWrap: 'wrap' },
118
- h(Card, {},
119
- h(CardContent, {},
118
+ h(Card, {}, h(CardContent, {},
119
h(Btn, {
120
icon: UpdateIcon,
121
...!x.isNewer && { color: 'warning', variant: 'outlined' },
frontend/src/useFetchList.ts
+2
-2
@@ -17,7 +17,7 @@ export function usePath() {
17
18
export default function useFetchList() {
19
const snap = useSnapState()
20
- const uri = usePath()
20
+ const uri = usePath().slice(1)
21
const search = snap.remoteSearch || undefined
22
const lastUri = useRef('')
23
const lastReq = useRef<any>()
@@ -89,7 +89,7 @@ export default function useFetchList() {
89
lastReq.current = null
90
continue
91
}
92
- if (!uri.endsWith('/')) // now we know it was a folder for sure
92
+ if (uri && !uri.endsWith('/')) // now we know it was a folder for sure
93
return navigate(uri + '/')
94
if (op === 'props') {
95
Object.assign(state, _.pick(par, ['can_upload', 'can_delete', 'accept']))
plugins/vhosting/plugin.js
+15
-15
@@ -1,5 +1,5 @@
1
exports.description = "If you want to have different home folders, based on domain"
2
-exports.version = 3.12
2
+exports.version = 3.2
3
exports.apiRequired = 2 // 2 is for the config 'array'
4
5
exports.config = {
@@ -27,12 +27,11 @@ exports.init = api => {
27
middleware(ctx) {
28
let params // undefined if we are not going to work on api parameters
29
if (ctx.path.startsWith(api.const.SPECIAL_URI)) { // special uris should be excluded...
30
- // ...unless it's a frontend api with a path param
31
- if (!ctx.path.startsWith(api.const.API_URI)) return
30
+ if (!ctx.path.startsWith(api.const.API_URI)) return // ...unless it's an api
31
let { referer } = ctx.headers
32
referer &&= new URL(referer).pathname
33
if (referer?.startsWith(ctx.state.revProxyPath + api.const.ADMIN_URI)) return // exclude apis for admin-panel
35
- params = ctx.params || ctx.query
34
+ params = ctx.params || ctx.query // for api we'll translate params
35
}
36
37
const hosts = api.getConfig('hosts')
@@ -46,17 +45,18 @@ exports.init = api => {
45
return
46
}
47
let { root='' } = row
49
- if (root.endsWith('/'))
50
- root = root.slice(0, -1)
51
- if (root && root[0] !== '/') // normalize
52
- root = '/' + root
53
- if (!root) return
54
- if (params === undefined)
55
- ctx.path = root + ctx.path
56
- else
57
- for (const [k,v] of Object.entries(params))
58
- if (k.startsWith('uri'))
59
- params[k] = Array.isArray(v) ? v.map(x => root + x) : root + v
48
+ if (!root || root === '/') return
49
+ if (params === undefined) {
50
+ ctx.path = join(root, ctx.path)
51
+ return
52
+ }
53
+ for (const [k,v] of Object.entries(params))
54
+ if (k.startsWith('uri'))
55
+ params[k] = Array.isArray(v) ? v.map(x => join(root, x)) : join(root, v)
56
}
57
}
58
}
59
+
60
+function join(a, b) {
61
+ return a + (b && b[0] !== '/' ? '/' : '') + b
62
+}
\ No newline at end of file