@social-mail/social-mail-web-server 1.8.49 → 1.8.50

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@social-mail/social-mail-web-server",
3
- "version": "1.8.49",
3
+ "version": "1.8.50",
4
4
  "description": "## Phase 1",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-console */
1
2
  import Workflow, { UniqueActivity } from "@entity-access/entity-access/dist/workflows/Workflow.js";
2
3
  import Inject, { ServiceProvider } from "@entity-access/entity-access/dist/di/di.js";
3
4
  import SocialMailContext from "../../model/SocialMailContext.js";
@@ -13,6 +14,7 @@ import { Extract } from "../../services/extract/Extract.js";
13
14
  import { AppWorkflowContext } from "../AppWorkflowContext.js";
14
15
  import { appendFile } from "fs/promises";
15
16
  import BufferHelper from "../../../common/BufferHelper.js";
17
+ import sleep from "../../../common/sleep.js";
16
18
 
17
19
  export default class IndexAppFilesWorkflow extends Workflow {
18
20
 
@@ -110,6 +112,8 @@ export default class IndexAppFilesWorkflow extends Workflow {
110
112
 
111
113
  private async saveTextContent(appFile: AppFile, tempFileService: TempFileService, db: SocialMailContext) {
112
114
 
115
+ let searchable = "";
116
+
113
117
  // check if file content already has text content to remove duplicates
114
118
  const has = await db.textDocuments.statements.select({}, { textDocumentID: appFile.fileContentID });
115
119
  if(has) {
@@ -121,23 +125,35 @@ export default class IndexAppFilesWorkflow extends Workflow {
121
125
  fileContentID: appFile.fileContentID
122
126
  };
123
127
 
124
- const file = await tempFileService.downloadAppFile(appFile);
128
+ let file: LocalFile = null;
129
+
130
+ for(let i=0;i<3;i++) {
131
+ try {
132
+ file = await tempFileService.downloadAppFile(appFile);
133
+ break;
134
+ } catch (error) {
135
+ // this should not happen...
136
+ console.error(error);
137
+ searchable = "";
138
+ await sleep(1000);
139
+ }
140
+ }
125
141
 
126
- const fx = await this.extractText(file, tempFileService, db);
142
+ if (file) {
143
+ const fx = await this.extractText(file, tempFileService, db);
127
144
 
128
- let searchable = "";
145
+ if (fx.contentSize < 10*1024*1024) {
129
146
 
130
- if (fx.contentSize < 10*1024*1024) {
147
+ // we need to first remove 00 byte sequence...
148
+ const newFile = await tempFileService.createTempFile("txt");
149
+ const empty = Buffer.from("\n");
150
+ for await (const buffer of fx.readBuffers()) {
151
+ BufferHelper.replace00(buffer, empty);
152
+ await appendFile(newFile.path, buffer);
153
+ }
131
154
 
132
- // we need to first remove 00 byte sequence...
133
- const newFile = await tempFileService.createTempFile("txt");
134
- const empty = Buffer.from("\n");
135
- for await (const buffer of fx.readBuffers()) {
136
- BufferHelper.replace00(buffer, empty);
137
- await appendFile(newFile.path, buffer);
155
+ searchable = await newFile.readAsText();
138
156
  }
139
-
140
- searchable = await newFile.readAsText();
141
157
  }
142
158
 
143
159
  const td = await db.textDocuments.statements.upsert({