Invite and remove track coauthors from the library songs list

This commit is contained in:
2026-09-25 02:21:37 +02:00
parent 153c33bf51
commit 058a902a81
11 changed files with 601 additions and 1 deletions
@@ -6,6 +6,7 @@ import { formIds, formString } from '$lib/server/forms/fields';
import { tagged } from '$lib/server/actions/tagged';
import { loadLibraryTracks, loadStatusCounts } from '$lib/server/libraryTracks';
import { deleteTracks, setTracksPublished } from '$lib/server/tracks';
import { inviteCoauthors, removeCoauthor } from '$lib/server/coauthors';
import { parseTrackFilter } from '$lib/data/libraryTracks';
export const load: PageServerLoad = async ({ locals, url, fetch }) => {
@@ -44,5 +45,18 @@ export const actions: Actions = {
const result = await setTracksPublished(api, trackIds, isPublished);
if (isActionFailure(result)) return result;
return { ...result, isPublished };
}),
inviteCoauthors: tagged('inviteCoauthors', async ({ api, form }) => {
const trackId = formString(form, 'trackId');
if (!trackId) return fail(400, { message: 'Falta la canción.' });
return inviteCoauthors(api, trackId, formIds(form, 'userIds'));
}),
removeCoauthor: tagged('removeCoauthor', async ({ api, form }) => {
const trackId = formString(form, 'trackId');
const userId = formString(form, 'userId');
if (!trackId || !userId) return fail(400, { message: 'Falta el coautor.' });
return removeCoauthor(api, trackId, userId);
})
};
@@ -5,7 +5,13 @@
let { data, form } = $props();
const errorMessage = $derived(
form && 'message' in form && form.action !== 'saveAlbum' ? form.message : undefined
form &&
'message' in form &&
form.action !== 'saveAlbum' &&
form.action !== 'inviteCoauthors' &&
form.action !== 'removeCoauthor'
? form.message
: undefined
);
const published = $derived(
form?.action === 'setPublished' ? (form as { skipped?: number; isPublished?: boolean }) : null
@@ -0,0 +1,13 @@
import type { RequestHandler } from './$types';
import { json } from '@sveltejs/kit';
import { apiFor } from '$lib/server/api';
import { requireUser } from '$lib/server/guards';
import { searchUsers } from '$lib/server/coauthors';
import { SEARCH_MIN_LENGTH } from '$lib/config';
export const GET: RequestHandler = async ({ url, locals, fetch }) => {
requireUser(locals, url);
const query = url.searchParams.get('q')?.trim() ?? '';
if (query.length < SEARCH_MIN_LENGTH) return json([]);
return json(await searchUsers(apiFor({ fetch, locals }), query));
};