@@ -117106,7 +117106,7 @@ const Xun$1 = new XunDriver();
117106117106/**
117107117107* 网盘服务模块集合
117108117108* 统一导入和导出各种网盘服务提供商的实现
117109- *
117109+ *
117110117110* 支持的网盘服务:
117111117111* - Ali: 阿里云盘服务
117112117112* - Baidu: 百度网盘服务
@@ -117116,7 +117116,7 @@ const Xun$1 = new XunDriver();
117116117116* - Quark: 夸克网盘服务
117117117117* - UC: UC网盘服务
117118117118* - Yun: 115网盘服务
117119- *
117119+ *
117120117120* @example
117121117121* import pans from './pans.js';
117122117122* const aliPan = new pans.Ali(config);
@@ -383621,6 +383621,52 @@ var FileHeaderManager = class {
383621383621 }
383622383622 };
383623383623 /**
383624+ * Find the @header(...) block in the comment text
383625+ * @param {string} text Comment text
383626+ * @param {string} ext File extension (.js or .py)
383627+ * @returns {Object|null} { start, end, content }
383628+ */
383629+ static findHeaderBlock(text, ext) {
383630+ const startIndex = text.indexOf("@header(");
383631+ if (startIndex === -1) return null;
383632+ let index = startIndex + 8;
383633+ let balance = 1;
383634+ let inString = false;
383635+ let stringChar = "";
383636+ let escape = false;
383637+ let inLineComment = false;
383638+ for (; index < text.length; index++) {
383639+ const char = text[index];
383640+ if (inLineComment) {
383641+ if (char === "\n") inLineComment = false;
383642+ continue;
383643+ }
383644+ if (inString) {
383645+ if (escape) escape = false;
383646+ else if (char === "\\") escape = true;
383647+ else if (char === stringChar) inString = false;
383648+ continue;
383649+ }
383650+ if (char === "/" && text[index + 1] === "/") {
383651+ inLineComment = true;
383652+ index++;
383653+ } else if (ext === ".py" && char === "#") inLineComment = true;
383654+ else if (char === "\"" || char === "'") {
383655+ inString = true;
383656+ stringChar = char;
383657+ } else if (char === "(") balance++;
383658+ else if (char === ")") {
383659+ balance--;
383660+ if (balance === 0) return {
383661+ start: startIndex,
383662+ end: index + 1,
383663+ content: text.substring(startIndex + 8, index)
383664+ };
383665+ }
383666+ }
383667+ return null;
383668+ }
383669+ /**
383624383670 * 解析JavaScript对象字面量(支持无引号属性名)
383625383671 * @param {string} str 对象字符串
383626383672 * @returns {Object} 解析后的对象
@@ -383649,10 +383695,10 @@ var FileHeaderManager = class {
383649383695 if (!config) throw new Error(`Unsupported file type: ${ext}`);
383650383696 const match = content.match(config.regex);
383651383697 if (!match) return null;
383652- const headerMatch = match[0].match(config.headerRegex );
383653- if (!headerMatch ) return null;
383698+ const headerBlock = this.findHeaderBlock( match[0], ext );
383699+ if (!headerBlock ) return null;
383654383700 try {
383655- return this.parseObjectLiteral(headerMatch[1] .trim());
383701+ return this.parseObjectLiteral(headerBlock.content .trim());
383656383702 } catch {
383657383703 return null;
383658383704 }
@@ -383715,12 +383761,15 @@ var FileHeaderManager = class {
383715383761 const commentStartIndex = content.indexOf(fullComment);
383716383762 const commentEndIndex = commentStartIndex + fullComment.length;
383717383763 if (content.substring(0, commentStartIndex).trim() !== "") newContent = config.createComment(headerStr) + "\n\n" + content;
383718- else if (config.headerRegex.test(fullComment)) {
383719- const updatedComment = fullComment.replace(config.headerRegex, headerStr);
383720- newContent = content.substring(0, commentStartIndex) + updatedComment + content.substring(commentEndIndex);
383721- } else {
383722- const updatedComment = fullComment.replace(config.end, "").trim() + `\n${headerStr}\n${config.end}`;
383723- newContent = content.substring(0, commentStartIndex) + updatedComment + content.substring(commentEndIndex);
383764+ else {
383765+ const headerBlock = this.findHeaderBlock(fullComment, ext);
383766+ if (headerBlock) {
383767+ const updatedComment = fullComment.substring(0, headerBlock.start) + headerStr + fullComment.substring(headerBlock.end);
383768+ newContent = content.substring(0, commentStartIndex) + updatedComment + content.substring(commentEndIndex);
383769+ } else {
383770+ const updatedComment = fullComment.replace(config.end, "").trim() + `\n${headerStr}\n${config.end}`;
383771+ newContent = content.substring(0, commentStartIndex) + updatedComment + content.substring(commentEndIndex);
383772+ }
383724383773 }
383725383774 } else newContent = config.createComment(headerStr) + "\n\n" + content;
383726383775 if (!newContent.replace(config.regex, "").trim()) throw new Error("写入失败:内容不能只包含文件头而无原始内容");
@@ -383788,13 +383837,13 @@ var FileHeaderManager = class {
383788383837 }
383789383838 const match = content.match(config.regex);
383790383839 if (!match) return content.trim();
383791- let [fullComment, innerContent ] = match;
383792- if (config.headerRegex.test(innerContent)) {
383793- innerContent = innerContent.replace(config.headerRegex, "");
383794- const cleanedInner = innerContent .split("\n").filter((line) => line.trim().length > 0).join("\n");
383840+ let [fullComment] = match;
383841+ const headerBlock = this.findHeaderBlock(fullComment, ext);
383842+ if (headerBlock) {
383843+ let cleanedInner = (fullComment.substring(0, headerBlock.start) + fullComment.substring(headerBlock.end)).replace(config.start, "").replace(config.end, "") .split("\n").filter((line) => line.trim().length > 0).join("\n");
383795383844 if (!cleanedInner.trim()) content = content.replace(fullComment, "");
383796383845 else {
383797- const newComment = `${config.start}${cleanedInner}${config.end}`;
383846+ const newComment = `${config.start}\n ${cleanedInner}\n ${config.end}`;
383798383847 content = content.replace(fullComment, newComment);
383799383848 }
383800383849 }
0 commit comments