From 75e1ba8e2543a8574cb30d357925497aa5c2c360 Mon Sep 17 00:00:00 2001 From: "Xc@centOs" Date: Thu, 9 Nov 2023 13:05:55 +0800 Subject: [PATCH] =?UTF-8?q?extraFile/commit=E5=A4=84=E7=90=86=E4=BA=86?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=A4=B1=E8=B4=A5=E5=90=8E=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E7=9A=84id=E4=BF=9D=E5=AD=98=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- es/checkers/userEntityGrant.js | 21 ++++++++++++--- lib/checkers/userEntityGrant.js | 21 ++++++++++++--- src/checkers/userEntityGrant.ts | 21 ++++++++++++--- src/components/extraFile/commit/index.ts | 31 +++++++++++++++++++--- src/components/extraFile/commit/web.pc.tsx | 7 ++--- src/components/extraFile/commit/web.tsx | 7 ++--- 6 files changed, 87 insertions(+), 21 deletions(-) diff --git a/es/checkers/userEntityGrant.js b/es/checkers/userEntityGrant.js index 4e88545d6..6cd4b5b58 100644 --- a/es/checkers/userEntityGrant.js +++ b/es/checkers/userEntityGrant.js @@ -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]); } } ]; diff --git a/lib/checkers/userEntityGrant.js b/lib/checkers/userEntityGrant.js index e17c56373..c63841b8a 100644 --- a/lib/checkers/userEntityGrant.js +++ b/lib/checkers/userEntityGrant.js @@ -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]); } } ]; diff --git a/src/checkers/userEntityGrant.ts b/src/checkers/userEntityGrant.ts index 8edc46559..016014eb4 100644 --- a/src/checkers/userEntityGrant.ts +++ b/src/checkers/userEntityGrant.ts @@ -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) => { - const { relationEntity } = userEntityGrant; + const dealInner = (userEntityGrant: Partial) => { + 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]); } } ]; diff --git a/src/components/extraFile/commit/index.ts b/src/components/extraFile/commit/index.ts index 9c9e8ea12..0487d0350 100644 --- a/src/components/extraFile/commit/index.ts +++ b/src/components/extraFile/commit/index.ts @@ -37,6 +37,9 @@ export default OakComponent({ | undefined | Promise, }, + data: { + failureIds: undefined as string[] | undefined, + }, methods: { getEfIds() { const entity = this.features.runningTree.getEntity( @@ -98,18 +101,38 @@ export default OakComponent({ } const promises: Promise[] = []; + 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(); } diff --git a/src/components/extraFile/commit/web.pc.tsx b/src/components/extraFile/commit/web.pc.tsx index 904a98ffb..a7552ce1c 100644 --- a/src/components/extraFile/commit/web.pc.tsx +++ b/src/components/extraFile/commit/web.pc.tsx @@ -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 }); diff --git a/src/components/extraFile/commit/web.tsx b/src/components/extraFile/commit/web.tsx index c684e96b0..45c1d2f8b 100644 --- a/src/components/extraFile/commit/web.tsx +++ b/src/components/extraFile/commit/web.tsx @@ -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 });