diff --git a/apps/nestjs-backend/src/features/import/open-api/import.class.ts b/apps/nestjs-backend/src/features/import/open-api/import.class.ts index 2169f5877..7e038875f 100644 --- a/apps/nestjs-backend/src/features/import/open-api/import.class.ts +++ b/apps/nestjs-backend/src/features/import/open-api/import.class.ts @@ -2,7 +2,7 @@ import { BadRequestException } from '@nestjs/common'; import { getUniqName, FieldType } from '@teable/core'; import type { IValidateTypes, IAnalyzeVo } from '@teable/openapi'; import { SUPPORTEDTYPE, importTypeMap } from '@teable/openapi'; -import { zip, toString, intersection } from 'lodash'; +import { zip, toString, intersection, chunk as chunkArray } from 'lodash'; import fetch from 'node-fetch'; import sizeof from 'object-sizeof'; import Papa from 'papaparse'; @@ -317,10 +317,20 @@ export class ExcelImporter extends Importer { if (options && chunk) { const { skipFirstNLines, key } = options; - if (skipFirstNLines) { - parseResult[key].splice(0, 1); + + const parseResults = chunkArray(parseResult[key], Importer.MAX_CHUNK_LENGTH); + + for (let i = 0; i < parseResults.length; i++) { + const currentChunk = parseResults[i]; + if (i === 0 && skipFirstNLines) { + currentChunk.splice(0, 1); + } + try { + await chunk({ [key]: currentChunk }); + } catch (e) { + onError?.((e as Error)?.message || Importer.DEFAULT_ERROR_MESSAGE); + } } - await chunk(parseResult); onFinished?.(); } diff --git a/apps/nestjs-backend/src/features/table/open-api/table-open-api.service.ts b/apps/nestjs-backend/src/features/table/open-api/table-open-api.service.ts index 3d588a5e7..f1a290136 100644 --- a/apps/nestjs-backend/src/features/table/open-api/table-open-api.service.ts +++ b/apps/nestjs-backend/src/features/table/open-api/table-open-api.service.ts @@ -30,6 +30,7 @@ import type { ITableVo, IUpdateOrderRo, } from '@teable/openapi'; +import { nanoid } from 'nanoid'; import { ThresholdConfig, IThresholdConfig } from '../../../configs/threshold.config'; import { InjectDbProvider } from '../../../db-provider/db.provider'; import { IDbProvider } from '../../../db-provider/db.provider.interface'; @@ -117,7 +118,22 @@ export class TableOpenApiService { ) ); } - return fields; + + const repeatedDbFieldNames = fields + .map((f) => f.dbFieldName) + .filter((value, index, self) => self.indexOf(value) !== index); + + // generator dbFieldName may repeat, this is fix it. + return fields.map((f) => { + const newField = { ...f }; + const { dbFieldName } = newField; + + if (repeatedDbFieldNames.includes(dbFieldName)) { + newField.dbFieldName = `${dbFieldName}_${nanoid(3)}`; + } + + return newField; + }); } async createTable(baseId: string, tableRo: ICreateTableWithDefault): Promise {