qiniu cos getFileStat针对线上实测修正
This commit is contained in:
parent
f7ea97cfcf
commit
0388ce6291
|
|
@ -38,17 +38,16 @@ export default OakComponent({
|
||||||
getEfIds() {
|
getEfIds() {
|
||||||
const { efPaths } = this.props;
|
const { efPaths } = this.props;
|
||||||
const { oakFullpath } = this.state;
|
const { oakFullpath } = this.state;
|
||||||
assert(efPaths);
|
assert(efPaths && efPaths.length > 0);
|
||||||
if (oakFullpath) {
|
if (oakFullpath) {
|
||||||
const ids = efPaths.map(
|
const ids = efPaths.map(
|
||||||
(path) => {
|
(path) => {
|
||||||
const path2 = path ? `${oakFullpath}.${path}` : oakFullpath;
|
const path2 = path ? `${oakFullpath}.${path}` : oakFullpath;
|
||||||
const data = this.features.runningTree.getFreshValue(path2);
|
const data = this.features.runningTree.getFreshValue(path2);
|
||||||
if (data) {
|
assert(data, `efPath为${path}的路径上取不到extraFile数据,请设置正确的相对路径`);
|
||||||
return (data as EntityDict['extraFile']['OpSchema'][]).map(
|
return (data as EntityDict['extraFile']['OpSchema'][]).map(
|
||||||
ele => ele.id
|
ele => ele.id
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
).flat().filter(
|
).flat().filter(
|
||||||
ele => !!ele
|
ele => !!ele
|
||||||
|
|
@ -59,6 +58,7 @@ export default OakComponent({
|
||||||
},
|
},
|
||||||
async upload() {
|
async upload() {
|
||||||
const ids = this.getEfIds();
|
const ids = this.getEfIds();
|
||||||
|
assert(ids.length > 0);
|
||||||
|
|
||||||
const promises: Promise<void>[] = [];
|
const promises: Promise<void>[] = [];
|
||||||
ids.forEach(
|
ids.forEach(
|
||||||
|
|
|
||||||
|
|
@ -161,7 +161,7 @@ export abstract class BackendRuntimeContext<ED extends EntityDict & BaseEntityDi
|
||||||
await this.begin();
|
await this.begin();
|
||||||
const closeRootMode = this.openRootMode();
|
const closeRootMode = this.openRootMode();
|
||||||
try {
|
try {
|
||||||
const { a: appId, t: tokenValue } = data;
|
const { a: appId, t: tokenValue, rm } = data;
|
||||||
const promises: Promise<void>[] = [];
|
const promises: Promise<void>[] = [];
|
||||||
if (appId) {
|
if (appId) {
|
||||||
promises.push(this.setApplication(appId));
|
promises.push(this.setApplication(appId));
|
||||||
|
|
@ -172,7 +172,9 @@ export abstract class BackendRuntimeContext<ED extends EntityDict & BaseEntityDi
|
||||||
if (promises.length > 0) {
|
if (promises.length > 0) {
|
||||||
await Promise.all(promises);
|
await Promise.all(promises);
|
||||||
}
|
}
|
||||||
closeRootMode();
|
if (!rm) {
|
||||||
|
closeRootMode();
|
||||||
|
}
|
||||||
await this.commit();
|
await this.commit();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
closeRootMode();
|
closeRootMode();
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import { QiniuCosConfig } from '../../types/Config';
|
||||||
import { QiniuCloudInstance } from 'oak-external-sdk';
|
import { QiniuCloudInstance } from 'oak-external-sdk';
|
||||||
import { urlSafeBase64Encode } from '../sign';
|
import { urlSafeBase64Encode } from '../sign';
|
||||||
import { OakUploadException } from '../../types/Exception';
|
import { OakUploadException } from '../../types/Exception';
|
||||||
|
import { OakExternalException } from 'oak-domain';
|
||||||
|
|
||||||
const QiniuSearchUrl = 'https://rs.qiniuapi.com/stat/EncodedEntryURI';
|
const QiniuSearchUrl = 'https://rs.qiniuapi.com/stat/EncodedEntryURI';
|
||||||
|
|
||||||
|
|
@ -120,10 +121,23 @@ export default class Qiniu implements Cos<ED, BRC, FRC> {
|
||||||
|
|
||||||
// web环境下访问不了七牛接口,用mockData过
|
// web环境下访问不了七牛接口,用mockData过
|
||||||
const mockData = process.env.OAK_PLATFORM === 'web' ? { fsize: 100 } : undefined;
|
const mockData = process.env.OAK_PLATFORM === 'web' ? { fsize: 100 } : undefined;
|
||||||
const result = await (instance as QiniuCloudInstance).getKodoFileStat(extraFile.bucket!, key, mockData);
|
|
||||||
|
|
||||||
const { fsize } = result;
|
try {
|
||||||
return fsize > 0;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ async function checkWhetherSuccess(context: BackendRuntimeContext<EntityDict>, a
|
||||||
}
|
}
|
||||||
}, {});
|
}, {});
|
||||||
}
|
}
|
||||||
else {
|
if (failedIds.length > 0) {
|
||||||
await context.operate('extraFile', {
|
await context.operate('extraFile', {
|
||||||
id: await generateNewIdAsync(),
|
id: await generateNewIdAsync(),
|
||||||
action: 'update',
|
action: 'update',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue