|
|
@ -162,87 +162,87 @@ function workspaceEndpoints(app) { |
|
|
// }
|
|
|
// }
|
|
|
// );
|
|
|
// );
|
|
|
|
|
|
|
|
|
app.post( |
|
|
|
|
|
"/workspace/:slug/upload", |
|
|
|
|
|
[ |
|
|
|
|
|
validatedRequest, |
|
|
|
|
|
flexUserRoleValid([ROLES.admin, ROLES.manager]), |
|
|
|
|
|
handleFileUpload, |
|
|
|
|
|
], |
|
|
|
|
|
async function (request, response) { |
|
|
|
|
|
try { |
|
|
|
|
|
const user = await userFromSession(request, response); |
|
|
|
|
|
const deptUserRecord = await DeptUsers.get({ userId: user.id }); |
|
|
|
|
|
if (!deptUserRecord.deptUser) { |
|
|
|
|
|
return response.status(500).json({ success: false, error: "没有发现用户组织机构" }); |
|
|
|
|
|
} |
|
|
|
|
|
const Collector = new CollectorApi(); |
|
|
|
|
|
const { originalname } = request.file; |
|
|
|
|
|
const processingOnline = await Collector.online(); |
|
|
|
|
|
|
|
|
|
|
|
if (!processingOnline) { |
|
|
|
|
|
response |
|
|
|
|
|
.status(500) |
|
|
|
|
|
.json({ |
|
|
|
|
|
success: false, |
|
|
|
|
|
error: `Document processing API is not online. Document ${originalname} will not be processed automatically.`, |
|
|
|
|
|
}) |
|
|
|
|
|
.end(); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const { success, reason, documents } = |
|
|
|
|
|
await Collector.processDocument(originalname); |
|
|
|
|
|
if (!success) { |
|
|
|
|
|
response.status(500).json({ success: false, error: reason }).end(); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
|
|
// 假设路径字符串
|
|
|
|
|
|
const location = documents[0].location; |
|
|
|
|
|
// 将路径中的反斜杠替换为正斜杠(可选,但通常更通用)
|
|
|
|
|
|
const unixStylePath = location.replace(/\\/g, '/'); |
|
|
|
|
|
// 找到最后一个目录分隔符的位置
|
|
|
|
|
|
const lastIndex = unixStylePath.lastIndexOf('/'); |
|
|
|
|
|
// 提取文件名
|
|
|
|
|
|
const parsedFileName = unixStylePath.substring(lastIndex + 1); |
|
|
|
|
|
const fileExtension = path.extname(request.file.path).toLowerCase(); |
|
|
|
|
|
const sourceFile = path.resolve(__dirname, request.file.destination, request.file.originalname); |
|
|
|
|
|
const targetDir = |
|
|
|
|
|
process.env.NODE_ENV === "development" |
|
|
|
|
|
? path.resolve(__dirname, `../../server/storage/localFile`) |
|
|
|
|
|
: path.resolve(process.env.STORAGE_DIR, `../../server/storage/localFile`); |
|
|
|
|
|
const newFileName = uuidv4() + fileExtension; // 新文件名
|
|
|
|
|
|
moveAndRenameFile(sourceFile, targetDir, newFileName); |
|
|
|
|
|
const deptDocData = { |
|
|
|
|
|
deptId: deptUserRecord.deptUser.deptId, |
|
|
|
|
|
parsedFileName: parsedFileName, |
|
|
|
|
|
parsedFilePath: location, |
|
|
|
|
|
realFileName: originalname, |
|
|
|
|
|
realFileAlias: newFileName, |
|
|
|
|
|
realFilePath: targetDir, |
|
|
|
|
|
}; |
|
|
|
|
|
await DeptDocument.create(deptDocData); |
|
|
|
|
|
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
|
|
|
|
|
|
|
|
Collector.log( |
|
|
|
|
|
`Document ${originalname} uploaded processed and successfully. It is now available in documents.` |
|
|
|
|
|
); |
|
|
|
|
|
await Telemetry.sendTelemetry("document_uploaded"); |
|
|
|
|
|
await EventLogs.logEvent( |
|
|
|
|
|
"document_uploaded", |
|
|
|
|
|
{ |
|
|
|
|
|
documentName: originalname, |
|
|
|
|
|
}, |
|
|
|
|
|
response.locals?.user?.id |
|
|
|
|
|
); |
|
|
|
|
|
response.status(200).json({ success: true, error: null }); |
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
console.error(e.message, e); |
|
|
|
|
|
response.sendStatus(500).end(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
// app.post(
|
|
|
|
|
|
// "/workspace/:slug/upload",
|
|
|
|
|
|
// [
|
|
|
|
|
|
// validatedRequest,
|
|
|
|
|
|
// flexUserRoleValid([ROLES.admin, ROLES.manager]),
|
|
|
|
|
|
// handleFileUpload,
|
|
|
|
|
|
// ],
|
|
|
|
|
|
// async function (request, response) {
|
|
|
|
|
|
// try {
|
|
|
|
|
|
// const user = await userFromSession(request, response);
|
|
|
|
|
|
// const deptUserRecord = await DeptUsers.get({ userId: user.id });
|
|
|
|
|
|
// if (!deptUserRecord.deptUser) {
|
|
|
|
|
|
// return response.status(500).json({ success: false, error: "没有发现用户组织机构" });
|
|
|
|
|
|
// }
|
|
|
|
|
|
// const Collector = new CollectorApi();
|
|
|
|
|
|
// const { originalname } = request.file;
|
|
|
|
|
|
// const processingOnline = await Collector.online();
|
|
|
|
|
|
//
|
|
|
|
|
|
// if (!processingOnline) {
|
|
|
|
|
|
// response
|
|
|
|
|
|
// .status(500)
|
|
|
|
|
|
// .json({
|
|
|
|
|
|
// success: false,
|
|
|
|
|
|
// error: `Document processing API is not online. Document ${originalname} will not be processed automatically.`,
|
|
|
|
|
|
// })
|
|
|
|
|
|
// .end();
|
|
|
|
|
|
// return;
|
|
|
|
|
|
// }
|
|
|
|
|
|
//
|
|
|
|
|
|
// const { success, reason, documents } =
|
|
|
|
|
|
// await Collector.processDocument(originalname);
|
|
|
|
|
|
// if (!success) {
|
|
|
|
|
|
// response.status(500).json({ success: false, error: reason }).end();
|
|
|
|
|
|
// return;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
|
|
// // 假设路径字符串
|
|
|
|
|
|
// const location = documents[0].location;
|
|
|
|
|
|
// // 将路径中的反斜杠替换为正斜杠(可选,但通常更通用)
|
|
|
|
|
|
// const unixStylePath = location.replace(/\\/g, '/');
|
|
|
|
|
|
// // 找到最后一个目录分隔符的位置
|
|
|
|
|
|
// const lastIndex = unixStylePath.lastIndexOf('/');
|
|
|
|
|
|
// // 提取文件名
|
|
|
|
|
|
// const parsedFileName = unixStylePath.substring(lastIndex + 1);
|
|
|
|
|
|
// const fileExtension = path.extname(request.file.path).toLowerCase();
|
|
|
|
|
|
// const sourceFile = path.resolve(__dirname, request.file.destination, request.file.originalname);
|
|
|
|
|
|
// const targetDir =
|
|
|
|
|
|
// process.env.NODE_ENV === "development"
|
|
|
|
|
|
// ? path.resolve(__dirname, `../../server/storage/localFile`)
|
|
|
|
|
|
// : path.resolve(process.env.STORAGE_DIR, `../../server/storage/localFile`);
|
|
|
|
|
|
// const newFileName = uuidv4() + fileExtension; // 新文件名
|
|
|
|
|
|
// moveAndRenameFile(sourceFile, targetDir, newFileName);
|
|
|
|
|
|
// const deptDocData = {
|
|
|
|
|
|
// deptId: deptUserRecord.deptUser.deptId,
|
|
|
|
|
|
// parsedFileName: parsedFileName,
|
|
|
|
|
|
// parsedFilePath: location,
|
|
|
|
|
|
// realFileName: originalname,
|
|
|
|
|
|
// realFileAlias: newFileName,
|
|
|
|
|
|
// realFilePath: targetDir,
|
|
|
|
|
|
// };
|
|
|
|
|
|
// await DeptDocument.create(deptDocData);
|
|
|
|
|
|
// // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
|
|
//
|
|
|
|
|
|
// Collector.log(
|
|
|
|
|
|
// `Document ${originalname} uploaded processed and successfully. It is now available in documents.`
|
|
|
|
|
|
// );
|
|
|
|
|
|
// await Telemetry.sendTelemetry("document_uploaded");
|
|
|
|
|
|
// await EventLogs.logEvent(
|
|
|
|
|
|
// "document_uploaded",
|
|
|
|
|
|
// {
|
|
|
|
|
|
// documentName: originalname,
|
|
|
|
|
|
// },
|
|
|
|
|
|
// response.locals?.user?.id
|
|
|
|
|
|
// );
|
|
|
|
|
|
// response.status(200).json({ success: true, error: null });
|
|
|
|
|
|
// } catch (e) {
|
|
|
|
|
|
// console.error(e.message, e);
|
|
|
|
|
|
// response.sendStatus(500).end();
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -255,6 +255,7 @@ function workspaceEndpoints(app) { |
|
|
], |
|
|
], |
|
|
async function (request, response) { |
|
|
async function (request, response) { |
|
|
try { |
|
|
try { |
|
|
|
|
|
const user = await userFromSession(request, response); |
|
|
const deptUserRecord = await DeptUsers.get({ userId: user.id }); |
|
|
const deptUserRecord = await DeptUsers.get({ userId: user.id }); |
|
|
if (!deptUserRecord.deptUser) { |
|
|
if (!deptUserRecord.deptUser) { |
|
|
return response.status(500).json({ success: false, error: "没有发现用户组织机构" }); |
|
|
return response.status(500).json({ success: false, error: "没有发现用户组织机构" }); |
|
|
@ -314,6 +315,7 @@ function workspaceEndpoints(app) { |
|
|
realFileName: originalname, |
|
|
realFileName: originalname, |
|
|
realFileAlias: newFileName, |
|
|
realFileAlias: newFileName, |
|
|
realFilePath: targetDir, |
|
|
realFilePath: targetDir, |
|
|
|
|
|
// parsedFileId: targetDir,
|
|
|
}; |
|
|
}; |
|
|
await DeptDocument.create(deptDocData); |
|
|
await DeptDocument.create(deptDocData); |
|
|
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
@ -395,6 +397,8 @@ function workspaceEndpoints(app) { |
|
|
? await Workspace.getWithUser(user, { slug }) |
|
|
? await Workspace.getWithUser(user, { slug }) |
|
|
: await Workspace.get({ slug }); |
|
|
: await Workspace.get({ slug }); |
|
|
|
|
|
|
|
|
|
|
|
console.log("adds===============", adds); |
|
|
|
|
|
|
|
|
if (!currWorkspace) { |
|
|
if (!currWorkspace) { |
|
|
response.sendStatus(400).end(); |
|
|
response.sendStatus(400).end(); |
|
|
return; |
|
|
return; |
|
|
@ -539,7 +543,7 @@ function workspaceEndpoints(app) { |
|
|
const workspace = multiUserMode(response) |
|
|
const workspace = multiUserMode(response) |
|
|
? await Workspace.getWithUser(user, { slug }) |
|
|
? await Workspace.getWithUser(user, { slug }) |
|
|
: await Workspace.get({ slug }); |
|
|
: await Workspace.get({ slug }); |
|
|
|
|
|
|
|
|
|
|
|
console.log("workspace++++++++++++++++++++++++++++", workspace); |
|
|
response.status(200).json({ workspace }); |
|
|
response.status(200).json({ workspace }); |
|
|
} catch (e) { |
|
|
} catch (e) { |
|
|
console.error(e.message, e); |
|
|
console.error(e.message, e); |
|
|
|