v1.3.260115 增加教学数据清除API
This commit is contained in:
@@ -55,74 +55,74 @@ const initialConnectionMap = {
|
||||
"Room1-TO-1": {
|
||||
type: "copper",
|
||||
apitype:"t568b",
|
||||
connectedTo: "1A-1",
|
||||
connectedTo: "Rack1-1A-1",
|
||||
wiremapstatus: "pass",
|
||||
performancestatus: "pass"
|
||||
},
|
||||
"Room1-TO-2": {
|
||||
type: "copper",
|
||||
apitype:"t568b",
|
||||
connectedTo: "1A-2",
|
||||
connectedTo: "Rack1-1A-2",
|
||||
wiremapstatus: "open",
|
||||
performancestatus: "pass"
|
||||
},
|
||||
"Room2-TO-1": {
|
||||
type: "copper",
|
||||
apitype:"t568b",
|
||||
connectedTo: "1A-3",
|
||||
connectedTo: "Rack1-1A-3",
|
||||
wiremapstatus: "short",
|
||||
performancestatus: "pass"
|
||||
},
|
||||
"Room2-TO-2": {
|
||||
type: "copper",
|
||||
apitype:"t568b",
|
||||
connectedTo: "1A-4",
|
||||
connectedTo: "Rack1-1A-4",
|
||||
wiremapstatus: "cross",
|
||||
performancestatus: "pass"
|
||||
},
|
||||
"Room3-TO-1": {
|
||||
type: "copper",
|
||||
apitype:"t568b",
|
||||
connectedTo: "1A-5",
|
||||
connectedTo: "Rack1-1A-5",
|
||||
wiremapstatus: "reversed",
|
||||
performancestatus: "pass"
|
||||
},
|
||||
"Room3-TO-2": {
|
||||
type: "copper",
|
||||
apitype:"t568b",
|
||||
connectedTo: "1A-6",
|
||||
connectedTo: "Rack1-1A-6",
|
||||
wiremapstatus: "miswire",
|
||||
performancestatus: "pass"
|
||||
},
|
||||
"Room4-CAM": {
|
||||
type: "copper",
|
||||
apitype:"t568b",
|
||||
connectedTo: "1A-7",
|
||||
connectedTo: "Rack1-1A-7",
|
||||
wiremapstatus: "pass",
|
||||
performancestatus: "return-loss-fail"
|
||||
},
|
||||
"1B-1": {
|
||||
"Rack1-1B-1": {
|
||||
type: "fiber",
|
||||
apitype:"olts",
|
||||
connectedTo: "1B-5",
|
||||
apitype:"otdr",
|
||||
connectedTo: "Rack1-1B-5",
|
||||
fiberstatus: "sm-pass"
|
||||
},
|
||||
"1B-2": {
|
||||
"Rack1-1B-2": {
|
||||
type: "fiber",
|
||||
apitype:"olts",
|
||||
connectedTo: "1B-6",
|
||||
apitype:"otdr",
|
||||
connectedTo: "Rack1-1B-6",
|
||||
fiberstatus: "connector-fail-start"
|
||||
},
|
||||
"1B-3": {
|
||||
"Rack1-1B-3": {
|
||||
type: "fiber",
|
||||
apitype:"olts",
|
||||
connectedTo: "1B-7",
|
||||
apitype:"otdr",
|
||||
connectedTo: "Rack1-1B-7",
|
||||
fiberstatus: "splice-fail"
|
||||
},
|
||||
"1B-4": {
|
||||
"Rack1-1B-4": {
|
||||
type: "fiber",
|
||||
apitype:"olts",
|
||||
connectedTo: "1B-8",
|
||||
apitype:"otdr",
|
||||
connectedTo: "Rack1-1B-8",
|
||||
fiberstatus: "bend"
|
||||
}
|
||||
},
|
||||
@@ -796,6 +796,51 @@ app.get('/api/teaching/data', (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/api/teaching/clear', (req, res) => {
|
||||
const { scenario, org, fingerprint } = req.body;
|
||||
if (!scenario) {
|
||||
return res.status(400).json({ error: '缺少scenario参数' });
|
||||
}
|
||||
try {
|
||||
if (!fs.existsSync(teachingDir)) {
|
||||
return res.json({ success: true });
|
||||
}
|
||||
const filePath = path.join(teachingDir, `${scenario}.json`);
|
||||
if (!fs.existsSync(filePath)) {
|
||||
return res.json({ success: true });
|
||||
}
|
||||
if (!org && !fingerprint) {
|
||||
fs.unlinkSync(filePath);
|
||||
return res.json({ success: true });
|
||||
}
|
||||
const content = fs.readFileSync(filePath, 'utf8');
|
||||
const store = JSON.parse(content || '{}');
|
||||
if (fingerprint) {
|
||||
const entry = store[fingerprint];
|
||||
if (!entry) {
|
||||
return res.json({ success: true });
|
||||
}
|
||||
if (org && String(entry.org || '').toLowerCase() !== String(org).toLowerCase()) {
|
||||
return res.json({ success: true });
|
||||
}
|
||||
delete store[fingerprint];
|
||||
fs.writeFileSync(filePath, JSON.stringify(store, null, 2));
|
||||
return res.json({ success: true });
|
||||
}
|
||||
if (org) {
|
||||
const filtered = Object.fromEntries(
|
||||
Object.entries(store).filter(([_, v]) => String((v && v.org) || '').toLowerCase() !== String(org).toLowerCase())
|
||||
);
|
||||
fs.writeFileSync(filePath, JSON.stringify(filtered, null, 2));
|
||||
return res.json({ success: true });
|
||||
}
|
||||
res.json({ success: true });
|
||||
} catch (error) {
|
||||
console.error('清除教学数据失败:', error);
|
||||
res.status(500).json({ error: '服务器内部错误' });
|
||||
}
|
||||
});
|
||||
|
||||
// -----------------**************--------------------------***************--------------
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user