Compare commits
2 Commits
8e4ce66cc4
...
42adeb290c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
42adeb290c | ||
|
|
8c270fc4ea |
1
.gitignore
vendored
1
.gitignore
vendored
@ -32,6 +32,7 @@ yarn-error.log*
|
|||||||
|
|
||||||
# env files (can opt-in for committing if needed)
|
# env files (can opt-in for committing if needed)
|
||||||
.env*
|
.env*
|
||||||
|
/runtimeConfig.json
|
||||||
|
|
||||||
# vercel
|
# vercel
|
||||||
.vercel
|
.vercel
|
||||||
|
|||||||
@ -8,7 +8,7 @@ export async function redirectRequest(
|
|||||||
proxyUrl: string,
|
proxyUrl: string,
|
||||||
backendBaseUrl: string
|
backendBaseUrl: string
|
||||||
): Promise<NextResponse> {
|
): Promise<NextResponse> {
|
||||||
const reqUrl = req.url // full URL e.g. http://localhost:3000/api/proxy?id=123&foo=bar
|
const reqUrl = req.url // full URL e.g. http://localhost:3000/api/proxy?id=123
|
||||||
|
|
||||||
// Find position of proxyPath in reqUrl
|
// Find position of proxyPath in reqUrl
|
||||||
const proxyIndex = reqUrl.indexOf(proxyUrl)
|
const proxyIndex = reqUrl.indexOf(proxyUrl)
|
||||||
@ -17,9 +17,9 @@ export async function redirectRequest(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Replace '/api/proxy/parserBackend' with backend URL, preserve everything after
|
// Replace '/api/proxy/parserBackend' with backend URL, preserve everything after
|
||||||
// e.g. '/api/proxy/extra/path?id=123' -> 'http://your-backend-server/extra/path?id=123'
|
// e.g. '/api/proxy/extra/path?id=123' -> 'http://backend-server/extra/path?id=123'
|
||||||
const backendUrl = backendBaseUrl + reqUrl.substring(proxyIndex + proxyUrl.length)
|
const backendUrl = backendBaseUrl + reqUrl.substring(proxyIndex + proxyUrl.length)
|
||||||
console.log('redirecting', req.url, 'to', backendUrl)
|
// console.log('redirecting', req.url, 'to', backendUrl)
|
||||||
|
|
||||||
const backendRes = await fetch(backendUrl, {
|
const backendRes = await fetch(backendUrl, {
|
||||||
method: req.method,
|
method: req.method,
|
||||||
@ -41,7 +41,7 @@ export async function redirectRequest(
|
|||||||
/// Browsers send OPTIONS request sometimes to check webserver allowed headers and methods.
|
/// Browsers send OPTIONS request sometimes to check webserver allowed headers and methods.
|
||||||
/// My backend doesn't support such requests so use proxy to answer to it that all headers and methods are allowed
|
/// My backend doesn't support such requests so use proxy to answer to it that all headers and methods are allowed
|
||||||
export async function responseToOPTIONS(req: NextRequest): Promise<NextResponse> {
|
export async function responseToOPTIONS(req: NextRequest): Promise<NextResponse> {
|
||||||
console.log('proxy responding to CORS OPTIONS', req.url)
|
// console.log('proxy responding to CORS OPTIONS', req.url)
|
||||||
|
|
||||||
return new NextResponse(null, {
|
return new NextResponse(null, {
|
||||||
status: 200,
|
status: 200,
|
||||||
@ -1,8 +1,8 @@
|
|||||||
import type { NextRequest } from 'next/server'
|
import type { NextRequest } from 'next/server'
|
||||||
import { NextResponse } from 'next/server'
|
import { NextResponse } from 'next/server'
|
||||||
import { redirectRequest, responseToOPTIONS as respondToOPTIONS } from '@/app/api/proxy/proxyFunctions'
|
import { redirectRequest, responseToOPTIONS as respondToOPTIONS } from '@/app/api/proxy/functions'
|
||||||
import { appConfig } from '@/app/lib/configLoader'
|
import { PROXY_PATHS } from '@/app/api/proxy/paths'
|
||||||
import { PROXY_PATHS } from '../../paths'
|
import { appConfig } from '@/lib/configLoader'
|
||||||
|
|
||||||
async function redirect(req: NextRequest): Promise<NextResponse> {
|
async function redirect(req: NextRequest): Promise<NextResponse> {
|
||||||
return await redirectRequest(req, PROXY_PATHS.saveParserBackend, appConfig.services.saveParserBackend.url)
|
return await redirectRequest(req, PROXY_PATHS.saveParserBackend, appConfig.services.saveParserBackend.url)
|
||||||
|
|||||||
@ -5,6 +5,8 @@ import { AllCommunityModule, themeQuartz } from 'ag-grid-community'
|
|||||||
import { useState, useEffect } from 'react'
|
import { useState, useEffect } from 'react'
|
||||||
import { colorSchemeDark } from 'ag-grid-community'
|
import { colorSchemeDark } from 'ag-grid-community'
|
||||||
|
|
||||||
|
// TODO: create tabs with general info, tables, plots
|
||||||
|
|
||||||
export default function BrowsePage() {
|
export default function BrowsePage() {
|
||||||
const [agTheme, setAgTheme] = useState(themeQuartz)
|
const [agTheme, setAgTheme] = useState(themeQuartz)
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
import 'bootstrap/dist/css/bootstrap.min.css'
|
import 'bootstrap/dist/css/bootstrap.min.css'
|
||||||
import './globals.css'
|
import './globals.css'
|
||||||
import '@/app/lib/customConsoleLog'
|
|
||||||
import type { Metadata } from 'next'
|
import type { Metadata } from 'next'
|
||||||
import { ModuleRegistry, AllCommunityModule } from 'ag-grid-community'
|
import { ModuleRegistry, AllCommunityModule } from 'ag-grid-community'
|
||||||
import Navbar from '@/components/Navbar'
|
import Navbar from '@/components/Navbar'
|
||||||
|
|||||||
@ -23,6 +23,7 @@ export default function LoginPage() {
|
|||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
setError(null)
|
||||||
try {
|
try {
|
||||||
console.log('Log in:', formData)
|
console.log('Log in:', formData)
|
||||||
const result = await authService.login(formData.email, formData.password)
|
const result = await authService.login(formData.email, formData.password)
|
||||||
|
|||||||
@ -26,6 +26,7 @@ export default function RegisterPage() {
|
|||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
setError(null)
|
||||||
try {
|
try {
|
||||||
if (formData.password !== formData.confirmPassword) {
|
if (formData.password !== formData.confirmPassword) {
|
||||||
throw new Error('Passwords do not match.')
|
throw new Error('Passwords do not match.')
|
||||||
@ -34,7 +35,6 @@ export default function RegisterPage() {
|
|||||||
console.log('Register', formData)
|
console.log('Register', formData)
|
||||||
const result = await authService.register(formData.name, formData.email, formData.password)
|
const result = await authService.register(formData.name, formData.email, formData.password)
|
||||||
console.log('Registered:', result)
|
console.log('Registered:', result)
|
||||||
|
|
||||||
router.push('/login') // Redirect after success
|
router.push('/login') // Redirect after success
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
console.error(err.message)
|
console.error(err.message)
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import { font_Hack } from '@/app/lib/myFonts'
|
import { font_Hack } from '@/lib/myFonts'
|
||||||
|
|
||||||
export default function Navbar() {
|
export default function Navbar() {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { saveParserBackendService, UploadSaveResponse } from '@/services/SaveParserBackendService'
|
import { saveParserBackendService, SaveStatusResponse, UploadSaveResponse } from '@/services/SaveParserBackendService'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import FormError from './FormError'
|
import FormError from './FormError'
|
||||||
|
|
||||||
@ -13,8 +13,14 @@ export default function SaveFileUploadingDialog() {
|
|||||||
const [error, setError] = useState<string | null>(null)
|
const [error, setError] = useState<string | null>(null)
|
||||||
const [selectedFile, setSelectedFile] = useState<File | null>(null)
|
const [selectedFile, setSelectedFile] = useState<File | null>(null)
|
||||||
const [game, setGame] = useState<GameEnum>(GameEnum.EU4)
|
const [game, setGame] = useState<GameEnum>(GameEnum.EU4)
|
||||||
|
const [uploadDisabled, setUploadDisabled] = useState(false)
|
||||||
|
const [saveStatus, setSaveStatus] = useState<SaveStatusResponse | null>(null)
|
||||||
const [uploadResult, setUploadResult] = useState<UploadSaveResponse | null>(null)
|
const [uploadResult, setUploadResult] = useState<UploadSaveResponse | null>(null)
|
||||||
|
|
||||||
|
const handleGameSelect = (e: React.ChangeEvent<HTMLSelectElement>) => {
|
||||||
|
setGame(e.target.value as GameEnum)
|
||||||
|
}
|
||||||
|
|
||||||
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
if (e.target.files && e.target.files[0]) {
|
if (e.target.files && e.target.files[0]) {
|
||||||
setSelectedFile(e.target.files[0])
|
setSelectedFile(e.target.files[0])
|
||||||
@ -22,58 +28,82 @@ export default function SaveFileUploadingDialog() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleUpload = async () => {
|
const handleUpload = async () => {
|
||||||
|
setError(null)
|
||||||
|
setUploadDisabled(true)
|
||||||
try {
|
try {
|
||||||
if (!selectedFile) return
|
if (!selectedFile) return
|
||||||
|
|
||||||
console.log('Uploading file:', selectedFile.name)
|
console.log('Uploading file:', selectedFile.name)
|
||||||
const result = await saveParserBackendService.uploadSave(game, selectedFile)
|
const uploadResponse = await saveParserBackendService.uploadSave(game, selectedFile)
|
||||||
console.log('Got response:', result)
|
console.log('Upload response:', uploadResponse)
|
||||||
setUploadResult(result)
|
setUploadResult(uploadResponse)
|
||||||
|
|
||||||
|
const pollInterval = 1000 // ms
|
||||||
|
const intervalId = setInterval(async () => {
|
||||||
|
try {
|
||||||
|
const statusResponse = await saveParserBackendService.getSaveStatus(uploadResponse.id)
|
||||||
|
console.log('Save status:', statusResponse.status)
|
||||||
|
setSaveStatus(statusResponse)
|
||||||
|
if (statusResponse.status.toLowerCase() === 'done') {
|
||||||
|
clearInterval(intervalId)
|
||||||
|
setUploadDisabled(false)
|
||||||
|
}
|
||||||
|
} catch (err: any) {
|
||||||
|
console.error('Error while polling status:', err)
|
||||||
|
clearInterval(intervalId)
|
||||||
|
setError(err.message)
|
||||||
|
setUploadDisabled(false)
|
||||||
|
}
|
||||||
|
}, pollInterval)
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
console.error(err.message)
|
console.error(err.message)
|
||||||
setError(err.message)
|
setError(err.message)
|
||||||
|
setUploadDisabled(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const gameEnumOptions = Object.values(GameEnum).map((value) => (
|
||||||
|
<option key={value} value={value}>
|
||||||
|
{value}
|
||||||
|
</option>
|
||||||
|
))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="container mt-5" style={{ maxWidth: '500px' }}>
|
<div className="container mt-5" style={{ maxWidth: '500px' }}>
|
||||||
<h3 className="mb-2 fw-semibold">Select game save file</h3>
|
<h3 className="mb-2 fw-semibold">Select game save file</h3>
|
||||||
<FormError message={error} />
|
<FormError message={error} />
|
||||||
|
|
||||||
<div className="mb-3">
|
<div className="row align-items-center mb-3">
|
||||||
<label htmlFor="gameSelect" className="form-label">
|
<div className="col-auto">Select Game</div>
|
||||||
Select Game
|
<select id="gameSelect" className="col-auto" value={game} onChange={handleGameSelect}>
|
||||||
</label>
|
{gameEnumOptions}
|
||||||
<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>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input type="file" className="form-control mb-3" onChange={handleFileChange} />
|
<div className="row align-items-center mb-3">
|
||||||
<button className="btn btn-primary" onClick={handleUpload} disabled={!selectedFile}>
|
<div className="col-auto">File</div>
|
||||||
|
<input id="fileInput" type="file" className="col-auto" onChange={handleFileChange} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button className="btn btn-primary" onClick={handleUpload} disabled={!selectedFile || uploadDisabled}>
|
||||||
Upload File
|
Upload File
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
{selectedFile && (
|
{/* TODO: extract this to a component
|
||||||
<div className="mt-3">
|
<ConditionalView cond={uploadResult}> <LabeledValue val={}/> </ConditionalView> */}
|
||||||
File: <strong>{selectedFile.name}</strong>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{uploadResult && (
|
{uploadResult && (
|
||||||
<div className="mt-3">
|
<div className="mt-3">
|
||||||
Save Id: <strong>{uploadResult.id}</strong>
|
Save Id: <strong>{uploadResult.id}</strong>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{saveStatus && (
|
||||||
|
<div className="mt-3">
|
||||||
|
Status: <strong>{saveStatus.status}</strong>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* add link to <ConditionalView cond={done}> /browse?id=${saveStatus.id} */}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
1
src/config/.gitignore
vendored
1
src/config/.gitignore
vendored
@ -1 +0,0 @@
|
|||||||
/runtimeConfig.json
|
|
||||||
@ -4,6 +4,7 @@ export const defaultConfig = {
|
|||||||
saveParserBackend: {
|
saveParserBackend: {
|
||||||
url: 'http://127.0.0.1:5226',
|
url: 'http://127.0.0.1:5226',
|
||||||
},
|
},
|
||||||
|
// TODO: implement auth api
|
||||||
auth: {},
|
auth: {},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
5
src/instrumentation.ts
Normal file
5
src/instrumentation.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import '@/lib/customConsoleLog'
|
||||||
|
|
||||||
|
export function register() {
|
||||||
|
console.log('hello from instrumentation.ts!')
|
||||||
|
}
|
||||||
@ -1,9 +1,9 @@
|
|||||||
'server'
|
'server'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { AppConfig, defaultConfig } from '@/config/defaultConfig'
|
import { AppConfig, defaultConfig } from '@/config/AppConfig'
|
||||||
|
|
||||||
const configFilePath = path.join(process.cwd(), 'config', 'runtimeConfig.json')
|
const configFilePath = path.join(process.cwd(), 'runtimeConfig.json')
|
||||||
|
|
||||||
function loadConfig(): AppConfig {
|
function loadConfig(): AppConfig {
|
||||||
let config = defaultConfig
|
let config = defaultConfig
|
||||||
|
|||||||
@ -1,8 +1,13 @@
|
|||||||
'server'
|
let _custom_console_log_injected = false
|
||||||
|
if (!_custom_console_log_injected) {
|
||||||
|
_custom_console_log_injected = true
|
||||||
const originalLog = console.log
|
const originalLog = console.log
|
||||||
|
|
||||||
console.log = (message?: any, ...optionalParams: any[]) => {
|
function customLog(message?: any, ...optionalParams: any[]) {
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
const timestamp = now.toTimeString().split(' ')[0] // hh:mm:ss
|
const timestamp = now.toTimeString().split(' ')[0] // hh:mm:ss
|
||||||
originalLog(`[${timestamp}] ${message}`, ...optionalParams)
|
originalLog(`[${timestamp}] ${message}`, ...optionalParams, ':3')
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log = customLog
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
import { PROXY_PATHS } from '@/app/api/proxy/paths'
|
||||||
|
|
||||||
export interface UploadSaveResponse {
|
export interface UploadSaveResponse {
|
||||||
id: string
|
id: string
|
||||||
}
|
}
|
||||||
@ -10,7 +12,7 @@ export interface SaveStatusResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class SaveParserBackendService {
|
export class SaveParserBackendService {
|
||||||
private API_BASE = '/api/proxy/parserBackend'
|
private API_BASE = PROXY_PATHS.saveParserBackend
|
||||||
|
|
||||||
private async tryGetResponseJson(res: Response): Promise<string> {
|
private async tryGetResponseJson(res: Response): Promise<string> {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user