pg-mvc-service 2.1.1 → 2.1.2
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/dist/Service.d.ts +0 -3
- package/dist/Service.d.ts.map +1 -1
- package/dist/Service.js +0 -8
- package/dist/clients/AwsS3Client.d.ts +0 -1
- package/dist/clients/AwsS3Client.d.ts.map +1 -1
- package/dist/clients/AwsS3Client.js +13 -28
- package/dist/cron/BaseCron.d.ts +0 -3
- package/dist/cron/BaseCron.d.ts.map +1 -1
- package/dist/cron/BaseCron.js +0 -7
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/package.json +1 -2
- package/dist/clients/Base64Client.d.ts +0 -31
- package/dist/clients/Base64Client.d.ts.map +0 -1
- package/dist/clients/Base64Client.js +0 -292
package/dist/Service.d.ts
CHANGED
|
@@ -5,7 +5,6 @@ import { Pool, type PoolClient } from 'pg';
|
|
|
5
5
|
import { RequestType } from './reqestResponse/RequestType';
|
|
6
6
|
import { ResponseType } from './reqestResponse/ResponseType';
|
|
7
7
|
import { AwsS3Client } from './clients/AwsS3Client';
|
|
8
|
-
import { Base64Client } from './clients/Base64Client';
|
|
9
8
|
import { StringClient } from './clients/StringClient';
|
|
10
9
|
import { EncryptClient } from './clients/EncryptClient';
|
|
11
10
|
type TStatusCode = 200 | 201 | 400 | 401 | 403 | 404 | 409 | 422 | 500 | 503;
|
|
@@ -66,8 +65,6 @@ export declare class Service {
|
|
|
66
65
|
release(): Promise<void>;
|
|
67
66
|
private s3Client?;
|
|
68
67
|
get S3Client(): AwsS3Client;
|
|
69
|
-
private base64Client?;
|
|
70
|
-
get Base64Client(): Base64Client;
|
|
71
68
|
private stringClient?;
|
|
72
69
|
get StringClient(): StringClient;
|
|
73
70
|
private encryptClient?;
|
package/dist/Service.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Service.d.ts","sourceRoot":"","sources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I,CAAC;IAOzB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAOrC,OAAO,CAAC,QAAQ,CAAC,CAAc;IAC/B,IAAI,QAAQ,IAAI,WAAW,CAU1B;IAED,OAAO,CAAC,YAAY,CAAC,CAAgB;IACrC,IAAI,YAAY,IAAI,YAAY,CAK/B;IAED,OAAO,CAAC,aAAa,CAAC,CAAgB;IACtC,IAAI,aAAa,IAAI,aAAa,CASjC;IAEY,UAAU,CAAC,QAAQ,GAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,SAAS,GAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,EAChF,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,GAAG,OAAO,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;CA0C1H"}
|
package/dist/Service.js
CHANGED
|
@@ -18,7 +18,6 @@ const Exception_1 = require("./exceptions/Exception");
|
|
|
18
18
|
const RequestType_1 = require("./reqestResponse/RequestType");
|
|
19
19
|
const ResponseType_1 = require("./reqestResponse/ResponseType");
|
|
20
20
|
const AwsS3Client_1 = require("./clients/AwsS3Client");
|
|
21
|
-
const Base64Client_1 = require("./clients/Base64Client");
|
|
22
21
|
const StringClient_1 = require("./clients/StringClient");
|
|
23
22
|
const EncryptClient_1 = require("./clients/EncryptClient");
|
|
24
23
|
const PoolManager_1 = __importDefault(require("./PoolManager"));
|
|
@@ -61,7 +60,6 @@ class Service {
|
|
|
61
60
|
this.response = new ResponseType_1.ResponseType();
|
|
62
61
|
this.tags = [];
|
|
63
62
|
this.errorList = [];
|
|
64
|
-
// Context<{ Bindings: Bindings }>
|
|
65
63
|
this.dbUser = process.env.DB_USER;
|
|
66
64
|
this.dbHost = process.env.DB_HOST;
|
|
67
65
|
this.dbName = process.env.DB_DATABASE;
|
|
@@ -238,12 +236,6 @@ class Service {
|
|
|
238
236
|
}
|
|
239
237
|
return this.s3Client;
|
|
240
238
|
}
|
|
241
|
-
get Base64Client() {
|
|
242
|
-
if (this.base64Client === undefined) {
|
|
243
|
-
this.base64Client = new Base64Client_1.Base64Client();
|
|
244
|
-
}
|
|
245
|
-
return this.base64Client;
|
|
246
|
-
}
|
|
247
239
|
get StringClient() {
|
|
248
240
|
if (this.stringClient === undefined) {
|
|
249
241
|
this.stringClient = new StringClient_1.StringClient();
|
|
@@ -19,7 +19,6 @@ export declare class AwsS3Client {
|
|
|
19
19
|
uploadJson(path: string, fileName: string, data: {
|
|
20
20
|
[key: string]: any;
|
|
21
21
|
}): Promise<void>;
|
|
22
|
-
uploadToPdf(path: string, fileName: string, base64Datas: Array<string>): Promise<void>;
|
|
23
22
|
uploadText(path: string, fileName: string, text: string): Promise<void>;
|
|
24
23
|
uploadBase64Data(path: string, fileName: string, base64Data: string): Promise<IUploadResponse>;
|
|
25
24
|
uploadFromUrl(path: string, fileName: string, url: string): Promise<IUploadResponse>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AwsS3Client.d.ts","sourceRoot":"","sources":["../../src/clients/AwsS3Client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAuG,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"AwsS3Client.d.ts","sourceRoot":"","sources":["../../src/clients/AwsS3Client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAuG,MAAM,oBAAoB,CAAC;AAIlJ,KAAK,eAAe,GAAG;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;CACpB,CAAA;AAED,qBAAa,WAAW;IACpB,OAAO,CAAC,MAAM,CAAW;IAEzB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC;IAC5B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IACxB,IAAI,SAAS,I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AAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAatC,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,GAAE,OAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAqBpF"}
|
|
@@ -21,7 +21,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
22
|
exports.AwsS3Client = void 0;
|
|
23
23
|
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
24
|
-
const Base64Client_1 = require("./Base64Client");
|
|
25
24
|
const Exception_1 = require("../exceptions/Exception");
|
|
26
25
|
const axios_1 = __importDefault(require("axios"));
|
|
27
26
|
class AwsS3Client {
|
|
@@ -80,20 +79,18 @@ class AwsS3Client {
|
|
|
80
79
|
yield this.client.send(command);
|
|
81
80
|
});
|
|
82
81
|
}
|
|
83
|
-
uploadToPdf(path, fileName, base64Datas) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
});
|
|
96
|
-
}
|
|
82
|
+
// public async uploadToPdf(path: string, fileName: string, base64Datas: Array<string>) {
|
|
83
|
+
// const base64Client = new Base64Client();
|
|
84
|
+
// const mergedPdfBase64 = await base64Client.mergeToPdfBase64(base64Datas);
|
|
85
|
+
// const command = new PutObjectCommand({
|
|
86
|
+
// Bucket: this.bucketName,
|
|
87
|
+
// Key: this.makeKey(path, fileName),
|
|
88
|
+
// Body: Buffer.from(mergedPdfBase64, 'base64'),
|
|
89
|
+
// ContentEncoding: 'base64',
|
|
90
|
+
// ContentType: 'application/pdf'
|
|
91
|
+
// });
|
|
92
|
+
// await this.client.send(command);
|
|
93
|
+
// }
|
|
97
94
|
uploadText(path, fileName, text) {
|
|
98
95
|
return __awaiter(this, void 0, void 0, function* () {
|
|
99
96
|
const command = new client_s3_1.PutObjectCommand({
|
|
@@ -107,24 +104,12 @@ class AwsS3Client {
|
|
|
107
104
|
}
|
|
108
105
|
uploadBase64Data(path, fileName, base64Data) {
|
|
109
106
|
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
-
const base64Client = new Base64Client_1.Base64Client();
|
|
111
|
-
const type = base64Client.getMimeType(base64Data);
|
|
112
|
-
const extension = {
|
|
113
|
-
'image/png': '.png',
|
|
114
|
-
'image/jpeg': '.jpeg',
|
|
115
|
-
'image/gif': '.gif',
|
|
116
|
-
'application/pdf': '.pdf'
|
|
117
|
-
}[type];
|
|
118
|
-
if (fileName.endsWith(extension) === false) {
|
|
119
|
-
fileName += extension;
|
|
120
|
-
}
|
|
121
107
|
const key = this.makeKey(path, fileName);
|
|
122
108
|
const command = new client_s3_1.PutObjectCommand({
|
|
123
109
|
Bucket: this.bucketName,
|
|
124
110
|
Key: key,
|
|
125
111
|
Body: Buffer.from(base64Data, 'base64'),
|
|
126
|
-
ContentEncoding: 'base64'
|
|
127
|
-
ContentType: type
|
|
112
|
+
ContentEncoding: 'base64'
|
|
128
113
|
});
|
|
129
114
|
yield this.client.send(command);
|
|
130
115
|
return {
|
package/dist/cron/BaseCron.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { PoolClient } from "pg";
|
|
2
2
|
import { DateType, DayType, HourType, MinuteSecondType, MonthType } from "./CronType";
|
|
3
3
|
import { AwsS3Client } from "../clients/AwsS3Client";
|
|
4
|
-
import { Base64Client } from "../clients/Base64Client";
|
|
5
4
|
export declare class BaseCron {
|
|
6
5
|
protected readonly isTest: boolean;
|
|
7
6
|
protected dbUser?: string;
|
|
@@ -29,7 +28,5 @@ export declare class BaseCron {
|
|
|
29
28
|
tearDown(): Promise<void>;
|
|
30
29
|
private s3Client?;
|
|
31
30
|
get S3Client(): AwsS3Client;
|
|
32
|
-
private base64Client?;
|
|
33
|
-
get Base64Client(): Base64Client;
|
|
34
31
|
}
|
|
35
32
|
//# sourceMappingURL=BaseCron.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseCron.d.ts","sourceRoot":"","sources":["../../src/cron/BaseCron.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,UAAU,EAAE,MAAM,IAAI,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEtF,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"BaseCron.d.ts","sourceRoot":"","sources":["../../src/cron/BaseCron.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,UAAU,EAAE,MAAM,IAAI,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEtF,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,qBAAa,QAAQ;IAEjB,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAmC;IACrE,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,CAAgE;IACzF,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,CAAgE;IACzF,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,CAAwE;IACjG,SAAS,CAAC,UAAU,CAAC,EAAE,MAAM,CAAwE;IACrG,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAgE;IAClG,SAAS,CAAC,cAAc,EAAE,OAAO,CAAiF;IAElH,OAAO,CAAC,iBAAiB,CAAkB;IAC3C,OAAO,CAAC,IAAI,CAAC,CAAO;IACpB,OAAO,CAAC,MAAM,CAAC,CAAa;IAC5B,SAAS,KAAK,MAAM,IAAI,UAAU,CAKjC;cAEe,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;cAKvB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAUzC,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAM;IAChC,SAAS,CAAC,MAAM,EAAE,gBAAgB,GAAG,GAAG,CAAO;IAC/C,SAAS,CAAC,IAAI,EAAE,QAAQ,GAAG,GAAG,CAAO;IACrC,SAAS,CAAC,IAAI,EAAE,QAAQ,GAAG,GAAG,CAAO;IACrC,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,GAAG,CAAO;IACvC,SAAS,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,CAAO;IACtB,GAAG;IAKhB,IAAI,YAAY,IAAI,MAAM,CAQzB;IACD,IAAI,QAAQ,IAAI,MAAM,CAA0B;IAEnC,KAAK;IAwBL,QAAQ;IAcrB,OAAO,CAAC,QAAQ,CAAC,CAAc;IAC/B,IAAI,QAAQ,IAAI,WAAW,CAU1B;CACJ"}
|
package/dist/cron/BaseCron.js
CHANGED
|
@@ -15,7 +15,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.BaseCron = void 0;
|
|
16
16
|
const PoolManager_1 = __importDefault(require("../PoolManager"));
|
|
17
17
|
const AwsS3Client_1 = require("../clients/AwsS3Client");
|
|
18
|
-
const Base64Client_1 = require("../clients/Base64Client");
|
|
19
18
|
class BaseCron {
|
|
20
19
|
constructor() {
|
|
21
20
|
this.isTest = process.env.NODE_ENV === 'test';
|
|
@@ -124,11 +123,5 @@ class BaseCron {
|
|
|
124
123
|
}
|
|
125
124
|
return this.s3Client;
|
|
126
125
|
}
|
|
127
|
-
get Base64Client() {
|
|
128
|
-
if (this.base64Client === undefined) {
|
|
129
|
-
this.base64Client = new Base64Client_1.Base64Client();
|
|
130
|
-
}
|
|
131
|
-
return this.base64Client;
|
|
132
|
-
}
|
|
133
126
|
}
|
|
134
127
|
exports.BaseCron = BaseCron;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { Service } from './Service';
|
|
2
|
+
export type { MethodType } from './Service';
|
|
2
3
|
export { MaintenanceException, AuthException, InputErrorException, ForbiddenException, DbConflictException, UnprocessableException, NotFoundException } from './exceptions/Exception';
|
|
3
4
|
export { createSwagger } from './documents/Swagger';
|
|
4
5
|
export { AwsS3Client } from './clients/AwsS3Client';
|
|
5
|
-
export { Base64Client } from './clients/Base64Client';
|
|
6
6
|
export { StringClient } from './clients/StringClient';
|
|
7
7
|
export { EncryptClient } from './clients/EncryptClient';
|
|
8
8
|
export { RequestType } from './reqestResponse/RequestType';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AACtL,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,YAAY,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AACtL,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAG3D,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAG7D,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC3F,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runCron = exports.BaseCron = exports.rollback = exports.migrate = exports.MigrateDatabase = exports.MigrateTable = exports.createTableDoc = exports.WhereExpression = exports.TableModel = exports.ResponseType = exports.RequestType = exports.EncryptClient = exports.StringClient = exports.
|
|
3
|
+
exports.runCron = exports.BaseCron = exports.rollback = exports.migrate = exports.MigrateDatabase = exports.MigrateTable = exports.createTableDoc = exports.WhereExpression = exports.TableModel = exports.ResponseType = exports.RequestType = exports.EncryptClient = exports.StringClient = exports.AwsS3Client = exports.createSwagger = exports.NotFoundException = exports.UnprocessableException = exports.DbConflictException = exports.ForbiddenException = exports.InputErrorException = exports.AuthException = exports.MaintenanceException = exports.Service = void 0;
|
|
4
4
|
var Service_1 = require("./Service");
|
|
5
5
|
Object.defineProperty(exports, "Service", { enumerable: true, get: function () { return Service_1.Service; } });
|
|
6
6
|
var Exception_1 = require("./exceptions/Exception");
|
|
@@ -15,8 +15,6 @@ var Swagger_1 = require("./documents/Swagger");
|
|
|
15
15
|
Object.defineProperty(exports, "createSwagger", { enumerable: true, get: function () { return Swagger_1.createSwagger; } });
|
|
16
16
|
var AwsS3Client_1 = require("./clients/AwsS3Client");
|
|
17
17
|
Object.defineProperty(exports, "AwsS3Client", { enumerable: true, get: function () { return AwsS3Client_1.AwsS3Client; } });
|
|
18
|
-
var Base64Client_1 = require("./clients/Base64Client");
|
|
19
|
-
Object.defineProperty(exports, "Base64Client", { enumerable: true, get: function () { return Base64Client_1.Base64Client; } });
|
|
20
18
|
var StringClient_1 = require("./clients/StringClient");
|
|
21
19
|
Object.defineProperty(exports, "StringClient", { enumerable: true, get: function () { return StringClient_1.StringClient; } });
|
|
22
20
|
var EncryptClient_1 = require("./clients/EncryptClient");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pg-mvc-service",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"homepage": "https://github.com/n-daira/npm-pack_mvc-service#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -40,7 +40,6 @@
|
|
|
40
40
|
"hono": "4.11.2",
|
|
41
41
|
"node-cron": "4.2.1",
|
|
42
42
|
"pdf-lib": "1.17.1",
|
|
43
|
-
"sharp": "0.34.1",
|
|
44
43
|
"type-utils-n-daira": "1.0.11"
|
|
45
44
|
}
|
|
46
45
|
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export type TPng = 'image/png';
|
|
2
|
-
export type TJpeg = 'image/jpeg';
|
|
3
|
-
export type TGif = 'image/gif';
|
|
4
|
-
export type TImage = TPng | TJpeg | TGif;
|
|
5
|
-
export type TPdf = 'application/pdf';
|
|
6
|
-
export type TJson = 'application/json';
|
|
7
|
-
export declare class Base64Client {
|
|
8
|
-
readonly PREFIX_JPEG_DATA = "/9j/";
|
|
9
|
-
readonly PREFIX_PNG_DATA = "iVBORw0KGgo";
|
|
10
|
-
constructor();
|
|
11
|
-
tryDecode(base64: string): Buffer | false;
|
|
12
|
-
getMimeType(data: string | Buffer): TImage | TPdf;
|
|
13
|
-
mergeToPdfBase64(datas: string[]): Promise<string>;
|
|
14
|
-
private convertImageToPdf;
|
|
15
|
-
isJpeg(value: any): value is string;
|
|
16
|
-
isPng(value: any): value is string;
|
|
17
|
-
tryConvertToPng(base64Value: any): Promise<string | false>;
|
|
18
|
-
resizeImage(base64Data: string, toSize: {
|
|
19
|
-
w: number;
|
|
20
|
-
} | {
|
|
21
|
-
h: number;
|
|
22
|
-
} | {
|
|
23
|
-
w: number;
|
|
24
|
-
h: number;
|
|
25
|
-
func: 'max' | 'min';
|
|
26
|
-
} | {
|
|
27
|
-
rate: number;
|
|
28
|
-
}): Promise<string>;
|
|
29
|
-
fetchImageAsBase64(imageUrl: string): Promise<string>;
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=Base64Client.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Base64Client.d.ts","sourceRoot":"","sources":["../../src/clients/Base64Client.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,IAAI,GAAG,WAAW,CAAC;AAC/B,MAAM,MAAM,KAAK,GAAG,YAAY,CAAC;AACjC,MAAM,MAAM,IAAI,GAAG,WAAW,CAAC;AAC/B,MAAM,MAAM,MAAM,GAAG,IAAI,GAAG,KAAK,GAAG,IAAI,CAAC;AAEzC,MAAM,MAAM,IAAI,GAAG,iBAAiB,CAAC;AACrC,MAAM,MAAM,KAAK,GAAG,kBAAkB,CAAC;AAEvC,qBAAa,YAAY;IACrB,SAAgB,gBAAgB,UAAU;IAC1C,SAAgB,eAAe,iBAAiB;;IAQzC,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK;IA2BzC,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI;IAuC3C,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;YA4BjD,iBAAiB;IA2CxB,MAAM,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,MAAM;IAqBnC,KAAK,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,MAAM;IAqB5B,eAAe,CAAC,WAAW,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC;IAsB1D,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE;QAAC,CAAC,EAAE,MAAM,CAAA;KAAC,GAAG;QAAC,CAAC,EAAE,MAAM,CAAA;KAAC,GAAG;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,KAAK,GAAG,KAAK,CAAA;KAAC,GAAE;QAAC,IAAI,EAAE,MAAM,CAAA;KAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IAiEjJ,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAerE"}
|
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.Base64Client = void 0;
|
|
16
|
-
const axios_1 = __importDefault(require("axios"));
|
|
17
|
-
const pdf_lib_1 = require("pdf-lib");
|
|
18
|
-
const sharp_1 = __importDefault(require("sharp"));
|
|
19
|
-
const type_utils_n_daira_1 = require("type-utils-n-daira");
|
|
20
|
-
class Base64Client {
|
|
21
|
-
constructor() {
|
|
22
|
-
this.PREFIX_JPEG_DATA = '/9j/';
|
|
23
|
-
this.PREFIX_PNG_DATA = 'iVBORw0KGgo';
|
|
24
|
-
}
|
|
25
|
-
// public encode(text: string): string {
|
|
26
|
-
// return Buffer.from(text).toString('base64');
|
|
27
|
-
// }
|
|
28
|
-
tryDecode(base64) {
|
|
29
|
-
try {
|
|
30
|
-
// Data URLのパターンをチェック
|
|
31
|
-
if (base64.startsWith('data:')) {
|
|
32
|
-
const matches = base64.match(/^data:([A-Za-z-+/]+);base64,(.+)$/);
|
|
33
|
-
if (!matches || matches.length !== 3) {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
// base64部分のみを取得
|
|
37
|
-
base64 = matches[2];
|
|
38
|
-
}
|
|
39
|
-
if (base64.length % 4 !== 0) {
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
const regex = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
43
|
-
if (!regex.test(base64)) {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
return Buffer.from(base64, 'base64');
|
|
47
|
-
}
|
|
48
|
-
catch (_a) {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
getMimeType(data) {
|
|
53
|
-
try {
|
|
54
|
-
let buffer;
|
|
55
|
-
if (typeof data === 'string') {
|
|
56
|
-
// Data URLのパターンをチェック
|
|
57
|
-
if (data.startsWith('data:')) {
|
|
58
|
-
const matches = data.match(/^data:([A-Za-z-+/]+);base64,(.+)$/);
|
|
59
|
-
if (!matches || matches.length !== 3) {
|
|
60
|
-
throw new Error('Invalid Data URL format');
|
|
61
|
-
}
|
|
62
|
-
// base64部分のみを取得
|
|
63
|
-
data = matches[2];
|
|
64
|
-
}
|
|
65
|
-
buffer = this.tryDecode(data);
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
buffer = data;
|
|
69
|
-
}
|
|
70
|
-
if (buffer === false) {
|
|
71
|
-
throw new Error('Cannot getMineType because the input is not in base64 format.');
|
|
72
|
-
}
|
|
73
|
-
const header = buffer.subarray(0, 4);
|
|
74
|
-
if (header[0] === 0x25 && header[1] === 0x50 && header[2] === 0x44 && header[3] === 0x46) {
|
|
75
|
-
return 'application/pdf';
|
|
76
|
-
}
|
|
77
|
-
else if (header[0] === 0x89 && header[1] === 0x50 && header[2] === 0x4E && header[3] === 0x47) {
|
|
78
|
-
return 'image/png';
|
|
79
|
-
}
|
|
80
|
-
else if (header[0] === 0xFF && header[1] === 0xD8) {
|
|
81
|
-
return 'image/jpeg';
|
|
82
|
-
}
|
|
83
|
-
else if (header[0] === 0x47 && header[1] === 0x49 && header[2] === 0x46 && header[3] === 0x38) {
|
|
84
|
-
return 'image/gif';
|
|
85
|
-
}
|
|
86
|
-
throw new Error('Cannot getMimeType because the file type is not PDF, PNG, JPEG, or GIF.');
|
|
87
|
-
}
|
|
88
|
-
catch (_a) {
|
|
89
|
-
throw new Error('Cannot getMineType because the input is not in base64 format.');
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
mergeToPdfBase64(datas) {
|
|
93
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
-
const mergedPdf = yield pdf_lib_1.PDFDocument.create();
|
|
95
|
-
for (const data of datas) {
|
|
96
|
-
const buffer = this.tryDecode(data);
|
|
97
|
-
if (buffer === false) {
|
|
98
|
-
throw new Error('Cannot mergeToPdf because the input is not in base64 format.');
|
|
99
|
-
}
|
|
100
|
-
const fileType = this.getMimeType(buffer);
|
|
101
|
-
if (fileType === 'application/pdf') {
|
|
102
|
-
const pdfDoc = yield pdf_lib_1.PDFDocument.load(buffer);
|
|
103
|
-
const pages = yield mergedPdf.copyPages(pdfDoc, pdfDoc.getPageIndices());
|
|
104
|
-
pages.forEach(page => mergedPdf.addPage(page));
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
// convert from image to pdf
|
|
108
|
-
const imagePdf = yield this.convertImageToPdf(buffer);
|
|
109
|
-
const pdfDoc = yield pdf_lib_1.PDFDocument.load(imagePdf);
|
|
110
|
-
const pages = yield mergedPdf.copyPages(pdfDoc, pdfDoc.getPageIndices());
|
|
111
|
-
pages.forEach(page => mergedPdf.addPage(page));
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
// 結合したPDFをBase64に変換
|
|
115
|
-
const mergedPdfBytes = yield mergedPdf.save();
|
|
116
|
-
return Buffer.from(mergedPdfBytes).toString('base64');
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
convertImageToPdf(imageBuffer) {
|
|
120
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
-
const fileType = this.getMimeType(imageBuffer);
|
|
122
|
-
let optimizedImage;
|
|
123
|
-
if (fileType === 'image/gif') {
|
|
124
|
-
// gifの場合はpngに変換して処理
|
|
125
|
-
optimizedImage = yield (0, sharp_1.default)(imageBuffer)
|
|
126
|
-
.png()
|
|
127
|
-
.toBuffer();
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
optimizedImage = yield (0, sharp_1.default)(imageBuffer).toBuffer();
|
|
131
|
-
}
|
|
132
|
-
// 新しいPDFドキュメントを作成
|
|
133
|
-
const pdfDoc = yield pdf_lib_1.PDFDocument.create();
|
|
134
|
-
const page = pdfDoc.addPage();
|
|
135
|
-
// 画像をPDFに埋め込み
|
|
136
|
-
let image;
|
|
137
|
-
if (fileType === 'image/jpeg') {
|
|
138
|
-
image = yield pdfDoc.embedJpg(optimizedImage);
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
image = yield pdfDoc.embedPng(optimizedImage);
|
|
142
|
-
}
|
|
143
|
-
const { width, height } = image.scale(1);
|
|
144
|
-
// ページサイズを画像に合わせる
|
|
145
|
-
page.setSize(width, height);
|
|
146
|
-
// 画像を描画
|
|
147
|
-
page.drawImage(image, {
|
|
148
|
-
x: 0,
|
|
149
|
-
y: 0,
|
|
150
|
-
width,
|
|
151
|
-
height,
|
|
152
|
-
});
|
|
153
|
-
// PDFをバッファに変換
|
|
154
|
-
const pdfBytes = yield pdfDoc.save();
|
|
155
|
-
return Buffer.from(pdfBytes);
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
isJpeg(value) {
|
|
159
|
-
if (type_utils_n_daira_1.ValidateStringUtil.isBase64(value) === false) {
|
|
160
|
-
return false;
|
|
161
|
-
}
|
|
162
|
-
if (value.startsWith('data:')) {
|
|
163
|
-
if (value.startsWith('data:image/jpeg,') === false && value.startsWith('data:image/jpg,') === false) {
|
|
164
|
-
return false;
|
|
165
|
-
}
|
|
166
|
-
const valueParts = value.split(',');
|
|
167
|
-
if (valueParts.length !== 2) {
|
|
168
|
-
return false;
|
|
169
|
-
}
|
|
170
|
-
return valueParts[1].startsWith(this.PREFIX_JPEG_DATA);
|
|
171
|
-
}
|
|
172
|
-
return value.startsWith(this.PREFIX_JPEG_DATA);
|
|
173
|
-
}
|
|
174
|
-
isPng(value) {
|
|
175
|
-
if (type_utils_n_daira_1.ValidateStringUtil.isBase64(value) === false) {
|
|
176
|
-
return false;
|
|
177
|
-
}
|
|
178
|
-
if (value.startsWith('data:')) {
|
|
179
|
-
if (value.startsWith('data:image/png,') === false) {
|
|
180
|
-
return false;
|
|
181
|
-
}
|
|
182
|
-
const valueParts = value.split(',');
|
|
183
|
-
if (valueParts.length !== 2) {
|
|
184
|
-
return false;
|
|
185
|
-
}
|
|
186
|
-
return valueParts[1].startsWith(this.PREFIX_PNG_DATA);
|
|
187
|
-
}
|
|
188
|
-
return value.startsWith(this.PREFIX_PNG_DATA);
|
|
189
|
-
}
|
|
190
|
-
tryConvertToPng(base64Value) {
|
|
191
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
192
|
-
if (type_utils_n_daira_1.ValidateStringUtil.isBase64(base64Value) === false) {
|
|
193
|
-
return false;
|
|
194
|
-
}
|
|
195
|
-
const base64Data = base64Value.startsWith('data:') ? base64Value.split(',')[1] : base64Value;
|
|
196
|
-
if (this.isPng(base64Data)) {
|
|
197
|
-
return base64Data;
|
|
198
|
-
}
|
|
199
|
-
else if (this.isJpeg(base64Data)) {
|
|
200
|
-
const buffer = Buffer.from(base64Data, 'base64');
|
|
201
|
-
try {
|
|
202
|
-
const pngBuffer = yield (0, sharp_1.default)(buffer)
|
|
203
|
-
.ensureAlpha().png().toBuffer();
|
|
204
|
-
return pngBuffer.toString('base64');
|
|
205
|
-
}
|
|
206
|
-
catch (e) {
|
|
207
|
-
return false;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
return false;
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
resizeImage(base64Data, toSize) {
|
|
214
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
215
|
-
if (type_utils_n_daira_1.ValidateStringUtil.isBase64(base64Data) === false) {
|
|
216
|
-
throw new Error("The specified data is not in base64 format");
|
|
217
|
-
}
|
|
218
|
-
const imageBuffer = Buffer.from(base64Data, 'base64');
|
|
219
|
-
const metadata = yield (0, sharp_1.default)(imageBuffer).metadata();
|
|
220
|
-
const { width, height, format } = metadata;
|
|
221
|
-
if (width === undefined || height === undefined) {
|
|
222
|
-
throw new Error("Failed to retrieve image dimensions");
|
|
223
|
-
}
|
|
224
|
-
let rate = 1;
|
|
225
|
-
if ('rate' in toSize) {
|
|
226
|
-
rate = toSize.rate;
|
|
227
|
-
}
|
|
228
|
-
else if ('w' in toSize && 'h' in toSize && 'func' in toSize) {
|
|
229
|
-
const wRate = toSize.w / width;
|
|
230
|
-
const hRate = toSize.h / height;
|
|
231
|
-
switch (toSize.func) {
|
|
232
|
-
case 'max':
|
|
233
|
-
rate = Math.max(wRate, hRate);
|
|
234
|
-
break;
|
|
235
|
-
case 'min':
|
|
236
|
-
rate = Math.min(wRate, hRate);
|
|
237
|
-
break;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
else if ('w' in toSize) {
|
|
241
|
-
rate = toSize.w / width;
|
|
242
|
-
}
|
|
243
|
-
else if ('h' in toSize) {
|
|
244
|
-
rate = toSize.h / height;
|
|
245
|
-
}
|
|
246
|
-
// 画像は1倍より大きくできないので
|
|
247
|
-
if (rate >= 1 || rate <= 0) {
|
|
248
|
-
return base64Data;
|
|
249
|
-
}
|
|
250
|
-
let resizedImage;
|
|
251
|
-
// フォーマットに応じて処理を分岐
|
|
252
|
-
const targetWidth = Math.round(width * rate);
|
|
253
|
-
const targetHeight = Math.round(height * rate);
|
|
254
|
-
if (format === 'png') {
|
|
255
|
-
resizedImage = yield (0, sharp_1.default)(imageBuffer)
|
|
256
|
-
.resize(targetWidth, targetHeight, {
|
|
257
|
-
fit: 'inside',
|
|
258
|
-
withoutEnlargement: true
|
|
259
|
-
})
|
|
260
|
-
.png({ quality: 90 })
|
|
261
|
-
.toBuffer();
|
|
262
|
-
}
|
|
263
|
-
else {
|
|
264
|
-
// JPEG、その他のフォーマット
|
|
265
|
-
resizedImage = yield (0, sharp_1.default)(imageBuffer)
|
|
266
|
-
.resize(targetWidth, targetHeight, {
|
|
267
|
-
fit: 'inside',
|
|
268
|
-
withoutEnlargement: true
|
|
269
|
-
})
|
|
270
|
-
.jpeg({ quality: 90 })
|
|
271
|
-
.toBuffer();
|
|
272
|
-
}
|
|
273
|
-
return resizedImage.toString('base64');
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
fetchImageAsBase64(imageUrl) {
|
|
277
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
278
|
-
const res = yield axios_1.default.get(imageUrl, {
|
|
279
|
-
responseType: 'arraybuffer' // これを追加
|
|
280
|
-
});
|
|
281
|
-
// Content-Typeをチェック
|
|
282
|
-
const contentType = res.headers['content-type'];
|
|
283
|
-
if (!(contentType === null || contentType === void 0 ? void 0 : contentType.startsWith('image/'))) {
|
|
284
|
-
throw new Error(`Invalid content type: ${contentType}. Expected image/*`);
|
|
285
|
-
}
|
|
286
|
-
// ArrayBufferをBufferに変換してBase64にエンコード
|
|
287
|
-
const buffer = Buffer.from(res.data);
|
|
288
|
-
return buffer.toString('base64');
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
exports.Base64Client = Base64Client;
|