extraFile/commit处理了上传失败后重复上传的id保存问题

This commit is contained in:
Xu Chang 2023-11-09 13:05:55 +08:00
parent a1a06441b5
commit 75e1ba8e25
6 changed files with 87 additions and 21 deletions

View File

@ -21,6 +21,14 @@ const checkers = [
}
},
},
{
type: 'row',
entity: 'userEntityGrant',
action: 'claim',
filter: {
expired: false,
},
},
{
type: 'logical',
entity: 'userEntityGrant',
@ -35,11 +43,16 @@ const checkers = [
data: {
id: 1,
relationEntity: 1,
multiple: 1,
},
filter,
}, option);
const createUserRelations = (userEntityGrant) => {
const { relationEntity } = userEntityGrant;
const dealInner = (userEntityGrant) => {
const { relationEntity, multiple } = userEntityGrant;
if (!multiple) {
userEntityGrant.expired = true;
userEntityGrant.expiresAt = Date.now();
}
userEntityClaim$ueg.forEach((uec) => {
const { action, data } = uec;
assert(action === 'create');
@ -61,9 +74,9 @@ const checkers = [
return userEntityClaim$ueg.length;
};
if (result instanceof Promise) {
return result.then(([ueg]) => createUserRelations(ueg));
return result.then(([ueg]) => dealInner(ueg));
}
return createUserRelations(result[0]);
return dealInner(result[0]);
}
}
];

View File

@ -24,6 +24,14 @@ const checkers = [
}
},
},
{
type: 'row',
entity: 'userEntityGrant',
action: 'claim',
filter: {
expired: false,
},
},
{
type: 'logical',
entity: 'userEntityGrant',
@ -38,11 +46,16 @@ const checkers = [
data: {
id: 1,
relationEntity: 1,
multiple: 1,
},
filter,
}, option);
const createUserRelations = (userEntityGrant) => {
const { relationEntity } = userEntityGrant;
const dealInner = (userEntityGrant) => {
const { relationEntity, multiple } = userEntityGrant;
if (!multiple) {
userEntityGrant.expired = true;
userEntityGrant.expiresAt = Date.now();
}
userEntityClaim$ueg.forEach((uec) => {
const { action, data } = uec;
(0, assert_1.default)(action === 'create');
@ -64,9 +77,9 @@ const checkers = [
return userEntityClaim$ueg.length;
};
if (result instanceof Promise) {
return result.then(([ueg]) => createUserRelations(ueg));
return result.then(([ueg]) => dealInner(ueg));
}
return createUserRelations(result[0]);
return dealInner(result[0]);
}
}
];

View File

@ -38,6 +38,14 @@ const checkers: Checker<
}
},
},
{
type: 'row',
entity: 'userEntityGrant',
action: 'claim',
filter: {
expired: false,
},
},
{
type: 'logical',
entity:'userEntityGrant',
@ -53,11 +61,16 @@ const checkers: Checker<
data: {
id: 1,
relationEntity: 1,
multiple: 1,
},
filter,
}, option);
const createUserRelations = (userEntityGrant: Partial<EntityDict['userEntityGrant']['OpSchema']>) => {
const { relationEntity } = userEntityGrant;
const dealInner = (userEntityGrant: Partial<EntityDict['userEntityGrant']['OpSchema']>) => {
const { relationEntity, multiple } = userEntityGrant;
if (!multiple) {
userEntityGrant.expired = true;
userEntityGrant.expiresAt = Date.now();
}
userEntityClaim$ueg.forEach(
(uec) => {
const { action, data } = uec as EntityDict['userEntityClaim']['CreateSingle'];
@ -83,10 +96,10 @@ const checkers: Checker<
}
if (result instanceof Promise) {
return result.then(
([ueg]) => createUserRelations(ueg)
([ueg]) => dealInner(ueg)
);
}
return createUserRelations(result[0]);
return dealInner(result[0]);
}
}
];

View File

@ -37,6 +37,9 @@ export default OakComponent({
| undefined
| Promise<boolean | undefined>,
},
data: {
failureIds: undefined as string[] | undefined,
},
methods: {
getEfIds() {
const entity = this.features.runningTree.getEntity(
@ -98,18 +101,38 @@ export default OakComponent({
}
const promises: Promise<void>[] = [];
const failureIds = [] as string[];
ids.forEach((id) => {
const fileState = this.features.extraFile.getFileState(id);
if (fileState) {
const { state } = fileState;
if (['local', 'failed'].includes(state)) {
promises.push(this.features.extraFile.upload(id));
promises.push(
(async () => {
try {
await this.features.extraFile.upload(id);
}
catch (err) {
failureIds.push(id);
}
})()
);
}
}
});
if (promises.length > 0) {
if (promises.length > 0) {
await Promise.all(promises);
if (failureIds.length > 0) {
this.setState({
failureIds,
});
}
else {
this.setState({
failureIds: undefined,
});
}
}
},
async onSubmit() {
@ -131,7 +154,9 @@ export default OakComponent({
afterCommit();
}
} else {
await this.upload(ids);
const { failureIds } = this.state;
assert(failureIds && failureIds.length > 0);
await this.upload(failureIds);
if (afterCommit) {
afterCommit();
}

View File

@ -16,6 +16,7 @@ export default function render(
type?: ButtonProps['type'];
executeText?: string;
action?: string;
failureIds?: string[];
buttonProps?: ButtonProps;
},
{
@ -30,15 +31,15 @@ export default function render(
size,
block,
type,
failureIds,
executeText,
buttonProps = {},
} = props.data;
const { t, onSubmit } = props.methods;
const disabled =
oakExecuting ||
const disabled = (oakExecuting ||
['uploading'].includes(state) ||
(oakExecutable !== true && ['uploaded'].includes(state));
(oakExecutable !== true && ['uploaded'].includes(state))) && !failureIds;
let text = executeText || t('common::submit');
if (oakExecuting) {
text = t('executing', { text });

View File

@ -16,6 +16,7 @@ export default function render(
type?: ButtonProps['type'];
executeText?: string;
action?: string;
failureIds?: string[];
buttonProps?: ButtonProps;
},
{
@ -32,14 +33,14 @@ export default function render(
block,
type,
executeText,
failureIds,
buttonProps,
} = props.data;
const { t, onSubmit } = props.methods;
const disabled =
oakExecuting ||
const disabled = (oakExecuting ||
['uploading'].includes(state) ||
(oakExecutable === false && ['uploaded'].includes(state));
(oakExecutable !== true && ['uploaded'].includes(state))) && !failureIds;
let text = executeText || t('common:submit');
if (oakExecuting) {
text = t('executing', { text });