增加了autoInform方法

This commit is contained in:
Xu Chang 2023-10-06 12:00:21 +08:00
parent 7daedef769
commit a0b1148247
12 changed files with 60 additions and 34 deletions

View File

@ -66,16 +66,18 @@ export class ExtraFile2 extends Feature {
try {
const cos = getCos(extraFile.origin);
await cos.upload(extraFile, up.uploadFile, file);
await this.cache.exec('operate', {
entity: 'extraFile',
operation: {
id: await generateNewIdAsync(),
action: 'update',
data: {
uploadState: 'success',
if (!cos.autoInform()) {
await this.cache.exec('operate', {
entity: 'extraFile',
operation: {
id: await generateNewIdAsync(),
action: 'update',
data: {
uploadState: 'success',
},
},
},
});
});
}
item.state = 'uploaded';
item.percentage = undefined;
this.publish();

4
es/types/Cos.d.ts vendored
View File

@ -9,6 +9,10 @@ import { FrontendRuntimeContext, AspectDict } from '../context/FrontendRuntimeCo
*/
export default interface Cos<ED extends EntityDict & BaseEntityDict, Cxt extends BackendRuntimeContext<ED>, FrontCxt extends FrontendRuntimeContext<ED, Cxt, AspectDict<ED, Cxt>>> {
name: string;
/**
* extraFile的uploadState)
*/
autoInform(): boolean;
/**
* extrafile生成之前token等信息生成并存放在uploadMeta属性中
* @param extraFileextraFile数据

View File

@ -3,6 +3,7 @@ import Cos from "../../types/Cos";
import { OpSchema } from '../../oak-app-domain/ExtraFile/Schema';
export default class Qiniu implements Cos<ED, BRC, FRC> {
name: string;
autoInform(): boolean;
formUploadMeta(extraFile: OpSchema, context: BRC): Promise<void>;
upload(extraFile: OpSchema, uploadFn: (file: File | string, name: string, // 文件的part name
uploadUrl: string, // 上传的url

View File

@ -5,6 +5,9 @@ import { OakUploadException } from '../../types/Exception';
const QiniuSearchUrl = 'https://rs.qiniuapi.com/stat/EncodedEntryURI';
export default class Qiniu {
name = 'qiniu';
autoInform() {
return false;
}
async formUploadMeta(extraFile, context) {
const { origin, objectId, extension, entity, bucket } = extraFile;
// 构造文件上传所需的key

View File

@ -69,16 +69,18 @@ class ExtraFile2 extends oak_frontend_base_1.Feature {
try {
const cos = (0, cos_1.getCos)(extraFile.origin);
await cos.upload(extraFile, up.uploadFile, file);
await this.cache.exec('operate', {
entity: 'extraFile',
operation: {
id: await (0, oak_domain_1.generateNewIdAsync)(),
action: 'update',
data: {
uploadState: 'success',
if (!cos.autoInform()) {
await this.cache.exec('operate', {
entity: 'extraFile',
operation: {
id: await (0, oak_domain_1.generateNewIdAsync)(),
action: 'update',
data: {
uploadState: 'success',
},
},
},
});
});
}
item.state = 'uploaded';
item.percentage = undefined;
this.publish();

4
lib/types/Cos.d.ts vendored
View File

@ -9,6 +9,10 @@ import { FrontendRuntimeContext, AspectDict } from '../context/FrontendRuntimeCo
*/
export default interface Cos<ED extends EntityDict & BaseEntityDict, Cxt extends BackendRuntimeContext<ED>, FrontCxt extends FrontendRuntimeContext<ED, Cxt, AspectDict<ED, Cxt>>> {
name: string;
/**
* extraFile的uploadState)
*/
autoInform(): boolean;
/**
* extrafile生成之前token等信息生成并存放在uploadMeta属性中
* @param extraFileextraFile数据

View File

@ -3,6 +3,7 @@ import Cos from "../../types/Cos";
import { OpSchema } from '../../oak-app-domain/ExtraFile/Schema';
export default class Qiniu implements Cos<ED, BRC, FRC> {
name: string;
autoInform(): boolean;
formUploadMeta(extraFile: OpSchema, context: BRC): Promise<void>;
upload(extraFile: OpSchema, uploadFn: (file: File | string, name: string, // 文件的part name
uploadUrl: string, // 上传的url

View File

@ -7,6 +7,9 @@ const Exception_1 = require("../../types/Exception");
const QiniuSearchUrl = 'https://rs.qiniuapi.com/stat/EncodedEntryURI';
class Qiniu {
name = 'qiniu';
autoInform() {
return false;
}
async formUploadMeta(extraFile, context) {
const { origin, objectId, extension, entity, bucket } = extraFile;
// 构造文件上传所需的key

View File

@ -102,16 +102,18 @@ export class ExtraFile2<
up.uploadFile,
file
);
await this.cache.exec('operate', {
entity: 'extraFile',
operation: {
id: await generateNewIdAsync(),
action: 'update',
data: {
uploadState: 'success',
},
} as ED['extraFile']['Operation'],
});
if (!cos.autoInform()) {
await this.cache.exec('operate', {
entity: 'extraFile',
operation: {
id: await generateNewIdAsync(),
action: 'update',
data: {
uploadState: 'success',
},
} as ED['extraFile']['Operation'],
});
}
item.state = 'uploaded';
item.percentage = undefined;
this.publish();

View File

@ -21,11 +21,9 @@ const triggers: Trigger<EntityDict, 'extraFile', BackendRuntimeContext<EntityDic
throw new OakException(`origin为${origin}的extraFile没有定义Cos类请调用registerCos注入`);
}
await cos.formUploadMeta(data, context);
Object.assign(
data, {
Object.assign(data, {
uploadState: 'uploading',
}
)
});
}
if (data instanceof Array) {
await Promise.all(

View File

@ -14,6 +14,10 @@ export default interface Cos<
FrontCxt extends FrontendRuntimeContext<ED, Cxt, AspectDict<ED, Cxt>>> {
name: string;
/**
* extraFile的uploadState)
*/
autoInform(): boolean;
/**
* extrafile生成之前token等信息生成并存放在uploadMeta属性中
* @param extraFileextraFile数据
@ -31,7 +35,6 @@ export default interface Cos<
* @param extraFile
* @returns
*/
upload: (
extraFile: EntityDict['extraFile']['OpSchema'],
uploadFn: (
@ -44,7 +47,6 @@ export default interface Cos<
file: string | File
) => Promise<void>;
// 前端上传时对回调的处理
composeFileUrl: (
extraFile: EntityDict['extraFile']['OpSchema'],
context: FrontCxt,

View File

@ -14,6 +14,10 @@ const QiniuSearchUrl = 'https://rs.qiniuapi.com/stat/EncodedEntryURI';
export default class Qiniu implements Cos<ED, BRC, FRC> {
name = 'qiniu';
autoInform(): boolean {
return false;
}
async formUploadMeta(
extraFile: OpSchema,