Compare commits
98 Commits
Author | SHA1 | Date |
---|---|---|
|
e697660a48 | |
|
694bb8ca19 | |
|
2c922fc0eb | |
|
740104df26 | |
|
8f9bfd071a | |
|
5fc66917c5 | |
|
089fcef4ca | |
|
a46c288744 | |
|
bd71cbbd0c | |
|
61b1b20e9a | |
|
7af2e396a9 | |
|
0a22fab875 | |
|
e5833f1f9c | |
|
c19cd3a889 | |
|
2e98137088 | |
|
c96da4e30f | |
|
4c47a71b84 | |
|
ebcf811bc7 | |
|
8e631e5da5 | |
|
11fca38500 | |
|
c3385ea7b8 | |
|
ac3dfd95a6 | |
|
baa78d8933 | |
|
11baf70a48 | |
|
38fc85e6df | |
|
f856f89a81 | |
|
5f22ef3e27 | |
|
a316f5a3fa | |
|
40c51ce4c7 | |
|
339cab776a | |
|
00991ad93c | |
|
e04dbdce01 | |
|
7c8b5fff1b | |
|
1f4d6e66e2 | |
|
2239fbf169 | |
|
251f363bc5 | |
|
3ca6108431 | |
|
0ef4cb8e5b | |
|
d77949f0dd | |
|
520d6bee7c | |
|
c038eacce4 | |
|
2de0b52143 | |
|
0a98f6fd35 | |
|
f3683624e3 | |
|
8633524a94 | |
|
9ab44b4b43 | |
|
aa5d2673c6 | |
|
c32f809e56 | |
|
d42cd02105 | |
|
b27228890e | |
|
15ec8f5dbe | |
|
088c88997f | |
|
bd266eb973 | |
|
ed49a7f23a | |
|
9064d51ba1 | |
|
fec13f71fa | |
|
63e3efac7d | |
|
51c92081c4 | |
|
abe31e46bd | |
|
d18ccefa26 | |
|
633a8e6192 | |
|
c8b5baf66b | |
|
9f338ddac7 | |
|
82d00ffa41 | |
|
ff9744d46a | |
|
f8f3ea2614 | |
|
1c29e925a5 | |
|
2f904a1051 | |
|
4e07fd63de | |
|
0320d987ed | |
|
ccf9aef580 | |
|
621e86e5cb | |
|
4a0b8ca6c7 | |
|
f1ec83c48a | |
|
edfa1f7b24 | |
|
5b7b1c0d7c | |
|
e3c41fc573 | |
|
34ed648a90 | |
|
b0206c0ccd | |
|
c129c09d19 | |
|
6dab85e168 | |
|
5296f27ed0 | |
|
cb81c4f20b | |
|
c795ca0d14 | |
|
7e952c1ef8 | |
|
7ebb596e83 | |
|
cdd3d58b09 | |
|
e69435efab | |
|
afb37d98b4 | |
|
131d99a4f3 | |
|
e798837998 | |
|
8a32a4967b | |
|
d63adfb17d | |
|
8f3d7ded67 | |
|
85d4cf1b93 | |
|
bff65c4f7d | |
|
aa41495512 | |
|
35f3d56e95 |
|
@ -1,4 +1,8 @@
|
||||||
name: Build image
|
name: Build image
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
packages: write
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
paths:
|
paths:
|
||||||
|
@ -9,41 +13,32 @@ on:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
container:
|
runs-on: ubuntu-latest
|
||||||
image: docker:dind
|
|
||||||
volumes:
|
|
||||||
- /data/.cache/act:/data/.cache/act
|
|
||||||
- /var/lib/docker/image:/var/lib/docker/image
|
|
||||||
- /var/lib/docker/overlay2:/var/lib/docker/overlay2
|
|
||||||
steps:
|
steps:
|
||||||
- name: Starting docker daemon
|
|
||||||
run: docker-init -- dockerd --host=unix:///var/run/docker.sock &
|
|
||||||
- name: Installing necessary packages
|
|
||||||
run: apk add nodejs git curl bash
|
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
|
||||||
- name: Docker meta
|
- name: Docker meta
|
||||||
id: meta
|
id: meta
|
||||||
uses: https://github.com/docker/metadata-action@v5
|
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5
|
||||||
with:
|
with:
|
||||||
# list of Docker images to use as base name for tags
|
# list of Docker images to use as base name for tags
|
||||||
images: |
|
images: |
|
||||||
git.fai.st/fedi-image-bot/moderation-fe
|
git.fai.st/${{ github.repository }}
|
||||||
# generate Docker tags based on the following events/attributes
|
# generate Docker tags based on the following events/attributes
|
||||||
tags: |
|
tags: |
|
||||||
type=raw,value=latest
|
type=raw,value=latest
|
||||||
type=ref,event=branch
|
type=ref,event=branch
|
||||||
type=semver,pattern={{raw}}
|
type=semver,pattern={{raw}}
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v2
|
uses: docker/setup-buildx-action@f7ce87c1d6bead3e36075b2ce75da1f6cc28aaca # v3
|
||||||
- name: Login to fai.st docker registry
|
- name: Login to fai.st docker registry
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
|
||||||
with:
|
with:
|
||||||
registry: git.fai.st
|
registry: git.fai.st
|
||||||
username: ${{ secrets.DOCKER_USER }}
|
username: ${{ secrets.DOCKER_USER }}
|
||||||
password: ${{ secrets.DOCKER_PASS }}
|
password: ${{ secrets.DOCKER_PASS }}
|
||||||
- name: Build and push
|
- name: Build and push
|
||||||
uses: docker/build-push-action@v4
|
uses: docker/build-push-action@0adf9959216b96bec444f325f1e493d4aa344497 # v6
|
||||||
with:
|
with:
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
context: .
|
context: .
|
|
@ -0,0 +1,26 @@
|
||||||
|
name: renovate
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
schedule:
|
||||||
|
- cron: "@daily"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
renovate:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||||
|
- name: Self-hosted Renovate
|
||||||
|
uses: https://github.com/renovatebot/github-action@e084b5ac6fd201023db6dd7743aec023babb02c8 # v41.0.13
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.RENOVATE_TOKEN }}
|
||||||
|
env-regex: "^(?:RENOVATE_\\w+|GITHUB_COM_TOKEN)$"
|
||||||
|
env:
|
||||||
|
RENOVATE_ENDPOINT: ${{ github.server_url }}
|
||||||
|
RENOVATE_PLATFORM: "gitea"
|
||||||
|
RENOVATE_GIT_AUTHOR: "Renovate Bot <contact@siesta.cat>"
|
||||||
|
RENOVATE_REPOSITORIES: ${{ github.repository }}
|
||||||
|
GITHUB_COM_TOKEN: ${{ secrets.RENOVATE_GHPAT }}
|
|
@ -0,0 +1 @@
|
||||||
|
nodejs 23.8.0
|
|
@ -1,9 +1,9 @@
|
||||||
FROM --platform=$BUILDPLATFORM node:23-alpine AS install
|
FROM --platform=$BUILDPLATFORM node:23.8.0-alpine AS install
|
||||||
RUN mkdir -p /temp/prod
|
RUN mkdir -p /temp/prod
|
||||||
COPY package*.json /temp/prod/
|
COPY package*.json /temp/prod/
|
||||||
RUN cd /temp/prod && npm install --frozen-lockfile
|
RUN cd /temp/prod && npm install --frozen-lockfile
|
||||||
COPY . /temp/prod/
|
COPY . /temp/prod/
|
||||||
RUN cd /temp/prod && npm run build
|
RUN cd /temp/prod && npm run build
|
||||||
|
|
||||||
FROM nginx AS release
|
FROM nginx:1.27.3-alpine3.20-slim AS release
|
||||||
COPY --from=install /temp/prod/dist /usr/share/nginx/html
|
COPY --from=install /temp/prod/dist /usr/share/nginx/html
|
||||||
|
|
35
compose.yaml
35
compose.yaml
|
@ -1,7 +1,7 @@
|
||||||
services:
|
services:
|
||||||
mongodb:
|
mongodb:
|
||||||
image: mongo:bionic
|
image: mongo:bionic
|
||||||
container_name: mongodb
|
container_name: fe-mongodb
|
||||||
ports:
|
ports:
|
||||||
- "27017:27017"
|
- "27017:27017"
|
||||||
environment:
|
environment:
|
||||||
|
@ -10,32 +10,34 @@ services:
|
||||||
MONGO_INITDB_DATABASE: bot
|
MONGO_INITDB_DATABASE: bot
|
||||||
volumes:
|
volumes:
|
||||||
- ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
|
- ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
|
||||||
- mongodb_data:/data/db
|
|
||||||
|
|
||||||
bot-api:
|
bot-api:
|
||||||
image: git.fai.st/fedi-image-bot/bot-api:latest
|
image: ghcr.io/siesta-cat/2chi-api:v1.1.0
|
||||||
container_name: bot-api
|
container_name: fe-2chi-api
|
||||||
|
restart: on-failure
|
||||||
ports:
|
ports:
|
||||||
- "8080:8080"
|
- 8080:8080
|
||||||
depends_on:
|
depends_on:
|
||||||
- mongodb
|
- mongodb
|
||||||
environment:
|
environment:
|
||||||
PORT: 8080
|
PORT: 8080
|
||||||
MONGODB_URI: "mongodb://mongodb:27017/bot"
|
DB_HOST: "mongodb"
|
||||||
MONGODB_USER: "root"
|
DB_NAME: "bot"
|
||||||
MONGODB_PASS: "password"
|
DB_USER: "root"
|
||||||
JWTSECRET: "cooljwtsecret"
|
DB_PASS: "password"
|
||||||
|
|
||||||
fe-middleware:
|
fe-middleware:
|
||||||
image: git.fai.st/fedi-image-bot/fe-middleware:latest
|
image: ghcr.io/siesta-cat/2chi-verifier-be:v2.1.3
|
||||||
container_name: fe-middleware
|
container_name: fe-2chi-verifier-be
|
||||||
|
stop_signal: sigkill
|
||||||
ports:
|
ports:
|
||||||
- "8081:8081"
|
- 8081:8081
|
||||||
depends_on:
|
depends_on:
|
||||||
- bot-api
|
- bot-api
|
||||||
environment:
|
environment:
|
||||||
PORT: 8081
|
PORT: 8081
|
||||||
BOT_API_URI: "http://bot-api:8080"
|
BOT_API_BASE_URL: "http://bot-api:8080"
|
||||||
|
TOKEN_SECRET: Y2hpY2FzZWNyZXQK
|
||||||
GELBOORU_IMAGES_PER_REQUEST: 100 # Number of images per request, maximum 100
|
GELBOORU_IMAGES_PER_REQUEST: 100 # Number of images per request, maximum 100
|
||||||
GELBOORU_TAGS: "2girls sleeping" # Tags of the images. The images will have all of these tags
|
GELBOORU_TAGS: "2girls sleeping" # Tags of the images. The images will have all of these tags
|
||||||
|
|
||||||
|
@ -43,13 +45,12 @@ services:
|
||||||
build: .
|
build: .
|
||||||
container_name: bot-image-moderation-fe
|
container_name: bot-image-moderation-fe
|
||||||
ports:
|
ports:
|
||||||
- "80:80"
|
- 80:80
|
||||||
|
environment:
|
||||||
|
VITE_BACKEND_URL: "http://localhost:8081"
|
||||||
develop:
|
develop:
|
||||||
watch:
|
watch:
|
||||||
- action: rebuild
|
- action: rebuild
|
||||||
path: .
|
path: .
|
||||||
ignore:
|
ignore:
|
||||||
- node_modules/
|
- node_modules/
|
||||||
|
|
||||||
volumes:
|
|
||||||
mongodb_data:
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
12
package.json
12
package.json
|
@ -8,14 +8,12 @@
|
||||||
"build": "tsc && vite build"
|
"build": "tsc && vite build"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"react": "^18.2.0",
|
"react-dom": "19.0.0",
|
||||||
"react-dom": "^18.2.0",
|
"typescript": "5.7.3",
|
||||||
"typescript": "^5.2.2",
|
"vite": "6.1.1"
|
||||||
"vite": "^6.0.0"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/react": "^18.2.43",
|
"@types/react-dom": "19.0.4",
|
||||||
"@types/react-dom": "^18.2.17",
|
"@vitejs/plugin-react-swc": "3.8.0"
|
||||||
"@vitejs/plugin-react-swc": "^3.5.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
{
|
{
|
||||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
}
|
"extends": ["config:recommended", "helpers:pinGitHubActionDigests"],
|
||||||
|
"rangeStrategy": "pin"
|
||||||
|
}
|
26
src/App.tsx
26
src/App.tsx
|
@ -1,30 +1,14 @@
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
import GetBackendUrl from "./components/ImageModerator/GetBackendUrl";
|
||||||
import ImageModerator from "./components/ImageModerator/ImageModerator";
|
import ImageModerator from "./components/ImageModerator/ImageModerator";
|
||||||
import Login from "./components/Login/Login";
|
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const [{ apiUrl, middlewareUrl, token }, setRemote] = useState({
|
const [backendUrl, setBackendUrl] = useState("");
|
||||||
apiUrl: "",
|
|
||||||
middlewareUrl: "",
|
|
||||||
token: "",
|
|
||||||
});
|
|
||||||
|
|
||||||
if (token) {
|
if (backendUrl) {
|
||||||
return (
|
return <ImageModerator backendUrl={backendUrl} />;
|
||||||
<>
|
|
||||||
<ImageModerator
|
|
||||||
token={token}
|
|
||||||
apiUrl={apiUrl}
|
|
||||||
middlewareUrl={middlewareUrl}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
return (
|
return <GetBackendUrl setRemote={setBackendUrl} />;
|
||||||
<>
|
|
||||||
<Login setRemote={setRemote} />
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
|
export default function GetBackendUrl({ setRemote }: { setRemote: Function }) {
|
||||||
|
const sendLabel = "Input Backend URL";
|
||||||
|
const [backendUrl, setBackendUrl] = useState("");
|
||||||
|
|
||||||
|
function sendAction() {
|
||||||
|
event?.preventDefault();
|
||||||
|
try {
|
||||||
|
if (backendUrl) {
|
||||||
|
localStorage.setItem("backendUrl", backendUrl);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
setRemote(backendUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleChange(
|
||||||
|
e: {
|
||||||
|
target: { value: React.SetStateAction<string> };
|
||||||
|
},
|
||||||
|
setter: React.Dispatch<React.SetStateAction<string>>
|
||||||
|
): void {
|
||||||
|
setter(e.target.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const savedRemote = localStorage.getItem("backendUrl");
|
||||||
|
|
||||||
|
if (savedRemote) {
|
||||||
|
setRemote(savedRemote);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
height: "100vh",
|
||||||
|
width: "100vw",
|
||||||
|
}}>
|
||||||
|
<form
|
||||||
|
style={{
|
||||||
|
height: "100%",
|
||||||
|
width: "100%",
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "column",
|
||||||
|
justifyContent: "center",
|
||||||
|
alignItems: "center",
|
||||||
|
}}
|
||||||
|
onSubmit={sendAction}>
|
||||||
|
<label>Backend URL: </label>
|
||||||
|
<input
|
||||||
|
type="url"
|
||||||
|
id="backend"
|
||||||
|
name="backend"
|
||||||
|
value={backendUrl}
|
||||||
|
onChange={(e) => handleChange(e, setBackendUrl)}
|
||||||
|
/>
|
||||||
|
<button type="submit">{sendLabel}</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
|
@ -2,50 +2,45 @@ import { useEffect, useState } from "react";
|
||||||
import Button from "../Button/Button";
|
import Button from "../Button/Button";
|
||||||
|
|
||||||
interface ImageModeratorProps {
|
interface ImageModeratorProps {
|
||||||
token: string;
|
backendUrl: string;
|
||||||
apiUrl: string;
|
|
||||||
middlewareUrl: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ImageModerator({
|
export default function ImageModerator({ backendUrl }: ImageModeratorProps) {
|
||||||
token,
|
|
||||||
apiUrl,
|
|
||||||
middlewareUrl,
|
|
||||||
}: ImageModeratorProps) {
|
|
||||||
const acceptLabel = "Accept";
|
const acceptLabel = "Accept";
|
||||||
const discardLabel = "Discard";
|
const discardLabel = "Discard";
|
||||||
|
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
const [imageData, setImageData] = useState({ url: "", tags: [] });
|
const [imageData, setImageData] = useState({
|
||||||
const [imageAlt, setImageAlt] = useState("No image");
|
url: "",
|
||||||
|
token: "",
|
||||||
|
alt: "No image",
|
||||||
|
});
|
||||||
|
|
||||||
function acceptAction() {
|
function acceptAction() {
|
||||||
fetch(`${apiUrl}/images`, {
|
fetch(`${backendUrl}/image/review`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
url: imageData.url,
|
url: imageData.url,
|
||||||
status: "available",
|
token: imageData.token,
|
||||||
tags: imageData.tags,
|
is_accepted: true,
|
||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
"Content-type": "application/json",
|
"Content-type": "application/json",
|
||||||
Authorization: `Bearer ${token}`,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function discardAction() {
|
function discardAction() {
|
||||||
fetch(`${apiUrl}/images`, {
|
fetch(`${backendUrl}/image/review`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
url: imageData.url,
|
url: imageData.url,
|
||||||
status: "unavailable",
|
token: imageData.token,
|
||||||
tags: imageData.tags,
|
is_accepted: false,
|
||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
"Content-type": "application/json",
|
"Content-type": "application/json",
|
||||||
Authorization: `Bearer ${token}`,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
@ -53,8 +48,8 @@ export default function ImageModerator({
|
||||||
|
|
||||||
const getNewImage = () => {
|
const getNewImage = () => {
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
setImageData({ url: "", tags: [] });
|
setImageData({ url: "", token: "", alt: "Loading..." });
|
||||||
fetch(`${middlewareUrl}/image`, {
|
fetch(`${backendUrl}/image`, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
@ -62,12 +57,10 @@ export default function ImageModerator({
|
||||||
return response.json();
|
return response.json();
|
||||||
})
|
})
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
const url = data.url;
|
setImageData({ url: data.url, token: data.token, alt: data.url });
|
||||||
const tags = data.tags;
|
|
||||||
setImageData({ url, tags });
|
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
setImageAlt("Error");
|
setImageData({ url: "", token: "", alt: "Error" });
|
||||||
console.error(error);
|
console.error(error);
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
|
@ -93,7 +86,7 @@ export default function ImageModerator({
|
||||||
) : (
|
) : (
|
||||||
<img
|
<img
|
||||||
src={imageData.url}
|
src={imageData.url}
|
||||||
alt={imageAlt}
|
alt={imageData.alt}
|
||||||
style={{
|
style={{
|
||||||
width: "100%",
|
width: "100%",
|
||||||
height: "100%",
|
height: "100%",
|
||||||
|
|
|
@ -1,111 +0,0 @@
|
||||||
import { useEffect, useState } from "react";
|
|
||||||
|
|
||||||
export default function Login({ setRemote }: { setRemote: Function }) {
|
|
||||||
const sendLabel = "Login";
|
|
||||||
const [middlewareUrl, setMiddlewareUrl] = useState("");
|
|
||||||
const [apiUrl, setApiUrl] = useState("");
|
|
||||||
const [app, setApp] = useState("");
|
|
||||||
const [secret, setSecret] = useState("");
|
|
||||||
|
|
||||||
function sendAction() {
|
|
||||||
event?.preventDefault();
|
|
||||||
try {
|
|
||||||
if (apiUrl && middlewareUrl && app && secret) {
|
|
||||||
localStorage.setItem(
|
|
||||||
"credentials",
|
|
||||||
JSON.stringify({ apiUrl, middlewareUrl, app, secret })
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
fetch(`${apiUrl}/login`, {
|
|
||||||
method: "POST",
|
|
||||||
body: JSON.stringify({ app, secret }),
|
|
||||||
headers: { "Content-type": "application/json" },
|
|
||||||
})
|
|
||||||
.then((response) => {
|
|
||||||
return response.json();
|
|
||||||
})
|
|
||||||
.then((body) => {
|
|
||||||
setRemote({ apiUrl, middlewareUrl, token: body.token });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleChange(
|
|
||||||
e: {
|
|
||||||
target: { value: React.SetStateAction<string> };
|
|
||||||
},
|
|
||||||
setter: React.Dispatch<React.SetStateAction<string>>
|
|
||||||
): void {
|
|
||||||
setter(e.target.value);
|
|
||||||
}
|
|
||||||
useEffect(() => {
|
|
||||||
const savedRemote = localStorage.getItem("credentials");
|
|
||||||
|
|
||||||
if (savedRemote) {
|
|
||||||
const savedData = JSON.parse(savedRemote);
|
|
||||||
setApiUrl(savedData.apiUrl);
|
|
||||||
setMiddlewareUrl(savedData.middlewareUrl);
|
|
||||||
setApp(savedData.app);
|
|
||||||
setSecret(savedData.secret);
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (secret) {
|
|
||||||
sendAction();
|
|
||||||
}
|
|
||||||
}, [secret]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
height: "100vh",
|
|
||||||
width: "100vw",
|
|
||||||
}}>
|
|
||||||
<form
|
|
||||||
style={{
|
|
||||||
height: "100%",
|
|
||||||
width: "100%",
|
|
||||||
display: "flex",
|
|
||||||
flexDirection: "column",
|
|
||||||
justifyContent: "center",
|
|
||||||
alignItems: "center",
|
|
||||||
}}
|
|
||||||
onSubmit={sendAction}>
|
|
||||||
<label>API URL: </label>
|
|
||||||
<input
|
|
||||||
type="url"
|
|
||||||
id="api"
|
|
||||||
name="api"
|
|
||||||
value={apiUrl}
|
|
||||||
onChange={(e) => handleChange(e, setApiUrl)}
|
|
||||||
/>
|
|
||||||
<label>Source URL: </label>
|
|
||||||
<input
|
|
||||||
type="url"
|
|
||||||
id="middleware"
|
|
||||||
name="middleware"
|
|
||||||
value={middlewareUrl}
|
|
||||||
onChange={(e) => handleChange(e, setMiddlewareUrl)}
|
|
||||||
/>
|
|
||||||
<label>App name: </label>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
id="username"
|
|
||||||
name="username"
|
|
||||||
value={app}
|
|
||||||
onChange={(e) => handleChange(e, setApp)}
|
|
||||||
/>
|
|
||||||
<label>Secret: </label>
|
|
||||||
<input
|
|
||||||
type="password"
|
|
||||||
value={secret}
|
|
||||||
onChange={(e) => handleChange(e, setSecret)}
|
|
||||||
/>
|
|
||||||
<button type="submit">{sendLabel}</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
Loading…
Reference in New Issue