fix runid
This commit is contained in:
+40
-5
@@ -496,6 +496,39 @@ function createApp({
|
||||
return notification;
|
||||
}
|
||||
|
||||
function findIdentificationFeedbackRecord(database, deviceId, fileName) {
|
||||
if (!deviceId || !fileName) return null;
|
||||
const normalizedFileName = String(fileName);
|
||||
return database.identificationFeedback.find((item) =>
|
||||
item.deviceId === deviceId
|
||||
&& (item.fileName === normalizedFileName || item.runId === normalizedFileName)
|
||||
) || null;
|
||||
}
|
||||
|
||||
function resolveIdentificationRunId(database, record) {
|
||||
if (!record) return null;
|
||||
if (record.runId) return String(record.runId);
|
||||
const feedback = findIdentificationFeedbackRecord(database, record.deviceId, record.fileName);
|
||||
if (feedback) return String(feedback.runId);
|
||||
if (record.fileName) return String(record.fileName);
|
||||
return null;
|
||||
}
|
||||
|
||||
function enrichIdentificationFile(database, record) {
|
||||
const runId = resolveIdentificationRunId(database, record);
|
||||
return runId ? { ...record, runId } : { ...record };
|
||||
}
|
||||
|
||||
function enrichNotification(database, notification) {
|
||||
if (!notification || notification.type !== "identification_result_ready" || !notification.fileID) {
|
||||
return notification;
|
||||
}
|
||||
const related = database.identificationFiles.find((item) => item.fileID === notification.fileID)
|
||||
|| database.panelInbox.find((item) => item.fileID === notification.fileID);
|
||||
const runId = resolveIdentificationRunId(database, related);
|
||||
return runId ? { ...notification, runId } : notification;
|
||||
}
|
||||
|
||||
async function purgeExpiredIdentificationFiles() {
|
||||
return store.update(async (database) => {
|
||||
backfillIdentificationFiles(database);
|
||||
@@ -901,16 +934,16 @@ function createApp({
|
||||
const message = database.panelInbox.find((item) => {
|
||||
if (item.deviceId !== deviceId) return false;
|
||||
if (item.mediaType !== "csv") return true;
|
||||
return database.identificationFeedback.some((feedback) =>
|
||||
feedback.deviceId === deviceId && feedback.runId === item.fileName
|
||||
);
|
||||
return Boolean(findIdentificationFeedbackRecord(database, deviceId, item.fileName));
|
||||
});
|
||||
if (!message) return { success: true, pending: false };
|
||||
const runId = resolveIdentificationRunId(database, message);
|
||||
return {
|
||||
success: true,
|
||||
pending: true,
|
||||
fileID: message.fileID,
|
||||
fileName: message.fileName,
|
||||
runId,
|
||||
mediaType: message.mediaType,
|
||||
uploadTime: message.uploadTime,
|
||||
url: issueDownloadUrl(req, message.fileID)
|
||||
@@ -923,7 +956,7 @@ function createApp({
|
||||
const database = await store.read();
|
||||
const notification = database.panelNotifications.find((item) => item.deviceId === deviceId);
|
||||
return notification
|
||||
? { success: true, pending: true, notification }
|
||||
? { success: true, pending: true, notification: enrichNotification(database, notification) }
|
||||
: { success: true, pending: false };
|
||||
}
|
||||
case "ackPanelNotification": {
|
||||
@@ -988,7 +1021,7 @@ function createApp({
|
||||
const offset = (page - 1) * pageSize;
|
||||
return {
|
||||
success: true,
|
||||
files: files.slice(offset, offset + pageSize),
|
||||
files: files.slice(offset, offset + pageSize).map((record) => enrichIdentificationFile(database, record)),
|
||||
total: files.length,
|
||||
page,
|
||||
pageSize
|
||||
@@ -1065,10 +1098,12 @@ function createApp({
|
||||
if (!historyRecord || !fileRecord || !store.resolveStoredFile(fileRecord.fileID)) {
|
||||
return { success: false, errMsg: "辨识文件不存在" };
|
||||
}
|
||||
const runId = resolveIdentificationRunId(database, historyRecord);
|
||||
return {
|
||||
success: true,
|
||||
fileID: fileRecord.fileID,
|
||||
fileName: fileRecord.fileName,
|
||||
runId,
|
||||
mediaType: historyRecord.mediaType,
|
||||
url: issueDownloadUrl(req, fileRecord.fileID)
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user