文件存储
SQLite
数据库路径由 config.storage.databaseFile 决定。
user 表:
| 字段 | 类型 | 说明 |
|---|---|---|
users_id |
INTEGER | 主键 |
u_name |
TEXT | 用户名,唯一索引 |
当前写死:
users_id=1, u_name='1'
users_id=2, u_name='2'
files 表:
| 字段 | 类型 | 说明 |
|---|---|---|
files_id |
INTEGER | 主键 |
hash |
BLOB | 文件 hash(UTF-8 字节) |
u_time |
INTEGER | Unix 秒级时间戳 |
owner |
INTEGER | 所属用户 id |
HashFileStorage
src/utils/hashFileStorage.mjs 只负责磁盘文件,不操作 SQLite。
目录规则:
<filesDirectory>/
└─ ab/
└─ cd/
└─ abcdef... # 完整 hash,无扩展名
主要方法:
saveFiles([{hash, blob}])getFiles([hash])deleteFiles([hash])getFilePath(hash)commitFileFromPath(hash, sourcePath)
处理流水线
src/utils/hashFileProcessor.mjs 负责通用处理流程:
- 从
HashFileStorage定位原 hash 文件 - 在
config.storage.cacheDirectory下创建temp_<原hash> - 调用
handler({inputPath, tempPath, originalHash}) - 对
tempPath计算 SHA-256 - 用新 hash 移动到
HashFileStorage对应目录 - 清理临时文件
图片元数据清理使用同一套流水线,处理结果会生成新 hash,原文件保留。