@samitouri / QOSami-HFS / commits / cdca90fb

doc: outdated info on preventing api.events

Massimo Melina committed Dec 6, 2025 at 11:25 UTC cdca90fb85380b531146b8f0985d47e46ee13199
2 files changed +27 -7
dev-plugins.md
+26 -6
@@ -650,7 +650,7 @@ exports.init = function(api) {
650 }
651 ```
652
653 -Of course the example above can be written more shortly as follows, but they are equivalent.
653 +But javascript allows a shorter and equivalent syntax for the example above:
654
655 ```js
656 exports.init = api => ({
@@ -667,11 +667,14 @@ api.events.on('deleting', async () => your-code-here)
667
668 ### Stop, the way you prevent default behavior
669
670 -Some events allow you to stop their default behavior, by returning `api.events.preventDefault`.
670 +Some events allow you to stop their default behavior, by returning `api.events.stop`.
671 This is reported in the list below with the word "preventable".
672
673 ```js
674 -api.events.on('deleting', ({ node }) => node.source.endsWith('.jpg'))
674 +api.events.on('deleting', ({ node }) => {
675 + if (!node.source.endsWith('.jpg'))
676 + return api.events.stop
677 +})
678 ```
679
680 The example above will return false only when the file is NOT ending with .jpg, thus allowing only jpg files to be deleted.
@@ -685,7 +688,9 @@ This section is still partially documented, and you may need to have a look at t
688 - async supported
689 - preventable
690 - `login`
691 + - parameters: { ctx }
692 - `logout`
693 + - parameters: { ctx }
694 - `attemptingLogin` called when the login process starts
695 - parameters: { ctx, username, via? }
696 - via?: string
@@ -695,7 +700,7 @@ This section is still partially documented, and you may need to have a look at t
700 - preventable
701 - `failedLogin`
702 - parameters: { ctx, username, via? }
698 -- - `clearTextLogin` give plugins the chance to authenticate users
703 +- `clearTextLogin` give plugins the chance to authenticate users
704 - parameters: { ctx, username, password, via: 'url' | 'header' }
705 - async supported
706 - return: `true` to consider authentication done
@@ -705,15 +710,25 @@ This section is still partially documented, and you may need to have a look at t
710 - merge of all inputs both from body and URL
711 - all fields with a `name` attribute in the form, included those added by plugins, are included
712 - async supported
708 -- `config ready`
713 +- `configReady` when the config is fully loaded (the boolean flags whether we started without an existing config file)
714 + - parameters: { startedWithoutConfig: boolean }
715 - `config.KEY` where KEY is the key of a config that has changed
716 + - parameters: newValue
717 - `connectionClosed`
718 + - parameters: connection
719 - `connection`
720 + - parameters: connection
721 - `connectionUpdated`
722 + - parameters: connection
723 +- connectionNewIp
724 + - parameters: connection
725 - `console`
726 + - parameters: { ts, msg, k: 'log' | 'warn' | 'error' | 'debug' }
727 - `dynamicDnsError`
715 -- `httpsReady`
728 + - parameters: { ts, error, url }
729 +- `httpsReady` when the HTTPS server becomes available (no parameters)
730 - `spam`
731 + - parameters: { ctx }
732 - `log`
733 - parameters: { ctx, length, user, ts, uri, extra }
734 - `error_log`
@@ -723,9 +738,12 @@ This section is still partially documented, and you may need to have a look at t
738 - `pluginDownload`
739 - `pluginUpdated`
740 - `pluginInstalled`
741 + - parameters: plugin
742 - `pluginUninstalled`
743 - `pluginStopped`
744 - `pluginStarted`
745 +- `listening`
746 + - parameters: { server, port }
747 - `httpsServerOptions` if you need to customize the options of the https server.
748 - return: object with some properties [documented here](https://nodejs.org/api/https.html#httpscreateserveroptions-requestlistener).
749 - `uploadStart`
@@ -1006,6 +1024,7 @@ If you want to override a text regardless of the language, use the special langu
1024 - frontend event: menuZip
1025 - config.type:username
1026 - api.events class has changed
1027 + - backend event: deleting
1028 - frontend event "fileMenu": changed props format
1029 - api.getConfig() without parameters
1030 - api.notifyClient + HFS.getNotifications
@@ -1024,6 +1043,7 @@ If you want to override a text regardless of the language, use the special langu
1043 - frontend event: showPlay
1044 - api.addBlock
1045 - api.misc
1046 + - api.events.stop
1047 - frontend event: paste
1048 - exports.customRest + HFS.customRestCall
1049 - config.type: vfs_path
src/events.ts
+1 -1
@@ -68,7 +68,7 @@ export class BetterEventEmitter {
68 }
69 for (const cb of cbs) {
70 const res = cb(...args, extra)
71 - if (res === this.preventDefault)
71 + if (res === this.stop)
72 extra.preventDefault()
73 else if (res !== undefined)
74 output.push(res)