+33
-2
@@ -7,15 +7,40 @@ export interface FileRecord {
|
||||
type: string;
|
||||
lastModified: number;
|
||||
inspection?: FileInspection;
|
||||
inspectionStatus?:
|
||||
"queued" | "inspecting" | "inspected" | "error" | "cancelled";
|
||||
inspectionError?: string;
|
||||
sha256?: string;
|
||||
sha512?: string;
|
||||
}
|
||||
|
||||
function inspectionStatus(
|
||||
record: FileRecord,
|
||||
): NonNullable<FileRecord["inspectionStatus"]> {
|
||||
return (
|
||||
record.inspectionStatus ?? (record.inspection ? "inspected" : "queued")
|
||||
);
|
||||
}
|
||||
|
||||
export function manifestJson(records: FileRecord[]): string {
|
||||
return JSON.stringify(
|
||||
{
|
||||
schemaVersion: 1,
|
||||
generatedBy: "add-ideas File Tools 0.1.0",
|
||||
schemaVersion: 2,
|
||||
generatedBy: "add-ideas File Tools 0.2.0",
|
||||
inspectionCoverage: {
|
||||
total: records.length,
|
||||
inspected: records.filter(
|
||||
(record) => inspectionStatus(record) === "inspected",
|
||||
).length,
|
||||
failed: records.filter((record) => inspectionStatus(record) === "error")
|
||||
.length,
|
||||
cancelled: records.filter(
|
||||
(record) => inspectionStatus(record) === "cancelled",
|
||||
).length,
|
||||
pending: records.filter((record) =>
|
||||
["queued", "inspecting"].includes(inspectionStatus(record)),
|
||||
).length,
|
||||
},
|
||||
files: [...records]
|
||||
.sort((left, right) => left.path.localeCompare(right.path))
|
||||
.map((record) => ({
|
||||
@@ -24,6 +49,8 @@ export function manifestJson(records: FileRecord[]): string {
|
||||
lastModified: new Date(record.lastModified).toISOString(),
|
||||
claimedMime: record.type || null,
|
||||
detectedMime: record.inspection?.detected?.mime ?? null,
|
||||
inspectionStatus: inspectionStatus(record),
|
||||
inspectionError: record.inspectionError ?? null,
|
||||
sha256: record.sha256 ?? null,
|
||||
sha512: record.sha512 ?? null,
|
||||
findings: record.inspection?.findings ?? [],
|
||||
@@ -48,6 +75,8 @@ export function manifestCsv(records: FileRecord[]): string {
|
||||
"lastModified",
|
||||
"claimedMime",
|
||||
"detectedMime",
|
||||
"inspectionStatus",
|
||||
"inspectionError",
|
||||
"sha256",
|
||||
"sha512",
|
||||
]
|
||||
@@ -64,6 +93,8 @@ export function manifestCsv(records: FileRecord[]): string {
|
||||
new Date(record.lastModified).toISOString(),
|
||||
record.type,
|
||||
record.inspection?.detected?.mime,
|
||||
inspectionStatus(record),
|
||||
record.inspectionError,
|
||||
record.sha256,
|
||||
record.sha512,
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user