plugins: api.normalizeFilename

Massimo Melina committed Nov 30, 2025 at 18:11 UTC 17ca7b4eaa5353ee90e3d37767735aa83536fd12
4 files changed +10 -6
dev-plugins.md
+6 -2
@@ -360,6 +360,9 @@ The `api` object you get as parameter of the `init` contains the following:
360 - `onServer(cb: (Server) => any)` execute your callback on every instance of Server created by HFS.
361 It is the standard Node.js class, and it can be http or https. It can be instantiated multiple times.
362
363 +- `normalizeFilename(filename: string): string` HFS applies some normalization to files, and so should you.
364 + It's necessary when running on Mac and Windows, as they are case-insensitive.
365 +
366 ## Frontend JS
367
368 The following information applies to the frontend bundled with HFS.
@@ -1086,5 +1089,6 @@ If you want to override a text regardless of the language, use the special langu
1089 - 12.94 (v0.57.24)
1090 - HFS.onEvent now supports :after
1091 - HFS.userBelongsTo now supports array of usernames
1089 -- 12.95 (v0.57.27)
1090 - - frontend events: loginOk, loginFailed
\ No newline at end of file
1092 +- 12.96 (v0.57.27)
1093 + - frontend events: loginOk, loginFailed
1094 + - api.normalizeFilename
\ No newline at end of file
src/const.ts
+1 -1
@@ -9,7 +9,7 @@ import { formatTimestamp } from './cross'
9 import { argv } from './argv'
10 export * from './cross-const'
11
12 -export const API_VERSION = 12.95
12 +export const API_VERSION = 12.96
13 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
14
15 // you can add arguments with this file, currently used for the update process on mac/linux
src/plugins.ts
+2 -2
@@ -15,7 +15,7 @@ import {
15 import * as misc from './misc'
16 import { defineConfig, getConfig, subMultipleConfigs } from './config'
17 import { DirEntry } from './api.get_file_list'
18 -import { VfsNode } from './vfs'
18 +import { normalizeFilename, VfsNode } from './vfs'
19 import { serveFile } from './serveFile'
20 import events from './events'
21 import { mkdir, readdir, readFile, rm } from 'fs/promises'
@@ -157,7 +157,7 @@ async function initPlugin(pl: any, morePassedToInit?: { id: string } & Dict<any>
157 controlledEvents.on('listening', ({ server }: any) => cb(server))
158 },
159 misc, _,
160 - customApiCall, notifyClient, addBlock, ctxBelongsTo, getConnections,
160 + customApiCall, notifyClient, addBlock, ctxBelongsTo, getConnections, normalizeFilename,
161 getCurrentUsername, getAccount, getUsernames, addAccount, delAccount, updateAccount, renameAccount,
162 ...morePassedToInit
163 })
src/vfs.ts
+1 -1
@@ -85,7 +85,7 @@ export function isSameFilenameAs(name: string) {
85 normalized === normalizeFilename(typeof other === 'string' ? other : getNodeName(other))
86 }
87
88 -function normalizeFilename(x: string) {
88 +export function normalizeFilename(x: string) {
89 return (IS_WINDOWS || IS_MAC ? x.toLocaleLowerCase() : x).normalize()
90 }
91