@studyllm/resume-preview 0.0.0-stage → 3.1.0
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/LICENSE +21 -0
- package/README.en.md +318 -0
- package/README.md +313 -2
- package/build/constants.js +217 -0
- package/build/diagram-service.js +143 -0
- package/build/file-utils.js +350 -0
- package/build/handlers.js +172 -0
- package/build/html-utils.js +20 -0
- package/build/i18n.js +198 -0
- package/build/index.js +171 -0
- package/build/live-server.js +488 -0
- package/build/logger.js +92 -0
- package/build/mermaid-cli.js +48 -0
- package/build/page-renderer.js +152 -0
- package/build/preview/favicon.svg +23 -0
- package/build/preview/gallery.css +217 -0
- package/build/preview/gallery.html +59 -0
- package/build/preview/gallery.js +259 -0
- package/build/preview/i18n/en.json +57 -0
- package/build/preview/i18n/zh-CN.json +57 -0
- package/build/preview/i18n.js +125 -0
- package/build/preview/resume-template.html +13 -0
- package/build/preview/resume.css +214 -0
- package/build/preview/resume.js +393 -0
- package/build/preview/shared.css +529 -0
- package/build/resume-renderer.js +486 -0
- package/build/resume-service.js +117 -0
- package/build/routes.js +335 -0
- package/build/serve.js +46 -0
- package/build/types.js +5 -0
- package/package.json +63 -4
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Application-wide constants
|
|
3
|
+
* Centralizes all magic strings and numbers for maintainability
|
|
4
|
+
*/
|
|
5
|
+
// ===== Application Configuration =====
|
|
6
|
+
export const APP_NAME = "resume-preview";
|
|
7
|
+
/**
|
|
8
|
+
* App directory name used before the project was renamed. The data directory
|
|
9
|
+
* is migrated from it once, on startup — see `migrateLegacyAppDir()`.
|
|
10
|
+
*/
|
|
11
|
+
export const LEGACY_APP_NAME = "claude-mermaid";
|
|
12
|
+
// ===== Server Configuration =====
|
|
13
|
+
export const SERVER_PORT_START = 3737;
|
|
14
|
+
export const SERVER_PORT_END = 3747;
|
|
15
|
+
// Bind to loopback only — this is a local developer tool with no auth,
|
|
16
|
+
// and binding to all interfaces would expose the unauthenticated
|
|
17
|
+
// gallery + resume API to anyone on the LAN.
|
|
18
|
+
export const SERVER_HOST = "127.0.0.1";
|
|
19
|
+
// ===== File Names =====
|
|
20
|
+
export const FILE_NAMES = {
|
|
21
|
+
RESUME_CONTENT: "resume.json",
|
|
22
|
+
RESUME_OPTIONS: "options.json",
|
|
23
|
+
RESUME_HTML: "resume.html",
|
|
24
|
+
RESUME_EXPORT_HTML: "resume.export.html",
|
|
25
|
+
RESUME_PDF: "resume.pdf",
|
|
26
|
+
};
|
|
27
|
+
// ===== Directory Names =====
|
|
28
|
+
export const DIR_NAMES = {
|
|
29
|
+
LOGS: "logs",
|
|
30
|
+
PREVIEW: "preview",
|
|
31
|
+
RESUMES: "resumes",
|
|
32
|
+
};
|
|
33
|
+
// ===== Template Files =====
|
|
34
|
+
export const TEMPLATE_FILES = {
|
|
35
|
+
GALLERY: "gallery.html",
|
|
36
|
+
RESUME_TEMPLATE: "resume-template.html",
|
|
37
|
+
};
|
|
38
|
+
// ===== Static Asset Files =====
|
|
39
|
+
export const ASSET_FILES = {
|
|
40
|
+
SHARED_STYLE: "shared.css",
|
|
41
|
+
GALLERY_STYLE: "gallery.css",
|
|
42
|
+
GALLERY_SCRIPT: "gallery.js",
|
|
43
|
+
RESUME_STYLE: "resume.css",
|
|
44
|
+
RESUME_SCRIPT: "resume.js",
|
|
45
|
+
I18N_SCRIPT: "i18n.js",
|
|
46
|
+
FAVICON: "favicon.svg",
|
|
47
|
+
};
|
|
48
|
+
// ===== Internationalization =====
|
|
49
|
+
// Two independent locale axes: the UI language (chrome, toolbars, dialogs)
|
|
50
|
+
// and the resume language (section headings, exported documents). They are
|
|
51
|
+
// deliberately separate so an exported PDF never depends on the browser's
|
|
52
|
+
// Accept-Language header.
|
|
53
|
+
export const SUPPORTED_LOCALES = ["zh-CN", "en"];
|
|
54
|
+
/** Language of the page chrome. Resolved per request (query > header > default). */
|
|
55
|
+
export const DEFAULT_UI_LOCALE = "zh-CN";
|
|
56
|
+
/** Language of the resume itself. Stored per resume in options.json. */
|
|
57
|
+
export const DEFAULT_RESUME_LOCALE = "zh-CN";
|
|
58
|
+
/** Locale used when a key is missing from the requested language. */
|
|
59
|
+
export const FALLBACK_LOCALE = "en";
|
|
60
|
+
/**
|
|
61
|
+
* Dictionary key holding the native name of each locale. Used to label the
|
|
62
|
+
* language switcher, so a switcher can name every supported language in the
|
|
63
|
+
* language it names.
|
|
64
|
+
*/
|
|
65
|
+
export const LOCALE_LABEL_KEYS = {
|
|
66
|
+
"zh-CN": "common.langZh",
|
|
67
|
+
en: "common.langEn",
|
|
68
|
+
};
|
|
69
|
+
/** Directory inside the preview assets that holds the locale dictionaries. */
|
|
70
|
+
export const I18N_DIR = "i18n";
|
|
71
|
+
/** Suffix of a served dictionary file. */
|
|
72
|
+
export const I18N_FILE_SUFFIX = ".json";
|
|
73
|
+
// ===== HTTP Routes =====
|
|
74
|
+
export const ROUTES = {
|
|
75
|
+
ROOT: "/",
|
|
76
|
+
GALLERY: "/",
|
|
77
|
+
FAVICON_SVG: "/favicon.svg",
|
|
78
|
+
FAVICON_ICO: "/favicon.ico",
|
|
79
|
+
SHARED_STYLE: "/shared.css",
|
|
80
|
+
GALLERY_STYLE: "/gallery.css",
|
|
81
|
+
GALLERY_SCRIPT: "/gallery.js",
|
|
82
|
+
I18N_SCRIPT: "/i18n.js",
|
|
83
|
+
};
|
|
84
|
+
// ===== Resume Routes =====
|
|
85
|
+
// Matching is a sequential prefix scan, so the more specific prefixes
|
|
86
|
+
// (EXPORT / VIEW) must be tested before the generic LIVE prefix.
|
|
87
|
+
export const RESUME_ROUTES = {
|
|
88
|
+
API: "/api/resumes",
|
|
89
|
+
API_ITEM: "/api/resumes/", // + :id
|
|
90
|
+
LIVE: "/resume/",
|
|
91
|
+
VIEW: "/resume/view/",
|
|
92
|
+
EXPORT: "/resume/export/",
|
|
93
|
+
STYLE: "/resume.css",
|
|
94
|
+
SCRIPT: "/resume.js",
|
|
95
|
+
};
|
|
96
|
+
// ===== i18n Routes =====
|
|
97
|
+
export const I18N_ROUTES = {
|
|
98
|
+
/** + :locale.json — serves a locale dictionary. The locale is whitelisted. */
|
|
99
|
+
DICTIONARY: "/i18n/",
|
|
100
|
+
};
|
|
101
|
+
// ===== HTTP Headers =====
|
|
102
|
+
export const CONTENT_TYPES = {
|
|
103
|
+
HTML: "text/html",
|
|
104
|
+
CSS: "text/css",
|
|
105
|
+
JAVASCRIPT: "application/javascript",
|
|
106
|
+
JSON: "application/json",
|
|
107
|
+
SVG: "image/svg+xml",
|
|
108
|
+
PDF: "application/pdf",
|
|
109
|
+
PLAIN: "text/plain",
|
|
110
|
+
};
|
|
111
|
+
export const CACHE_CONTROL = {
|
|
112
|
+
NO_STORE: "no-store",
|
|
113
|
+
PUBLIC_24H: "public, max-age=86400",
|
|
114
|
+
};
|
|
115
|
+
// Content Security Policy
|
|
116
|
+
// - default-src 'none': Deny all by default
|
|
117
|
+
// - script-src 'self': Only allow scripts from same origin
|
|
118
|
+
// - style-src 'self' 'unsafe-inline': Allow CSS from same origin and inline styles
|
|
119
|
+
// - img-src 'self' data: blob:: Allow images from same origin, data URIs, and blob URLs (for PNG export)
|
|
120
|
+
// - connect-src 'self' ws://localhost:*: Allow WebSocket connections
|
|
121
|
+
export const CSP_HEADER = "default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; connect-src 'self' ws://localhost:*";
|
|
122
|
+
// ===== Validation Patterns =====
|
|
123
|
+
export const PREVIEW_ID_REGEX = /^[a-zA-Z0-9_-]+$/;
|
|
124
|
+
// ===== CJK Characters =====
|
|
125
|
+
// Characters a generic sans-serif cannot render: they need a CJK-capable font
|
|
126
|
+
// (Microsoft YaHei, Noto Sans CJK SC, ...) or they come out as tofu boxes.
|
|
127
|
+
// Covers Han ideographs, kana, hangul, CJK punctuation and fullwidth forms.
|
|
128
|
+
//
|
|
129
|
+
// Two boundaries are deliberate:
|
|
130
|
+
// - the CJK ideographic comma (U+3001) lives in the punctuation block, not
|
|
131
|
+
// with the Han characters — a Han-only range would miss it;
|
|
132
|
+
// - General Punctuation (U+2000–U+206F) is **excluded**: the renderer joins
|
|
133
|
+
// start/end dates with an EN DASH (U+2013), which nearly every dated
|
|
134
|
+
// experience carries, so including it would block every English resume.
|
|
135
|
+
//
|
|
136
|
+
// No `g` flag on purpose: `RegExp.test` keeps `lastIndex` under `g`, so the
|
|
137
|
+
// same input would alternate between true and false.
|
|
138
|
+
export const CJK_CHAR_REGEX = /[⺀- -〿-ヿ㐀-䶿一-鿿가-豈--]/;
|
|
139
|
+
/**
|
|
140
|
+
* Locales whose exported document always contains CJK characters, whatever the
|
|
141
|
+
* content says: their section headings, document title and placeholders are
|
|
142
|
+
* Chinese. These always need a CJK font. Every other locale is judged from the
|
|
143
|
+
* document's own characters.
|
|
144
|
+
*/
|
|
145
|
+
export const CJK_ALWAYS_LOCALES = ["zh-CN"];
|
|
146
|
+
// ===== System Paths (Security) =====
|
|
147
|
+
export const UNIX_SYSTEM_PATHS = [
|
|
148
|
+
"/etc",
|
|
149
|
+
"/bin",
|
|
150
|
+
"/sbin",
|
|
151
|
+
"/usr/bin",
|
|
152
|
+
"/usr/sbin",
|
|
153
|
+
"/boot",
|
|
154
|
+
"/sys",
|
|
155
|
+
"/proc",
|
|
156
|
+
];
|
|
157
|
+
export const WINDOWS_SYSTEM_PATHS = ["C:\\Windows", "C:\\Program Files"];
|
|
158
|
+
// ===== WebSocket Messages =====
|
|
159
|
+
export const WS_MESSAGES = {
|
|
160
|
+
RELOAD: "reload",
|
|
161
|
+
};
|
|
162
|
+
// ===== Template Placeholders =====
|
|
163
|
+
export const TEMPLATE_VARS = {
|
|
164
|
+
CONTENT: "{{CONTENT}}",
|
|
165
|
+
NAV: "{{NAV}}",
|
|
166
|
+
FOOTER: "{{FOOTER}}",
|
|
167
|
+
RESUME_ID: "{{RESUME_ID}}",
|
|
168
|
+
PORT: "{{PORT}}",
|
|
169
|
+
LIVE_ENABLED: "{{LIVE_ENABLED}}",
|
|
170
|
+
PAGE_TITLE: "{{PAGE_TITLE}}",
|
|
171
|
+
PAGE_SCRIPTS: "{{PAGE_SCRIPTS}}",
|
|
172
|
+
PAGE_STYLES: "{{PAGE_STYLES}}",
|
|
173
|
+
PAGE_HEAD: "{{PAGE_HEAD}}",
|
|
174
|
+
PAGE_SHELL: "{{PAGE_SHELL}}",
|
|
175
|
+
BODY_ATTRIBUTES: "{{BODY_ATTRIBUTES}}",
|
|
176
|
+
LANG: "{{LANG}}",
|
|
177
|
+
LANG_SWITCH: "{{LANG_SWITCH}}",
|
|
178
|
+
I18N_SCRIPT: "{{I18N_SCRIPT}}",
|
|
179
|
+
};
|
|
180
|
+
// ===== Resume Options =====
|
|
181
|
+
/**
|
|
182
|
+
* Templates and themes only list what is actually implemented. Adding a
|
|
183
|
+
* template means adding its id here plus the matching resource file — the
|
|
184
|
+
* validation layer and the rendering path already exist.
|
|
185
|
+
*/
|
|
186
|
+
export const RESUME_TEMPLATES = ["default"];
|
|
187
|
+
export const RESUME_THEMES = ["default"];
|
|
188
|
+
export const RESUME_FORMATS = ["pdf", "html"];
|
|
189
|
+
export const DEFAULT_RESUME_TEMPLATE = "default";
|
|
190
|
+
export const DEFAULT_RESUME_THEME = "default";
|
|
191
|
+
export const DEFAULT_RESUME_FORMAT = "pdf";
|
|
192
|
+
// ===== Resume Limits =====
|
|
193
|
+
/** Version stamped into resume.json so future content-model changes can migrate. */
|
|
194
|
+
export const RESUME_CONTENT_VERSION = 1;
|
|
195
|
+
/** Upper bound for the resume content accepted by the MCP tool (1 MB). */
|
|
196
|
+
export const RESUME_MAX_CONTENT_BYTES = 1024 * 1024;
|
|
197
|
+
/** Length of the hash suffix appended to a slugified resume id. */
|
|
198
|
+
export const RESUME_SLUG_HASH_LENGTH = 6;
|
|
199
|
+
/**
|
|
200
|
+
* Font files that provide CJK coverage. Checked before rendering a document
|
|
201
|
+
* that contains CJK characters, so a missing Chinese font fails loudly
|
|
202
|
+
* instead of producing tofu boxes.
|
|
203
|
+
*/
|
|
204
|
+
export const CJK_FONT_FILES = [
|
|
205
|
+
"msyh.ttc",
|
|
206
|
+
"msyh.ttf",
|
|
207
|
+
"msyhl.ttc",
|
|
208
|
+
"simsun.ttc",
|
|
209
|
+
"simhei.ttf",
|
|
210
|
+
"Deng.ttf",
|
|
211
|
+
];
|
|
212
|
+
// ===== Resume Storage =====
|
|
213
|
+
/** Namespace prefixes for live-server session keys. */
|
|
214
|
+
export const SESSION_NAMESPACES = {
|
|
215
|
+
RESUME: "resume",
|
|
216
|
+
};
|
|
217
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diagram Service
|
|
3
|
+
* Single Responsibility: Business logic for diagram data access and management
|
|
4
|
+
*/
|
|
5
|
+
import { readdir, stat } from "fs/promises";
|
|
6
|
+
import { getLiveDir, validatePreviewId, getDiagramFilePath, deleteDiagram as deleteDiagramFiles, } from "./file-utils.js";
|
|
7
|
+
import { DIAGRAM_FORMATS } from "./constants.js";
|
|
8
|
+
import { webLogger } from "./logger.js";
|
|
9
|
+
/**
|
|
10
|
+
* Lists all diagrams in the live directory
|
|
11
|
+
* @returns Array of diagram info sorted by modification time (newest first)
|
|
12
|
+
*/
|
|
13
|
+
export async function listDiagrams() {
|
|
14
|
+
try {
|
|
15
|
+
const liveDir = getLiveDir();
|
|
16
|
+
const entries = await readdir(liveDir, { withFileTypes: true });
|
|
17
|
+
const diagrams = [];
|
|
18
|
+
for (const entry of entries) {
|
|
19
|
+
if (!entry.isDirectory()) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
// Validate the directory name is a valid preview ID
|
|
24
|
+
validatePreviewId(entry.name);
|
|
25
|
+
const info = await getDiagramInfo(entry.name);
|
|
26
|
+
if (info) {
|
|
27
|
+
diagrams.push(info);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
// Skip invalid or inaccessible diagrams
|
|
32
|
+
webLogger.debug(`Skipping diagram directory: ${entry.name}`, {
|
|
33
|
+
error: error instanceof Error ? error.message : String(error),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// Sort by modification time (newest first)
|
|
38
|
+
diagrams.sort((a, b) => b.modifiedAt.getTime() - a.modifiedAt.getTime());
|
|
39
|
+
webLogger.debug(`Listed ${diagrams.length} diagrams`);
|
|
40
|
+
return diagrams;
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
webLogger.error("Failed to list diagrams", {
|
|
44
|
+
error: error instanceof Error ? error.message : String(error),
|
|
45
|
+
});
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Gets detailed information about a specific diagram
|
|
51
|
+
* @param previewId The diagram ID
|
|
52
|
+
* @returns Diagram info or null if not found
|
|
53
|
+
*/
|
|
54
|
+
export async function getDiagramInfo(previewId) {
|
|
55
|
+
try {
|
|
56
|
+
validatePreviewId(previewId);
|
|
57
|
+
// Try each format to find the diagram
|
|
58
|
+
for (const format of Object.values(DIAGRAM_FORMATS)) {
|
|
59
|
+
try {
|
|
60
|
+
const filePath = getDiagramFilePath(previewId, format);
|
|
61
|
+
const stats = await stat(filePath);
|
|
62
|
+
return {
|
|
63
|
+
id: previewId,
|
|
64
|
+
format,
|
|
65
|
+
modifiedAt: stats.mtime,
|
|
66
|
+
sizeBytes: stats.size,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
// Try next format
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
webLogger.debug(`Diagram not found: ${previewId}`);
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
webLogger.error(`Error getting diagram info: ${previewId}`, {
|
|
79
|
+
error: error instanceof Error ? error.message : String(error),
|
|
80
|
+
});
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Searches diagrams by ID
|
|
86
|
+
* @param query Search query (case-insensitive)
|
|
87
|
+
* @returns Filtered array of diagram info
|
|
88
|
+
*/
|
|
89
|
+
export async function searchDiagrams(query) {
|
|
90
|
+
if (!query || !query.trim()) {
|
|
91
|
+
return listDiagrams();
|
|
92
|
+
}
|
|
93
|
+
const allDiagrams = await listDiagrams();
|
|
94
|
+
const normalizedQuery = query.toLowerCase().trim();
|
|
95
|
+
return allDiagrams.filter((diagram) => diagram.id.toLowerCase().includes(normalizedQuery));
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Checks if a diagram exists
|
|
99
|
+
* @param previewId The diagram ID
|
|
100
|
+
* @returns True if diagram exists
|
|
101
|
+
*/
|
|
102
|
+
export async function diagramExists(previewId) {
|
|
103
|
+
try {
|
|
104
|
+
validatePreviewId(previewId);
|
|
105
|
+
const info = await getDiagramInfo(previewId);
|
|
106
|
+
return info !== null;
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Gets the count of diagrams
|
|
114
|
+
* @returns Total number of diagrams
|
|
115
|
+
*/
|
|
116
|
+
export async function getDiagramCount() {
|
|
117
|
+
const diagrams = await listDiagrams();
|
|
118
|
+
return diagrams.length;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Deletes a diagram and all its associated files
|
|
122
|
+
* @param previewId The diagram ID
|
|
123
|
+
*/
|
|
124
|
+
export async function deleteDiagram(previewId) {
|
|
125
|
+
try {
|
|
126
|
+
validatePreviewId(previewId);
|
|
127
|
+
// Check if diagram exists
|
|
128
|
+
const info = await getDiagramInfo(previewId);
|
|
129
|
+
if (!info) {
|
|
130
|
+
throw new Error(`Diagram not found: ${previewId}`);
|
|
131
|
+
}
|
|
132
|
+
// Delete the diagram
|
|
133
|
+
await deleteDiagramFiles(previewId);
|
|
134
|
+
webLogger.info(`Deleted diagram: ${previewId}`);
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
webLogger.error(`Error deleting diagram: ${previewId}`, {
|
|
138
|
+
error: error instanceof Error ? error.message : String(error),
|
|
139
|
+
});
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=diagram-service.js.map
|