|
|
|
@ -114,49 +114,34 @@ export const takePhotoWithWaterMark = async ({ |
|
|
|
} |
|
|
|
|
|
|
|
// 将文件从公共目录复制到应用私有目录(解决 Android 11+ 分区存储导致的 EACCES 权限问题)
|
|
|
|
const copyFileToAppDir = (sourcePath) => { |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
if (!window.cordova?.file?.dataDirectory) { |
|
|
|
reject(new Error('cordova.file.dataDirectory 不可用')) |
|
|
|
return |
|
|
|
} |
|
|
|
window.resolveLocalFileSystemURL( |
|
|
|
sourcePath, |
|
|
|
(fileEntry) => { |
|
|
|
window.resolveLocalFileSystemURL( |
|
|
|
window.cordova.file.dataDirectory, |
|
|
|
(dataDirEntry) => { |
|
|
|
const fileName = fileEntry.name |
|
|
|
fileEntry.copyTo( |
|
|
|
dataDirEntry, |
|
|
|
fileName, |
|
|
|
(newFileEntry) => { |
|
|
|
console.log('[w6sMedia] 文件已复制到应用私有目录:', newFileEntry.fullPath) |
|
|
|
resolve(newFileEntry.fullPath) |
|
|
|
}, |
|
|
|
(copyErr) => { |
|
|
|
console.error('[w6sMedia] 复制文件失败:', copyErr) |
|
|
|
reject(copyErr) |
|
|
|
} |
|
|
|
) |
|
|
|
}, |
|
|
|
(dirErr) => { |
|
|
|
console.error('[w6sMedia] 获取应用私有目录失败:', dirErr) |
|
|
|
reject(dirErr) |
|
|
|
} |
|
|
|
) |
|
|
|
}, |
|
|
|
(fileErr) => { |
|
|
|
console.error('[w6sMedia] 解析源文件失败:', fileErr, 'sourcePath:', sourcePath) |
|
|
|
reject(fileErr) |
|
|
|
} |
|
|
|
) |
|
|
|
const copyFileToAppDir = async (sourcePath) => { |
|
|
|
if (!window.cordova?.file?.dataDirectory) { |
|
|
|
throw new Error('cordova.file.dataDirectory 不可用') |
|
|
|
} |
|
|
|
console.log('[w6sMedia] copyFileToAppDir sourcePath:', sourcePath) |
|
|
|
|
|
|
|
const sourceEntry = await new Promise((resolve, reject) => { |
|
|
|
window.resolveLocalFileSystemURL(sourcePath, resolve, reject) |
|
|
|
}) |
|
|
|
console.log('[w6sMedia] 源文件 entry:', sourceEntry.fullPath, 'name:', sourceEntry.name) |
|
|
|
|
|
|
|
const dataDirEntry = await new Promise((resolve, reject) => { |
|
|
|
window.resolveLocalFileSystemURL(window.cordova.file.dataDirectory, resolve, reject) |
|
|
|
}) |
|
|
|
console.log('[w6sMedia] 应用私有目录:', dataDirEntry.fullPath) |
|
|
|
|
|
|
|
const newFileEntry = await new Promise((resolve, reject) => { |
|
|
|
sourceEntry.copyTo(dataDirEntry, sourceEntry.name, resolve, reject) |
|
|
|
}) |
|
|
|
// toURL() 返回 file:// 格式的 URL,FileTransfer 可直接使用
|
|
|
|
const fileUrl = newFileEntry.toURL() |
|
|
|
console.log('[w6sMedia] 文件已复制到应用私有目录, fileUrl:', fileUrl, 'fullPath:', newFileEntry.fullPath) |
|
|
|
return fileUrl |
|
|
|
} |
|
|
|
|
|
|
|
// 录制视频(使用 Cordova 原生 Media Capture API)
|
|
|
|
export const startVideoRecorder = async ({ |
|
|
|
duration = 60, |
|
|
|
duration = 0, |
|
|
|
quality = 1, // 0 高清 / 1 一般 / 2 流畅
|
|
|
|
front = false, |
|
|
|
syncSystemAlbum = false, |
|
|
|
@ -202,7 +187,7 @@ export const startVideoRecorder = async ({ |
|
|
|
console.error('[w6sMedia] captureVideo fail:', error, 'code:', error?.code, 'message:', error?.message) |
|
|
|
reject(error) |
|
|
|
}, |
|
|
|
{ limit: 1, duration } |
|
|
|
duration ? { limit: 1, duration } : { limit: 1 } |
|
|
|
) |
|
|
|
}) |
|
|
|
} |
|
|
|
@ -249,7 +234,7 @@ export const uploadLocalFileToBackend = async ({ |
|
|
|
success: (res) => { |
|
|
|
console.log('[w6sMedia] file.upload success 原始返回:', res) |
|
|
|
try { |
|
|
|
const parsed = typeof res.response === 'string' ? JSON.parse(res.response) : res.response |
|
|
|
const parsed = JSON.parse(res.response) |
|
|
|
console.log('[w6sMedia] 解析后的上传响应:', parsed) |
|
|
|
resolve(parsed) |
|
|
|
} catch (e) { |
|
|
|
@ -264,7 +249,8 @@ export const uploadLocalFileToBackend = async ({ |
|
|
|
}, |
|
|
|
opts |
|
|
|
).catch((err) => { |
|
|
|
console.error('[w6sMedia] w6s.file.upload 异常:', err) |
|
|
|
// w6s.file.upload 在 responseCode !== 200 时会 reject 但不调用 fail 回调
|
|
|
|
console.error('[w6sMedia] w6s.file.upload Promise reject:', err) |
|
|
|
reject(err) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|