diff --git a/.example.env b/.example.env index 792cbd2..2183a0b 100644 --- a/.example.env +++ b/.example.env @@ -5,3 +5,8 @@ HOST=0.0.0.0 #REDIS_HOST=127.0.0.1 #REDIS_PORT=6379 REDIS_PASSWORD=pasw0rd + +#REQUIRED if you want to use the e621 API +E621_USER_AGENT=YourBotName/1.0 (by username on e621) +E621_USERNAME=username +E621_API_KEY=apikey diff --git a/.gitignore b/.gitignore index afefd98..be0baea 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ bun.lockb /config/secrets.ts .env +/logs diff --git a/README.md b/README.md index d053111..44976d1 100644 --- a/README.md +++ b/README.md @@ -2,27 +2,49 @@ ## Setup Instructions -1. Rename the example environment file to `.env`: +### Production Environment + +1. Clone the repository: + ```bash + git clone + cd booru-api + ``` + +2. Rename the example environment file to `.env`: ```bash mv .example.env .env ``` -2. Start the application in detached mode: +3. Start the application in detached mode: ```bash docker compose up -d ``` --- -## Default `config/secrets.ts` File +### Development Environment -```typescript -const e621Auth: Record = { - "User-Agent": "your-domain/1.0 (by your-username on e621)", - Authorization: "Basic " + btoa("your-username:your-password"), -}; +1. Clone the repository: + ```bash + git clone + cd booru-api + ``` -export { e621Auth }; -``` +2. Rename the example environment file to `.env`: + ```bash + mv .example.env .env + ``` + +3. Install dependencies using Bun: + ```bash + bun install + ``` + +4. Start the development server: + ```bash + bun dev + ``` + +--- > **Note** Replace `your-username` and `your-password` with your e621 account credentials. Update the `User-Agent` string to include your domain and comply with e621's API guidelines. diff --git a/config/booru.ts b/config/booru.ts index 1b22eb5..a71f64c 100644 --- a/config/booru.ts +++ b/config/booru.ts @@ -1,6 +1,6 @@ // cSpell:disable -import { e621Auth } from "./secrets"; +import { getE621Auth } from "./environment"; const booruDefaults: IBooruDefaults = { search: "index.php?page=dapi&s=post&q=index&json=1", @@ -68,8 +68,6 @@ export const booruConfig: IBooruConfigMap = { random: "defaultRandom", id: ["posts/", ".json"], }, - auth: { - ...e621Auth, - }, + auth: getE621Auth(), }, }; diff --git a/config/environment.ts b/config/environment.ts index d469948..4c4b59a 100644 --- a/config/environment.ts +++ b/config/environment.ts @@ -19,3 +19,30 @@ export const redisConfig: RedisConfig = { port: parseInt(process.env.REDIS_PORT || "6379", 10), password: process.env.REDIS_PASSWORD || undefined, }; + +if ( + !process.env.E621_USER_AGENT || + !process.env.E621_USERNAME || + !process.env.E621_API_KEY +) { + logger.error("Missing e621 credentials in .env file"); +} else { + if ( + process.env.E621_USERNAME === "username" || + process.env.E621_API_KEY === "apikey" + ) { + logger.error("Please update your e621 credentials in the .env file"); + } +} + +export function getE621Auth(): Record { + const e621UserAgent: string | undefined = process.env.E621_USER_AGENT; + const e621Username: string | undefined = process.env.E621_USERNAME; + const e621ApiKey: string | undefined = process.env.E621_API_KEY; + + return { + "User-Agent": e621UserAgent || "", + Authorization: + "Basic " + btoa(`${e621Username || ""}:${e621ApiKey || ""}`), + }; +}