MCPcopy
hub / github.com/stemdeckapp/stemdeck / addTrackToLibrary

Function addTrackToLibrary

static/js/catalog.js:250–284  ·  view source on GitHub ↗
(track)

Source from the content-addressed store, hash-verified

248// ─── Track management ───
249
250export function addTrackToLibrary(track) {
251 // track: { id, title, channel, thumb, stems, status, sourceUrl }
252 const existingId = findTrackBySource(track.sourceUrl, track.id);
253 if (existingId) {
254 const trash = getTrashFolder();
255 const inTrash = trash?.items.includes(existingId);
256 if (inTrash) {
257 // Old track was trashed — delete it silently so the new import lands
258 // in the library instead of inheriting the trash placement.
259 delete tracks[existingId];
260 for (const f of folders) f.items = f.items.filter((id) => id !== existingId);
261 } else {
262 replaceTrackId(existingId, track.id);
263 }
264 }
265 const existing = tracks[track.id] || {};
266 tracks[track.id] = {
267 ...existing,
268 ...track,
269 createdAt: existing.createdAt ?? track.createdAt ?? (Date.now() / 1000),
270 favorite: existing.favorite ?? false,
271 };
272 const alreadyPlaced = folders.some((folder) => folder.items.includes(track.id));
273 if (!alreadyPlaced) {
274 // Put into first non-trash folder or create an "Unsorted" folder.
275 let target = folders.find((folder) => folder.id !== TRASH_ID);
276 if (!target) {
277 target = makeFolder({ id: "f-unsorted", name: "Unsorted" });
278 folders.unshift(target);
279 }
280 target.items.unshift(track.id);
281 }
282 saveState();
283 render();
284}
285
286export function updateTrackStatus(trackId, status) {
287 if (tracks[trackId]) {

Callers 4

applyStateFunction · 0.90
importFromUrlFunction · 0.90
wireJobFormFunction · 0.90
syncWithServerFunction · 0.85

Calls 6

findTrackBySourceFunction · 0.85
getTrashFolderFunction · 0.85
replaceTrackIdFunction · 0.85
makeFolderFunction · 0.85
saveStateFunction · 0.85
renderFunction · 0.70

Tested by

no test coverage detected