增加了autoInform方法
This commit is contained in:
parent
7daedef769
commit
a0b1148247
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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 extraFile,要生成的extraFile数据
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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 extraFile,要生成的extraFile数据
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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 extraFile,要生成的extraFile数据
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue