Compare commits
No commits in common. "main" and "v1.0.2" have entirely different histories.
|
@ -1,8 +1,4 @@
|
|||
name: Build image
|
||||
permissions:
|
||||
contents: write
|
||||
packages: write
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
|
@ -13,32 +9,41 @@ on:
|
|||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
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:
|
||||
- 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
|
||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
|
||||
uses: actions/checkout@v4
|
||||
- name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5
|
||||
uses: https://github.com/docker/metadata-action@v5
|
||||
with:
|
||||
# list of Docker images to use as base name for tags
|
||||
images: |
|
||||
git.fai.st/${{ github.repository }}
|
||||
git.fai.st/fedi-image-bot/moderation-fe
|
||||
# generate Docker tags based on the following events/attributes
|
||||
tags: |
|
||||
type=raw,value=latest
|
||||
type=ref,event=branch
|
||||
type=semver,pattern={{raw}}
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@f7ce87c1d6bead3e36075b2ce75da1f6cc28aaca # v3
|
||||
uses: docker/setup-buildx-action@v2
|
||||
- name: Login to fai.st docker registry
|
||||
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: git.fai.st
|
||||
username: ${{ secrets.DOCKER_USER }}
|
||||
password: ${{ secrets.DOCKER_PASS }}
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@0adf9959216b96bec444f325f1e493d4aa344497 # v6
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
platforms: linux/amd64,linux/arm64
|
||||
context: .
|
|
@ -1,26 +0,0 @@
|
|||
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 }}
|
|
@ -1 +0,0 @@
|
|||
nodejs 23.8.0
|
|
@ -1,9 +1,9 @@
|
|||
FROM --platform=$BUILDPLATFORM node:23.8.0-alpine AS install
|
||||
FROM --platform=$BUILDPLATFORM node:23-alpine AS install
|
||||
RUN mkdir -p /temp/prod
|
||||
COPY package*.json /temp/prod/
|
||||
RUN cd /temp/prod && npm install --frozen-lockfile
|
||||
COPY . /temp/prod/
|
||||
RUN cd /temp/prod && npm run build
|
||||
|
||||
FROM nginx:1.27.3-alpine3.20-slim AS release
|
||||
FROM nginx AS release
|
||||
COPY --from=install /temp/prod/dist /usr/share/nginx/html
|
||||
|
|
35
compose.yaml
35
compose.yaml
|
@ -1,7 +1,7 @@
|
|||
services:
|
||||
mongodb:
|
||||
image: mongo:bionic
|
||||
container_name: fe-mongodb
|
||||
container_name: mongodb
|
||||
ports:
|
||||
- "27017:27017"
|
||||
environment:
|
||||
|
@ -10,34 +10,32 @@ services:
|
|||
MONGO_INITDB_DATABASE: bot
|
||||
volumes:
|
||||
- ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
|
||||
- mongodb_data:/data/db
|
||||
|
||||
bot-api:
|
||||
image: ghcr.io/siesta-cat/2chi-api:v1.1.0
|
||||
container_name: fe-2chi-api
|
||||
restart: on-failure
|
||||
image: git.fai.st/fedi-image-bot/bot-api:latest
|
||||
container_name: bot-api
|
||||
ports:
|
||||
- 8080:8080
|
||||
- "8080:8080"
|
||||
depends_on:
|
||||
- mongodb
|
||||
environment:
|
||||
PORT: 8080
|
||||
DB_HOST: "mongodb"
|
||||
DB_NAME: "bot"
|
||||
DB_USER: "root"
|
||||
DB_PASS: "password"
|
||||
MONGODB_URI: "mongodb://mongodb:27017/bot"
|
||||
MONGODB_USER: "root"
|
||||
MONGODB_PASS: "password"
|
||||
JWTSECRET: "cooljwtsecret"
|
||||
|
||||
fe-middleware:
|
||||
image: ghcr.io/siesta-cat/2chi-verifier-be:v2.1.3
|
||||
container_name: fe-2chi-verifier-be
|
||||
stop_signal: sigkill
|
||||
image: git.fai.st/fedi-image-bot/fe-middleware:latest
|
||||
container_name: fe-middleware
|
||||
ports:
|
||||
- 8081:8081
|
||||
- "8081:8081"
|
||||
depends_on:
|
||||
- bot-api
|
||||
environment:
|
||||
PORT: 8081
|
||||
BOT_API_BASE_URL: "http://bot-api:8080"
|
||||
TOKEN_SECRET: Y2hpY2FzZWNyZXQK
|
||||
BOT_API_URI: "http://bot-api:8080"
|
||||
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
|
||||
|
||||
|
@ -45,12 +43,13 @@ services:
|
|||
build: .
|
||||
container_name: bot-image-moderation-fe
|
||||
ports:
|
||||
- 80:80
|
||||
environment:
|
||||
VITE_BACKEND_URL: "http://localhost:8081"
|
||||
- "80:80"
|
||||
develop:
|
||||
watch:
|
||||
- action: rebuild
|
||||
path: .
|
||||
ignore:
|
||||
- node_modules/
|
||||
|
||||
volumes:
|
||||
mongodb_data:
|
||||
|
|
File diff suppressed because it is too large
Load Diff
12
package.json
12
package.json
|
@ -8,12 +8,14 @@
|
|||
"build": "tsc && vite build"
|
||||
},
|
||||
"dependencies": {
|
||||
"react-dom": "19.0.0",
|
||||
"typescript": "5.7.3",
|
||||
"vite": "6.1.1"
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"typescript": "^5.2.2",
|
||||
"vite": "^6.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react-dom": "19.0.4",
|
||||
"@vitejs/plugin-react-swc": "3.8.0"
|
||||
"@types/react": "^18.2.43",
|
||||
"@types/react-dom": "^18.2.17",
|
||||
"@vitejs/plugin-react-swc": "^3.5.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"extends": ["config:recommended", "helpers:pinGitHubActionDigests"],
|
||||
"rangeStrategy": "pin"
|
||||
}
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
|
||||
}
|
||||
|
|
26
src/App.tsx
26
src/App.tsx
|
@ -1,14 +1,30 @@
|
|||
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 [backendUrl, setBackendUrl] = useState("");
|
||||
const [{ apiUrl, middlewareUrl, token }, setRemote] = useState({
|
||||
apiUrl: "",
|
||||
middlewareUrl: "",
|
||||
token: "",
|
||||
});
|
||||
|
||||
if (backendUrl) {
|
||||
return <ImageModerator backendUrl={backendUrl} />;
|
||||
if (token) {
|
||||
return (
|
||||
<>
|
||||
<ImageModerator
|
||||
token={token}
|
||||
apiUrl={apiUrl}
|
||||
middlewareUrl={middlewareUrl}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
} else {
|
||||
return <GetBackendUrl setRemote={setBackendUrl} />;
|
||||
return (
|
||||
<>
|
||||
<Login setRemote={setRemote} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
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,45 +2,50 @@ import { useEffect, useState } from "react";
|
|||
import Button from "../Button/Button";
|
||||
|
||||
interface ImageModeratorProps {
|
||||
backendUrl: string;
|
||||
token: string;
|
||||
apiUrl: string;
|
||||
middlewareUrl: string;
|
||||
}
|
||||
|
||||
export default function ImageModerator({ backendUrl }: ImageModeratorProps) {
|
||||
export default function ImageModerator({
|
||||
token,
|
||||
apiUrl,
|
||||
middlewareUrl,
|
||||
}: ImageModeratorProps) {
|
||||
const acceptLabel = "Accept";
|
||||
const discardLabel = "Discard";
|
||||
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [imageData, setImageData] = useState({
|
||||
url: "",
|
||||
token: "",
|
||||
alt: "No image",
|
||||
});
|
||||
const [imageData, setImageData] = useState({ url: "", tags: [] });
|
||||
const [imageAlt, setImageAlt] = useState("No image");
|
||||
|
||||
function acceptAction() {
|
||||
fetch(`${backendUrl}/image/review`, {
|
||||
fetch(`${apiUrl}/images`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
url: imageData.url,
|
||||
token: imageData.token,
|
||||
is_accepted: true,
|
||||
status: "available",
|
||||
tags: imageData.tags,
|
||||
}),
|
||||
headers: {
|
||||
"Content-type": "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
setIsLoading(true);
|
||||
}
|
||||
|
||||
function discardAction() {
|
||||
fetch(`${backendUrl}/image/review`, {
|
||||
fetch(`${apiUrl}/images`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
url: imageData.url,
|
||||
token: imageData.token,
|
||||
is_accepted: false,
|
||||
status: "unavailable",
|
||||
tags: imageData.tags,
|
||||
}),
|
||||
headers: {
|
||||
"Content-type": "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
setIsLoading(true);
|
||||
|
@ -48,8 +53,8 @@ export default function ImageModerator({ backendUrl }: ImageModeratorProps) {
|
|||
|
||||
const getNewImage = () => {
|
||||
if (isLoading) {
|
||||
setImageData({ url: "", token: "", alt: "Loading..." });
|
||||
fetch(`${backendUrl}/image`, {
|
||||
setImageData({ url: "", tags: [] });
|
||||
fetch(`${middlewareUrl}/image`, {
|
||||
method: "GET",
|
||||
})
|
||||
.then((response) => {
|
||||
|
@ -57,10 +62,12 @@ export default function ImageModerator({ backendUrl }: ImageModeratorProps) {
|
|||
return response.json();
|
||||
})
|
||||
.then((data) => {
|
||||
setImageData({ url: data.url, token: data.token, alt: data.url });
|
||||
const url = data.url;
|
||||
const tags = data.tags;
|
||||
setImageData({ url, tags });
|
||||
})
|
||||
.catch((error) => {
|
||||
setImageData({ url: "", token: "", alt: "Error" });
|
||||
setImageAlt("Error");
|
||||
console.error(error);
|
||||
})
|
||||
.finally(() => {
|
||||
|
@ -86,7 +93,7 @@ export default function ImageModerator({ backendUrl }: ImageModeratorProps) {
|
|||
) : (
|
||||
<img
|
||||
src={imageData.url}
|
||||
alt={imageData.alt}
|
||||
alt={imageAlt}
|
||||
style={{
|
||||
width: "100%",
|
||||
height: "100%",
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
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