From 5cc68345328fa99452380215f707884cd20f9746 Mon Sep 17 00:00:00 2001 From: voldemort <5692900+yell0wsuit@users.noreply.github.com> Date: Sun, 20 Jul 2025 16:56:34 +0700 Subject: [PATCH] add export to json button --- frontend/src/components/results.jsx | 78 +++++++++++++++++++++++------ 1 file changed, 64 insertions(+), 14 deletions(-) diff --git a/frontend/src/components/results.jsx b/frontend/src/components/results.jsx index 8339113..fe9ffe7 100644 --- a/frontend/src/components/results.jsx +++ b/frontend/src/components/results.jsx @@ -18,10 +18,10 @@ function Results() { "manifestURL", ], (result) => { - if (result.drmType) setDrmType(result.drmType); - if (result.latestPSSH) setPssh(result.latestPSSH); - if (result.licenseURL) setLicenseUrl(result.licenseURL); - if (result.manifestURL) setManifestUrl(result.manifestURL); + if (result.drmType) setDrmType(result.drmType || ""); + if (result.latestPSSH) setPssh(result.latestPSSH || ""); + if (result.licenseURL) setLicenseUrl(result.licenseURL || ""); + if (result.manifestURL) setManifestUrl(result.manifestURL || ""); if (result.latestKeys) { try { const parsed = Array.isArray(result.latestKeys) @@ -39,19 +39,19 @@ function Results() { const handleChange = (changes, area) => { if (area === "local") { if (changes.drmType) { - setDrmType(changes.drmType.newValue); + setDrmType(changes.drmType.newValue || ""); } if (changes.latestPSSH) { - setPssh(changes.latestPSSH.newValue); + setPssh(changes.latestPSSH.newValue || ""); } if (changes.licenseURL) { - setLicenseUrl(changes.licenseURL.newValue); + setLicenseUrl(changes.licenseURL.newValue || ""); } if (changes.manifestURL) { - setManifestUrl(changes.manifestURL.newValue); + setManifestUrl(changes.manifestURL.newValue || ""); } if (changes.latestKeys) { - setKeys(changes.latestKeys.newValue); + setKeys(changes.latestKeys.newValue || []); } } }; @@ -63,10 +63,10 @@ function Results() { const handleCapture = () => { // Reset stored values chrome.storage.local.set({ - drmType: "None", - latestPSSH: "None", - licenseURL: "None", - manifestURL: "None", + drmType: "", + latestPSSH: "", + licenseURL: "", + manifestURL: "", latestKeys: [], }); @@ -102,11 +102,52 @@ function Results() { }); }; + // Export to JSON file + + const hasData = () => { + return ( + drmType || + pssh || + licenseUrl || + manifestUrl || + (Array.isArray(keys) && keys.filter((k) => k.type !== "SIGNING").length > 0) + ); + }; + + const handleExportJSON = () => { + const exportData = { + drmType: drmType || null, + manifestUrl: manifestUrl || null, + pssh: pssh || null, + licenseUrl: licenseUrl || null, + keys: + Array.isArray(keys) && keys.length > 0 + ? keys + .filter((k) => k.type !== "SIGNING") + .map((k) => `${k.key_id || k.keyId}:${k.key}`) + : null, + exportedAt: new Date().toISOString(), + }; + + const blob = new Blob([JSON.stringify(exportData, null, 2)], { + type: "application/json", + }); + + const url = URL.createObjectURL(blob); + const a = document.createElement("a"); + a.href = url; + a.download = `drm-data-${new Date().toISOString().slice(0, 19).replace(/:/g, "-")}.json`; + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + URL.revokeObjectURL(url); + }; + return (
@@ -158,6 +199,15 @@ function Results() { [Not available] )}
+ + {hasData() && ( + + )} ); }