plugins: event getList
Massimo Melina committed
Oct 8, 2024 at 10:49 UTC
b3ecbd5623a071a12beee4c001fe42fde9f6f23b
3 files changed
+9
-1
dev-plugins.md
+5
@@ -500,6 +500,11 @@ This section is still partially documented, and you may need to have a look at t
500
- `newSocket`
501
- parameters: { socket,ip }
502
- preventable
503
+- `getList`
504
+ - parameters: { node, ctx }
505
+ - called when get=list on legit requests to ?get=list
506
+ - async supported
507
+ - stoppable
508
509
# Notifications (backend-to-frontend events)
510
src/const.ts
+1
-1
@@ -7,7 +7,7 @@ import _ from 'lodash'
7
import { basename, dirname, join } from 'path'
8
export * from './cross-const'
9
10
-export const API_VERSION = 9.6
10
+export const API_VERSION = 10
11
export const COMPATIBLE_API_VERSION = 1 // while changes in the api are not breaking, this number stays the same, otherwise it is made equal to API_VERSION
12
export const HFS_REPO = 'rejetto/hfs'
13
src/serveGuiAndSharedFiles.ts
+3
@@ -2,6 +2,7 @@ import Koa from 'koa'
2
import { basename, dirname } from 'path'
3
import { getNodeName, nodeIsDirectory, statusCodeForMissingPerm, urlToNode, vfs, VfsNode, walkNode } from './vfs'
4
import { sendErrorPage } from './errorPages'
5
+import events from './events'
6
import { ADMIN_URI, FRONTEND_URI, HTTP_BAD_REQUEST, HTTP_FORBIDDEN, HTTP_METHOD_NOT_ALLOWED, HTTP_NOT_FOUND,
7
HTTP_UNAUTHORIZED, HTTP_SERVER_ERROR, HTTP_OK } from './cross-const'
8
import { uploadWriter } from './upload'
@@ -131,6 +132,8 @@ export const serveGuiAndSharedFiles: Koa.Middleware = async (ctx, next) => {
132
}
133
134
async function sendFolderList(node: VfsNode, ctx: Koa.Context) {
135
+ if ((await events.emitAsync('getList', { node, ctx }))?.isDefaultPrevented())
136
+ return
137
let { depth=0, folders, prepend } = ctx.query
138
ctx.type = 'text'
139
if (prepend === undefined || prepend === '*') { // * = force auto-detection even if we have baseUrl set