qiniu cos getFileStat针对线上实测修正

This commit is contained in:
Xu Chang 2023-10-10 20:19:12 +08:00
parent f7ea97cfcf
commit 0388ce6291
4 changed files with 28 additions and 12 deletions

View File

@ -38,17 +38,16 @@ export default OakComponent({
getEfIds() {
const { efPaths } = this.props;
const { oakFullpath } = this.state;
assert(efPaths);
assert(efPaths && efPaths.length > 0);
if (oakFullpath) {
const ids = efPaths.map(
(path) => {
const path2 = path ? `${oakFullpath}.${path}` : oakFullpath;
const data = this.features.runningTree.getFreshValue(path2);
if (data) {
return (data as EntityDict['extraFile']['OpSchema'][]).map(
ele => ele.id
);
}
assert(data, `efPath为${path}的路径上取不到extraFile数据请设置正确的相对路径`);
return (data as EntityDict['extraFile']['OpSchema'][]).map(
ele => ele.id
);
}
).flat().filter(
ele => !!ele
@ -59,6 +58,7 @@ export default OakComponent({
},
async upload() {
const ids = this.getEfIds();
assert(ids.length > 0);
const promises: Promise<void>[] = [];
ids.forEach(

View File

@ -161,7 +161,7 @@ export abstract class BackendRuntimeContext<ED extends EntityDict & BaseEntityDi
await this.begin();
const closeRootMode = this.openRootMode();
try {
const { a: appId, t: tokenValue } = data;
const { a: appId, t: tokenValue, rm } = data;
const promises: Promise<void>[] = [];
if (appId) {
promises.push(this.setApplication(appId));
@ -172,7 +172,9 @@ export abstract class BackendRuntimeContext<ED extends EntityDict & BaseEntityDi
if (promises.length > 0) {
await Promise.all(promises);
}
closeRootMode();
if (!rm) {
closeRootMode();
}
await this.commit();
} catch (err) {
closeRootMode();

View File

@ -9,6 +9,7 @@ import { QiniuCosConfig } from '../../types/Config';
import { QiniuCloudInstance } from 'oak-external-sdk';
import { urlSafeBase64Encode } from '../sign';
import { OakUploadException } from '../../types/Exception';
import { OakExternalException } from 'oak-domain';
const QiniuSearchUrl = 'https://rs.qiniuapi.com/stat/EncodedEntryURI';
@ -120,10 +121,23 @@ export default class Qiniu implements Cos<ED, BRC, FRC> {
// web环境下访问不了七牛接口用mockData过
const mockData = process.env.OAK_PLATFORM === 'web' ? { fsize: 100 } : undefined;
const result = await (instance as QiniuCloudInstance).getKodoFileStat(extraFile.bucket!, key, mockData);
const { fsize } = result;
return fsize > 0;
try {
const result = await (instance as QiniuCloudInstance).getKodoFileStat(extraFile.bucket!, key, mockData);
const { fsize } = result;
return fsize > 0;
}
catch (err: any) {
// 七牛如果文件不存在会抛出status 612的异常
if (err instanceof OakExternalException) {
const data = err.data;
if (data && data.status === 612) {
return false;
}
}
throw err;
}
}

View File

@ -38,7 +38,7 @@ async function checkWhetherSuccess(context: BackendRuntimeContext<EntityDict>, a
}
}, {});
}
else {
if (failedIds.length > 0) {
await context.operate('extraFile', {
id: await generateNewIdAsync(),
action: 'update',