importENTITY错误说明改为buffer格式
This commit is contained in:
parent
97e95a796f
commit
4348b641b0
|
|
@ -42,7 +42,7 @@ export declare type CommonAspectDict<ED extends EntityDict & BaseEntityDict, Cxt
|
||||||
namespace: string | string[];
|
namespace: string | string[];
|
||||||
locale: string;
|
locale: string;
|
||||||
}) => Promise<any>;
|
}) => Promise<any>;
|
||||||
importEntity: (params: FormData, context: Cxt) => Promise<void | NodeJS.ReadableStream>;
|
importEntity: (params: FormData, context: Cxt) => Promise<void | ArrayBuffer>;
|
||||||
exportEntity: <T extends keyof ED>(params: {
|
exportEntity: <T extends keyof ED>(params: {
|
||||||
entity: T;
|
entity: T;
|
||||||
id: string;
|
id: string;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { Importation, Exportation } from 'oak-domain/lib/types/Port';
|
||||||
import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore';
|
import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore';
|
||||||
export declare function registerPorts<ED extends EntityDict>(importations: Importation<ED, keyof ED, any>[], exportations: Exportation<ED, keyof ED, any>[]): void;
|
export declare function registerPorts<ED extends EntityDict>(importations: Importation<ED, keyof ED, any>[], exportations: Exportation<ED, keyof ED, any>[]): void;
|
||||||
export declare function clearPorts(): void;
|
export declare function clearPorts(): void;
|
||||||
export declare function importEntity<ED extends EntityDict, Cxt extends AsyncContext<ED>>(params: FormData, context: Cxt): Promise<NodeJS.ReadableStream | void>;
|
export declare function importEntity<ED extends EntityDict, Cxt extends AsyncContext<ED>>(params: FormData, context: Cxt): Promise<ArrayBuffer | void>;
|
||||||
export declare function exportEntity<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>>(params: {
|
export declare function exportEntity<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>>(params: {
|
||||||
entity: T;
|
entity: T;
|
||||||
id: string;
|
id: string;
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ async function importEntity(params, context) {
|
||||||
for (const sheetData of errorSheets) {
|
for (const sheetData of errorSheets) {
|
||||||
xlsx_1.utils.book_append_sheet(errorWorkbook, sheetData.worksheet, sheetData.sheetName);
|
xlsx_1.utils.book_append_sheet(errorWorkbook, sheetData.worksheet, sheetData.sheetName);
|
||||||
}
|
}
|
||||||
return await (0, xlsx_1.write)(errorWorkbook, { type: 'file' });
|
return await (0, xlsx_1.write)(errorWorkbook, { type: 'buffer' });
|
||||||
}
|
}
|
||||||
// throw new Error('not implement yet');
|
// throw new Error('not implement yet');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ export type CommonAspectDict<ED extends EntityDict & BaseEntityDict, Cxt extends
|
||||||
namespace: string | string[];
|
namespace: string | string[];
|
||||||
locale: string;
|
locale: string;
|
||||||
}) => Promise<any>;
|
}) => Promise<any>;
|
||||||
importEntity: (params: FormData, context: Cxt) => Promise<void | NodeJS.ReadableStream>;
|
importEntity: (params: FormData, context: Cxt) => Promise<void | ArrayBuffer>;
|
||||||
exportEntity: <T extends keyof ED>(params: {
|
exportEntity: <T extends keyof ED>(params: {
|
||||||
entity: T;
|
entity: T;
|
||||||
id: string;
|
id: string;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import { Importation, Exportation } from 'oak-domain/lib/types/Port';
|
||||||
import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore';
|
import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore';
|
||||||
import { read, utils, write } from 'xlsx';
|
import { read, utils, write } from 'xlsx';
|
||||||
import { buffer } from 'stream/consumers';
|
import { buffer } from 'stream/consumers';
|
||||||
|
import { Duplex } from 'stream';
|
||||||
const Importations: Record<string, any> = {};
|
const Importations: Record<string, any> = {};
|
||||||
const Exportations: Record<string, any> = {};
|
const Exportations: Record<string, any> = {};
|
||||||
|
|
||||||
|
|
@ -46,7 +47,7 @@ function getExportation<ED extends EntityDict, T extends keyof ED>(id: string) {
|
||||||
export async function importEntity<
|
export async function importEntity<
|
||||||
ED extends EntityDict,
|
ED extends EntityDict,
|
||||||
Cxt extends AsyncContext<ED>
|
Cxt extends AsyncContext<ED>
|
||||||
>(params: FormData, context: Cxt): Promise<NodeJS.ReadableStream | void> {
|
>(params: FormData, context: Cxt): Promise<ArrayBuffer | void> {
|
||||||
const entity = params.get('entity') as keyof ED;
|
const entity = params.get('entity') as keyof ED;
|
||||||
const file = params.get('file') as File;
|
const file = params.get('file') as File;
|
||||||
const id = params.get('id') as string;
|
const id = params.get('id') as string;
|
||||||
|
|
@ -57,6 +58,7 @@ export async function importEntity<
|
||||||
const workbook = read(arrayBuffer);
|
const workbook = read(arrayBuffer);
|
||||||
const { SheetNames, Sheets } = workbook;
|
const { SheetNames, Sheets } = workbook;
|
||||||
const errorSheets = [];
|
const errorSheets = [];
|
||||||
|
|
||||||
for (const sheetName of SheetNames) {
|
for (const sheetName of SheetNames) {
|
||||||
const sheet = Sheets[sheetName];
|
const sheet = Sheets[sheetName];
|
||||||
const dataList = utils.sheet_to_json(
|
const dataList = utils.sheet_to_json(
|
||||||
|
|
@ -77,7 +79,7 @@ export async function importEntity<
|
||||||
for (const sheetData of errorSheets) {
|
for (const sheetData of errorSheets) {
|
||||||
utils.book_append_sheet(errorWorkbook, sheetData.worksheet, sheetData.sheetName);
|
utils.book_append_sheet(errorWorkbook, sheetData.worksheet, sheetData.sheetName);
|
||||||
}
|
}
|
||||||
return await write(errorWorkbook, { type: 'file' });
|
return await write(errorWorkbook, { type: 'buffer' });
|
||||||
}
|
}
|
||||||
// throw new Error('not implement yet');
|
// throw new Error('not implement yet');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue