@social-mail/social-mail-web-server 1.7.199 → 1.7.201

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.7.199",
3
+ "version": "1.7.201",
4
4
  "description": "## Phase 1",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -18,23 +18,27 @@ export default class BaseDiskCache {
18
18
  protected readonly keepTTLSeconds: number;
19
19
  protected readonly minSize: number;
20
20
  protected readonly updateAccessTime: boolean;
21
+ protected readonly maxAge: number;
21
22
  constructor(
22
23
  {
23
24
  root,
24
25
  keepTTLSeconds = 3600,
25
26
  minSize = Number.MAX_SAFE_INTEGER,
26
- updateAccessTime = true
27
+ updateAccessTime = true,
28
+ maxAge = 1
27
29
  }: {
28
30
  root: string;
29
31
  keepTTLSeconds?: number;
30
32
  minSize?: number;
31
33
  updateAccessTime?: boolean;
34
+ maxAge?: number;
32
35
  }
33
36
  ) {
34
37
  this.root = root;
35
38
  this.keepTTLSeconds = keepTTLSeconds;
36
39
  this.minSize = minSize;
37
40
  this.updateAccessTime = updateAccessTime;
41
+ this.maxAge = maxAge;
38
42
  ensureDir(root);
39
43
  // eslint-disable-next-line no-console
40
44
  setTimeout(() => this.clean().catch(console.error), 1000);
@@ -130,13 +134,13 @@ export default class BaseDiskCache {
130
134
 
131
135
  let total = 0;
132
136
 
133
- for(let i=7;i>0;i--) {
137
+ for(let i=this.maxAge;i>0;i--) {
134
138
  const s = await fsp.statfs(this.root);
135
139
  const freeSize = s.bavail * s.bsize;
136
140
 
137
141
  if (freeSize < this.minSize) {
138
142
  try {
139
- const keep = Date.now() - this.keepTTLSeconds * i;
143
+ const keep = Date.now() - this.keepTTLSeconds * 1000 * i;
140
144
  const files = await this.getFilesToDelete(keep);
141
145
 
142
146
  for (const file of files) {
@@ -7,23 +7,20 @@ import SocialMailContext from "../SocialMailContext.js";
7
7
  import EmailAddressService from "../../services/EmailAddressService.js";
8
8
  import { ForeignKeyFilter } from "@entity-access/entity-access/dist/model/events/EntityEvents.js";
9
9
  import DateTime from "@entity-access/entity-access/dist/types/DateTime.js";
10
- import { ignoreFK } from "./UserMailboxEvents.js";
11
10
  import WorkflowContext from "@entity-access/entity-access/dist/workflows/WorkflowContext.js";
12
11
  import ExternalQuery from "@entity-access/server-pages/dist/decorators/ExternalQuery.js";
13
12
  import ExternalInvoke from "@entity-access/server-pages/dist/decorators/ExternalInvoke.js";
14
13
  import Sql from "@entity-access/entity-access/dist/sql/Sql.js";
15
14
  import Page from "@entity-access/server-pages/dist/Page.js";
16
- import { Prepare } from "@entity-access/server-pages/dist/decorators/Prepare.js";
17
15
  import EntityAccessError from "@entity-access/entity-access/dist/common/EntityAccessError.js";
18
16
  import SyncMailboxWorkflow from "../../workflows/sync/SyncMailboxWorkflow.js";
19
- import TagService from "../../services/tags/TagService.js";
20
17
  import WebSiteChannelService from "../../smtp/services/WebSiteChannelService.js";
21
18
  import ChannelEmail from "../entities/ChannelEmail.js";
22
19
  import MailboxTag from "../entities/MailboxTag.js";
23
20
  import MailboxContactEvent from "../entities/MailboxContactEvent.js";
24
21
  import ScopeVars from "../../../common/ScopeVars.js";
25
- import SessionSecurity from "@entity-access/server-pages/dist/services/SessionSecurity.js";
26
22
  import MailboxFolderService from "../../services/mailboxes/MailboxFolderService.js";
23
+ import MailService from "../../services/emails/MailService.js";
27
24
 
28
25
  export default class MailboxEvents extends AuthenticatedEvents<Mailbox> {
29
26
 
@@ -218,6 +215,9 @@ export default class MailboxEvents extends AuthenticatedEvents<Mailbox> {
218
215
  }
219
216
 
220
217
  async afterInsert(entity: Mailbox) {
218
+
219
+ const ea = await this.emailAddressService.getEmailAddress(entity.mailboxID);
220
+
221
221
  this.emailAddressService.cache?.clear("getHostedMailbox");
222
222
  this.emailAddressService.cache?.clear("getHostedMailboxID");
223
223
 
@@ -235,6 +235,15 @@ export default class MailboxEvents extends AuthenticatedEvents<Mailbox> {
235
235
  }
236
236
 
237
237
  await this.updateFolders(entity);
238
+ // const ms = ServiceProvider.resolve(this, MailService);
239
+ // await ms.sendNotificationEmail(`welcome-${entity.mailboxID}`, {
240
+ // from: "social@esocialmail.com",
241
+ // fromName: "Social Mail",
242
+ // subject: "Welcome to Social Mail",
243
+ // textBody: "",
244
+ // to: ea.emailAddress,
245
+ // htmlBody: ""
246
+ // });
238
247
  return this.updateIndex(entity);
239
248
  }
240
249
 
@@ -6,7 +6,6 @@ import { link } from "node:fs/promises";
6
6
  import FileSize from "../../../common/FileSize.js";
7
7
  import ensureDir from "../../../common/FileApi.js";
8
8
  import { LocalFile } from "@entity-access/server-pages/dist/core/LocalFile.js";
9
- import { unlinkSync } from "fs";
10
9
  import { randomUUID } from "crypto";
11
10
  import BaseDiskCache from "../../../common/BaseDiskCache.js";
12
11
 
@@ -18,9 +17,6 @@ ensureDir(serverCache);
18
17
  const tempSize = FileSize.parse(globalEnv.tmpSize);
19
18
  const minSize = tempSize / 2;
20
19
 
21
- const doNothing = () => void 0;
22
-
23
-
24
20
  @RegisterSingleton
25
21
  export default class DiskCacheService extends BaseDiskCache {
26
22
 
@@ -28,14 +24,16 @@ export default class DiskCacheService extends BaseDiskCache {
28
24
 
29
25
  constructor() {
30
26
  super({
31
- root: join(cacheRoot),
27
+ root: join(cacheRoot, "fc"),
32
28
  keepTTLSeconds: 86400,
33
- minSize
29
+ minSize,
30
+ maxAge:7
34
31
  });
35
32
 
36
33
  this.tmp = new BaseDiskCache({
37
34
  root: join(cacheRoot, "tmp"),
38
- keepTTLSeconds: 60*60
35
+ keepTTLSeconds: 60*60,
36
+ maxAge: 7
39
37
  });
40
38
  }
41
39
 
@@ -4,16 +4,20 @@ import EntityAccessError from "@entity-access/entity-access/dist/common/EntityAc
4
4
  import ensureDir from "../../../common/FileApi.js";
5
5
  import { spawnPromise } from "../../../common/spawnPromise.js";
6
6
  import TempFileService from "../../storage/TempFileService.js";
7
- import DiskCacheService from "../cache/DiskCacheService.js";
8
- import EncryptionService from "../encryption/EncryptionService.js";
9
7
  import { IVerification } from "./IVerification.js";
10
8
  import SocialMailContext from "../../model/SocialMailContext.js";
11
9
  import { randomUUID } from "crypto";
10
+ import BaseDiskCache from "../../../common/BaseDiskCache.js";
11
+ import { globalEnv } from "../../../common/globalEnv.js";
12
+ import FileSize from "../../../common/FileSize.js";
12
13
 
13
14
  const captchaCache = "/cache/captcha";
14
-
15
15
  ensureDir(captchaCache);
16
16
 
17
+ const tempSize = FileSize.parse(globalEnv.tmpSize);
18
+ const minSize = tempSize / 2;
19
+
20
+
17
21
  const zero = '0'.charCodeAt(0);
18
22
 
19
23
  const filter = "[0]pad=width=750:height=200:x=0:y=0:color=white[v0];"
@@ -30,11 +34,12 @@ const filter = "[0]pad=width=750:height=200:x=0:y=0:color=white[v0];"
30
34
  @RegisterScoped
31
35
  export default class CaptchaService {
32
36
 
33
- @Inject
34
- private diskCache: DiskCacheService;
35
-
36
- @Inject
37
- private encryption: EncryptionService;
37
+ private diskCache: BaseDiskCache = new BaseDiskCache({
38
+ root: captchaCache,
39
+ keepTTLSeconds: 86400,
40
+ minSize,
41
+ maxAge: 7
42
+ }) ;
38
43
 
39
44
  @Inject
40
45
  private db: SocialMailContext;
@@ -76,7 +81,7 @@ export default class CaptchaService {
76
81
  }
77
82
 
78
83
  async getVideo(code: string) {
79
- return this.diskCache.getOrCreateAsync("captcha/" + code + ".gif", (cf) => this.prepareVideo(code, cf.path));
84
+ return this.diskCache.getOrCreateAsync(code + ".gif", (cf) => this.prepareVideo(code, cf.path));
80
85
  }
81
86
 
82
87
  async prepareVideo(code: string, saveAs: string) {
@@ -106,7 +106,7 @@ export default abstract class BaseStorage {
106
106
 
107
107
  async downloadFile({ cloudPath, contentHash, compression}: FileContent) {
108
108
 
109
- return this.diskCache.getOrCreateAsync(path.join("fc", cloudPath), async (cf) => {
109
+ return this.diskCache.getOrCreateAsync(cloudPath, async (cf) => {
110
110
  let { stream } = await this.streamFile(cloudPath);
111
111
  if(compression) {
112
112
  switch(compression) {
@@ -86,7 +86,7 @@ export default class TempFileService {
86
86
  async downloadCloudFile(cloudPath: string, fileName: string, contentType?: string) {
87
87
  try {
88
88
 
89
- const localFile = await this.diskCache.getOrCreateAsync(path.join("fc", cloudPath), async (cf) => {
89
+ const localFile = await this.diskCache.getOrCreateAsync(cloudPath, async (cf) => {
90
90
  const { stream } = await this.storage.streamFile(cloudPath);
91
91
  await cf.writeAll(stream);
92
92
  } );