@kipicore/dbcore 1.1.341 → 1.1.343

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.
@@ -11,8 +11,6 @@ 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");
15
- const psql_1 = require("../models/psql");
16
14
  const uploadFileToS3 = async (localFilePath, s3Key, s3Bucket = env_1.ENV_VARIABLE.AWS_BUCKET_NAME) => {
17
15
  try {
18
16
  const fileContent = fs_1.default.readFileSync(localFilePath);
@@ -37,26 +35,28 @@ const uploadFileToS3 = async (localFilePath, s3Key, s3Bucket = env_1.ENV_VARIABL
37
35
  };
38
36
  exports.uploadFileToS3 = uploadFileToS3;
39
37
  const getPresignedUrl = async (bucket, fileStorage, expiresIn = 60 * 60 * 24) => {
40
- if (fileStorage.expiredAt && fileStorage.filePath) {
41
- const currentDate = (0, date_fns_1.getTime)((0, date_fns_1.subMinutes)(new Date(), 5));
42
- const expireDate = (0, date_fns_1.getTime)(new Date(fileStorage.expiredAt));
43
- if (currentDate < expireDate)
44
- return fileStorage.filePath;
45
- }
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
+ // }
46
43
  const s3Key = `${fileStorage.storagePath}/${fileStorage.storageFileName}`;
47
44
  const command = new client_s3_1.GetObjectCommand({
48
45
  Bucket: bucket,
49
46
  Key: s3Key,
50
47
  });
51
48
  const signedUrl = await (0, s3_request_presigner_1.getSignedUrl)(aws_1.s3, command, { expiresIn }); // in seconds
52
- if (fileStorage.id) {
53
- await psql_1.FileStorageModel.update({
54
- filePath: signedUrl,
55
- expiredAt: (0, date_fns_1.addDays)(new Date(), 1),
56
- }, {
57
- where: { id: fileStorage.id },
58
- });
59
- }
49
+ // if (fileStorage.id) {
50
+ // await FileStorageModel.update(
51
+ // {
52
+ // filePath: signedUrl,
53
+ // expiredAt: addDays(new Date(), 1),
54
+ // },I
55
+ // {
56
+ // where: { id: fileStorage.id },
57
+ // },
58
+ // );
59
+ // }
60
60
  return signedUrl;
61
61
  };
62
62
  exports.getPresignedUrl = getPresignedUrl;
@@ -3,6 +3,5 @@ import { IFileStorageAttributes } from '../../interfaces/fileStorageInterface';
3
3
  import { TFileStorageModelCreationAttributes } from '../../types/fileStorageType';
4
4
  declare class FileStorageModel extends Model<IFileStorageAttributes, TFileStorageModelCreationAttributes> {
5
5
  static associate(models: any): void;
6
- static addHooks(): void;
7
6
  }
8
7
  export default FileStorageModel;
@@ -3,8 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const sequelize_1 = require("sequelize");
4
4
  const index_1 = require("./index");
5
5
  const app_1 = require("../../constants/app");
6
- const helpers_1 = require("../../helpers");
7
- const configs_1 = require("../../configs");
8
6
  class FileStorageModel extends sequelize_1.Model {
9
7
  static associate(models) {
10
8
  const { UserModel, UserDirectoryModel } = models;
@@ -49,23 +47,6 @@ class FileStorageModel extends sequelize_1.Model {
49
47
  as: 'userDirectoryFile',
50
48
  });
51
49
  }
52
- static addHooks() {
53
- FileStorageModel.afterFind(async (instances) => {
54
- if (!instances)
55
- return;
56
- const instanceArray = Array.isArray(instances) ? instances : [instances];
57
- await Promise.all(instanceArray.map(async (instance) => {
58
- const data = typeof instance.get === 'function' ? instance.get() : instance;
59
- const signedUrl = await (0, helpers_1.getPresignedUrl)(configs_1.ENV_VARIABLE.AWS_BUCKET_NAME, data);
60
- if (typeof instance.setDataValue === 'function') {
61
- instance.setDataValue('filePath', signedUrl);
62
- }
63
- else {
64
- instance.filePath = signedUrl;
65
- }
66
- }));
67
- });
68
- }
69
50
  }
70
51
  FileStorageModel.init({
71
52
  id: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kipicore/dbcore",
3
- "version": "1.1.341",
3
+ "version": "1.1.343",
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",