Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions api/src/routes/artists/[slug]/+server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { TABLES } from '../../../../../shared/config';
import { handlePostgrestQuery, supabase } from '$lib/server/supabase';
import type { Artist } from '../../../../../shared/types/core';
import type { ArtistHydrated } from '../../../../../shared/types/hydrated';
import { json } from '@sveltejs/kit';
import { pinata } from '$lib/server/pinata';

export async function GET({ params }) {
return handlePostgrestQuery<ArtistHydrated>(
Expand All @@ -12,8 +12,38 @@ export async function GET({ params }) {
}

export async function PATCH({ request, params }) {
const body: Partial<Artist> = await request.json();
const { error } = await supabase.from(TABLES.artists).update(body).eq('id', params.slug);
const formData = await request.formData();

const artistImageNew = formData.get('artistImageNew') as File;
const artistName = formData.get('artistName') as string;
const artistBio = formData.get('artistBio') as string;
const artistWebsite = formData.get('artistWebsite') as string;

let imageCid: string | undefined;

if (artistImageNew && artistImageNew.size > 0) {
const pinataFileName = `${artistName} profile image`;
const upload = await pinata.upload.public
.file(artistImageNew)
.name(pinataFileName)
.group(import.meta.env.PINATA_ARTIST_IMAGES_GROUP);

if (!upload || !upload.cid) {
console.error('Error uploading artist image to Pinata:', upload);
}
// TODO: Delete old artist image if it exists
imageCid = upload.cid;
}

const { error } = await supabase
.from(TABLES.artists)
.update({
name: artistName,
bio: artistBio,
website_url: artistWebsite,
image_ipfs_cid: imageCid
})
.eq('id', params.slug);
if (error) {
return json({ error: 'Failed to update artist details' }, { status: 500 });
}
Expand Down
3 changes: 0 additions & 3 deletions dashboard/src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import {

export const PUBLIC_SUPABASE_URL = import.meta.env.VITE_SUPABASE_URL;
export const PUBLIC_SUPABASE_ANON_KEY = import.meta.env.VITE_SUPABASE_ANON_KEY;
export const PINATA_ARTIST_IMAGES_GROUP = import.meta.env.PINATA_ARTIST_IMAGES_GROUP;

export const POWER_USER_ID = import.meta.env.VITE_POWER_USER_ID;

export const API_BASE = dev ? `http://localhost:${API_LOCAL_PORT}` : API_DOMAIN;

Expand Down
39 changes: 12 additions & 27 deletions dashboard/src/lib/remote-functions/artist.remote.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { form, getRequestEvent, query } from '$app/server';
import { API_BASE, PINATA_ARTIST_IMAGES_GROUP, REQUEST_HEADER_BOILERPLATE } from '$lib/config';
import { API_BASE, DOMAIN_BASE } from '$lib/config';
import * as z from 'zod';
import { pinata } from '$lib/server/pinata';
import { fail, redirect } from '@sveltejs/kit';

const ArtistDetailsForm = z.object({
artistId: z.string(),
Expand All @@ -13,33 +11,20 @@ const ArtistDetailsForm = z.object({
});

export const updateArtistDetails = form(ArtistDetailsForm, async (data) => {
let imageCid: string | undefined;
if (data.artistImageNew && data.artistImageNew.size > 0) {
const pinataFileName = `${data.artistName} profile image`;
const upload = await pinata.upload.public
.file(data.artistImageNew)
.name(pinataFileName)
.group(PINATA_ARTIST_IMAGES_GROUP);

if (!upload || !upload.cid) {
console.error('Error uploading artist image to Pinata:', upload);
return fail(500, {
error: true,
message: 'Failed to upload artist image to Pinata'
});
}
// TODO: Delete old artist image if it exists
imageCid = upload.cid;
const formData = new FormData();
if (data.artistImageNew) {
formData.append('artistImageNew', data.artistImageNew);
}
formData.append('artistName', data.artistName);
formData.append('artistId', data.artistId);
formData.append('artistBio', data.artistBio || '');
formData.append('artistWebsite', data.artistWebsite || '');
await fetch(`${API_BASE}/artists/${data.artistId}`, {
method: 'PATCH',
headers: REQUEST_HEADER_BOILERPLATE,
body: JSON.stringify({
id: data.artistId,
image_ipfs_cid: imageCid,
bio: data.artistBio,
website_url: data.artistWebsite
})
headers: {
origin: DOMAIN_BASE
},
body: formData
});
});

Expand Down
4 changes: 1 addition & 3 deletions dashboard/src/lib/remote-functions/music.remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ export const addRelease = form(AddReleaseForm, async (data) => {
formData.append('releaseArtwork', data.releaseArtwork);
formData.append('releaseName', data.releaseName);
formData.append('releaseType', data.releaseType);
if (data.releaseDate) {
formData.append('releaseDate', data.releaseDate);
}
formData.append('releaseDate', data.releaseDate);
await fetch(`${API_BASE}/releases`, {
method: 'POST',
headers: {
Expand Down
8 changes: 0 additions & 8 deletions dashboard/src/lib/server/pinata.ts

This file was deleted.

21 changes: 8 additions & 13 deletions dashboard/src/routes/+layout.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { supabase } from '$lib/server/supabase';
import type { StreamLog } from '../../../shared/types/core';
import { sortReleasesByDate } from '../../../shared/utils';
import type { LayoutServerLoad } from './$types';
import { POWER_USER_ID } from '$lib/config';
import type { Artist, Track } from '../../../shared/types/core';
import type { ReleaseHydrated } from '../../../shared/types/hydrated';
import { TABLES } from '../../../shared/config';
Expand Down Expand Up @@ -38,24 +37,20 @@ export const load: LayoutServerLoad = async ({ locals: { safeGetSession }, cooki
return fail(500, { error: 'Failed to fetch user data' });
}

// Get all artist IDs for the user, unless they are a power user
// in which case fetch all artists
// Get all artist IDs for the user
const {
data: connectedArtists,
error: artistsError
}: {
data: Artist[] | null;
error: Error | null;
} =
userID === POWER_USER_ID
? await supabase.from(TABLES.artists).select('*')
: await supabase
.from(TABLES.artists)
.select('*')
.in(
'id',
userData.map((u) => u.artist_id)
);
} = await supabase
.from(TABLES.artists)
.select('*')
.in(
'id',
userData.map((u) => u.artist_id)
);

if (artistsError || !connectedArtists) {
console.error('Error fetching artists:', artistsError);
Expand Down
4 changes: 1 addition & 3 deletions dashboard/src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<script lang="ts">
import type { GroupListResponse } from 'pinata';
import type { StreamLog } from '../../../shared/types/core';
import { dashboardState } from '$lib/state.svelte';
import ProfileView from '$lib/components/views/profile/ProfileView.svelte';
import type { Artist, Release, Track } from '../../../shared/types/core';
import type { Artist, Track } from '../../../shared/types/core';
import type { ReleaseHydrated } from '../../../shared/types/hydrated';
import StatsView from '$lib/components/views/stats/StatsView.svelte';
import MusicView from '$lib/components/views/music/MusicView.svelte';
Expand All @@ -12,7 +11,6 @@
data
}: {
data: {
groups: GroupListResponse;
artists: Artist[];
songs: Track[];
releases: ReleaseHydrated[];
Expand Down