fix del api
This commit is contained in:
@@ -371,6 +371,28 @@ function createApp({
|
||||
return before - database.fileRecords.length;
|
||||
}
|
||||
|
||||
async function removeDeviceDirectories(deviceId) {
|
||||
const segments = String(deviceId || "").split("/");
|
||||
if (segments.length !== 2 || !segments[0] || !segments[1]) return 0;
|
||||
const [companyCode, lineCode] = segments;
|
||||
const targets = [
|
||||
path.join(store.modelsDirectory, companyCode, lineCode),
|
||||
path.join(store.filesDirectory, "ReinLoop_GUI", companyCode, lineCode)
|
||||
];
|
||||
let removed = 0;
|
||||
for (const directory of targets) {
|
||||
try {
|
||||
const stat = await fs.promises.stat(directory);
|
||||
if (!stat.isDirectory()) continue;
|
||||
} catch (_error) {
|
||||
continue;
|
||||
}
|
||||
await fs.promises.rm(directory, { recursive: true, force: true });
|
||||
removed += 1;
|
||||
}
|
||||
return removed;
|
||||
}
|
||||
|
||||
function backfillIdentificationFiles(database) {
|
||||
for (const record of database.fileRecords) {
|
||||
if (!record.folder.endsWith("/ind_data") || ![".csv", ".json"].includes(path.extname(record.fileName).toLowerCase())) continue;
|
||||
@@ -549,12 +571,14 @@ function createApp({
|
||||
!(item.companyId === companyId && item.productionLineId === productionLineId)
|
||||
);
|
||||
|
||||
const deletedDirectories = await removeDeviceDirectories(deviceId);
|
||||
database.productionLines = database.productionLines.filter((item) => item.id !== productionLineId);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
deletedProductionLineId: productionLineId,
|
||||
deletedFiles: deletedFileCount,
|
||||
deletedDirectories,
|
||||
deletedLicenses: revokedLicenses,
|
||||
deletedFeedback,
|
||||
deletedVolumeRequests: deletedRequests,
|
||||
|
||||
Reference in New Issue
Block a user