Compare commits

..

No commits in common. "main" and "v1.1.0" have entirely different histories.
main ... v1.1.0

12 changed files with 269 additions and 1008 deletions

View File

@ -1,8 +1,4 @@
name: Build image name: Build image
permissions:
contents: write
packages: write
on: on:
pull_request: pull_request:
paths: paths:
@ -13,32 +9,41 @@ on:
jobs: jobs:
build: 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: 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@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 uses: actions/checkout@v4
- name: Docker meta - name: Docker meta
id: meta id: meta
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5 uses: https://github.com/docker/metadata-action@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/${{ github.repository }} git.fai.st/fedi-image-bot/moderation-fe
# 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@f7ce87c1d6bead3e36075b2ce75da1f6cc28aaca # v3 uses: docker/setup-buildx-action@v2
- name: Login to fai.st docker registry - name: Login to fai.st docker registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3 uses: docker/login-action@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@0adf9959216b96bec444f325f1e493d4aa344497 # v6 uses: docker/build-push-action@v4
with: with:
platforms: linux/amd64,linux/arm64 platforms: linux/amd64,linux/arm64
context: . context: .

View File

@ -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 }}

View File

@ -1 +0,0 @@
nodejs 23.8.0

View File

@ -1,4 +1,4 @@
FROM --platform=$BUILDPLATFORM node:23.8.0-alpine AS install FROM --platform=$BUILDPLATFORM node:23.4-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

View File

@ -1,7 +1,7 @@
services: services:
mongodb: mongodb:
image: mongo:bionic image: mongo:bionic
container_name: fe-mongodb container_name: mongodb-fe
ports: ports:
- "27017:27017" - "27017:27017"
environment: environment:
@ -10,34 +10,32 @@ 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: ghcr.io/siesta-cat/2chi-api:v1.1.0 image: git.fai.st/fedi-image-bot/bot-api:latest
container_name: fe-2chi-api container_name: bot-api-fe
restart: on-failure
ports: ports:
- 8080:8080 - 8080:8080
depends_on: depends_on:
- mongodb - mongodb
environment: environment:
PORT: 8080 PORT: 8080
DB_HOST: "mongodb" MONGODB_URI: "mongodb://mongodb:27017/bot"
DB_NAME: "bot" MONGODB_USER: "root"
DB_USER: "root" MONGODB_PASS: "password"
DB_PASS: "password" JWTSECRET: "cooljwtsecret"
fe-middleware: fe-middleware:
image: ghcr.io/siesta-cat/2chi-verifier-be:v2.1.3 image: git.fai.st/fedi-image-bot/fe-middleware:latest
container_name: fe-2chi-verifier-be container_name: fe-middleware-fe
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_BASE_URL: "http://bot-api:8080" BOT_API_URI: "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
@ -46,11 +44,12 @@ services:
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:

937
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -8,12 +8,12 @@
"build": "tsc && vite build" "build": "tsc && vite build"
}, },
"dependencies": { "dependencies": {
"react-dom": "19.0.0", "react-dom": "^19.0.0",
"typescript": "5.7.3", "typescript": "^5.2.2",
"vite": "6.1.1" "vite": "^6.0.0"
}, },
"devDependencies": { "devDependencies": {
"@types/react-dom": "19.0.4", "@types/react-dom": "^19.0.0",
"@vitejs/plugin-react-swc": "3.8.0" "@vitejs/plugin-react-swc": "^3.5.0"
} }
} }

View File

@ -1,5 +1,3 @@
{ {
"$schema": "https://docs.renovatebot.com/renovate-schema.json", "$schema": "https://docs.renovatebot.com/renovate-schema.json"
"extends": ["config:recommended", "helpers:pinGitHubActionDigests"], }
"rangeStrategy": "pin"
}

View File

@ -1,14 +1,24 @@
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 [backendUrl, setBackendUrl] = useState(""); const [{ apiUrl, middlewareUrl, token }, setRemote] = useState({
apiUrl: "",
middlewareUrl: "",
token: "",
});
if (backendUrl) { if (token) {
return <ImageModerator backendUrl={backendUrl} />; return (
<ImageModerator
token={token}
apiUrl={apiUrl}
middlewareUrl={middlewareUrl}
/>
);
} else { } else {
return <GetBackendUrl setRemote={setBackendUrl} />; return <Login setRemote={setRemote} />;
} }
} }

View File

@ -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>
);
}

View File

@ -2,45 +2,50 @@ import { useEffect, useState } from "react";
import Button from "../Button/Button"; import Button from "../Button/Button";
interface ImageModeratorProps { 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 acceptLabel = "Accept";
const discardLabel = "Discard"; const discardLabel = "Discard";
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
const [imageData, setImageData] = useState({ const [imageData, setImageData] = useState({ url: "", tags: [] });
url: "", const [imageAlt, setImageAlt] = useState("No image");
token: "",
alt: "No image",
});
function acceptAction() { function acceptAction() {
fetch(`${backendUrl}/image/review`, { fetch(`${apiUrl}/images`, {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
url: imageData.url, url: imageData.url,
token: imageData.token, status: "available",
is_accepted: true, tags: imageData.tags,
}), }),
headers: { headers: {
"Content-type": "application/json", "Content-type": "application/json",
Authorization: `Bearer ${token}`,
}, },
}); });
setIsLoading(true); setIsLoading(true);
} }
function discardAction() { function discardAction() {
fetch(`${backendUrl}/image/review`, { fetch(`${apiUrl}/images`, {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
url: imageData.url, url: imageData.url,
token: imageData.token, status: "unavailable",
is_accepted: false, tags: imageData.tags,
}), }),
headers: { headers: {
"Content-type": "application/json", "Content-type": "application/json",
Authorization: `Bearer ${token}`,
}, },
}); });
setIsLoading(true); setIsLoading(true);
@ -48,8 +53,8 @@ export default function ImageModerator({ backendUrl }: ImageModeratorProps) {
const getNewImage = () => { const getNewImage = () => {
if (isLoading) { if (isLoading) {
setImageData({ url: "", token: "", alt: "Loading..." }); setImageData({ url: "", tags: [] });
fetch(`${backendUrl}/image`, { fetch(`${middlewareUrl}/image`, {
method: "GET", method: "GET",
}) })
.then((response) => { .then((response) => {
@ -57,10 +62,13 @@ export default function ImageModerator({ backendUrl }: ImageModeratorProps) {
return response.json(); return response.json();
}) })
.then((data) => { .then((data) => {
setImageData({ url: data.url, token: data.token, alt: data.url }); const url = data.url;
const tags = data.tags;
setImageData({ url, tags });
setImageAlt(url);
}) })
.catch((error) => { .catch((error) => {
setImageData({ url: "", token: "", alt: "Error" }); setImageAlt("Error");
console.error(error); console.error(error);
}) })
.finally(() => { .finally(() => {
@ -86,7 +94,7 @@ export default function ImageModerator({ backendUrl }: ImageModeratorProps) {
) : ( ) : (
<img <img
src={imageData.url} src={imageData.url}
alt={imageData.alt} alt={imageAlt}
style={{ style={{
width: "100%", width: "100%",
height: "100%", height: "100%",

View File

@ -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>
);
}