New UI who dis

This commit is contained in:
oitsjustjose 2023-04-20 23:53:56 -05:00
commit 43fc7d78d0
14 changed files with 440 additions and 0 deletions

5
frontend/.dockerignore Normal file
View file

@ -0,0 +1,5 @@
build/**
.idea/
node_modules/
vs_code/
Dockerfile

28
frontend/.eslintrc.json Normal file
View file

@ -0,0 +1,28 @@
{
"env": {
"browser": true,
"es6": true,
"jest": true
},
"extends": ["plugin:react/recommended", "airbnb"],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 11,
"sourceType": "module"
},
"plugins": ["react"],
"rules": {
"import/no-cycle": 0,
"no-unused-expressions": 0,
"react/jsx-props-no-spreading": 0,
"react/prop-types": 0,
"react/function-component-definition": 0,
"react/no-alert": 0
}
}

28
frontend/.gitignore vendored Normal file
View file

@ -0,0 +1,28 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
yarn.lock
.vscode/
.vscode/*

6
frontend/.prettierrc Normal file
View file

@ -0,0 +1,6 @@
{
"arrowParens": "avoid",
"trailingComma": "es5",
"singleQuote": true,
"semi": true
}

24
frontend/Dockerfile Normal file
View file

@ -0,0 +1,24 @@
FROM node:18-alpine AS builder
RUN apk update && apk upgrade && \
apk add --no-cache bash git openssh
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
FROM node:18-alpine AS server
ENV NODE_ENV=production
RUN npm install -g serve
WORKDIR /app
COPY package*.json ./
COPY --from=builder /app/build ./build
ENV PORT=3000
EXPOSE 3000
USER node
CMD ["serve", "-s", "build"]

45
frontend/package.json Normal file
View file

@ -0,0 +1,45 @@
{
"name": "ctmmm-ui",
"version": "1.0.0",
"private": true,
"dependencies": {
"@popperjs/core": "^2.11.7",
"bootstrap": "^5.2.3",
"react": "18.2.0",
"react-bootstrap": "^2.7.4",
"react-dom": "18.2.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"devDependencies": {
"eslint": "^8.13.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-prefer-arrow-functions": "^3.1.4",
"eslint-plugin-react": "^7.21.4",
"eslint-plugin-react-hooks": "^4.1.2"
},
"proxy": "http://localhost:3000",
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}

View file

@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/app-icon.png" />
<meta name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" />
<meta name="theme-color" content="#17a2b8" />
<link rel="shortcut icon" href="./app-icon.png" type="image/x-icon" />
<meta name="description" content="A Migration Tool to Pull CF Files and Move Them to Modrinth!" />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/app-icon.png" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>CTMMM</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
</html>

View file

@ -0,0 +1,15 @@
{
"short_name": "Curseforge to Modrinth Exporter",
"name": "A Migration Tool to Pull CF Files and Move Them to Modrinth!",
"icons": [
{
"src": "app-icon.png",
"type": "image/png",
"sizes": "128x128"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#252525",
"background_color": "#252525"
}

9
frontend/src/App.css Normal file
View file

@ -0,0 +1,9 @@
.juse-form {
border: 1px solid var(--bs-border-color);
border-radius: 8px;
padding: 2rem;
}
.output-log {
margin-top: 2rem;
}

4
frontend/src/App.jsx Normal file
View file

@ -0,0 +1,4 @@
import React from 'react';
import Home from './pages/Home';
export default () => (<Home />);

View file

@ -0,0 +1,52 @@
import React, { useState } from 'react';
export default () => {
const [render, setRender] = useState(true);
const hide = () => {
window.localStorage.setItem('info-dismissed', true);
setRender(false);
};
return render && (
<div>
<p>
<b>Welcome!</b>
{' '}
In order to use this tool you&apos;ll need to have already created (if it&apos;s
still &quot;Under Review&quot;, that&apos;s ok) your Modrinth Page, and a few other things:
<ul>
<li>
A
{' '}
<a href="https://docs.github.com/en/enterprise-server@3.4/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token" target="_blank" rel="noreferrer">
GitHub Personal Access Token
</a>
{' '}
for the Account you used to log into Modrinth. No
permissions need to be granted to the PAT, this token will be encrypted from end
to end (even in storage), and it will only be used for requests to Modrinth
(feel encouraged to browse this source code to verify).
</li>
<li>
The CurseForge Slug for your Mod. This can be found in the General Settings for your
project page
</li>
<li>
The Modrinth Project ID. This can be found in the side panel of your Modrinth project
</li>
</ul>
This tool works on a queue-based system since I cannot afford enough computing for everyone,
so you&apos;ll be able to see your status and place in the queue down below in the
&quot;Status &amp; Output Log&quot;. You will not lose your place in the queue if you close
this tab or leave this page, as long as you do not clear browser storage you will still be
able to track progress here, or of course on your Modrinth project page!
</p>
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
<a style={{ float: 'right', marginTop: '-2rem' }} href="#" role="button" onClick={hide}><sup>[Hide]</sup></a>
</div>
);
};

View file

@ -0,0 +1,19 @@
import React, { useState, useEffect } from 'react';
export default ({ id }) => {
const [logs, setLogs] = useState('');
useEffect(() => {
const handle = setInterval(async () => {
const resp = await fetch(`/jobs/status/${id}`);
if (resp.ok) {
setLogs(await resp.text());
} else {
setLogs(`${resp.status}: ${resp.statusText}`);
}
}, 500);
return () => clearInterval(handle);
}, [setLogs, id]);
return (<code>{logs}</code>);
};

10
frontend/src/index.js Normal file
View file

@ -0,0 +1,10 @@
import { createRoot } from 'react-dom/client';
import App from './App';
import './App.css';
import 'bootstrap/dist/css/bootstrap.min.css';
const container = document.getElementById('root');
const root = createRoot(container);
root.render(App());

173
frontend/src/pages/Home.jsx Normal file
View file

@ -0,0 +1,173 @@
import React, { useState } from 'react';
import {
Form, Button, Container, Accordion, Modal,
} from 'react-bootstrap';
import OutputLog from '../components/OutputLog';
import Info from '../components/Info';
export default () => {
const [help, setHelp] = useState(null);
const [jobId, setJobId] = useState(window.localStorage.getItem('last-jobid'));
const [formData, setFormData] = useState({
githubPat: '',
slug: '',
projId: '',
});
// eslint-disable-next-line max-len
const isValidState = () => !!formData.githubPat.length && !!formData.slug.length && !!formData.projId.length;
const delimHelp = (evt) => {
evt.preventDefault();
setHelp((
<div>
<p>
This is the splitter between parts of the filename. Geolosys uses format
{' '}
<code>MODNAME-MCVER-MAJOR.MINOR.PATCH</code>
, where
{' '}
<code>-</code>
{' '}
is the delimiter.
</p>
<p>
Using this logic, it is assumed that the Minecraft version for this
{' '}
<code>.jar</code>
-file is between the first and second delimiter, and that the mod version is between
the second and the end of the file. Formatting aside from this is not supported,
unfortunately, as I&apos;ve got a bit of trauma
{' '}
<sup>(/s)</sup>
{' '}
from
{' '}
<a href="https://dv2ls.com/code?id=lUY-c4A2H" target="_blank" rel="noreferrer">
this Regular Expression I wrote.
</a>
</p>
</div>
));
};
const makeJob = async (evt) => {
evt.preventDefault();
if (!isValidState()) return;
const resp = await fetch('/jobs/new', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(formData),
});
if (resp && resp.ok) {
const data = await resp.text();
setJobId(data);
window.localStorage.setItem('last-jobid', data);
}
};
return (
<div style={{ margin: 'auto', maxWidth: '768px' }}>
<h2 className="mb-4 text-center">
CurseForge to Modrinth Mod Migrator (CTMMM)
</h2>
{!window.localStorage.getItem('info-dismissed') && (<Info />)}
<Container style={{ margin: '1rem auto', maxWidth: '512px' }}>
<Form onSubmit={makeJob} className="juse-form">
<Form.Group className="mb-3" controlId="githubPat">
<Form.Label>GitHub Personal Access Token</Form.Label>
<Form.Control
type="password"
required
placeholder="This field is required"
value={formData.githubPat}
onChange={(x) => setFormData({
...formData,
githubPat: x.target.value,
})}
/>
<Form.Text className="text-muted">
This value is encrypted from end-to-end and even in storage
</Form.Text>
</Form.Group>
<Form.Group className="mb-3" controlId="slug">
<Form.Label>CurseForge Project Slug</Form.Label>
<Form.Control
type="text"
required
placeholder="This field is required"
value={formData.slug}
onChange={(x) => setFormData({
...formData,
slug: x.target.value,
})}
/>
</Form.Group>
<Form.Group className="mb-3" controlId="projId">
<Form.Label>Modrinth Project ID</Form.Label>
<Form.Control
type="text"
required
placeholder="This field is required"
value={formData.projId}
onChange={(x) => setFormData({
...formData,
projId: x.target.value,
})}
/>
</Form.Group>
<Form.Group className="mb-3" controlId="delimiter">
<Form.Label>
Delimiter (Optional)
{' '}
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
<a onClick={delimHelp} style={{ textDecoration: 'none' }} href="#">❔</a>
</Form.Label>
<Form.Control
placeholder="Defaults to Hyphen (-)"
type="text"
value={formData.delimiter}
onChange={(x) => setFormData({
...formData,
delimiter: x.target.value,
})}
/>
</Form.Group>
<Button
variant="success"
type="submit"
disabled={!isValidState()}
>
Submit
</Button>
</Form>
{jobId && (
<Accordion defaultActiveKey="0" className="mt-2">
<Accordion.Item eventKey="1">
<Accordion.Header>
<div>
Status &amp; Output Log for Job
{' '}
<code>{`#${jobId}`}</code>
</div>
</Accordion.Header>
<Accordion.Body>{jobId && (<OutputLog id={jobId} />)}</Accordion.Body>
</Accordion.Item>
</Accordion>
)}
</Container>
<Modal centered show={!!help} onHide={() => setHelp(null)}>
<Modal.Body>{help}</Modal.Body>
</Modal>
</div>
);
};