diff --git a/src/components/input/common.js b/src/components/input/common.js --- a/src/components/input/common.js +++ b/src/components/input/common.js @@ -1,6 +1,25 @@ import { base64url } from "iso-base/rfc4648"; /** + * @import {Track} from "@definitions/types.d.ts" + */ + +/** + * @param {{ fileUriOrScheme: string; handleFileUri: (args: { fileURI: string; tracks: Track[] }) => Track[]; inputScheme: string; tracks: Track[] }} _ + */ +export function detach( + { fileUriOrScheme, handleFileUri, inputScheme, tracks }, +) { + if (!fileUriOrScheme.includes("://")) { + // Delete everything if scheme matches + if (fileUriOrScheme === inputScheme) return []; + return tracks; + } + + return handleFileUri({ fileURI: fileUriOrScheme, tracks }); +} + +/** * @param {string} scheme * @param {string} groupId */ diff --git a/src/components/input/opensubsonic/common.js b/src/components/input/opensubsonic/common.js --- a/src/components/input/opensubsonic/common.js +++ b/src/components/input/opensubsonic/common.js @@ -2,7 +2,7 @@ import * as URI from "uri-js"; import QS from "query-string"; -import { IDB_SERVERS, SCHEME } from "./constants.js"; +import { SCHEME } from "./constants.js"; /** * @import {Child} from "subsonic-api" diff --git a/src/components/input/opensubsonic/constants.js b/src/components/input/opensubsonic/constants.js --- a/src/components/input/opensubsonic/constants.js +++ b/src/components/input/opensubsonic/constants.js @@ -1,3 +1,1 @@ -export const IDB_PREFIX = "@components/input/opensubsonic"; -export const IDB_SERVERS = `${IDB_PREFIX}/servers`; export const SCHEME = "opensubsonic"; diff --git a/src/components/input/opensubsonic/worker.js b/src/components/input/opensubsonic/worker.js --- a/src/components/input/opensubsonic/worker.js +++ b/src/components/input/opensubsonic/worker.js @@ -2,6 +2,7 @@ import { ostiary, rpc } from "@common/worker.js"; import { SCHEME } from "./constants.js"; +import { detach as detachUtil, groupKeyHash } from "../common.js"; import { autoTypeToTrackKind, buildURI, @@ -11,7 +12,6 @@ parseURI, serverId, } from "./common.js"; -import { groupKeyHash } from "../common.js"; /** * @import {Child, SubsonicAPI} from "subsonic-api" @@ -42,9 +42,23 @@ /** * @type {Actions['detach']} */ -export async function detach({ fileUriOrScheme, tracks }) { - console.log("opensubsonic", fileUriOrScheme); - return tracks; +export async function detach(args) { + return detachUtil({ + ...args, + + inputScheme: SCHEME, + handleFileUri: ({ fileURI, tracks }) => { + const result = parseURI(fileURI); + if (!result) return tracks; + + const sid = serverId(result.server); + const groups = groupTracksByServer(tracks); + + delete groups[sid]; + + return Object.values(groups).map((a) => a.tracks).flat(1); + }, + }); } /** diff --git a/src/components/input/s3/worker.js b/src/components/input/s3/worker.js --- a/src/components/input/s3/worker.js +++ b/src/components/input/s3/worker.js @@ -1,4 +1,9 @@ -import { groupKeyHash, isAudioFile } from "@components/input/common.js"; +import { ostiary, rpc } from "@common/worker.js"; +import { + detach as detachUtil, + groupKeyHash, + isAudioFile, +} from "@components/input/common.js"; import { bucketId, buildURI, @@ -8,7 +13,6 @@ parseURI, } from "./common.js"; import { SCHEME } from "./constants.js"; -import { ostiary, rpc } from "@common/worker.js"; /** * @import { InputActions as Actions, ConsultGrouping } from "@components/input/types.d.ts"; @@ -38,9 +42,23 @@ /** * @type {Actions['detach']} */ -export async function detach({ fileUriOrScheme, tracks }) { - console.log("s3", fileUriOrScheme); - return tracks; +export async function detach(args) { + return detachUtil({ + ...args, + + inputScheme: SCHEME, + handleFileUri: ({ fileURI, tracks }) => { + const result = parseURI(fileURI); + if (!result) return tracks; + + const bid = bucketId(result.bucket); + const groups = groupTracksByBucket(tracks); + + delete groups[bid]; + + return Object.values(groups).map((a) => a.tracks).flat(1); + }, + }); } /**