BREAKING CHANGE: deprecated use of auth and bot api to only use 2chi verifier be
This commit is contained in:
parent
e04dbdce01
commit
00991ad93c
29
compose.yaml
29
compose.yaml
|
@ -1,7 +1,7 @@
|
|||
services:
|
||||
mongodb:
|
||||
image: mongo:bionic
|
||||
container_name: mongodb-fe
|
||||
container_name: fe-mongodb
|
||||
ports:
|
||||
- "27017:27017"
|
||||
environment:
|
||||
|
@ -10,32 +10,34 @@ services:
|
|||
MONGO_INITDB_DATABASE: bot
|
||||
volumes:
|
||||
- ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
|
||||
- mongodb_data:/data/db
|
||||
|
||||
bot-api:
|
||||
image: git.fai.st/fedi-image-bot/bot-api:v1.0.2
|
||||
container_name: bot-api-fe
|
||||
image: ghcr.io/siesta-cat/2chi-api:v1.0.1
|
||||
container_name: fe-2chi-api
|
||||
restart: on-failure
|
||||
ports:
|
||||
- 8080:8080
|
||||
depends_on:
|
||||
- mongodb
|
||||
environment:
|
||||
PORT: 8080
|
||||
MONGODB_URI: "mongodb://mongodb:27017/bot"
|
||||
MONGODB_USER: "root"
|
||||
MONGODB_PASS: "password"
|
||||
JWTSECRET: "cooljwtsecret"
|
||||
DB_HOST: "mongodb"
|
||||
DB_NAME: "bot"
|
||||
DB_USER: "root"
|
||||
DB_PASS: "password"
|
||||
|
||||
fe-middleware:
|
||||
image: git.fai.st/fedi-image-bot/fe-middleware:v1.0.2
|
||||
container_name: fe-middleware-fe
|
||||
image: ghcr.io/siesta-cat/2chi-verifier-be:v2.1.2
|
||||
container_name: fe-2chi-verifier-be
|
||||
stop_signal: sigkill
|
||||
ports:
|
||||
- 8081:8081
|
||||
depends_on:
|
||||
- bot-api
|
||||
environment:
|
||||
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_TAGS: "2girls sleeping" # Tags of the images. The images will have all of these tags
|
||||
|
||||
|
@ -44,12 +46,11 @@ services:
|
|||
container_name: bot-image-moderation-fe
|
||||
ports:
|
||||
- 80:80
|
||||
environment:
|
||||
VITE_BACKEND_URL: "http://localhost:8081"
|
||||
develop:
|
||||
watch:
|
||||
- action: rebuild
|
||||
path: .
|
||||
ignore:
|
||||
- node_modules/
|
||||
|
||||
volumes:
|
||||
mongodb_data:
|
||||
|
|
20
src/App.tsx
20
src/App.tsx
|
@ -1,24 +1,14 @@
|
|||
import { useState } from "react";
|
||||
import GetBackendUrl from "./components/ImageModerator/GetBackendUrl";
|
||||
import ImageModerator from "./components/ImageModerator/ImageModerator";
|
||||
import Login from "./components/Login/Login";
|
||||
|
||||
function App() {
|
||||
const [{ apiUrl, middlewareUrl, token }, setRemote] = useState({
|
||||
apiUrl: "",
|
||||
middlewareUrl: "",
|
||||
token: "",
|
||||
});
|
||||
const [backendUrl, setBackendUrl] = useState("");
|
||||
|
||||
if (token) {
|
||||
return (
|
||||
<ImageModerator
|
||||
token={token}
|
||||
apiUrl={apiUrl}
|
||||
middlewareUrl={middlewareUrl}
|
||||
/>
|
||||
);
|
||||
if (backendUrl) {
|
||||
return <ImageModerator backendUrl={backendUrl} />;
|
||||
} else {
|
||||
return <Login setRemote={setRemote} />;
|
||||
return <GetBackendUrl setRemote={setBackendUrl} />;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
setBackendUrl(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,42 @@ import { useEffect, useState } from "react";
|
|||
import Button from "../Button/Button";
|
||||
|
||||
interface ImageModeratorProps {
|
||||
token: string;
|
||||
apiUrl: string;
|
||||
middlewareUrl: string;
|
||||
backendUrl: string;
|
||||
}
|
||||
|
||||
export default function ImageModerator({
|
||||
token,
|
||||
apiUrl,
|
||||
middlewareUrl,
|
||||
}: ImageModeratorProps) {
|
||||
export default function ImageModerator({ backendUrl }: ImageModeratorProps) {
|
||||
const acceptLabel = "Accept";
|
||||
const discardLabel = "Discard";
|
||||
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [imageData, setImageData] = useState({ url: "", tags: [] });
|
||||
const [imageData, setImageData] = useState({ url: "", token: "" });
|
||||
const [imageAlt, setImageAlt] = useState("No image");
|
||||
|
||||
function acceptAction() {
|
||||
fetch(`${apiUrl}/images`, {
|
||||
fetch(`${backendUrl}/image/review`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
url: imageData.url,
|
||||
status: "available",
|
||||
tags: imageData.tags,
|
||||
token: imageData.token,
|
||||
is_accepted: true,
|
||||
}),
|
||||
headers: {
|
||||
"Content-type": "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
setIsLoading(true);
|
||||
}
|
||||
|
||||
function discardAction() {
|
||||
fetch(`${apiUrl}/images`, {
|
||||
fetch(`${backendUrl}/image/review`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
url: imageData.url,
|
||||
status: "unavailable",
|
||||
tags: imageData.tags,
|
||||
token: imageData.token,
|
||||
is_accepted: false,
|
||||
}),
|
||||
headers: {
|
||||
"Content-type": "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
setIsLoading(true);
|
||||
|
@ -53,8 +45,8 @@ export default function ImageModerator({
|
|||
|
||||
const getNewImage = () => {
|
||||
if (isLoading) {
|
||||
setImageData({ url: "", tags: [] });
|
||||
fetch(`${middlewareUrl}/image`, {
|
||||
setImageData({ url: "", token: "" });
|
||||
fetch(`${backendUrl}/image`, {
|
||||
method: "GET",
|
||||
})
|
||||
.then((response) => {
|
||||
|
@ -62,10 +54,8 @@ export default function ImageModerator({
|
|||
return response.json();
|
||||
})
|
||||
.then((data) => {
|
||||
const url = data.url;
|
||||
const tags = data.tags;
|
||||
setImageData({ url, tags });
|
||||
setImageAlt(url);
|
||||
setImageData({ url: data.url, token: data.token });
|
||||
setImageAlt(data.url);
|
||||
})
|
||||
.catch((error) => {
|
||||
setImageAlt("Error");
|
||||
|
|
|
@ -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