@rowengine/common 1.1.16 → 1.1.18

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.
@@ -10,8 +10,10 @@ export declare const getTileFromProjectInGCS: (projectId: string, coordinates: {
10
10
  export declare const getFileFromProjectInGCS: (projectId: string, fileName: string) => Promise<import("@google-cloud/storage").File | null>;
11
11
  export declare const getFileFromProjectFieldInGCS: (projectId: string, fieldId: string, fileName: string) => Promise<import("@google-cloud/storage").File | null>;
12
12
  export declare const deleteProjectFromGCS: (projectId: string) => Promise<void>;
13
- export interface FileToUpload {
13
+ export interface File {
14
14
  localFilePath: string;
15
15
  gcsPath: string;
16
16
  }
17
- export declare const uploadFilesToProjectInGCS: (projectId: string, files: FileToUpload[]) => Promise<void>;
17
+ export declare const uploadFilesToProjectInGCS: (projectId: string, files: File[]) => Promise<void>;
18
+ export declare const downloadFilesFromProjectInGCS: (projectId: string, files: File[]) => Promise<string[]>;
19
+ export declare const getCompanyLogo: (companyId: string) => Promise<import("@google-cloud/storage").File | null>;
package/build/utils/gc.js CHANGED
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.uploadFilesToProjectInGCS = exports.deleteProjectFromGCS = exports.getFileFromProjectFieldInGCS = exports.getFileFromProjectInGCS = exports.getTileFromProjectInGCS = exports.downloadProjectFileFromGCS = exports.getFilesFromGCSFolder = void 0;
15
+ exports.getCompanyLogo = exports.downloadFilesFromProjectInGCS = exports.uploadFilesToProjectInGCS = exports.deleteProjectFromGCS = exports.getFileFromProjectFieldInGCS = exports.getFileFromProjectInGCS = exports.getTileFromProjectInGCS = exports.downloadProjectFileFromGCS = exports.getFilesFromGCSFolder = void 0;
16
16
  exports.uploadFileToGCS = uploadFileToGCS;
17
17
  exports.uploadFolderToGCS = uploadFolderToGCS;
18
18
  const promises_1 = __importDefault(require("fs/promises"));
@@ -125,3 +125,26 @@ const uploadFilesToProjectInGCS = (projectId, files) => __awaiter(void 0, void 0
125
125
  yield Promise.all(files.map(({ localFilePath, gcsPath }) => limit(() => uploadFileToGCS(localFilePath, `projects/${projectId}/${gcsPath}`, fs_1.default.statSync(localFilePath).size))));
126
126
  });
127
127
  exports.uploadFilesToProjectInGCS = uploadFilesToProjectInGCS;
128
+ const downloadFilesFromProjectInGCS = (projectId, files) => __awaiter(void 0, void 0, void 0, function* () {
129
+ const limit = (0, p_limit_1.default)(UPLOAD_CONCURRENCY);
130
+ const downloadedFilePaths = yield Promise.all(files.map(({ localFilePath, gcsPath }) => limit(() => __awaiter(void 0, void 0, void 0, function* () {
131
+ const gcFilePath = `projects/${projectId}/${gcsPath}`;
132
+ const gcFile = gc_storage_1.default.file(gcFilePath);
133
+ const [fileExists] = yield gcFile.exists();
134
+ if (!fileExists)
135
+ return null;
136
+ yield gcFile.download({ destination: localFilePath });
137
+ return localFilePath;
138
+ }))));
139
+ return downloadedFilePaths.filter((filePath) => filePath !== null);
140
+ });
141
+ exports.downloadFilesFromProjectInGCS = downloadFilesFromProjectInGCS;
142
+ const getCompanyLogo = (companyId) => __awaiter(void 0, void 0, void 0, function* () {
143
+ const logoPath = `companies/${companyId}.png`;
144
+ const gcFile = gc_storage_1.default.file(logoPath);
145
+ const [fileExists] = yield gcFile.exists();
146
+ if (!fileExists)
147
+ return null;
148
+ return gcFile;
149
+ });
150
+ exports.getCompanyLogo = getCompanyLogo;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rowengine/common",
3
- "version": "1.1.16",
3
+ "version": "1.1.18",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "private": false,