mirror of
https://github.com/stackblitz-labs/bolt.diy
synced 2025-06-25 17:56:12 +00:00
Migrate to blobs for repository_contents, solution, and prompt
This commit is contained in:
parent
501488cec0
commit
bccd07021e
@ -71,11 +71,69 @@ export async function supabaseGetProblem(problemId: string): Promise<BoltProblem
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fetch blob data from storage if paths are available
|
||||||
|
let repositoryContents = '';
|
||||||
|
let prompt = undefined;
|
||||||
|
let solution = undefined;
|
||||||
|
|
||||||
|
// Create a supabase instance for storage operations
|
||||||
|
const supabase = getSupabase();
|
||||||
|
|
||||||
|
// Fetch repository contents from storage if path is available
|
||||||
|
if (data.repository_contents_path) {
|
||||||
|
try {
|
||||||
|
const { data: blobData, error: blobError } = await supabase.storage
|
||||||
|
.from('repository-contents')
|
||||||
|
.download(data.repository_contents_path);
|
||||||
|
|
||||||
|
if (!blobError && blobData) {
|
||||||
|
repositoryContents = await blobData.text();
|
||||||
|
} else {
|
||||||
|
console.error('Error fetching repository contents:', blobError);
|
||||||
|
}
|
||||||
|
} catch (storageError) {
|
||||||
|
console.error('Error downloading repository contents:', storageError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch repository contents from storage if path is available
|
||||||
|
if (data.prompt_path) {
|
||||||
|
try {
|
||||||
|
const { data: blobData, error: blobError } = await supabase.storage.from('prompts').download(data.prompt_path);
|
||||||
|
|
||||||
|
if (!blobError && blobData) {
|
||||||
|
prompt = await blobData.text();
|
||||||
|
} else {
|
||||||
|
console.error('Error fetching repository contents:', blobError);
|
||||||
|
}
|
||||||
|
} catch (storageError) {
|
||||||
|
console.error('Error downloading repository contents:', storageError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch solution from storage if path is available
|
||||||
|
if (data.solution_path) {
|
||||||
|
try {
|
||||||
|
const { data: blobData, error: blobError } = await supabase.storage
|
||||||
|
.from('solutions')
|
||||||
|
.download(data.solution_path);
|
||||||
|
|
||||||
|
if (!blobError && blobData) {
|
||||||
|
const solutionText = await blobData.text();
|
||||||
|
solution = JSON.parse(solutionText);
|
||||||
|
} else {
|
||||||
|
console.error('Error fetching solution:', blobError);
|
||||||
|
}
|
||||||
|
} catch (storageError) {
|
||||||
|
console.error('Error downloading solution:', storageError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If the problem has a user_id, fetch the profile information
|
// If the problem has a user_id, fetch the profile information
|
||||||
let username = null;
|
let username = null;
|
||||||
|
|
||||||
if (data.user_id) {
|
if (data.user_id) {
|
||||||
const { data: profileData, error: profileError } = await getSupabase()
|
const { data: profileData, error: profileError } = await supabase
|
||||||
.from('profiles')
|
.from('profiles')
|
||||||
.select('username')
|
.select('username')
|
||||||
.eq('id', data.user_id)
|
.eq('id', data.user_id)
|
||||||
@ -94,8 +152,9 @@ export async function supabaseGetProblem(problemId: string): Promise<BoltProblem
|
|||||||
description: data.description,
|
description: data.description,
|
||||||
status: data.status as BoltProblemStatus,
|
status: data.status as BoltProblemStatus,
|
||||||
keywords: data.keywords,
|
keywords: data.keywords,
|
||||||
repositoryContents: data.repository_contents,
|
repositoryContents,
|
||||||
username,
|
username,
|
||||||
|
solution: solution || prompt,
|
||||||
comments: data.problem_comments.map((comment: any) => ({
|
comments: data.problem_comments.map((comment: any) => ({
|
||||||
id: comment.id,
|
id: comment.id,
|
||||||
timestamp: comment.created_at,
|
timestamp: comment.created_at,
|
||||||
|
@ -121,6 +121,7 @@ async function importProblems(): Promise<void> {
|
|||||||
async function uploadBlob(bucket: string, path: string, contents: string) {
|
async function uploadBlob(bucket: string, path: string, contents: string) {
|
||||||
const { error } = await supabase.storage.from(bucket).upload(path, contents);
|
const { error } = await supabase.storage.from(bucket).upload(path, contents);
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
if (error && error.error !== 'Duplicate') {
|
if (error && error.error !== 'Duplicate') {
|
||||||
console.error(` ❌ Error uploading ${path}:`, error.message, error);
|
console.error(` ❌ Error uploading ${path}:`, error.message, error);
|
||||||
throw error;
|
throw error;
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
// vite takes care of building everything, not tsc
|
// vite takes care of building everything, not tsc
|
||||||
"noEmit": true
|
"noEmit": true
|
||||||
},
|
},
|
||||||
|
"exclude": ["migrate-problems/**/*.ts"],
|
||||||
"include": [
|
"include": [
|
||||||
"**/*.ts",
|
"**/*.ts",
|
||||||
"**/*.tsx",
|
"**/*.tsx",
|
||||||
|
Loading…
Reference in New Issue
Block a user