Capturing pack and cover
This commit is contained in:
@@ -10,8 +10,6 @@ const WAVEFORM_PATH_RE = /\.wv\.json$/i;
|
||||
const SCRAMBLED_PATH_RE = /-scrambled\//i;
|
||||
const HASH_RE = /^[a-f0-9]{64}$/i;
|
||||
const GRAPHQL_URL = "https://surfaces-graphql.splice.com/graphql";
|
||||
const DEBUG_TRACE = true;
|
||||
const DEBUG_TRACE_MARKER = "S3DBG_MAPTRACE_V1";
|
||||
|
||||
function isDomainAllowed(pageUrl) {
|
||||
return typeof pageUrl === "string" && SPLICE_DOMAIN_RE.test(pageUrl);
|
||||
@@ -81,24 +79,6 @@ function normalizeName(value) {
|
||||
return typeof value === "string" ? value.trim().toLowerCase() : "";
|
||||
}
|
||||
|
||||
function debugMapTrace(stage, entry) {
|
||||
if (!DEBUG_TRACE) {
|
||||
return;
|
||||
}
|
||||
const safe = entry && typeof entry === "object" ? entry : {};
|
||||
console.debug(DEBUG_TRACE_MARKER, stage, {
|
||||
sampleId: safe.sampleId || "",
|
||||
fileName: safe.fileName || "",
|
||||
key: safe.key || "",
|
||||
bpm: safe.bpm || "",
|
||||
tagsCount: Array.isArray(safe.tags) ? safe.tags.length : 0,
|
||||
coverImageUrl: safe.coverImageUrl || "",
|
||||
previewUrl: safe.previewUrl || "",
|
||||
fullUrl: safe.fullUrl || "",
|
||||
source: safe.source || ""
|
||||
});
|
||||
}
|
||||
|
||||
function extractSampleIdFromUrl(url) {
|
||||
try {
|
||||
const parsed = new URL(url);
|
||||
@@ -164,6 +144,7 @@ function mergeEntry(tabState, inputEntry, source, options) {
|
||||
previewUrl: "",
|
||||
fullUrl: "",
|
||||
fileName: "",
|
||||
packName: "",
|
||||
key: "",
|
||||
bpm: "",
|
||||
tags: [],
|
||||
@@ -191,6 +172,9 @@ function mergeEntry(tabState, inputEntry, source, options) {
|
||||
if (inputEntry.fileName) {
|
||||
merged.fileName = String(inputEntry.fileName).trim();
|
||||
}
|
||||
if (typeof inputEntry.packName === "string" && inputEntry.packName.trim()) {
|
||||
merged.packName = inputEntry.packName.trim();
|
||||
}
|
||||
if (typeof inputEntry.key === "string" && inputEntry.key.trim()) {
|
||||
merged.key = inputEntry.key.trim();
|
||||
}
|
||||
@@ -228,6 +212,7 @@ function upsertPreviewContext(tabId, context, source) {
|
||||
previewUrl,
|
||||
fullUrl: context.fullUrl ? normalizeUrl(context.fullUrl) : "",
|
||||
fileName: context.fileName || "",
|
||||
packName: context.packName || "",
|
||||
key: context.key || "",
|
||||
bpm: context.bpm || "",
|
||||
tags: Array.isArray(context.tags) ? context.tags : [],
|
||||
@@ -241,6 +226,7 @@ function upsertPreviewContext(tabId, context, source) {
|
||||
function upsertUrl(tabId, url, source) {
|
||||
const sourceTag = source && typeof source === "object" ? source.tag || "" : source || "";
|
||||
const sourceFileName = source && typeof source === "object" ? source.fileName || "" : "";
|
||||
const sourcePackName = source && typeof source === "object" ? source.packName || "" : "";
|
||||
const sourceKey = source && typeof source === "object" ? source.key || "" : "";
|
||||
const sourceBpm = source && typeof source === "object" ? source.bpm || "" : "";
|
||||
const sourceTags = source && typeof source === "object" && Array.isArray(source.tags) ? source.tags : [];
|
||||
@@ -260,6 +246,7 @@ function upsertUrl(tabId, url, source) {
|
||||
previewUrl: isPreviewUrl(normalized) ? normalized : "",
|
||||
fullUrl: isFullUrl(normalized) ? normalized : "",
|
||||
fileName: sourceFileName,
|
||||
packName: sourcePackName,
|
||||
key: sourceKey,
|
||||
bpm: sourceBpm,
|
||||
tags: sourceTags,
|
||||
@@ -302,6 +289,7 @@ async function appendHistoryRows(rows) {
|
||||
...existing,
|
||||
...row,
|
||||
fileName: row.fileName || existing.fileName || "",
|
||||
packName: row.packName || existing.packName || "",
|
||||
key: row.key || existing.key || "",
|
||||
bpm: row.bpm || existing.bpm || "",
|
||||
tags: Array.isArray(row.tags) && row.tags.length ? row.tags : (existing.tags || []),
|
||||
@@ -323,6 +311,7 @@ async function appendDownloadHistory(entry, result) {
|
||||
previewUrl: resolvedEntry.previewUrl || "",
|
||||
fullUrl: resolvedEntry.fullUrl || "",
|
||||
fileName: resolvedEntry.fileName || "",
|
||||
packName: resolvedEntry.packName || "",
|
||||
key: resolvedEntry.key || "",
|
||||
bpm: resolvedEntry.bpm || "",
|
||||
tags: Array.isArray(resolvedEntry.tags) ? resolvedEntry.tags : [],
|
||||
@@ -345,6 +334,7 @@ function makeDecodedPlaceholderRow(entry, source) {
|
||||
previewUrl: entry.previewUrl || "",
|
||||
fullUrl: entry.fullUrl || "",
|
||||
fileName: entry.fileName || "",
|
||||
packName: entry.packName || "",
|
||||
key: entry.key || "",
|
||||
bpm: entry.bpm || "",
|
||||
tags: Array.isArray(entry.tags) ? entry.tags : [],
|
||||
@@ -533,6 +523,7 @@ function findEntryInTabStates(sampleId) {
|
||||
previewUrl: normalizeUrl(entry.previewUrl || ""),
|
||||
fullUrl: normalizeUrl(entry.fullUrl || ""),
|
||||
fileName: entry.fileName || "",
|
||||
packName: entry.packName || "",
|
||||
key: entry.key || "",
|
||||
bpm: entry.bpm || "",
|
||||
tags: Array.isArray(entry.tags) ? entry.tags : [],
|
||||
@@ -559,6 +550,7 @@ async function hydrateEntryFromHistory(sampleId) {
|
||||
previewUrl,
|
||||
fullUrl,
|
||||
fileName: row.fileName || "",
|
||||
packName: row.packName || "",
|
||||
key: row.key || "",
|
||||
bpm: row.bpm || "",
|
||||
tags: Array.isArray(row.tags) ? row.tags : [],
|
||||
@@ -577,6 +569,7 @@ async function resolveAndDownloadEntry(entryInput) {
|
||||
previewUrl: normalizeUrl(entry.previewUrl || ""),
|
||||
fullUrl: normalizeUrl(entry.fullUrl || ""),
|
||||
fileName: entry.fileName || "",
|
||||
packName: entry.packName || "",
|
||||
key: entry.key || "",
|
||||
bpm: entry.bpm || "",
|
||||
tags: Array.isArray(entry.tags) ? entry.tags : [],
|
||||
@@ -629,6 +622,7 @@ function serializeEntry(entry) {
|
||||
previewUrl: entry.previewUrl || "",
|
||||
fullUrl: entry.fullUrl || "",
|
||||
fileName: entry.fileName || "",
|
||||
packName: entry.packName || "",
|
||||
key: entry.key || "",
|
||||
bpm: entry.bpm || "",
|
||||
tags: Array.isArray(entry.tags) ? entry.tags : [],
|
||||
@@ -661,10 +655,7 @@ browser.runtime.onMessage.addListener((message, sender) => {
|
||||
|
||||
const contexts = Array.isArray(message.contexts) ? message.contexts : [];
|
||||
for (const context of contexts) {
|
||||
const merged = upsertPreviewContext(tabId, context, "graphql_preview");
|
||||
if (merged) {
|
||||
debugMapTrace("CAPTURE_PREVIEW_CONTEXT_MERGED", merged);
|
||||
}
|
||||
upsertPreviewContext(tabId, context, "graphql_preview");
|
||||
}
|
||||
return Promise.resolve({ ok: true, added: contexts.length });
|
||||
}
|
||||
@@ -678,14 +669,12 @@ browser.runtime.onMessage.addListener((message, sender) => {
|
||||
const merged = upsertUrl(tabId, raw, {
|
||||
tag: message.source || "network_preview",
|
||||
fileName: canAttachPlaybackMeta ? (message.fileName || "") : "",
|
||||
packName: "",
|
||||
key: "",
|
||||
bpm: "",
|
||||
tags: [],
|
||||
coverImageUrl: ""
|
||||
});
|
||||
if (merged) {
|
||||
debugMapTrace("CAPTURE_URLS_MERGED", merged);
|
||||
}
|
||||
if (merged && merged.previewUrl && canAttachPlaybackMeta) {
|
||||
const row = makeDecodedPlaceholderRow(merged, message.source || "network_preview");
|
||||
if (row) {
|
||||
@@ -749,6 +738,7 @@ browser.runtime.onMessage.addListener((message, sender) => {
|
||||
return Promise.resolve({ ok: false });
|
||||
}
|
||||
const fileName = typeof message.fileName === "string" ? message.fileName.trim() : "";
|
||||
const packName = typeof message.packName === "string" ? message.packName.trim() : "";
|
||||
const key = typeof message.key === "string" ? message.key.trim() : "";
|
||||
const bpm = typeof message.bpm === "string" ? message.bpm.trim() : "";
|
||||
const tags = Array.isArray(message.tags) ? message.tags.map((x) => String(x).trim()).filter(Boolean) : [];
|
||||
@@ -779,6 +769,9 @@ browser.runtime.onMessage.addListener((message, sender) => {
|
||||
if (fileName) {
|
||||
targetEntry.fileName = fileName;
|
||||
}
|
||||
if (packName) {
|
||||
targetEntry.packName = packName;
|
||||
}
|
||||
if (key) {
|
||||
targetEntry.key = key;
|
||||
}
|
||||
@@ -794,7 +787,6 @@ browser.runtime.onMessage.addListener((message, sender) => {
|
||||
targetEntry.capturedAt = Date.now();
|
||||
state.entriesBySample.set(targetEntry.sampleId, targetEntry);
|
||||
state.latestSampleId = targetEntry.sampleId;
|
||||
debugMapTrace("UPDATE_ACTIVE_PLAYBACK_META_TARGET", targetEntry);
|
||||
const row = makeDecodedPlaceholderRow(targetEntry, targetEntry.source || "playback_meta");
|
||||
if (!row) {
|
||||
return Promise.resolve({ ok: true });
|
||||
|
||||
Reference in New Issue
Block a user