@social-mail/social-mail-web-server 1.8.473 → 1.8.474

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.473",
3
+ "version": "1.8.474",
4
4
  "description": "## Phase 1",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1,22 +1,30 @@
1
1
  /* eslint-disable no-console */
2
- import Inject, { RegisterSingleton } from "@entity-access/entity-access/dist/di/di.js";
2
+ import Inject, { RegisterScoped } from "@entity-access/entity-access/dist/di/di.js";
3
3
  import { fetch } from "undici";
4
4
  import { hash } from "crypto";
5
5
  import { globalEnv } from "../../../common/globalEnv.js";
6
6
  import LockFile from "../../storage/LockFile.js";
7
7
  import SiteDiskContentCache from "../files/SiteDiskContentCache.js";
8
+ import Page from "@entity-access/server-pages/dist/Page.js";
9
+ import AuthorizationService from "@entity-access/server-pages/dist/services/AuthorizationService.js";
8
10
 
9
11
  let port = globalEnv.puppeteer.port as any;
10
12
  if (/^\d+$/i.test(port)) {
11
13
  port = Number(port);
12
14
  }
13
15
 
14
- @RegisterSingleton
16
+ @RegisterScoped
15
17
  export default class PuppeteerService {
16
18
 
17
19
  @Inject
18
20
  siteCache: SiteDiskContentCache;
19
21
 
22
+ @Inject
23
+ page: Page;
24
+
25
+ @Inject
26
+ authService: AuthorizationService;
27
+
20
28
  async generate({
21
29
  url,
22
30
  mobile = false,
@@ -27,10 +35,15 @@ export default class PuppeteerService {
27
35
  packageHash = globalEnv.serverID,
28
36
  test = "true" as ("true" | "window.pageReady"),
29
37
  testDelay = 1000,
30
- timeout = 15000
38
+ timeout = 15000,
39
+ sendCookies = true,
31
40
  }) {
32
41
 
33
- const key = `previews/${packageHash}/${mobile? "mobile" : "desktop"}/preview-${hash("sha256", url, "hex")}.${output}`;
42
+ const u = new URL(url);
43
+
44
+ const cookies = sendCookies ? this.getCookies(u.hostname) : "";
45
+
46
+ const key = `previews/${packageHash}/${mobile? "mobile" : "desktop"}/preview-${hash("sha256", url + "&cookies=" + cookies, "hex")}.${output}`;
34
47
 
35
48
  const file = await this.siteCache.htmlCache.getOrCreateAsync(key, async (lf) => {
36
49
 
@@ -45,6 +58,7 @@ export default class PuppeteerService {
45
58
  test,
46
59
  testDelay: testDelay as any,
47
60
  timeout: timeout as any,
61
+ cookies,
48
62
  output
49
63
  });
50
64
 
@@ -82,4 +96,12 @@ export default class PuppeteerService {
82
96
 
83
97
  }
84
98
 
99
+ getCookies(domain): string {
100
+ const cookies = this.page?.request.cookies;
101
+ if (!cookies) {
102
+ return void 0;
103
+ }
104
+ return JSON.stringify(Object.entries(cookies).map(([name, value]) => ({ name, value, domain, httpOnly: true, secure: true })));
105
+ }
106
+
85
107
  }