vitepress-plugin-filelist 0.3.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,7 +7,8 @@
7
7
  - 📁 树形目录,文件夹按需加载
8
8
  - ✅ 勾选文件;选中文件夹会自动加载并选中其下所有层级的文件
9
9
  - 📦 批量打包 ZIP(基于 `fflate`),带进度;保留目录结构,不同目录的同名文件不会互相覆盖
10
- - ⬇️ 单文件下载与预览(`/d/`、`/p/`、`fs/get` 的 `raw_url`)
10
+ - ⬇️ 单文件下载(`fs/get` 的 `raw_url`,回退 `/d/`)
11
+ - 👁️ 弹窗预览(不跳转):图片、音视频、文本、PDF;Office 等其它类型显示文件信息与下载
11
12
  - 🔐 目录密码输入,可选只读 token
12
13
  - 🔎 当前树过滤,按名称 / 大小 / 日期排序
13
14
  - 🎨 紧凑表格:按文件类型着色的扩展名标签、层级引导线,跟随 VitePress 亮 / 暗主题
@@ -79,6 +80,7 @@ export default {
79
80
  | `expanded` | `boolean` | `false` | 目录根是否默认展开 |
80
81
  | `token` | `string` | `''` | 可选只读 token;不传则以游客身份请求 |
81
82
  | `password` | `string` | `''` | 目录密码,也可以在运行时输入 |
83
+ | `rememberPassword` | `boolean` | `true` | 输入密码时是否提供“在此标签页中记住”开关;`false` 时不写入 sessionStorage |
82
84
  | `title` | `string` | `''` | 工具栏标题;为空时回退到 OpenList 的 `site_title` |
83
85
  | `locale` | `'zh-CN' \| 'en-US'` | `'zh-CN'` | 内置文案预设 |
84
86
  | `labels` | `Partial<FileListLabels>` | `undefined` | 按 key 覆盖单条文案 |
@@ -102,7 +104,7 @@ export default {
102
104
  - 目录路径挂载为根文件夹,默认折叠;`expanded` 可为全局或单个 source 打开
103
105
  - 文件路径挂载为一条文件记录,直接预览/下载
104
106
  - 勾选根目录会加载并选中其下所有文件;ZIP 内以根节点名称(`title` 或路径末段)作为顶层文件夹,文件根保留原文件名
105
- - 每个 source 可单独设置 `title`、`password`;未设置 `password` 的 source 使用组件的 `password` 或运行时输入的密码,遇到需要密码的目录会弹出密码输入框
107
+ - 每个 source 可单独设置 `title`、`password`;未设置 `password` 的 source 使用组件的 `password` 或运行时输入的密码,遇到需要密码的目录会在该行原地显示密码输入框(见下文)
106
108
  - 根节点顺序按 `sources` 顺序,子项仍按名称/大小/日期排序
107
109
 
108
110
  ```ts
@@ -124,6 +126,16 @@ interface FileListSource {
124
126
  - 勾选后操作条吸附在组件顶部,位于 VitePress 导航栏 / “On this page” 栏下方,只在本组件范围内吸附
125
127
  - 颜色全部取自 VitePress 主题变量,暗色模式自动适配
126
128
 
129
+ ## 刷新与目录密码
130
+
131
+ - **刷新**:保留当前列表并调暗,表头下方显示进度条;完成后整体替换,已展开的目录和仍存在的勾选会保留。刷新失败时保留旧数据并提示。刷新只重新读取 OpenList 的目录缓存(游客没有写权限,无法强制刷新存储)
132
+ - **目录密码**:点击加锁目录(或勾选包含它的目录)时,密码输入框直接出现在该行的大小 / 日期位置,行高不变,下方文件不会移动;勾选在遇到加锁子目录时停下并请求密码
133
+ - Enter 提交,Esc 取消;密码错误时在原位提示“密码不正确或无权访问”(OpenList 无法区分密码错误和无权限)
134
+ - 钥匙按钮可开启“在此标签页中记住(关闭标签页后失效)”,密码存在 sessionStorage,按 OpenList 地址和目录区分,也覆盖子目录;已记住的目录显示“已记住 · 忘记”
135
+ - 保存的密码失效时自动删除,并提示重新输入
136
+ - 本次页面中输入过的密码(即使没有记住)在刷新后仍然有效
137
+ - 单一 `path` 本身需要密码时,在列表位置显示密码输入框
138
+
127
139
  吸顶偏移默认根据 `.VPNav`、`.VPLocalNav` 的实际高度自动计算;自定义主题可手动指定:
128
140
 
129
141
  ```css
@@ -132,6 +144,22 @@ interface FileListSource {
132
144
  }
133
145
  ```
134
146
 
147
+ ## 预览
148
+
149
+ 点击预览按钮在当前页面的弹窗(原生 `<dialog>`)中显示,不跳转、不打开新标签页。只有能在页面内显示的类型才有预览按钮;点击文件名仍是下载。
150
+
151
+ | 类型 | 扩展名(节选) | 方式 |
152
+ | --- | --- | --- |
153
+ | 图片 | png、jpg、gif、webp、svg、avif | `<img>`,可旋转、切换原始大小 |
154
+ | 视频 / 音频 | mp4、webm、mov / mp3、m4a、flac、wav | 原生播放器(格式以浏览器支持为准) |
155
+ | 文本 | txt、md、json、csv、yaml、日志与常见代码 | 只读取前 1 MB(Range 请求),纯文本显示 |
156
+ | PDF | pdf | 优先使用 OpenList `iframe_previews` 中配置的 PDF 查看器;未配置时用浏览器自带阅读器(下载后以 Blob 显示,上限 50 MB) |
157
+ | 其它(含 Office、压缩包) | — | 弹窗内显示文件信息和下载按钮 |
158
+
159
+ - 弹窗内 ← / → 切换当前列表中的可预览文件,Esc 或点击遮罩关闭
160
+ - 读取文本和浏览器 PDF 需要文件地址允许跨域:经 OpenList 代理(`/p/`)时由 OpenList 的 CORS 设置决定;网盘直链由网盘决定。失败时显示“无法在页面内预览”和下载按钮
161
+ - `iframe_previews` 来自 `/api/public/settings`,与 OpenList 网页端使用同一配置,占位符 `$url`、`$e_url`、`$b_url`、`$durl`、`$name` 的含义一致
162
+
135
163
  ## 国际化
136
164
 
137
165
  ```md
@@ -157,7 +185,7 @@ import { fileListLocales, formatLabel, resolveLabels } from 'vitepress-plugin-fi
157
185
  ## OpenList 要求
158
186
 
159
187
  1. **游客只读权限**:开启游客用户,或传入只读 `token`
160
- 2. **CORS**:OpenList 的 `cors.allow_origins` 必须包含站点来源(默认 `*`)
188
+ 2. **CORS**:OpenList 的 `cors.allow_origins` 必须包含站点来源(默认 `*`);使用 OpenList-Worker 时设置 `ALLOW_URLS`(逗号分隔,完整来源,如 `https://docs.example.com,http://localhost:5173`,不支持通配符)。出现“Failed to fetch”时组件会提示检查这两项。GET 请求不带 `Content-Type`,避免多余的预检
161
189
  3. **同协议**:HTTPS 页面不能请求 HTTP 的 OpenList(混合内容)
162
190
  4. **token 是公开的**:只放可撤销的只读 token,不要放管理 token
163
191
 
@@ -167,8 +195,8 @@ import { fileListLocales, formatLabel, resolveLabels } from 'vitepress-plugin-fi
167
195
  | --- | --- |
168
196
  | `POST /api/fs/list` | 目录列表(`per_page: 0`) |
169
197
  | `POST /api/fs/get` | 获取下载 / 预览 / 打包用的 `raw_url`;失败时回退到 `/d/...?sign=` |
170
- | `GET /api/public/settings` | 获取 `site_title` |
171
- | `GET /d/...`、`GET /p/...` | OpenList 生成的下载 / 预览链接 |
198
+ | `GET /api/public/settings` | 获取 `site_title`、`iframe_previews` |
199
+ | `GET /d/...`、`GET /p/...` | 下载与预览读取的文件地址 |
172
200
 
173
201
  ## 导出
174
202
 
@@ -32,6 +32,7 @@ interface FileListLabels {
32
32
  demoPreview: string;
33
33
  demoBatch: string;
34
34
  downloadFailed: string;
35
+ /** @deprecated Preview errors are shown in the dialog (`previewUnavailable`). */
35
36
  previewFailed: string;
36
37
  batchFailed: string;
37
38
  defaultZip: string;
@@ -52,6 +53,43 @@ interface FileListLabels {
52
53
  expand: string;
53
54
  /** Accessible name of the collapse button, `{name}`. */
54
55
  collapse: string;
56
+ /** Preview dialog: close button. */
57
+ close: string;
58
+ /** Preview dialog: previous / next previewable file. */
59
+ previous: string;
60
+ next: string;
61
+ /** Preview dialog: rotate image by 90°. */
62
+ rotate: string;
63
+ /** Preview dialog: toggle the image between fit-to-window and actual size. */
64
+ actualSize: string;
65
+ /** Preview dialog: file type that is not previewed (Office and others). */
66
+ previewUnsupported: string;
67
+ /** Preview dialog: preview failed (network, CORS, unsupported codec). */
68
+ previewUnavailable: string;
69
+ /** Preview dialog: PDF larger than the in-page limit, `{size}`. */
70
+ previewTooLarge: string;
71
+ /** Preview dialog: only the first `{size}` of a text file is shown. */
72
+ textTruncated: string;
73
+ /** Refresh button while refreshing. */
74
+ refreshing: string;
75
+ /** Refresh failed; the old rows stay. `{message}` */
76
+ refreshFailed: string;
77
+ cancel: string;
78
+ /** Placeholder / accessible name of a folder's password input. `{name}` */
79
+ passwordFor: string;
80
+ /** OpenList cannot tell a wrong password from missing permission. */
81
+ passwordWrong: string;
82
+ /** A password remembered in this tab no longer works. */
83
+ passwordStale: string;
84
+ /** The key toggle next to a password input. */
85
+ rememberPassword: string;
86
+ /** Tag on a folder whose password is remembered. */
87
+ remembered: string;
88
+ forgetPassword: string;
89
+ /** Lock button on a folder that needs a password. `{name}` */
90
+ unlockFolder: string;
91
+ /** Appended to failure toasts for browser network errors (usually CORS). */
92
+ networkHint: string;
55
93
  }
56
94
  interface FileListSource {
57
95
  /** OpenList path, directory or single file. */
@@ -78,6 +116,11 @@ interface FileListProps {
78
116
  password?: string;
79
117
  /** Toolbar title. Falls back to `site_title` from `/api/public/settings`. */
80
118
  title?: string;
119
+ /**
120
+ * Offer to remember folder passwords in this browser tab (sessionStorage,
121
+ * cleared when the tab closes). Defaults to `true`; `false` hides the option.
122
+ */
123
+ rememberPassword?: boolean;
81
124
  /** Built-in locale. Defaults to `zh-CN`. */
82
125
  locale?: FileListLocale;
83
126
  /** Per-key label overrides on top of the locale preset. */
@@ -102,6 +145,7 @@ declare const _default: import("vue").DefineComponent<FileListProps, {}, {}, {},
102
145
  token: string;
103
146
  password: string;
104
147
  title: string;
148
+ rememberPassword: boolean;
105
149
  locale: FileListLocale;
106
150
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
107
151
  declare global {
@@ -213,6 +257,32 @@ export declare function totalSize(items: Array<{
213
257
  size?: number;
214
258
  }>): number;
215
259
  export declare function compareNodes(a: SortableNode, b: SortableNode, key: SortKey, ascending?: boolean): number;
260
+ export type PreviewKind = 'image' | 'video' | 'audio' | 'text' | 'pdf' | 'none';
261
+ /**
262
+ * How a file is shown in the preview dialog. Office documents and anything
263
+ * else the browser cannot render are `none` (info + download).
264
+ */
265
+ export declare function previewKind(name: string): PreviewKind;
266
+ export interface IframePreview {
267
+ label: string;
268
+ scheme: string;
269
+ }
270
+ /**
271
+ * Viewers from OpenList's public `iframe_previews` setting that match a file,
272
+ * in the order OpenList lists them. Keys are comma-separated extensions or a
273
+ * `/regex/flags` tested against the extension, as in OpenList's frontend.
274
+ */
275
+ export declare function iframePreviewsFor(name: string, setting: string | undefined): IframePreview[];
276
+ /**
277
+ * Fill an OpenList preview scheme: `$name`, `$url` (raw URL) and `$durl`
278
+ * (signed download URL), each optionally prefixed with `e` (URI-encode) or
279
+ * `b` (base64), e.g. `$e_url`, `$b_url`, `$e_durl`.
280
+ */
281
+ export declare function fillPreviewUrl(scheme: string, args: {
282
+ name: string;
283
+ rawUrl: string;
284
+ downloadUrl: string;
285
+ }): string;
216
286
  /**
217
287
  * Register `<FileList>` and `<VPFileList>` globally.
218
288
  *