|
@@ -15,6 +15,109 @@ class SummaryFile extends API {
|
|
|
this.setPath("/AI/SummaryFile")
|
|
|
}
|
|
|
|
|
|
+ // 定义支持的语言后缀
|
|
|
+ languageExtensions = {
|
|
|
+ "JavaScript": [".js", ".jsx", ".mjs", ".cjs"],
|
|
|
+ "TypeScript": [".ts", ".tsx"],
|
|
|
+ "Python": [".py"],
|
|
|
+ "Java": [".java"],
|
|
|
+ "C": [".c"],
|
|
|
+ "C++": [".cpp", ".cc", ".cxx", ".h", ".hpp"],
|
|
|
+ "C#": [".cs"],
|
|
|
+ "Go": [".go"],
|
|
|
+ "PHP": [".php"],
|
|
|
+ "HTML": [".html", ".htm"],
|
|
|
+ "CSS": [".css"],
|
|
|
+ "SCSS": [".scss", ".sass"],
|
|
|
+ "JSON": [".json"],
|
|
|
+ "YAML": [".yml", ".yaml"],
|
|
|
+ "Markdown": [".md"],
|
|
|
+ "Shell": [".sh"],
|
|
|
+ "Bash": [".bash"],
|
|
|
+ "PowerShell": [".ps1"],
|
|
|
+ "Ruby": [".rb"],
|
|
|
+ "Vue": [".vue"], // Vue文件
|
|
|
+ "LESS": [".less"], // LESS样式文件
|
|
|
+ "Sass": [".sass"], // Sass文件
|
|
|
+ "Haml": [".haml"], // Haml文件
|
|
|
+ "Elixir": [".ex", ".exs"], // Elixir语言文件
|
|
|
+ "Erlang": [".erl", ".hrl"], // Erlang语言文件
|
|
|
+ "Swift": [".swift"], // Swift语言文件
|
|
|
+ "Kotlin": [".kt", ".kts"], // Kotlin语言文件
|
|
|
+ "Rust": [".rs"], // Rust语言文件
|
|
|
+ "Dart": [".dart"], // Dart语言文件
|
|
|
+ "Lua": [".lua"], // Lua语言文件
|
|
|
+ "R": [".r"], // R语言文件
|
|
|
+ "Perl": [".pl"], // Perl语言文件
|
|
|
+ "SQL": [".sql"], // SQL文件
|
|
|
+ "Dockerfile": [".dockerfile", "Dockerfile"], // Dockerfile
|
|
|
+ "GraphQL": [".graphql", ".gql"], // GraphQL文件
|
|
|
+ "JSON5": [".json5"], // JSON5文件
|
|
|
+ "TOML": [".toml"], // TOML文件
|
|
|
+ "Text": [".txt", ".text"],
|
|
|
+ "Assembly": [".asm", ".s"],
|
|
|
+ "Objective-C": [".m", ".mm"],
|
|
|
+ "F#": [".fs", ".fsi", ".fsx", ".fsscript"],
|
|
|
+ "Haskell": [".hs", ".lhs"],
|
|
|
+ "OCaml": [".ml", ".mli"],
|
|
|
+ "Nim": [".nim", ".nims"],
|
|
|
+ "Julia": [".jl"],
|
|
|
+ "Fortran": [".f", ".for", ".f90", ".f95"],
|
|
|
+ "COBOL": [".cbl", ".cob"],
|
|
|
+ "VHDL": [".vhd", ".vhdl"],
|
|
|
+ "Verilog": [".v", ".vh"],
|
|
|
+ "Ada": [".adb", ".ads"],
|
|
|
+ "Matlab": [".m"], // 注意 Objective-C 也使用 .m,可根据上下文判断
|
|
|
+ "Scala": [".scala"],
|
|
|
+ "VB.NET": [".vb"],
|
|
|
+ "Groovy": [".groovy", ".gvy", ".gy", ".gsh"],
|
|
|
+ "Makefile": ["Makefile", "makefile", ".mk"],
|
|
|
+ "Clojure": [".clj", ".cljs", ".cljc", ".edn"],
|
|
|
+ "Common Lisp": [".lisp", ".lsp"],
|
|
|
+ "Scheme": [".scm", ".ss"],
|
|
|
+ "Prolog": [".pl", ".pro", ".P"],
|
|
|
+ "Smalltalk": [".st", ".squeak"],
|
|
|
+ "Tcl": [".tcl"],
|
|
|
+ "Crystal": [".cr"],
|
|
|
+ "Solidity": [".sol"],
|
|
|
+ "Vim script": [".vim"],
|
|
|
+ "ReScript": [".res", ".resi"],
|
|
|
+ "ReasonML": [".re", ".rei"],
|
|
|
+ "Pug": [".pug", ".jade"],
|
|
|
+ "Handlebars": [".hbs", ".handlebars"],
|
|
|
+ "XML": [".xml"],
|
|
|
+ "INI": [".ini", ".cfg", ".conf"],
|
|
|
+ "Log": [".log"],
|
|
|
+ "ENV": [".env"],
|
|
|
+ "ReStructuredText": [".rst"],
|
|
|
+ "AsciiDoc": [".adoc", ".asciidoc"],
|
|
|
+ "Racket": [".rkt"],
|
|
|
+ "Zig": [".zig"],
|
|
|
+ "Haxe": [".hx"],
|
|
|
+ "Dotenv": [".env"],
|
|
|
+ "Config": [".config"],
|
|
|
+ "PlantUML": [".puml", ".plantuml"],
|
|
|
+ "Visual Basic": [".bas", ".vbs"],
|
|
|
+ "Batch": [".bat", ".cmd"],
|
|
|
+ "BibTeX": [".bib"],
|
|
|
+ "TeX/LaTeX": [".tex", ".ltx", ".sty", ".cls"],
|
|
|
+ "Apache": [".htaccess", "httpd.conf"],
|
|
|
+ "NGINX": ["nginx.conf"],
|
|
|
+ "Terraform": [".tf", ".tfvars"],
|
|
|
+ "HCL": [".hcl"],
|
|
|
+ "QML": [".qml"],
|
|
|
+ "Cue": [".cue"],
|
|
|
+ "GDScript": [".gd"], // 用于 Godot 引擎
|
|
|
+ "ANTLR": [".g4"],
|
|
|
+ "Pascal": [".pas"],
|
|
|
+ "Logtalk": [".lgt"],
|
|
|
+ "Awk": [".awk"],
|
|
|
+ "Sed": [".sed"],
|
|
|
+ "ConfigScript": [".conf", ".cfg"],
|
|
|
+ "YANG": [".yang"],
|
|
|
+ "NetLogo": [".nlogo"]
|
|
|
+ }
|
|
|
+
|
|
|
isBinaryFile(filePath) {
|
|
|
try {
|
|
|
return isBinaryFileSync(filePath)
|
|
@@ -37,6 +140,16 @@ class SummaryFile extends API {
|
|
|
...BaseStdResponse.ACCESS_DENIED
|
|
|
})
|
|
|
|
|
|
+ const ext = path.extname(filePath).toLowerCase()
|
|
|
+ const language = Object.keys(this.languageExtensions).find(lang =>
|
|
|
+ this.languageExtensions[lang].includes(ext)
|
|
|
+ )
|
|
|
+ if (!language)
|
|
|
+ return res.json({
|
|
|
+ ...BaseStdResponse.ERR,
|
|
|
+ msg: '该文件类型不支持AI分析!'
|
|
|
+ })
|
|
|
+
|
|
|
let sql = 'SELECT state, path, url FROM repos WHERE create_user = ? AND id = ?'
|
|
|
let rows = await db.query(sql, [uuid, id])
|
|
|
if (!rows || rows.length === 0)
|
|
@@ -54,7 +167,7 @@ class SummaryFile extends API {
|
|
|
try {
|
|
|
filePath = path.join(rows[0].path, filePath)
|
|
|
|
|
|
- if(this.isBinaryFile(filePath))
|
|
|
+ if (this.isBinaryFile(filePath))
|
|
|
return res.json({
|
|
|
...BaseStdResponse.ERR,
|
|
|
msg: '该文件类型不支持AI总结!'
|