@social-mail/social-mail-web-server 1.5.26 → 1.5.28

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.5.26",
3
+ "version": "1.5.28",
4
4
  "description": "## Phase 1",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -190,11 +190,11 @@ export default class TempFileService {
190
190
  const fileInfo = path.parse(fileName);
191
191
  const tf = await this.createTempFile(fileInfo.ext, fileName, contentType);
192
192
  // this should save some space...
193
- if (existsSync(tf.path)) {
194
- await fsp.unlink(tf.path);
195
- }
196
- await fsp.link(typeof src === "string" ? src : src.path, tf.path);
197
- // await fsp.writeFile(tf.path, content);
193
+ // if (existsSync(tf.path)) {
194
+ // await fsp.unlink(tf.path);
195
+ // }
196
+ // await fsp.link(typeof src === "string" ? src : src.path, tf.path);
197
+ await fsp.copyFile(typeof src === "string" ? src : src.path, tf.path);
198
198
  return tf;
199
199
  }
200
200
 
@@ -0,0 +1,41 @@
1
+ import Inject from "@entity-access/entity-access/dist/di/di.js";
2
+ import Workflow, { UniqueActivity } from "@entity-access/entity-access/dist/workflows/Workflow.js";
3
+ import SocialMailContext from "../../../model/SocialMailContext.js";
4
+ import BaseStorage from "../../../storage/BaseStorage.js";
5
+
6
+ export default class RepairCacheWorkflow extends Workflow {
7
+
8
+ async run() {
9
+ let start = 0;
10
+
11
+ while(start) {
12
+ start = await this.repair(start);
13
+ }
14
+ }
15
+
16
+ @UniqueActivity
17
+ async repair(start: number,
18
+ @Inject db?: SocialMailContext,
19
+ @Inject storage?: BaseStorage
20
+ ) {
21
+ const files = await db.cachedItems.where({ start }, (p) => (x) => x.itemID > p.start)
22
+ .limit(100)
23
+ .toArray();
24
+ if (!files.length) {
25
+ return 0;
26
+ }
27
+ for (const iterator of files) {
28
+ start = iterator.itemID;
29
+ try {
30
+ await using tx = await db.connection.createTransaction();
31
+ const cloudPath = `cache/${iterator.itemID}`;
32
+ await storage.deleteFile(cloudPath);
33
+ await db.cachedItems.statements.delete(iterator);
34
+ await tx.commit();
35
+ } catch {
36
+ // move to next... and ignore the error...
37
+ }
38
+ }
39
+ return start;
40
+ }
41
+ }