@mdfriday/foundry 25.9.1 → 25.9.2

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/README.md CHANGED
@@ -11,6 +11,13 @@ UNLICENSED - This is a private package for commercial use only. Copyright (c) 20
11
11
  zip -r clean.zip . -x "*/.DS_Store" -x "__MACOSX/*" -x "*/.*"
12
12
 
13
13
  ln -s /Users/weisun/github/mdfriday/foundry/example/ws/bk/content-ob-page /Users/weisun/github/mdfriday/foundry/example/ws/proj/content
14
+ ln -s /Users/weisun/github/mdfriday/foundry/example/ws/bk/content-ob-page-zh /Users/weisun/github/mdfriday/foundry/example/ws/proj/content.zh
15
+ ln -s /Users/weisun/github/mdfriday/foundry/example/ws/bk/content-ob-page-de /Users/weisun/github/mdfriday/foundry/example/ws/proj/content.de
16
+ ln -s /Users/weisun/github/mdfriday/foundry/example/ws/bk/content-ob-page-es /Users/weisun/github/mdfriday/foundry/example/ws/proj/content.es
17
+ ln -s /Users/weisun/github/mdfriday/foundry/example/ws/bk/content-ob-page-fr /Users/weisun/github/mdfriday/foundry/example/ws/proj/content.fr
18
+ ln -s /Users/weisun/github/mdfriday/foundry/example/ws/bk/content-ob-page-ja /Users/weisun/github/mdfriday/foundry/example/ws/proj/content.ja
19
+
20
+
14
21
  ln -s /Users/sunwei/github/mdfriday/foundry/example/ws/bk/content /Users/sunwei/github/mdfriday/foundry/example/ws/proj/content
15
22
  ln -s /Users/sunwei/github/mdfriday/foundry/example/ws/bk/content.zh /Users/sunwei/github/mdfriday/foundry/example/ws/proj/content.zh
16
23
 
@@ -1,13 +1,20 @@
1
1
  /**
2
2
  * HttpClient for fetching remote content via HTTP/HTTPS
3
+ * Uses Node.js http/https modules to avoid CORS issues in Obsidian plugin environment
3
4
  * Focuses solely on HTTP requests and returns string content
4
5
  */
5
6
  export declare class HttpClient {
7
+ private defaultTimeout;
8
+ private defaultHeaders;
6
9
  /**
7
- * Fetch content from a remote URI
10
+ * Fetch content from a remote URI using Node.js http/https modules
8
11
  * @param uri - The URI to fetch content from
12
+ * @param options - Optional request configuration
9
13
  * @returns Promise<string | null> - The fetched content as string or null if failed
10
14
  */
11
- fromRemote(uri: string): Promise<string | null>;
15
+ fromRemote(uri: string, options?: {
16
+ headers?: Record<string, string>;
17
+ timeout?: number;
18
+ }): Promise<string | null>;
12
19
  }
13
20
  //# sourceMappingURL=http.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../../../internal/domain/resources/entity/http.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,qBAAa,UAAU;IACrB;;;;OAIG;IACG,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAqBtD"}
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../../../internal/domain/resources/entity/http.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,cAAc,CAEpB;IAEF;;;;;OAKG;IACG,UAAU,CACd,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE;QACR,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACjC,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,GACA,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAoF1B"}
@@ -1,33 +1,130 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.HttpClient = void 0;
4
37
  const log_1 = require("../../../../pkg/log");
38
+ const http = __importStar(require("http"));
39
+ const https = __importStar(require("https"));
5
40
  const log = (0, log_1.getDomainLogger)('resources', { component: 'http-client' });
6
41
  /**
7
42
  * HttpClient for fetching remote content via HTTP/HTTPS
43
+ * Uses Node.js http/https modules to avoid CORS issues in Obsidian plugin environment
8
44
  * Focuses solely on HTTP requests and returns string content
9
45
  */
10
46
  class HttpClient {
47
+ constructor() {
48
+ this.defaultTimeout = 30000; // 30 seconds
49
+ this.defaultHeaders = {
50
+ 'User-Agent': 'MDFriday-Resources/1.0.0',
51
+ };
52
+ }
11
53
  /**
12
- * Fetch content from a remote URI
54
+ * Fetch content from a remote URI using Node.js http/https modules
13
55
  * @param uri - The URI to fetch content from
56
+ * @param options - Optional request configuration
14
57
  * @returns Promise<string | null> - The fetched content as string or null if failed
15
58
  */
16
- async fromRemote(uri) {
17
- try {
18
- const response = await fetch(uri);
19
- if (!response.ok) {
20
- log.errorf("❌ [HttpClient.fromRemote] HTTP error %d when fetching %s: %s", response.status, uri, response.statusText);
21
- return null;
59
+ async fromRemote(uri, options) {
60
+ return new Promise((resolve) => {
61
+ try {
62
+ // Use new URL constructor to parse the URI
63
+ const parsedUrl = new URL(uri);
64
+ const isHttps = parsedUrl.protocol === 'https:';
65
+ const httpModule = isHttps ? https : http;
66
+ const requestHeaders = {
67
+ ...this.defaultHeaders,
68
+ ...options?.headers,
69
+ };
70
+ const requestOptions = {
71
+ hostname: parsedUrl.hostname,
72
+ port: parsedUrl.port || (isHttps ? 443 : 80),
73
+ path: parsedUrl.pathname + parsedUrl.search,
74
+ method: 'GET',
75
+ headers: requestHeaders,
76
+ timeout: options?.timeout || this.defaultTimeout,
77
+ };
78
+ const request = httpModule.request(requestOptions, (response) => {
79
+ // Handle redirects
80
+ if (response.statusCode && response.statusCode >= 300 && response.statusCode < 400 && response.headers.location) {
81
+ log.infof("🔄 [HttpClient.fromRemote] Redirecting from %s to %s", uri, response.headers.location);
82
+ // Recursively handle redirect
83
+ this.fromRemote(response.headers.location, options).then(resolve);
84
+ return;
85
+ }
86
+ if (!response.statusCode || response.statusCode < 200 || response.statusCode >= 300) {
87
+ log.errorf("❌ [HttpClient.fromRemote] HTTP error %d when fetching %s: %s", response.statusCode || 0, uri, response.statusMessage || 'Unknown error');
88
+ resolve(null);
89
+ return;
90
+ }
91
+ const chunks = [];
92
+ response.on('data', (chunk) => {
93
+ chunks.push(chunk);
94
+ });
95
+ response.on('end', () => {
96
+ try {
97
+ const buffer = Buffer.concat(chunks);
98
+ const content = buffer.toString('utf8');
99
+ log.infof("✅ [HttpClient.fromRemote] Successfully fetched %d bytes from %s", content.length, uri);
100
+ resolve(content);
101
+ }
102
+ catch (error) {
103
+ log.errorf("❌ [HttpClient.fromRemote] Error converting response to string from %s: %s", uri, error);
104
+ resolve(null);
105
+ }
106
+ });
107
+ response.on('error', (error) => {
108
+ log.errorf("❌ [HttpClient.fromRemote] Response error when fetching %s: %s", uri, error.message);
109
+ resolve(null);
110
+ });
111
+ });
112
+ request.on('error', (error) => {
113
+ log.errorf("❌ [HttpClient.fromRemote] Request error when fetching %s: %s", uri, error.message);
114
+ resolve(null);
115
+ });
116
+ request.on('timeout', () => {
117
+ request.destroy();
118
+ log.errorf("❌ [HttpClient.fromRemote] Request timeout when fetching %s", uri);
119
+ resolve(null);
120
+ });
121
+ request.end();
122
+ }
123
+ catch (error) {
124
+ log.errorf("❌ [HttpClient.fromRemote] Error fetching content from %s: %s", uri, error);
125
+ resolve(null);
22
126
  }
23
- const content = await response.text();
24
- log.infof("✅ [HttpClient.fromRemote] Successfully fetched %d bytes from %s", content.length, uri);
25
- return content;
26
- }
27
- catch (error) {
28
- log.errorf("❌ [HttpClient.fromRemote] Error fetching content from %s: %s", uri, error);
29
- return null;
30
- }
127
+ });
31
128
  }
32
129
  }
33
130
  exports.HttpClient = HttpClient;
@@ -1 +1 @@
1
- {"version":3,"file":"http.js","sourceRoot":"","sources":["../../../../../internal/domain/resources/entity/http.ts"],"names":[],"mappings":";;;AAAA,kCAA2C;AAE3C,MAAM,GAAG,GAAG,IAAA,qBAAe,EAAC,WAAW,EAAE,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC,CAAC;AAEvE;;;GAGG;AACH,MAAa,UAAU;IACrB;;;;OAIG;IACH,KAAK,CAAC,UAAU,CAAC,GAAW;QAC1B,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;YAElC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;gBACjB,GAAG,CAAC,MAAM,CAAC,8DAA8D,EACvE,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;gBAC7C,OAAO,IAAI,CAAC;YACd,CAAC;YAED,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YAEtC,GAAG,CAAC,KAAK,CAAC,iEAAiE,EACzE,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;YAEv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;gBAEH,OAAO,CAAC,GAAG,EAAE,CAAC;YAEhB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,GAAG,CAAC,MAAM,CAAC,8DAA8D,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;gBACvF,OAAO,CAAC,IAAI,CAAC,CAAC;YAChB,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAtGD,gCAsGC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdfriday/foundry",
3
- "version": "25.9.1",
3
+ "version": "25.9.2",
4
4
  "description": "The core engine of MDFriday. Convert Markdown and shortcodes into fully themed static sites – Hugo-style, powered by TypeScript.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",