Stuff is broken right now but an auth provider would rule.
This commit is contained in:
@ -23,7 +23,7 @@ export const login = async (formData: FormData) => {
|
||||
}
|
||||
|
||||
revalidatePath('/', 'layout');
|
||||
redirect('/');
|
||||
redirect('/?refresh=true');
|
||||
};
|
||||
|
||||
export const signup = async (formData: FormData) => {
|
||||
@ -44,5 +44,5 @@ export const signup = async (formData: FormData) => {
|
||||
}
|
||||
|
||||
revalidatePath('/', 'layout');
|
||||
redirect('/');
|
||||
redirect('/?refresh=true');
|
||||
};
|
||||
|
47
src/server/actions/image.ts
Normal file
47
src/server/actions/image.ts
Normal file
@ -0,0 +1,47 @@
|
||||
'use server';
|
||||
import 'server-only';
|
||||
import { createClient } from '@/utils/supabase/server';
|
||||
|
||||
export const getImageUrl = async (
|
||||
bucket: string,
|
||||
path: string,
|
||||
): Promise<string> => {
|
||||
try {
|
||||
const supabase = await createClient();
|
||||
|
||||
// Download the image as a blob
|
||||
const { data, error } = await supabase.storage.from(bucket).download(path);
|
||||
|
||||
if (error) {
|
||||
console.error('Error downloading image:', error);
|
||||
throw new Error(`Failed to download image: ${error.message}`);
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
throw new Error('No data received from storage');
|
||||
}
|
||||
|
||||
// Convert blob to base64 string on the server
|
||||
const arrayBuffer = await data.arrayBuffer();
|
||||
const buffer = Buffer.from(arrayBuffer);
|
||||
const base64 = buffer.toString('base64');
|
||||
|
||||
// Determine MIME type from file extension or default to octet-stream
|
||||
let mimeType = 'application/octet-stream';
|
||||
if (path.endsWith('.png')) mimeType = 'image/png';
|
||||
else if (path.endsWith('.jpg') || path.endsWith('.jpeg'))
|
||||
mimeType = 'image/jpeg';
|
||||
else if (path.endsWith('.gif')) mimeType = 'image/gif';
|
||||
else if (path.endsWith('.svg')) mimeType = 'image/svg+xml';
|
||||
else if (path.endsWith('.webp')) mimeType = 'image/webp';
|
||||
|
||||
// Return as data URL
|
||||
return `data:${mimeType};base64,${base64}`;
|
||||
} catch (error) {
|
||||
console.error(
|
||||
'Error processing image:',
|
||||
error instanceof Error ? error.message : String(error),
|
||||
);
|
||||
throw new Error('Failed to process image');
|
||||
}
|
||||
};
|
@ -12,5 +12,5 @@ export const fetchHistory = async ({
|
||||
currentPage = 1,
|
||||
user = null,
|
||||
}: fetchHistoryProps): PaginatedHistory => {
|
||||
const supabase = createClient();
|
||||
const supabase = createClient();
|
||||
};
|
||||
|
Reference in New Issue
Block a user