Compare commits
No commits in common. "9faf3f761837c1089b5d0e83cb66c0225b15fcdc" and "044c2870e76aef27843491251b8e49842b808664" have entirely different histories.
9faf3f7618
...
044c2870e7
23
.vscode/launch.json
vendored
23
.vscode/launch.json
vendored
@ -1,23 +0,0 @@
|
|||||||
{
|
|
||||||
// Use IntelliSense to learn about possible attributes.
|
|
||||||
// Hover to view descriptions of existing attributes.
|
|
||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
||||||
"version": "0.2.0",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "node-terminal: npm run dev",
|
|
||||||
"command": "npm run dev",
|
|
||||||
"request": "launch",
|
|
||||||
"skipFiles": ["<node_internals>/**"],
|
|
||||||
"type": "node-terminal"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "node: npm run dev",
|
|
||||||
"request": "launch",
|
|
||||||
"runtimeArgs": ["run", "dev"],
|
|
||||||
"runtimeExecutable": "npm",
|
|
||||||
"skipFiles": ["<node_internals>/**"],
|
|
||||||
"type": "node"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@ -1,8 +1,7 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { authService } from '@/services/AuthService'
|
import { authService } from '@/services/authService'
|
||||||
import FormError from '@/components/FormError'
|
|
||||||
|
|
||||||
export default function LoginPage() {
|
export default function LoginPage() {
|
||||||
const [formData, setFormData] = useState({
|
const [formData, setFormData] = useState({
|
||||||
@ -11,7 +10,7 @@ export default function LoginPage() {
|
|||||||
stayLoggedIn: true,
|
stayLoggedIn: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
const [error, setError] = useState<string | null>(null)
|
const [error, setError] = useState('')
|
||||||
|
|
||||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
const { name, value, type, checked } = e.target
|
const { name, value, type, checked } = e.target
|
||||||
@ -37,7 +36,11 @@ export default function LoginPage() {
|
|||||||
<div className="container mt-5" style={{ maxWidth: '500px' }}>
|
<div className="container mt-5" style={{ maxWidth: '500px' }}>
|
||||||
<h2 className="mb-4">Login</h2>
|
<h2 className="mb-4">Login</h2>
|
||||||
|
|
||||||
<FormError message={error} />
|
{error && (
|
||||||
|
<div className="alert alert-danger" role="alert">
|
||||||
|
{error}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<form onSubmit={handleSubmit}>
|
<form onSubmit={handleSubmit}>
|
||||||
<div className="mb-3">
|
<div className="mb-3">
|
||||||
|
|||||||
@ -1,11 +0,0 @@
|
|||||||
import SaveFileUploadingDialog from '@/components/SaveFileUploadingDialog'
|
|
||||||
|
|
||||||
export default function HomePage() {
|
|
||||||
return (
|
|
||||||
<div className="container mt-5 text-center">
|
|
||||||
<h1 className="mb-4">Welcome to Paradox Save Parser!</h1>
|
|
||||||
|
|
||||||
<SaveFileUploadingDialog />
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { useRouter } from 'next/navigation'
|
import { useRouter } from 'next/navigation'
|
||||||
import { authService } from '@/services/AuthService'
|
import { authService } from '@/services/authService'
|
||||||
import FormError from '@/components/FormError'
|
|
||||||
|
|
||||||
export default function RegisterPage() {
|
export default function RegisterPage() {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@ -15,7 +14,7 @@ export default function RegisterPage() {
|
|||||||
confirmPassword: '',
|
confirmPassword: '',
|
||||||
})
|
})
|
||||||
|
|
||||||
const [error, setError] = useState<string | null>(null)
|
const [error, setError] = useState('')
|
||||||
|
|
||||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
setFormData((prev) => ({
|
setFormData((prev) => ({
|
||||||
@ -46,7 +45,11 @@ export default function RegisterPage() {
|
|||||||
<div className="container mt-5" style={{ maxWidth: '400px' }}>
|
<div className="container mt-5" style={{ maxWidth: '400px' }}>
|
||||||
<h2 className="mb-4 text-center">Register</h2>
|
<h2 className="mb-4 text-center">Register</h2>
|
||||||
|
|
||||||
<FormError message={error} />
|
{error && (
|
||||||
|
<div className="alert alert-danger" role="alert">
|
||||||
|
{error}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<form onSubmit={handleSubmit}>
|
<form onSubmit={handleSubmit}>
|
||||||
<div className="mb-3">
|
<div className="mb-3">
|
||||||
|
|||||||
@ -1,13 +0,0 @@
|
|||||||
interface FormErrorProps {
|
|
||||||
message: string | null
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function FormError(props: FormErrorProps) {
|
|
||||||
if (!props.message || props.message === '') return null
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="alert alert-danger" role="alert">
|
|
||||||
{props.message}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@ -1,79 +0,0 @@
|
|||||||
'use client'
|
|
||||||
|
|
||||||
import { saveParserBackendService, UploadSaveResponse } from '@/services/SaveParserBackendService'
|
|
||||||
import { useState } from 'react'
|
|
||||||
import FormError from './FormError'
|
|
||||||
|
|
||||||
export enum GameEnum {
|
|
||||||
EU4 = 'eu4',
|
|
||||||
Stellaris = 'stellaris',
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function SaveFileUploadingDialog() {
|
|
||||||
const [error, setError] = useState<string | null>(null)
|
|
||||||
const [selectedFile, setSelectedFile] = useState<File | null>(null)
|
|
||||||
const [game, setGame] = useState<GameEnum>(GameEnum.EU4)
|
|
||||||
const [uploadResult, setUploadResult] = useState<UploadSaveResponse | null>(null)
|
|
||||||
|
|
||||||
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
||||||
if (e.target.files && e.target.files[0]) {
|
|
||||||
setSelectedFile(e.target.files[0])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleUpload = async () => {
|
|
||||||
try {
|
|
||||||
if (!selectedFile) return
|
|
||||||
|
|
||||||
console.log('Uploading file:', selectedFile.name)
|
|
||||||
const result = await saveParserBackendService.uploadSave(game, selectedFile)
|
|
||||||
console.log('Got response:', result)
|
|
||||||
setUploadResult(result)
|
|
||||||
} catch (err: any) {
|
|
||||||
console.error(err.message)
|
|
||||||
setError(err.message)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="container mt-5" style={{ maxWidth: '500px' }}>
|
|
||||||
<h3 className="mb-2 fw-semibold">Select game save file</h3>
|
|
||||||
<FormError message={error} />
|
|
||||||
|
|
||||||
<div className="mb-3">
|
|
||||||
<label htmlFor="gameSelect" className="form-label">
|
|
||||||
Select Game
|
|
||||||
</label>
|
|
||||||
<select
|
|
||||||
id="gameSelect"
|
|
||||||
className="form-select"
|
|
||||||
value={game}
|
|
||||||
onChange={(e) => setGame(e.target.value as GameEnum)}
|
|
||||||
>
|
|
||||||
{Object.values(GameEnum).map((value) => (
|
|
||||||
<option key={value} value={value}>
|
|
||||||
{value}
|
|
||||||
</option>
|
|
||||||
))}
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<input type="file" className="form-control mb-3" onChange={handleFileChange} />
|
|
||||||
<button className="btn btn-primary" onClick={handleUpload} disabled={!selectedFile}>
|
|
||||||
Upload File
|
|
||||||
</button>
|
|
||||||
|
|
||||||
{selectedFile && (
|
|
||||||
<div className="mt-3">
|
|
||||||
File: <strong>{selectedFile.name}</strong>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{uploadResult && (
|
|
||||||
<div className="mt-3">
|
|
||||||
Save Id: <strong>{uploadResult.id}</strong>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@ -1,55 +0,0 @@
|
|||||||
export interface UploadSaveResponse {
|
|
||||||
id: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface SaveStatusResponse {
|
|
||||||
id: string
|
|
||||||
game: string
|
|
||||||
status: string
|
|
||||||
uploadDateTime: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export class SaveParserBackendService {
|
|
||||||
private API_BASE = 'http://localhost:5226'
|
|
||||||
|
|
||||||
async uploadSave(game: string, file: File): Promise<UploadSaveResponse> {
|
|
||||||
const url = `${this.API_BASE}/uploadSave?game=${encodeURIComponent(game)}`
|
|
||||||
const response = await fetch(url, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'text/plain',
|
|
||||||
},
|
|
||||||
body: file,
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`Failed to upload save: ${response.statusText} \n${await response.text()}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
return await response.json()
|
|
||||||
}
|
|
||||||
|
|
||||||
async getSaveStatus(id: string): Promise<SaveStatusResponse> {
|
|
||||||
const url = `${this.API_BASE}/getSaveStatus?id=${encodeURIComponent(id)}`
|
|
||||||
const response = await fetch(url)
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`Failed to get save status: ${response.statusText} \n${await response.text()}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
return await response.json()
|
|
||||||
}
|
|
||||||
|
|
||||||
async getParsedSave(id: string): Promise<Record<string, any>> {
|
|
||||||
const url = `${this.API_BASE}/getParsedSave?id=${encodeURIComponent(id)}`
|
|
||||||
const response = await fetch(url)
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`Failed to get parsed save: ${response.statusText} \n${await response.text()}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
return await response.json()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const saveParserBackendService = new SaveParserBackendService()
|
|
||||||
Loading…
Reference in New Issue
Block a user