Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
glsx
/
gl_tape
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
3
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 622eb262
authored
Oct 13, 2026
by
liimin
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
去掉文件上传前的文件是否存在的判断,直接上传 以免造成误判
1 parent
919dc8d4
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
7 deletions
.workbuddy/memory/2026-10-13.md
utils/recordManager/RecordSaveService.js
.workbuddy/memory/2026-10-13.md
0 → 100644
View file @
622eb26
# 2026-10-13 工作日志
## 诊断:checkFileExists 为何判定 /data/user/0/... 录音"不存在"
### 硬事实链(已读代码确认)
-
`RecordSaveService.js:493`
`file.file = PathUtils.normalizeLocalFilePath(file.file)`
—— 把裸
`/data/user/0/.../x.mp3`
改成
`file:///data/user/0/.../x.mp3`
(三斜杠:file:// + /data)。
-
`PathUtils.js:110`
:
`startsWith('/') ? 'file://'+rawPath : rawPath`
。
-
`RecordSaveService.js:535-551`
`checkFileExists`
用
`uni.getFileInfo({filePath})`
,前置
`isLegalFile`
(L554 仅查 endsWith('.mp3'),非元凶)。
-
`uni.getFileInfo`
底层
`plus.io.getFileInfo`
:targetSdk≥29 + scoped storage 下既不能按绝对路径访问内部私有目录,也不认
`file://`
scheme → fail → resolve(false) → 误判"不存在"。
### 结论
-
判不存在根因:getFileInfo 读不了
`/data/user/0/...`
内部私有绝对路径(即超人第9-11轮确认的"文件丢失"根因本身)。
-
L493 normalize 是
**上次复原 FileUploadManager.js:230 时漏掉的同款有害改动**
:给内部路径加 file:// 反而更读不到。
-
"没问题的"那批:路径非裸
`/`
开头(外部存储 file:///storage/... 或 _doc 虚拟路径,getFileInfo 能解析)或已是 http URL 被 L527 标 Uploaded 后 L494 continue 跳过不查。
### 待超人拍板的修复选项(未动代码)
-
A 删 L493 normalize(去有害转换,但裸路径 getFileInfo 仍可能 fail)
-
B 让 checkFileExists 失败不阻断上传(uploadFile 能读字节成功,最治本、改动最小,倾向此)
-
C 恢复 fileIo.fileExists Java 降级(超人之前因怕副作用否决过)
### 已确认(读 FileUploadManager.js:226)
-
上传传参
`const filePath = record.filePath + record.fileName`
;
`record.filePath`
来自 flattenData L497,由 L493 已污染的
`file.file`
(file:///data/...) split 得出。
-
故 L493 同时污染
**上传传参**
(传
`//file:///data/.../x.mp3`
坏路径)与 checkFileExists。删 L493 一举修复两处。
-
但删 L493 后 checkFileExists 拿裸 /data/user/0/... 仍 getFileInfo fail → 仍标 NotExist → uploadRecord 对 NotExist 直接回调跳过上传(L195)。故还需 B:checkFileExists false 不阻断上传。
-
**最小治本组合 = 删 L493 + 改 L500-503(false 时也尝试上传)**
。
### 已落地改动(超人指令:删 L493 + 不做存在判断直接上传)
-
删 RecordSaveService.js:493
`file.file = PathUtils.normalizeLocalFilePath(file.file)`
→ 恢复裸 /data/user/0/... 路径
-
删 flattenData 内 checkFileExists 判断块(reportError + 标 NotExist)→ 不再做文件存在判定,直接进 result
-
删悬挂 import L17
`PathUtils`
(仅 L493 用)
-
保留 checkFileExists/isLegalFile 方法(超人怕副作用,不动);checkFileExists 现无调用方(死方法)
-
node --check 语法通过
### 完整上传链路(已读全代码确认)
录制结束/入队 → save(data)
[
L111
]
→ enQueue
[
L294
]
→ task
[
L566
]
→ L581 await uploadRecord(record)
[
L317
]
→ FileUploadManager.uploadRecord(record, cb)
[
L322
]
├─ 上传成功: cb→handleUploadResult
[
L85
]
→save(data)
[
L87
]
→parseFileInfo
[
L113
]
→_changeFilePathToServer
[
L139
]
→_saveOrUpdate
[
L140
]
│ → _handleCompletedRecord
[
L377
]
(全 Uploaded)→ serverPaths 空?L387 黑名单✅ / saveRecCustomer
[
L399
]
失败throw→L149 黑名单✅
└─ 上传异常(reject): uploadRecord L326 catch→handleUploadResult(errorResult)
[
L344
]
→save→parseFileInfo L216 code≠0→error→L122抛→catch L149 黑名单✅
### 黑名单触发点(4处)
1.
L387 serverPaths 空 → 黑名单
2.
L149 save 异常(含上传失败 parseFileInfo 报错)→ 黑名单✅闭环完整
3.
L583 task 层 uploadRecord reject → 死代码(L326 不 rethrow,永不触发)
4.
L487/L507 flattenData 查询链黑名单
### 关键澄清(重要,已纠正此前错误结论)
-
**flattenData 的 result 经 `enQueue`(L293)→`Queue(snapshot)`→`task` 出队→`uploadRecord(record)`(L317)→`FileUploadManager.uploadRecord` 实际喂给上传链**
(不是纯查询链)。
-
L493 污染
`file.file`
(file:///...)→
`aFullPath=file.file.split('/')`
(L496)→
`filePath=aFullPath.join('/')+'/'`
(L498)→ result 的 filePath 带 file:// 前缀 → FileUploadManager L190
`fullPath=record.filePath+fileName`
拼成坏路径 →
`uni.uploadFile`
失败。
-
**删 L493 是修复上传传参的关键**
,不是"只清理查询逻辑"。10-12 复原 FileUploadManager L230 只去掉"再包一层 file://",但 record.filePath 仍带 file://(源自 flattenData L493),故那轮未真正修复上传路径;本次删 L493 才根治。
-
FileUploadManager L194 仍按
**DB 原始 record.status**
(NoFile/NotExist) 跳过上传;删 checkFileExists 不碰 DB status,上传跳过逻辑不变。
-
那 6 条能否传出去仍取决于
**DB 里 file.status 是否被标 NotExist**
(历史批次)。需查 DB 确认——若已是 NotExist,删 L493 也救不回,FileUploadManager L194 仍跳过;若非 NotExist,裸路径上传能成功(超人确认过)。
### 11:38 超人追问:两种路径上传能力 + 删 L493/去 checkFileExists 副作用
**两种绝对路径能否上传成功(底层 = UniAppStrategy.uploadFile → uni.uploadFile({filePath: file.path},L99;file.path=record.filePath+fileName 裸路径)):**
-
`uni.uploadFile`
是原生 HTTP 上传,直接读文件字节流,不走 plus.io/ContentResolver。
-
`/data/user/0/uni.gltap/...`
(内部私有)与
`/storage/emulated/0/Android/data/uni.gltap/...`
(外部私有)都是
**应用自己目录**
,原生 File 可读。
-
**不加 file://、裸绝对路径:两种都能上传成功**
✓。相反加
`file:///`
三斜杠反而失败(uni.uploadFile 的 filePath 不认 file:// scheme,当不存在路径→fail)。
-
前提约束:上述两条都在
`uni.gltap`
应用目录内(项目现状)。若
`/storage/emulated/0/...`
指向
**非应用私有**
目录(如 DCIM/Download),targetSdk≥29 scoped storage 下无权限→失败。但项目录音只落
`/data/user/0/...`
,日志落外部私有,均不涉及。
**副作用面(已查实):**
-
删 L493:纯正面,修复上传传参(坏 file:/// 路径→裸路径)。无负面副作用。
-
删 checkFileExists 判断块(不标 NotExist、不打"文件不存在"日志):
-
上传链不受影响:uploadRecord L194 按
**DB 原始 status**
跳过,flattenData result 的 status 已不再被改写。
-
UI 零依赖:pages 目录 grep
`NotExist|getRecordsSnapshotFlatten|snapshotFlatten|fileList`
**No matches**
→前端页面不依赖这些标记,无展示副作用。
-
日志:不再打"记录中有语音文件地址但文件不存在"reportError(减少噪声,正面)。
-
行为变化:文件真在盘→直接上传成功;真不在(包根切换旧路径)→
`uni.uploadFile`
fail→L149 黑名单。即"上传不成功进黑名单"闭环,且能救回被判丢失但实际在盘的文件。
-
是否引起别的问题:唯一变化是从"提前 check 拦截进黑名单"变"真实上传失败后进黑名单",多一次失败上传尝试,后果可控(进黑名单/告警/不卡死)。属超人要的效果。
-
残留待确认:DB 里那 6 条 file.status 是否被历史标成 NotExist——若是,删 L493 也救不回。建议本地查 DB。
### 加 `file.file = PathUtils.normalizeLocalFilePath(file.file)` 这行的目的 + 去掉是否影响前缀判断(超人 12:23 提问,已查清)
-
**加这行的目的**
:
`normalizeLocalFilePath`
(PathUtils.js:107-111)注释明确——把
`/`
开头的绝对路径补成
`file://`
形式,意图让底层 API(plus.io / getFileInfo / 上传策略)按 URL scheme 识别应用内部私有目录文件(scoped storage 下 plus.io 读不到绝对路径的"补丁"尝试)。但实测上传主链路 UniAppStrategy→
`uni.uploadFile`
**不认 file:// scheme**
(要裸绝对路径),所以对本项目上传是
**反向有害**
:把本可上传的裸路径改成
`uni.uploadFile`
拒绝的坏路径。
-
**DB 那 6 条 file.file 是裸 `/data/user/0/...`(无 file://)**
:证据=超人上一轮贴的日志原文路径
`.../doc/records/1791431937899_fda81fcb.mp3`
(无 scheme)。故 L493 对这 6 条确实做了"裸→file:/// 三斜杠"的加坏转换,删掉是正确修复(非 no-op)。
-
**去掉后 `file.file` 前缀判断的影响面(逐项查实):**
1.
flattenData 内部(L493-495):
`file.file.split('/')`
拆目录+文件名。裸路径拆出正确
`/data/...`
;file:// 版本拆出
`file:///data/...`
坏路径。去掉→修复上传传参,
**无副作用**
。
2.
**UploadManager._registerStrategies()(L167-169)只注册 WebViewStrategy + UniAppStrategy,NativeStrategy 未注册**
→
`NativeStrategy.js:90 if(filePath.startsWith('file://'))`
是
**死代码**
,对录音频链永不执行,去掉 file:// 不影响策略选择。
3.
**UniAppStrategy 上传链**
:拿裸
`record.filePath + fileName`
(RecordSaveService L494-495 split 产出),
`uni.uploadFile`
原生 HTTP 读字节,能读
`/data/user/0/...`
(内部私有)与
`/storage/emulated/0/...`
(外部私有,均 app 目录内),两种都成功。
4.
其他
`file://`
前缀判断点:
`RecordManager.js:169`
、
`TempRecord.js:244`
、
`fileIo.js:17`
、
`pathCache.js:8`
—— 这些消费的是
**录制时/存储归并阶段的路径**
,
**不消费 flattenData 改过的 file.file**
;且 L493 只改 flattenData 内部循环变量、不动 DB。故完全不受影响。
5.
平行链:
`UploadService.js`
、
`mixin/uploader.js`
也用
`file.file.split('/')`
+
`checkFileExists(file.file)`
,但它们是独立上传类/UI 上传器,各自读 DB 原始 file.file,
**不共享 RecordSaveService 的 file.file 状态**
,不在本次改动范围。
-
结论:删 L493 是修复(裸路径→uni.uploadFile 能读),不引发前缀判断类副作用;真正读 file:// 的上传策略未注册,其余前缀判断点不碰本链数据。
utils/recordManager/RecordSaveService.js
View file @
622eb26
...
@@ -14,7 +14,6 @@ import dayjs from 'dayjs'
...
@@ -14,7 +14,6 @@ import dayjs from 'dayjs'
import
store
from
'@/store'
import
store
from
'@/store'
import
FileUploadManager
from
'./FileUploadManager.js'
import
FileUploadManager
from
'./FileUploadManager.js'
import
{
Command
}
from
'../../ws/constants'
import
{
Command
}
from
'../../ws/constants'
import
PathUtils
from
'./PathUtils.js'
const
UPLOAD_INTERVAL
=
0.5
*
60
*
1000
const
UPLOAD_INTERVAL
=
0.5
*
60
*
1000
/**
/**
...
@@ -490,17 +489,11 @@ class RecordSaveService {
...
@@ -490,17 +489,11 @@ class RecordSaveService {
}
}
for
(
const
file
of
recordUrlList
)
{
for
(
const
file
of
recordUrlList
)
{
try
{
try
{
file
.
file
=
PathUtils
.
normalizeLocalFilePath
(
file
.
file
)
if
(
file
.
status
===
FileStatus
.
Uploaded
||
file
.
status
===
FileStatus
.
Completed
)
continue
if
(
file
.
status
===
FileStatus
.
Uploaded
||
file
.
status
===
FileStatus
.
Completed
)
continue
const
aFullPath
=
file
.
file
.
split
(
'/'
)
const
aFullPath
=
file
.
file
.
split
(
'/'
)
const
fileName
=
aFullPath
.
pop
()
const
fileName
=
aFullPath
.
pop
()
const
filePath
=
aFullPath
.
join
(
'/'
)
+
'/'
const
filePath
=
aFullPath
.
join
(
'/'
)
+
'/'
const
file2Up
=
{
...
file
,
recordId
:
cur
.
id
,
fileName
,
filePath
}
const
file2Up
=
{
...
file
,
recordId
:
cur
.
id
,
fileName
,
filePath
}
const
fileExists
=
await
this
.
checkFileExists
(
file
.
file
)
if
(
!
fileExists
)
{
this
.
reportError
(
'【接待记录保存服务】 == 记录中有语音文件地址,但是文件不存在'
,
{
record
:
cur
,
file
},
cur
.
id
,
file
.
file
)
file2Up
.
status
=
FileStatus
.
NotExist
}
result
.
push
(
file2Up
)
result
.
push
(
file2Up
)
}
catch
(
error
)
{
}
catch
(
error
)
{
this
.
reportError
(
`【接待记录保存服务】 == 解析处理文件异常 error:
${
error
.
message
}
`
,
{
record
:
cur
,
file
})
this
.
reportError
(
`【接待记录保存服务】 == 解析处理文件异常 error:
${
error
.
message
}
`
,
{
record
:
cur
,
file
})
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment