[RO-1083] fix problem loading

This commit is contained in:
D. Seifert 2025-03-27 18:15:44 +08:00
parent 3b890f27e3
commit dc21175300
6 changed files with 10 additions and 35 deletions

View File

@ -5,7 +5,6 @@ import { logStore } from '~/lib/stores/logs';
import { assert } from '~/lib/replay/ReplayProtocolClient';
import type { BoltProblem } from '~/lib/replay/Problems';
import { getProblem } from '~/lib/replay/Problems';
import { createRepositoryImported } from '~/lib/replay/Repository';
import type { Message } from '~/lib/persistence/message';
interface LoadProblemButtonProps {
@ -46,10 +45,9 @@ export async function loadProblem(
setLastLoadedProblem(problem);
const { repositoryContents, title: problemTitle } = problem;
const { repositoryId, title: problemTitle } = problem;
try {
const repositoryId = await createRepositoryImported(`ImportProblem:${problemId}`, repositoryContents);
const messages = createChatFromFolder('problem', repositoryId);
await importChat(`Problem: ${problemTitle}`, [...messages]);

View File

@ -4,7 +4,6 @@ import { useState, useEffect } from 'react';
import { workbenchStore } from '~/lib/stores/workbench';
import { submitProblem, BoltProblemStatus } from '~/lib/replay/Problems';
import type { BoltProblemInput } from '~/lib/replay/Problems';
import { getRepositoryContents } from '~/lib/replay/Repository';
import { shouldUseSupabase, getCurrentUser } from '~/lib/supabase/client';
import { authModalStore } from '~/lib/stores/authModal';
import { authStatusStore } from '~/lib/stores/auth';
@ -72,15 +71,13 @@ export function SaveProblem() {
return;
}
const repositoryContents = await getRepositoryContents(repositoryId);
const problem: BoltProblemInput = {
version: 2,
title: formData.title,
description: formData.description,
username: shouldUseSupabase() ? (undefined as any) : formData.username,
user_id: shouldUseSupabase() ? (await getCurrentUser())?.id || '' : undefined,
repositoryContents,
repositoryId,
status: BoltProblemStatus.Pending,
};

View File

@ -1,7 +1,7 @@
// Accessors for the API to access saved problems.
import { toast } from 'react-toastify';
import { sendCommandDedicatedClient } from './ReplayProtocolClient';
import { assert, sendCommandDedicatedClient } from './ReplayProtocolClient';
import type { Message } from '~/lib/persistence/message';
import Cookies from 'js-cookie';
import { shouldUseSupabase } from '~/lib/supabase/client';
@ -61,7 +61,7 @@ export interface BoltProblemDescription {
export interface BoltProblem extends BoltProblemDescription {
username?: string;
user_id?: string;
repositoryContents: string;
repositoryId: string;
comments?: BoltProblemComment[];
solution?: BoltProblemSolution;
}
@ -133,11 +133,7 @@ export async function getProblem(problemId: string): Promise<BoltProblem | null>
return null;
}
if ('prompt' in problem) {
// 2/11/2025: Update obsolete data format for older problems.
problem.repositoryContents = (problem as any).prompt.content;
delete problem.prompt;
}
assert(problem.repositoryId, 'Problem probably has outdated data format. Must have a repositoryId.');
} catch (error) {
console.error('Error fetching problem', error);

View File

@ -15,7 +15,7 @@ export interface Database {
description: string;
status: 'Pending' | 'Solved' | 'Unsolved';
keywords: string[];
repository_contents: Json;
repository_id: string;
user_id: string | null;
problem_comments: Database['public']['Tables']['problem_comments']['Row'][];
solution: Json;

View File

@ -84,18 +84,12 @@ export async function supabaseGetProblem(problemId: string): Promise<BoltProblem
}
// Fetch blob data from storage if paths are available
let repositoryContents = data.repository_contents;
let solution = data.solution;
const prompt = data.prompt;
// Create a supabase instance for storage operations
const supabase = getSupabase();
// Fetch repository contents from storage if path is available
if (data.repository_contents_path) {
repositoryContents = (await downloadBlob('repository-contents', data.repository_contents_path)) || '';
}
if (data.solution_path) {
solution = JSON.parse((await downloadBlob('solutions', data.solution_path)) || '{}');
}
@ -123,7 +117,7 @@ export async function supabaseGetProblem(problemId: string): Promise<BoltProblem
description: data.description,
status: data.status as BoltProblemStatus,
keywords: data.keywords,
repositoryContents,
repositoryId: data.repository_id,
username,
solution: solution || prompt,
comments: data.problem_comments.map((comment: any) => ({
@ -154,7 +148,7 @@ export async function supabaseSubmitProblem(problem: BoltProblemInput): Promise<
description: problem.description,
status: problem.status as BoltProblemStatus,
keywords: problem.keywords || [],
repository_contents: problem.repositoryContents,
repository_id: problem.repositoryId,
user_id: problem.user_id,
};
@ -202,7 +196,7 @@ export async function supabaseUpdateProblem(problemId: string, problem: BoltProb
description: problem.description,
status: problem.status,
keywords: problem.keywords || [],
repository_contents_path: problem.repositoryContents ? `problems/${problemId}.txt` : undefined,
repository_id: problem.repositoryId,
solution_path: problem.solution ? `solutions/${problemId}.json` : undefined,
};
@ -213,17 +207,6 @@ export async function supabaseUpdateProblem(problemId: string, problem: BoltProb
throw updateError;
}
if (updates.repository_contents_path) {
const { error: repositoryContentsError } = await getSupabase()
.storage.from('repository-contents')
.upload(updates.repository_contents_path, problem.repositoryContents);
// @ts-ignore - ignore duplicate error
if (repositoryContentsError && repositoryContentsError.error !== 'Duplicate') {
throw repositoryContentsError;
}
}
if (updates.solution_path) {
const { error: solutionError } = await getSupabase()
.storage.from('solutions')

View File

@ -7,6 +7,7 @@
"type": "module",
"version": "0.0.5",
"scripts": {
"checks": "pnpm run typecheck && pnpm run lint:fix",
"deploy": "vercel deploy --prod",
"build": "npx remix vite:build",
"dev": "node pre-start.cjs && npx remix vite:dev",