|
@@ -5,6 +5,7 @@ const db = require("../../plugin/DataBase/db")
|
|
|
const axios = require('axios')
|
|
|
const { core_url } = require('../../config.json')
|
|
|
const path = require('path')
|
|
|
+const { isBinaryFileSync } = require('isbinaryfile')
|
|
|
|
|
|
class SummaryFile extends API {
|
|
|
constructor() {
|
|
@@ -14,6 +15,14 @@ class SummaryFile extends API {
|
|
|
this.setPath("/AI/SummaryFile")
|
|
|
}
|
|
|
|
|
|
+ isBinaryFile(filePath) {
|
|
|
+ try {
|
|
|
+ return isBinaryFileSync(filePath)
|
|
|
+ } catch (err) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
async onRequest(req, res) {
|
|
|
let { uuid, session, id, hash, filePath } = req.query
|
|
|
|
|
@@ -43,8 +52,15 @@ class SummaryFile extends API {
|
|
|
})
|
|
|
|
|
|
try {
|
|
|
- const time = new Date().getTime()
|
|
|
filePath = path.join(rows[0].path, filePath)
|
|
|
+
|
|
|
+ if(this.isBinaryFile(filePath))
|
|
|
+ return res.json({
|
|
|
+ ...BaseStdResponse.ERR,
|
|
|
+ msg: '该文件类型不支持AI总结!'
|
|
|
+ })
|
|
|
+
|
|
|
+ const time = new Date().getTime()
|
|
|
sql = 'INSERT INTO file_summary_tasks (repo_id, create_time, create_user, repo_hash, filepath) VALUES (?, ?, ?, ?, ?)'
|
|
|
let r = await db.query(sql, [id, time, uuid, hash, filePath])
|
|
|
|