fix: 修复watcher检查分片文件的部分问题
This commit is contained in:
parent
14d593cc89
commit
fdf948d3ee
|
|
@ -87,7 +87,7 @@ const watchers = [
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '确定uploading的文件状态',
|
name: '处理长时间未完成分片上传的文件',
|
||||||
entity: 'extraFile',
|
entity: 'extraFile',
|
||||||
filter: async () => {
|
filter: async () => {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
|
@ -126,15 +126,32 @@ const watchers = [
|
||||||
successIds.push(d.id);
|
successIds.push(d.id);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// 这个文件不存在,此时去判断是否是上传完但是未合并的情况
|
// 这个文件不存在,此时去尝试合并,如果合并失败,则标记为失败
|
||||||
const { parts } = await cos.listMultipartUploads(context.getApplication(), d, context);
|
try {
|
||||||
assert(parts);
|
if (d.chunkInfo?.merged) {
|
||||||
const isDone = parts.every(p => p.etag && p.etag.length > 0);
|
// 已经合并过了,说明是合并后删除的
|
||||||
if (isDone) {
|
failedIds.push(d.id);
|
||||||
// 标记为成功
|
continue;
|
||||||
|
}
|
||||||
|
// 去合并分片
|
||||||
|
await cos.mergeChunkedUpload(context.getApplication(), d, context);
|
||||||
|
await context.operate('extraFile', {
|
||||||
|
id: await generateNewIdAsync(),
|
||||||
|
action: 'update',
|
||||||
|
data: {
|
||||||
|
chunkInfo: {
|
||||||
|
...d.chunkInfo,
|
||||||
|
merged: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
filter: {
|
||||||
|
id: d.id,
|
||||||
|
},
|
||||||
|
}, {});
|
||||||
successIds.push(d.id);
|
successIds.push(d.id);
|
||||||
}
|
}
|
||||||
else {
|
catch (err) {
|
||||||
|
console.log(`分片合并失败,文件: ${d.id} 标记为上传失败: `, err);
|
||||||
failedIds.push(d.id);
|
failedIds.push(d.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ const watchers = [
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '确定uploading的文件状态',
|
name: '处理长时间未完成分片上传的文件',
|
||||||
entity: 'extraFile',
|
entity: 'extraFile',
|
||||||
filter: async () => {
|
filter: async () => {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
|
@ -128,15 +128,32 @@ const watchers = [
|
||||||
successIds.push(d.id);
|
successIds.push(d.id);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// 这个文件不存在,此时去判断是否是上传完但是未合并的情况
|
// 这个文件不存在,此时去尝试合并,如果合并失败,则标记为失败
|
||||||
const { parts } = await cos.listMultipartUploads(context.getApplication(), d, context);
|
try {
|
||||||
(0, assert_1.assert)(parts);
|
if (d.chunkInfo?.merged) {
|
||||||
const isDone = parts.every(p => p.etag && p.etag.length > 0);
|
// 已经合并过了,说明是合并后删除的
|
||||||
if (isDone) {
|
failedIds.push(d.id);
|
||||||
// 标记为成功
|
continue;
|
||||||
|
}
|
||||||
|
// 去合并分片
|
||||||
|
await cos.mergeChunkedUpload(context.getApplication(), d, context);
|
||||||
|
await context.operate('extraFile', {
|
||||||
|
id: await (0, uuid_1.generateNewIdAsync)(),
|
||||||
|
action: 'update',
|
||||||
|
data: {
|
||||||
|
chunkInfo: {
|
||||||
|
...d.chunkInfo,
|
||||||
|
merged: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
filter: {
|
||||||
|
id: d.id,
|
||||||
|
},
|
||||||
|
}, {});
|
||||||
successIds.push(d.id);
|
successIds.push(d.id);
|
||||||
}
|
}
|
||||||
else {
|
catch (err) {
|
||||||
|
console.log(`分片合并失败,文件: ${d.id} 标记为上传失败: `, err);
|
||||||
failedIds.push(d.id);
|
failedIds.push(d.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ const watchers: Watcher<
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '确定uploading的文件状态',
|
name: '处理长时间未完成分片上传的文件',
|
||||||
entity: 'extraFile',
|
entity: 'extraFile',
|
||||||
filter: async () => {
|
filter: async () => {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
|
@ -148,19 +148,42 @@ const watchers: Watcher<
|
||||||
successIds.push(d.id!);
|
successIds.push(d.id!);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// 这个文件不存在,此时去判断是否是上传完但是未合并的情况
|
// 这个文件不存在,此时去尝试合并,如果合并失败,则标记为失败
|
||||||
const { parts } = await cos.listMultipartUploads(
|
try {
|
||||||
context.getApplication() as EntityDict['application']['Schema'],
|
if (d.chunkInfo?.merged) {
|
||||||
d as EntityDict['extraFile']['OpSchema'],
|
// 已经合并过了,说明是合并后删除的
|
||||||
context
|
failedIds.push(d.id!);
|
||||||
)
|
continue;
|
||||||
assert(parts);
|
}
|
||||||
const isDone = parts.every(p => p.etag && p.etag.length > 0);
|
|
||||||
if (isDone) {
|
// 去合并分片
|
||||||
// 标记为成功
|
await cos.mergeChunkedUpload(
|
||||||
|
context.getApplication() as EntityDict['application']['Schema'],
|
||||||
|
d as EntityDict['extraFile']['OpSchema'],
|
||||||
|
context
|
||||||
|
);
|
||||||
|
|
||||||
|
await context.operate(
|
||||||
|
'extraFile',
|
||||||
|
{
|
||||||
|
id: await generateNewIdAsync(),
|
||||||
|
action: 'update',
|
||||||
|
data: {
|
||||||
|
chunkInfo: {
|
||||||
|
...d.chunkInfo,
|
||||||
|
merged: true,
|
||||||
|
} as any,
|
||||||
|
},
|
||||||
|
filter: {
|
||||||
|
id: d.id!,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
|
||||||
successIds.push(d.id!);
|
successIds.push(d.id!);
|
||||||
}
|
} catch (err) {
|
||||||
else {
|
console.log(`分片合并失败,文件: ${d.id} 标记为上传失败: `, err);
|
||||||
failedIds.push(d.id!);
|
failedIds.push(d.id!);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue