@kipicore/dbcore 1.1.344 → 1.1.346

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.
@@ -0,0 +1,2 @@
1
+ export function up(queryInterface: any, Sequelize: any): Promise<void>;
2
+ export function down(queryInterface: any, Sequelize: any): Promise<void>;
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+ const up = async (queryInterface, Sequelize) => {
3
+ const table = await queryInterface.describeTable('file_storage');
4
+ if (table.file_path) {
5
+ await queryInterface.changeColumn('file_storage', 'file_path', {
6
+ type: Sequelize.TEXT,
7
+ allowNull: true,
8
+ field: 'file_path',
9
+ });
10
+ }
11
+ };
12
+ const down = async (queryInterface, Sequelize) => {
13
+ const table = await queryInterface.describeTable('file_storage');
14
+ if (table.file_path) {
15
+ await queryInterface.changeColumn('file_storage', 'file_path', {
16
+ type: Sequelize.STRING,
17
+ allowNull: true,
18
+ field: 'file_path',
19
+ });
20
+ }
21
+ };
22
+ module.exports = {
23
+ up,
24
+ down,
25
+ };
@@ -11,6 +11,7 @@ const aws_1 = require("../configs/aws");
11
11
  const env_1 = require("../configs/env");
12
12
  const client_s3_1 = require("@aws-sdk/client-s3");
13
13
  const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
14
+ const date_fns_1 = require("date-fns");
14
15
  const uploadFileToS3 = async (localFilePath, s3Key, s3Bucket = env_1.ENV_VARIABLE.AWS_BUCKET_NAME) => {
15
16
  try {
16
17
  const fileContent = fs_1.default.readFileSync(localFilePath);
@@ -35,11 +36,12 @@ const uploadFileToS3 = async (localFilePath, s3Key, s3Bucket = env_1.ENV_VARIABL
35
36
  };
36
37
  exports.uploadFileToS3 = uploadFileToS3;
37
38
  const getPresignedUrl = async (bucket, fileStorage, expiresIn = 60 * 60 * 24) => {
38
- // if (fileStorage.expiredAt && fileStorage.filePath) {
39
- // const currentDate = getTime(subMinutes(new Date(), 5));
40
- // const expireDate = getTime(new Date(fileStorage.expiredAt));
41
- // if (currentDate < expireDate) return fileStorage.filePath as string;
42
- // }
39
+ if (fileStorage.expiredAt && fileStorage.filePath) {
40
+ const currentDate = (0, date_fns_1.getTime)((0, date_fns_1.subMinutes)(new Date(), 5));
41
+ const expireDate = (0, date_fns_1.getTime)(new Date(fileStorage.expiredAt));
42
+ if (currentDate < expireDate)
43
+ return fileStorage.filePath;
44
+ }
43
45
  const s3Key = `${fileStorage.storagePath}/${fileStorage.storageFileName}`;
44
46
  const command = new client_s3_1.GetObjectCommand({
45
47
  Bucket: bucket,
@@ -102,7 +102,7 @@ FileStorageModel.init({
102
102
  allowNull: true,
103
103
  },
104
104
  filePath: {
105
- type: sequelize_1.DataTypes.STRING,
105
+ type: sequelize_1.DataTypes.TEXT,
106
106
  field: 'file_path',
107
107
  allowNull: true,
108
108
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kipicore/dbcore",
3
- "version": "1.1.344",
3
+ "version": "1.1.346",
4
4
  "description": "Reusable DB core package with Postgres, MongoDB, models, services, interfaces, and types",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",