feat: enhance import session handling by adding session UUID to commitImport function

This commit is contained in:
Wikid82
2025-11-22 15:58:12 -05:00
parent 185121d9f0
commit 8a60325464
6 changed files with 16 additions and 5 deletions

View File

@@ -14,6 +14,7 @@ import (
"github.com/Wikid82/CaddyProxyManagerPlus/backend/internal/models"
"github.com/Wikid82/CaddyProxyManagerPlus/backend/internal/server"
"github.com/Wikid82/CaddyProxyManagerPlus/backend/internal/version"
"github.com/gin-gonic/gin"
"gopkg.in/natefinch/lumberjack.v2"
)
@@ -38,6 +39,7 @@ func main() {
// Log to both stdout and file
mw := io.MultiWriter(os.Stdout, rotator)
log.SetOutput(mw)
gin.DefaultWriter = mw
// Handle CLI commands
if len(os.Args) > 1 && os.Args[1] == "reset-password" {

2
docker-entrypoint.sh Normal file → Executable file
View File

@@ -30,7 +30,7 @@ echo "Starting CPM+ management application..."
if [ "$CPMP_DEBUG" = "1" ]; then
DEBUG_PORT=${CPMP_DEBUG_PORT:-2345}
echo "Running CPM+ under Delve (port $DEBUG_PORT)"
/usr/local/bin/dlv exec /app/cpmp --headless --listen=":$DEBUG_PORT" --api-version=2 --accept-multiclient --log -- &
/usr/local/bin/dlv exec /app/cpmp --headless --listen=":$DEBUG_PORT" --api-version=2 --accept-multiclient --continue --log -- &
else
/app/cpmp &
fi

View File

@@ -27,8 +27,8 @@ export const getImportPreview = async (): Promise<ImportPreview> => {
return data;
};
export const commitImport = async (resolutions: Record<string, string>): Promise<void> => {
await client.post('/import/commit', { resolutions });
export const commitImport = async (sessionUUID: string, resolutions: Record<string, string>): Promise<void> => {
await client.post('/import/commit', { session_uuid: sessionUUID, resolutions });
};
export const cancelImport = async (): Promise<void> => {

View File

@@ -63,6 +63,11 @@ const mockNotifications: api.Notification[] = [
describe('NotificationCenter', () => {
beforeEach(() => {
vi.clearAllMocks()
vi.mocked(api.checkUpdates).mockResolvedValue({
available: false,
latest_version: '0.0.0',
changelog_url: '',
})
})
afterEach(() => {

View File

@@ -143,7 +143,7 @@ describe('useImport', () => {
await result.current.commit({ 'test.com': 'skip' })
})
expect(api.commitImport).toHaveBeenCalledWith({ 'test.com': 'skip' })
expect(api.commitImport).toHaveBeenCalledWith('session-2', { 'test.com': 'skip' })
await waitFor(() => {
expect(result.current.session).toBeNull()

View File

@@ -43,7 +43,11 @@ export function useImport() {
});
const commitMutation = useMutation({
mutationFn: (resolutions: Record<string, string>) => commitImport(resolutions),
mutationFn: (resolutions: Record<string, string>) => {
const sessionId = statusQuery.data?.session?.id;
if (!sessionId) throw new Error("No active session");
return commitImport(sessionId, resolutions);
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: QUERY_KEY });
queryClient.invalidateQueries({ queryKey: ['import-preview'] });