@ims-view/server 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # @ims-view/server
2
+
3
+ [![NPM version][version-image]][version-url] [![NPM downloads][download-image]][download-url]
4
+
5
+ ## License
6
+
7
+ [MIT](../../LICENSE) ® eternallycyf
8
+
9
+ <!-- npm url -->
10
+
11
+ [version-image]: http://img.shields.io/npm/v/@ims-view/server.svg?color=deepgreen&label=latest
12
+ [version-url]: http://npmjs.org/package/@ims-view/server
13
+ [download-image]: https://img.shields.io/npm/dm/@ims-view/server.svg
14
+ [download-url]: https://npmjs.org/package/@ims-view/server
15
+
16
+ <!-- docs url -->
17
+
18
+ - https://ims-view-pc-eternallycyfs-projects.vercel.app/server
19
+
20
+ ## 安装
21
+
22
+ ```shell
23
+ pnpm i @ims-view/server
24
+ ```
25
+
26
+ ## 独立启动
27
+
28
+ ```shell
29
+ # 全局 / npx
30
+ npx ims-view-server
31
+
32
+ # 或指定端口
33
+ IMS_SERVER_PORT=3010 npx ims-view-server
34
+ ```
35
+
36
+ 仓库内开发:
37
+
38
+ ```shell
39
+ IMS_SERVER_PORT=3010 pnpm start:server
40
+ ```
41
+
42
+ ## 嵌入 Nest 应用
43
+
44
+ ```ts
45
+ import { Module } from '@nestjs/common';
46
+ import { ExcelModule } from '@ims-view/server';
47
+
48
+ @Module({
49
+ imports: [ExcelModule],
50
+ })
51
+ export class AppModule {}
52
+ ```
53
+
54
+ ## 环境变量
55
+
56
+ | 变量 | 说明 | 默认 |
57
+ | ---- | ---- | ---- |
58
+ | `IMS_SERVER_PORT` | 服务端口(优先) | `3010` |
59
+ | `PORT` | 兼容通用端口变量 | - |
60
+
61
+ 前端对接:`IMS_EXCHANGE_ENDPOINT=http://localhost:3010`
62
+
63
+ ## API
64
+
65
+ 见文档站:
66
+
67
+ - https://ims-view-pc-eternallycyfs-projects.vercel.app/server
68
+ - https://ims-view-pc-eternallycyfs-projects.vercel.app/server/excel
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ require('../lib/main.js');
@@ -0,0 +1,2 @@
1
+ export declare class AppModule {
2
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.AppModule = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ const excel_module_1 = require("./excel/excel.module");
12
+ let AppModule = class AppModule {
13
+ };
14
+ exports.AppModule = AppModule;
15
+ exports.AppModule = AppModule = __decorate([
16
+ (0, common_1.Module)({
17
+ imports: [excel_module_1.ExcelModule],
18
+ })
19
+ ], AppModule);
20
+ //# sourceMappingURL=app.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.module.js","sourceRoot":"","sources":["../src/app.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,uDAAmD;AAK5C,IAAM,SAAS,GAAf,MAAM,SAAS;CAAG,CAAA;AAAZ,8BAAS;oBAAT,SAAS;IAHrB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,0BAAW,CAAC;KACvB,CAAC;GACW,SAAS,CAAG"}
@@ -0,0 +1,13 @@
1
+ import type { Response } from 'express';
2
+ import { ExcelService } from './excel.service';
3
+ import type { ExportExcelDto } from './types';
4
+ export declare class ExcelController {
5
+ private readonly excelService;
6
+ constructor(excelService: ExcelService);
7
+ health(): {
8
+ ok: boolean;
9
+ service: string;
10
+ };
11
+ importExcel(file: Express.Multer.File): Promise<import("@ims-view/utils").ExcelImportResult>;
12
+ exportExcel(body: ExportExcelDto, res: Response): Promise<void>;
13
+ }
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.ExcelController = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const platform_express_1 = require("@nestjs/platform-express");
18
+ const multer_1 = require("multer");
19
+ const excel_service_1 = require("./excel.service");
20
+ let ExcelController = class ExcelController {
21
+ constructor(excelService) {
22
+ this.excelService = excelService;
23
+ }
24
+ health() {
25
+ return { ok: true, service: 'excel-exchange' };
26
+ }
27
+ async importExcel(file) {
28
+ return this.excelService.importFile(file);
29
+ }
30
+ async exportExcel(body, res) {
31
+ const { buffer, fileName } = await this.excelService.exportFile(body);
32
+ res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
33
+ res.setHeader('Content-Disposition', `attachment; filename*=UTF-8''${encodeURIComponent(fileName)}`);
34
+ res.send(buffer);
35
+ }
36
+ };
37
+ exports.ExcelController = ExcelController;
38
+ __decorate([
39
+ (0, common_1.Get)('health'),
40
+ __metadata("design:type", Function),
41
+ __metadata("design:paramtypes", []),
42
+ __metadata("design:returntype", void 0)
43
+ ], ExcelController.prototype, "health", null);
44
+ __decorate([
45
+ (0, common_1.Post)('import'),
46
+ (0, common_1.UseInterceptors)((0, platform_express_1.FileInterceptor)('file', {
47
+ storage: (0, multer_1.memoryStorage)(),
48
+ limits: { fileSize: 20 * 1024 * 1024 },
49
+ })),
50
+ __param(0, (0, common_1.UploadedFile)()),
51
+ __metadata("design:type", Function),
52
+ __metadata("design:paramtypes", [Object]),
53
+ __metadata("design:returntype", Promise)
54
+ ], ExcelController.prototype, "importExcel", null);
55
+ __decorate([
56
+ (0, common_1.Post)('export'),
57
+ __param(0, (0, common_1.Body)()),
58
+ __param(1, (0, common_1.Res)()),
59
+ __metadata("design:type", Function),
60
+ __metadata("design:paramtypes", [Object, Object]),
61
+ __metadata("design:returntype", Promise)
62
+ ], ExcelController.prototype, "exportExcel", null);
63
+ exports.ExcelController = ExcelController = __decorate([
64
+ (0, common_1.Controller)('excel'),
65
+ __metadata("design:paramtypes", [excel_service_1.ExcelService])
66
+ ], ExcelController);
67
+ //# sourceMappingURL=excel.controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"excel.controller.js","sourceRoot":"","sources":["../../src/excel/excel.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAQwB;AACxB,+DAA2D;AAE3D,mCAAuC;AACvC,mDAA+C;AAKxC,IAAM,eAAe,GAArB,MAAM,eAAe;IAC1B,YAA6B,YAA0B;QAA1B,iBAAY,GAAZ,YAAY,CAAc;IAAG,CAAC;IAG3D,MAAM;QACJ,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,gBAAgB,EAAE,CAAC;IACjD,CAAC;IASK,AAAN,KAAK,CAAC,WAAW,CAAiB,IAAyB;QACzD,OAAO,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAC5C,CAAC;IAGK,AAAN,KAAK,CAAC,WAAW,CAAS,IAAoB,EAAS,GAAa;QAClE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAEtE,GAAG,CAAC,SAAS,CACX,cAAc,EACd,mEAAmE,CACpE,CAAC;QACF,GAAG,CAAC,SAAS,CACX,qBAAqB,EACrB,gCAAgC,kBAAkB,CAAC,QAAQ,CAAC,EAAE,CAC/D,CAAC;QACF,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACnB,CAAC;CACF,CAAA;AAjCY,0CAAe;AAI1B;IADC,IAAA,YAAG,EAAC,QAAQ,CAAC;;;;6CAGb;AASK;IAPL,IAAA,aAAI,EAAC,QAAQ,CAAC;IACd,IAAA,wBAAe,EACd,IAAA,kCAAe,EAAC,MAAM,EAAE;QACtB,OAAO,EAAE,IAAA,sBAAa,GAAE;QACxB,MAAM,EAAE,EAAE,QAAQ,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI,EAAE;KACvC,CAAC,CACH;IACkB,WAAA,IAAA,qBAAY,GAAE,CAAA;;;;kDAEhC;AAGK;IADL,IAAA,aAAI,EAAC,QAAQ,CAAC;IACI,WAAA,IAAA,aAAI,GAAE,CAAA;IAAwB,WAAA,IAAA,YAAG,GAAE,CAAA;;;;kDAYrD;0BAhCU,eAAe;IAD3B,IAAA,mBAAU,EAAC,OAAO,CAAC;qCAEyB,4BAAY;GAD5C,eAAe,CAiC3B"}
@@ -0,0 +1,2 @@
1
+ export type { ExcelImportResult, ExcelSheetImage, ICellData, IRange, IWorkbookData, IWorksheetData, } from '@ims-view/utils';
2
+ export { CellValueType, ensureXlsxBytes, excelBufferToImportResult, excelBufferToWorkbookData, workbookDataToExcelBuffer, workbookDataToExcelBytes, } from '@ims-view/utils';
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.workbookDataToExcelBytes = exports.workbookDataToExcelBuffer = exports.excelBufferToWorkbookData = exports.excelBufferToImportResult = exports.ensureXlsxBytes = exports.CellValueType = void 0;
4
+ var utils_1 = require("@ims-view/utils");
5
+ Object.defineProperty(exports, "CellValueType", { enumerable: true, get: function () { return utils_1.CellValueType; } });
6
+ Object.defineProperty(exports, "ensureXlsxBytes", { enumerable: true, get: function () { return utils_1.ensureXlsxBytes; } });
7
+ Object.defineProperty(exports, "excelBufferToImportResult", { enumerable: true, get: function () { return utils_1.excelBufferToImportResult; } });
8
+ Object.defineProperty(exports, "excelBufferToWorkbookData", { enumerable: true, get: function () { return utils_1.excelBufferToWorkbookData; } });
9
+ Object.defineProperty(exports, "workbookDataToExcelBuffer", { enumerable: true, get: function () { return utils_1.workbookDataToExcelBuffer; } });
10
+ Object.defineProperty(exports, "workbookDataToExcelBytes", { enumerable: true, get: function () { return utils_1.workbookDataToExcelBytes; } });
11
+ //# sourceMappingURL=excel.converter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"excel.converter.js","sourceRoot":"","sources":["../../src/excel/excel.converter.ts"],"names":[],"mappings":";;;AAWA,yCAOyB;AANvB,sGAAA,aAAa,OAAA;AACb,wGAAA,eAAe,OAAA;AACf,kHAAA,yBAAyB,OAAA;AACzB,kHAAA,yBAAyB,OAAA;AACzB,kHAAA,yBAAyB,OAAA;AACzB,iHAAA,wBAAwB,OAAA"}
@@ -0,0 +1,2 @@
1
+ export declare class ExcelModule {
2
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.ExcelModule = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ const excel_controller_1 = require("./excel.controller");
12
+ const excel_service_1 = require("./excel.service");
13
+ let ExcelModule = class ExcelModule {
14
+ };
15
+ exports.ExcelModule = ExcelModule;
16
+ exports.ExcelModule = ExcelModule = __decorate([
17
+ (0, common_1.Module)({
18
+ controllers: [excel_controller_1.ExcelController],
19
+ providers: [excel_service_1.ExcelService],
20
+ exports: [excel_service_1.ExcelService],
21
+ })
22
+ ], ExcelModule);
23
+ //# sourceMappingURL=excel.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"excel.module.js","sourceRoot":"","sources":["../../src/excel/excel.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,yDAAqD;AACrD,mDAA+C;AAOxC,IAAM,WAAW,GAAjB,MAAM,WAAW;CAAG,CAAA;AAAd,kCAAW;sBAAX,WAAW;IALvB,IAAA,eAAM,EAAC;QACN,WAAW,EAAE,CAAC,kCAAe,CAAC;QAC9B,SAAS,EAAE,CAAC,4BAAY,CAAC;QACzB,OAAO,EAAE,CAAC,4BAAY,CAAC;KACxB,CAAC;GACW,WAAW,CAAG"}
@@ -0,0 +1,9 @@
1
+ import type { ExcelImportResult } from './excel.converter';
2
+ import type { ExportExcelDto } from './types';
3
+ export declare class ExcelService {
4
+ importFile(file?: Express.Multer.File): Promise<ExcelImportResult>;
5
+ exportFile(body: ExportExcelDto): Promise<{
6
+ buffer: Buffer;
7
+ fileName: string;
8
+ }>;
9
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.ExcelService = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ const excel_converter_1 = require("./excel.converter");
12
+ let ExcelService = class ExcelService {
13
+ async importFile(file) {
14
+ if (!file?.buffer?.length) {
15
+ throw new common_1.BadRequestException('请上传 Excel 文件(.xlsx / .xls)');
16
+ }
17
+ return (0, excel_converter_1.excelBufferToImportResult)(file.buffer, file.originalname);
18
+ }
19
+ async exportFile(body) {
20
+ if (!body?.data) {
21
+ throw new common_1.BadRequestException('缺少工作簿数据 data');
22
+ }
23
+ const buffer = await (0, excel_converter_1.workbookDataToExcelBuffer)(body.data);
24
+ const rawName = body.fileName?.trim() || body.data.name || 'workbook';
25
+ const fileName = rawName.endsWith('.xlsx') ? rawName : `${rawName}.xlsx`;
26
+ return { buffer, fileName };
27
+ }
28
+ };
29
+ exports.ExcelService = ExcelService;
30
+ exports.ExcelService = ExcelService = __decorate([
31
+ (0, common_1.Injectable)()
32
+ ], ExcelService);
33
+ //# sourceMappingURL=excel.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"excel.service.js","sourceRoot":"","sources":["../../src/excel/excel.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAiE;AACjE,uDAG2B;AAKpB,IAAM,YAAY,GAAlB,MAAM,YAAY;IACvB,KAAK,CAAC,UAAU,CAAC,IAA0B;QACzC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;YAC1B,MAAM,IAAI,4BAAmB,CAAC,4BAA4B,CAAC,CAAC;QAC9D,CAAC;QAED,OAAO,IAAA,2CAAyB,EAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IACnE,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,IAAoB;QACnC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC;YAChB,MAAM,IAAI,4BAAmB,CAAC,cAAc,CAAC,CAAC;QAChD,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,IAAA,2CAAyB,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1D,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,UAAU,CAAC;QACtE,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,OAAO,CAAC;QAEzE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;IAC9B,CAAC;CACF,CAAA;AApBY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,mBAAU,GAAE;GACA,YAAY,CAoBxB"}
@@ -0,0 +1,6 @@
1
+ export type { ICellData, IRange, IWorkbookData, IWorksheetData, } from '@ims-view/utils';
2
+ export { CellValueType } from '@ims-view/utils';
3
+ export interface ExportExcelDto {
4
+ data: Partial<import('@ims-view/utils').IWorkbookData>;
5
+ fileName?: string;
6
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CellValueType = void 0;
4
+ var utils_1 = require("@ims-view/utils");
5
+ Object.defineProperty(exports, "CellValueType", { enumerable: true, get: function () { return utils_1.CellValueType; } });
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/excel/types.ts"],"names":[],"mappings":";;;AAMA,yCAAgD;AAAvC,sGAAA,aAAa,OAAA"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export { AppModule } from './app.module';
2
+ export { ExcelController } from './excel/excel.controller';
3
+ export { ExcelModule } from './excel/excel.module';
4
+ export { ExcelService } from './excel/excel.service';
5
+ export type { ExportExcelDto } from './excel/types';
6
+ export type { ICellData, IRange, IWorkbookData, IWorksheetData, } from './excel/types';
7
+ export { CellValueType } from './excel/types';
package/lib/index.js ADDED
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CellValueType = exports.ExcelService = exports.ExcelModule = exports.ExcelController = exports.AppModule = void 0;
4
+ var app_module_1 = require("./app.module");
5
+ Object.defineProperty(exports, "AppModule", { enumerable: true, get: function () { return app_module_1.AppModule; } });
6
+ var excel_controller_1 = require("./excel/excel.controller");
7
+ Object.defineProperty(exports, "ExcelController", { enumerable: true, get: function () { return excel_controller_1.ExcelController; } });
8
+ var excel_module_1 = require("./excel/excel.module");
9
+ Object.defineProperty(exports, "ExcelModule", { enumerable: true, get: function () { return excel_module_1.ExcelModule; } });
10
+ var excel_service_1 = require("./excel/excel.service");
11
+ Object.defineProperty(exports, "ExcelService", { enumerable: true, get: function () { return excel_service_1.ExcelService; } });
12
+ var types_1 = require("./excel/types");
13
+ Object.defineProperty(exports, "CellValueType", { enumerable: true, get: function () { return types_1.CellValueType; } });
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAIA,2CAAyC;AAAhC,uGAAA,SAAS,OAAA;AAClB,6DAA2D;AAAlD,mHAAA,eAAe,OAAA;AACxB,qDAAmD;AAA1C,2GAAA,WAAW,OAAA;AACpB,uDAAqD;AAA5C,6GAAA,YAAY,OAAA;AAQrB,uCAA8C;AAArC,sGAAA,aAAa,OAAA"}
package/lib/main.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/lib/main.js ADDED
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const core_1 = require("@nestjs/core");
37
+ const app_module_1 = require("./app.module");
38
+ const net = __importStar(require("net"));
39
+ const getPreferredPort = () => Number(process.env.IMS_SERVER_PORT || process.env.PORT || 3010);
40
+ const isPortFree = (port) => new Promise((resolve) => {
41
+ const server = net.createServer();
42
+ server.unref();
43
+ server.once('error', () => resolve(false));
44
+ server.once('listening', () => {
45
+ server.close(() => resolve(true));
46
+ });
47
+ server.listen(port, '0.0.0.0');
48
+ });
49
+ const findAvailablePort = async (preferred, maxTry = 20) => {
50
+ for (let i = 0; i < maxTry; i += 1) {
51
+ const port = preferred + i;
52
+ if (await isPortFree(port)) {
53
+ return port;
54
+ }
55
+ }
56
+ throw new Error(`端口 ${preferred}~${preferred + maxTry - 1} 均被占用,请释放后重试`);
57
+ };
58
+ async function bootstrap() {
59
+ const preferred = getPreferredPort();
60
+ const port = await findAvailablePort(preferred);
61
+ if (port !== preferred) {
62
+ console.warn(`[@ims-view/server] 端口 ${preferred} 已被占用,自动切换到 ${port}。请设置 IMS_EXCHANGE_ENDPOINT=http://localhost:${port}`);
63
+ }
64
+ const app = await core_1.NestFactory.create(app_module_1.AppModule);
65
+ app.enableCors({
66
+ origin: true,
67
+ credentials: true,
68
+ });
69
+ await app.listen(port);
70
+ console.log(`[@ims-view/server] listening on http://localhost:${port}`);
71
+ console.log(`[@ims-view/server] 前端可通过 IMS_EXCHANGE_ENDPOINT=http://localhost:${port} 对接`);
72
+ }
73
+ bootstrap().catch((error) => {
74
+ console.error('[@ims-view/server] 启动失败:', error);
75
+ process.exit(1);
76
+ });
77
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAA2C;AAC3C,6CAAyC;AACzC,yCAA2B;AAE3B,MAAM,gBAAgB,GAAG,GAAG,EAAE,CAC5B,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC;AAElE,MAAM,UAAU,GAAG,CAAC,IAAY,EAAoB,EAAE,CACpD,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;IACtB,MAAM,MAAM,GAAG,GAAG,CAAC,YAAY,EAAE,CAAC;IAClC,MAAM,CAAC,KAAK,EAAE,CAAC;IACf,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3C,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,EAAE;QAC5B,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;AACjC,CAAC,CAAC,CAAC;AAEL,MAAM,iBAAiB,GAAG,KAAK,EAAE,SAAiB,EAAE,MAAM,GAAG,EAAE,EAAmB,EAAE;IAClF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,GAAG,SAAS,GAAG,CAAC,CAAC;QAE3B,IAAI,MAAM,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YAC3B,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,MAAM,SAAS,IAAI,SAAS,GAAG,MAAM,GAAG,CAAC,cAAc,CAAC,CAAC;AAC3E,CAAC,CAAC;AAEF,KAAK,UAAU,SAAS;IACtB,MAAM,SAAS,GAAG,gBAAgB,EAAE,CAAC;IACrC,MAAM,IAAI,GAAG,MAAM,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAEhD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QAEvB,OAAO,CAAC,IAAI,CACV,yBAAyB,SAAS,eAAe,IAAI,+CAA+C,IAAI,EAAE,CAC3G,CAAC;IACJ,CAAC;IAED,MAAM,GAAG,GAAG,MAAM,kBAAW,CAAC,MAAM,CAAC,sBAAS,CAAC,CAAC;IAChD,GAAG,CAAC,UAAU,CAAC;QACb,MAAM,EAAE,IAAI;QACZ,WAAW,EAAE,IAAI;KAClB,CAAC,CAAC;IAEH,MAAM,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAEvB,OAAO,CAAC,GAAG,CAAC,oDAAoD,IAAI,EAAE,CAAC,CAAC;IAExE,OAAO,CAAC,GAAG,CACT,mEAAmE,IAAI,KAAK,CAC7E,CAAC;AACJ,CAAC;AAED,SAAS,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IAE1B,OAAO,CAAC,KAAK,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAC;IACjD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@ims-view/server",
3
+ "version": "1.0.0",
4
+ "description": "NestJS Excel import/export service for ExcelEditor (xlsx ↔ IWorkbookData)",
5
+ "license": "MIT",
6
+ "author": "eternallycyf(969475322@qq.com)",
7
+ "homepage": "https://github.com/eternallycyf/ims-view-pc#readme",
8
+ "bugs": {
9
+ "url": "https://github.com/eternallycyf/ims-view-pc/issues"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/eternallycyf/ims-view-pc.git",
14
+ "directory": "packages/server"
15
+ },
16
+ "main": "lib/index.js",
17
+ "types": "lib/index.d.ts",
18
+ "bin": {
19
+ "ims-view-server": "./bin/ims-view-server.js"
20
+ },
21
+ "files": [
22
+ "lib",
23
+ "bin",
24
+ "README.md"
25
+ ],
26
+ "scripts": {
27
+ "start": "nest start",
28
+ "start:dev": "nest start --watch",
29
+ "build": "nest build",
30
+ "clean": "rm -rf lib dist",
31
+ "doctor": "node -e \"require('fs').accessSync('src/index.ts'); console.log('[@ims-view/server] doctor ok')\"",
32
+ "prepublishOnly": "npm run build"
33
+ },
34
+ "dependencies": {
35
+ "@ims-view/utils": "1.22.0",
36
+ "@nestjs/common": "^11.0.0",
37
+ "@nestjs/core": "^11.0.0",
38
+ "@nestjs/platform-express": "^11.0.0",
39
+ "multer": "^1.4.5-lts.2",
40
+ "reflect-metadata": "^0.2.2",
41
+ "rxjs": "^7.8.2"
42
+ },
43
+ "devDependencies": {
44
+ "@nestjs/cli": "^11.0.0",
45
+ "@nestjs/schematics": "^11.0.0",
46
+ "@types/express": "^5.0.0",
47
+ "@types/multer": "^1.4.12",
48
+ "@types/node": "^22.0.0",
49
+ "typescript": "^5.4.5"
50
+ },
51
+ "publishConfig": {
52
+ "access": "public",
53
+ "registry": "https://registry.npmjs.org"
54
+ },
55
+ "engines": {
56
+ "node": ">=18"
57
+ },
58
+ "keywords": [
59
+ "nestjs",
60
+ "excel",
61
+ "xlsx",
62
+ "univer",
63
+ "ims-view"
64
+ ]
65
+ }