47 lines
1.5 KiB
JavaScript
47 lines
1.5 KiB
JavaScript
|
|
/**
|
|||
|
|
* Phase: upload — OSS 上传
|
|||
|
|
*
|
|||
|
|
* 将生成的图片(含首尾帧)上传到 OSS,回写 url
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
const path = require('path')
|
|||
|
|
const { saveManifest, log, getManifestDir } = require('./pipeline-utils')
|
|||
|
|
|
|||
|
|
async function phaseUpload(manifest, manifestPath) {
|
|||
|
|
const dir = getManifestDir(manifestPath)
|
|||
|
|
const { uploadFile } = require('../oss-upload')
|
|||
|
|
|
|||
|
|
const items = manifest.items.filter(it =>
|
|||
|
|
it.status === 'done' && it.file && !it.url
|
|||
|
|
)
|
|||
|
|
if (items.length === 0) { log('upload', '无待上传 item,跳过'); return }
|
|||
|
|
|
|||
|
|
log('upload', `共 ${items.length} 个文件`)
|
|||
|
|
|
|||
|
|
for (let i = 0; i < items.length; i++) {
|
|||
|
|
const item = items[i]
|
|||
|
|
const filePath = path.resolve(dir, item.file)
|
|||
|
|
try {
|
|||
|
|
const { url } = await uploadFile(filePath)
|
|||
|
|
item.url = url
|
|||
|
|
log('upload', `[${i + 1}/${items.length}] ${item.file} → ${url.substring(0, 60)}...`)
|
|||
|
|
} catch (err) {
|
|||
|
|
item.error = `上传失败: ${err.message}`
|
|||
|
|
log('upload', `[${i + 1}/${items.length}] 失败: ${err.message}`)
|
|||
|
|
}
|
|||
|
|
if (item.url && item.lastFrame && !item.lastFrameUrl) {
|
|||
|
|
const lastPath = path.resolve(dir, item.lastFrame)
|
|||
|
|
try {
|
|||
|
|
const { url } = await uploadFile(lastPath)
|
|||
|
|
item.lastFrameUrl = url
|
|||
|
|
log('upload', `[${i + 1}/${items.length}] lastFrame → OK`)
|
|||
|
|
} catch (err) {
|
|||
|
|
log('upload', `[${i + 1}/${items.length}] lastFrame 上传失败: ${err.message}`)
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
saveManifest(manifestPath, manifest)
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
module.exports = { phaseUpload }
|