pg-mvc-service 2.0.8 → 2.0.10
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.
|
@@ -209,5 +209,68 @@ class Base64Client {
|
|
|
209
209
|
return false;
|
|
210
210
|
});
|
|
211
211
|
}
|
|
212
|
+
resizeImage(base64Data, toSize) {
|
|
213
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
214
|
+
if (type_utils_n_daira_1.ValidateStringUtil.isBase64(base64Data) === false) {
|
|
215
|
+
throw new Error("The specified data is not in base64 format");
|
|
216
|
+
}
|
|
217
|
+
const imageBuffer = Buffer.from(base64Data, 'base64');
|
|
218
|
+
const metadata = yield (0, sharp_1.default)(imageBuffer).metadata();
|
|
219
|
+
const { width, height, format } = metadata;
|
|
220
|
+
if (width === undefined || height === undefined) {
|
|
221
|
+
throw new Error("Failed to retrieve image dimensions");
|
|
222
|
+
}
|
|
223
|
+
let rate = 1;
|
|
224
|
+
if ('rate' in toSize) {
|
|
225
|
+
rate = toSize.rate;
|
|
226
|
+
}
|
|
227
|
+
else if ('w' in toSize && 'h' in toSize && 'func' in toSize) {
|
|
228
|
+
const wRate = toSize.w / width;
|
|
229
|
+
const hRate = toSize.h / height;
|
|
230
|
+
switch (toSize.func) {
|
|
231
|
+
case 'max':
|
|
232
|
+
rate = Math.max(wRate, hRate);
|
|
233
|
+
break;
|
|
234
|
+
case 'min':
|
|
235
|
+
rate = Math.min(wRate, hRate);
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
else if ('w' in toSize) {
|
|
240
|
+
rate = toSize.w / width;
|
|
241
|
+
}
|
|
242
|
+
else if ('h' in toSize) {
|
|
243
|
+
rate = toSize.h / height;
|
|
244
|
+
}
|
|
245
|
+
// 画像は1倍より大きくできないので
|
|
246
|
+
if (rate >= 1 || rate <= 0) {
|
|
247
|
+
return base64Data;
|
|
248
|
+
}
|
|
249
|
+
let resizedImage;
|
|
250
|
+
// フォーマットに応じて処理を分岐
|
|
251
|
+
const targetWidth = Math.round(width * rate);
|
|
252
|
+
const targetHeight = Math.round(height * rate);
|
|
253
|
+
if (format === 'png') {
|
|
254
|
+
resizedImage = yield (0, sharp_1.default)(imageBuffer)
|
|
255
|
+
.resize(targetWidth, targetHeight, {
|
|
256
|
+
fit: 'inside',
|
|
257
|
+
withoutEnlargement: true
|
|
258
|
+
})
|
|
259
|
+
.png({ quality: 90 })
|
|
260
|
+
.toBuffer();
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
// JPEG、その他のフォーマット
|
|
264
|
+
resizedImage = yield (0, sharp_1.default)(imageBuffer)
|
|
265
|
+
.resize(targetWidth, targetHeight, {
|
|
266
|
+
fit: 'inside',
|
|
267
|
+
withoutEnlargement: true
|
|
268
|
+
})
|
|
269
|
+
.jpeg({ quality: 90 })
|
|
270
|
+
.toBuffer();
|
|
271
|
+
}
|
|
272
|
+
return resizedImage.toString('base64');
|
|
273
|
+
});
|
|
274
|
+
}
|
|
212
275
|
}
|
|
213
276
|
exports.Base64Client = Base64Client;
|
|
@@ -334,7 +334,7 @@ class TableModel {
|
|
|
334
334
|
let message = this.errorMessages[type];
|
|
335
335
|
const name = (column.alias === undefined || column.alias === '') ? columnName : column.alias;
|
|
336
336
|
message = message.replace('{name}', name);
|
|
337
|
-
if (message.includes("{length}") && (column.type === 'string' || column.type
|
|
337
|
+
if (message.includes("{length}") && (column.type === 'string' || column.type === 'string[]')) {
|
|
338
338
|
message = message.replace('{length}', ((_a = column.length) !== null && _a !== void 0 ? _a : '未設定').toString());
|
|
339
339
|
}
|
|
340
340
|
throw new Exception_1.UnprocessableException(code, message);
|
package/package.json
CHANGED
|
@@ -220,4 +220,69 @@ export class Base64Client {
|
|
|
220
220
|
|
|
221
221
|
return false;
|
|
222
222
|
}
|
|
223
|
+
|
|
224
|
+
public async resizeImage(base64Data: string, toSize: {w: number} | {h: number} | {w: number; h: number; func: 'max' | 'min'}| {rate: number}): Promise<string> {
|
|
225
|
+
if (ValidateStringUtil.isBase64(base64Data) === false) {
|
|
226
|
+
throw new Error("The specified data is not in base64 format");
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const imageBuffer = Buffer.from(base64Data, 'base64');
|
|
230
|
+
const metadata = await sharp(imageBuffer).metadata();
|
|
231
|
+
const { width, height, format } = metadata;
|
|
232
|
+
if (width === undefined || height === undefined) {
|
|
233
|
+
throw new Error("Failed to retrieve image dimensions");
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
let rate = 1;
|
|
237
|
+
if ('rate' in toSize) {
|
|
238
|
+
rate = toSize.rate;
|
|
239
|
+
} else if ('w' in toSize && 'h' in toSize && 'func' in toSize) {
|
|
240
|
+
const wRate = toSize.w / width;
|
|
241
|
+
const hRate = toSize.h / height;
|
|
242
|
+
switch (toSize.func) {
|
|
243
|
+
case 'max':
|
|
244
|
+
rate = Math.max(wRate, hRate);
|
|
245
|
+
break;
|
|
246
|
+
case 'min':
|
|
247
|
+
rate = Math.min(wRate, hRate);
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
} else if ('w' in toSize) {
|
|
252
|
+
rate = toSize.w / width;
|
|
253
|
+
} else if ('h' in toSize) {
|
|
254
|
+
rate = toSize.h / height;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// 画像は1倍より大きくできないので
|
|
258
|
+
if (rate >= 1 || rate <= 0) {
|
|
259
|
+
return base64Data;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
let resizedImage: Buffer;
|
|
263
|
+
|
|
264
|
+
// フォーマットに応じて処理を分岐
|
|
265
|
+
const targetWidth = Math.round(width * rate);
|
|
266
|
+
const targetHeight = Math.round(height * rate);
|
|
267
|
+
if (format === 'png') {
|
|
268
|
+
resizedImage = await sharp(imageBuffer)
|
|
269
|
+
.resize(targetWidth, targetHeight, {
|
|
270
|
+
fit: 'inside',
|
|
271
|
+
withoutEnlargement: true
|
|
272
|
+
})
|
|
273
|
+
.png({ quality: 90 })
|
|
274
|
+
.toBuffer();
|
|
275
|
+
} else {
|
|
276
|
+
// JPEG、その他のフォーマット
|
|
277
|
+
resizedImage = await sharp(imageBuffer)
|
|
278
|
+
.resize(targetWidth, targetHeight, {
|
|
279
|
+
fit: 'inside',
|
|
280
|
+
withoutEnlargement: true
|
|
281
|
+
})
|
|
282
|
+
.jpeg({ quality: 90 })
|
|
283
|
+
.toBuffer();
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
return resizedImage.toString('base64');
|
|
287
|
+
}
|
|
223
288
|
}
|
package/src/models/TableModel.ts
CHANGED
|
@@ -393,7 +393,7 @@ export class TableModel {
|
|
|
393
393
|
|
|
394
394
|
const name = (column.alias === undefined || column.alias === '') ? columnName : column.alias;
|
|
395
395
|
message = message.replace('{name}', name);
|
|
396
|
-
if (message.includes("{length}") && (column.type === 'string' || column.type
|
|
396
|
+
if (message.includes("{length}") && (column.type === 'string' || column.type === 'string[]')) {
|
|
397
397
|
message = message.replace('{length}', (column.length ?? '未設定').toString());
|
|
398
398
|
}
|
|
399
399
|
|