Skip to content

Commit 3e9e484

Browse files
committed
cleanup
1 parent f0d3b38 commit 3e9e484

File tree

6 files changed

+12
-31
lines changed

6 files changed

+12
-31
lines changed

.env.example

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
API_BASE_URL=http://localhost:5000 # Must match host name and port number of discit-api server
2-
API_KEY=any_string_value # Must match API_KEY value in discit-api server
1+
API_URL=http://localhost:5000 # must match host name and port number of discit-api server
2+
API_KEY=any_string_value # must match API_KEY value in discit-api server
33
REFRESH_DISCS_START=true
44
REFRESH_DISCS_CRON=true
5+
BACKUP_DIR=/absolue/path/to/backup/dir # absolute path of directory for disc data backups (defaults to /backup in project root)

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
- Install [bun](https://bun.sh).
66
- Install package dependencies: `bun i`
7-
- Clone, set up, and start running the [discit-api](https://github.com/cdleveille/discit-api) project locally.
7+
- Clone, set up, and start running the [discit-api](https://github.com/DiscIt-API/discit-api) project locally.
88
- Create and populate a `.env` file based on the `.env.example` file in the root directory.
9-
- The `API_BASE_URL` value must match the URL of the discit-api project (http://localhost:5000 by default if running locally).
9+
- The `API_URL` value must match the URL of the discit-api project (http://localhost:5000 by default if running locally).
1010
- The `API_KEY` value can be any string value, but must match the API_KEY in the discit-api project.
1111
- The `REFRESH_DISCS_START` value can be set to `true` to run the disc refresh process when the app starts.
1212
- The `REFRESH_DISCS_CRON` value can be set to `true` to automatically run the disc refresh process every night at midnight.
13+
- The `BACKUP_DIR` value can be set to an abosolute path for a directoy where the backup files will be stored.
1314
- Start the refresh process: `bun start`

src/api.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,17 @@ import type { IDisc } from "./types";
44
const headers = { Authorization: `Bearer ${Config.API_KEY}`, "Content-Type": "application/json" };
55

66
export const getAllDiscs = async () =>
7-
(await fetch(`${Config.API_BASE_URL}/disc`)).json() as Promise<IDisc[]>;
7+
(await fetch(`${Config.API_URL}/disc`)).json() as Promise<IDisc[]>;
88

99
export const insertDiscs = (discs: IDisc[]) =>
10-
fetch(`${Config.API_BASE_URL}/disc`, {
10+
fetch(`${Config.API_URL}/disc`, {
1111
method: "POST",
1212
headers,
1313
body: JSON.stringify(discs)
1414
});
1515

1616
export const deleteAllDiscs = () =>
17-
fetch(`${Config.API_BASE_URL}/disc`, {
17+
fetch(`${Config.API_URL}/disc`, {
1818
method: "DELETE",
1919
headers
2020
});
21-
22-
export const revalidateDiscItCache = () =>
23-
fetch(`${Config.DISCIT_URL}/api/revalidate`, { method: "POST", headers });

src/config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ import path from "node:path";
33
import type { IConfig } from "./types";
44

55
export const Config = {
6-
API_BASE_URL: Bun.env.API_BASE_URL || "http://localhost:5000",
6+
API_URL: Bun.env.API_URL || "http://localhost:5000",
77
API_KEY: Bun.env.API_KEY || undefined,
88
REFRESH_DISCS_START: Bun.env.REFRESH_DISCS_START?.toLowerCase() === "true",
99
REFRESH_DISCS_CRON: Bun.env.REFRESH_DISCS_CRON?.toLowerCase() === "true",
10-
DISCIT_URL: Bun.env.DISCIT_URL,
1110
BACKUP_DIR: Bun.env.BACKUP_DIR || path.resolve("./backup")
1211
} as IConfig;
1312

src/refresh.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import jsdom from "jsdom";
22

3-
import { deleteAllDiscs, getAllDiscs, insertDiscs, revalidateDiscItCache } from "./api";
3+
import { deleteAllDiscs, getAllDiscs, insertDiscs } from "./api";
44
import { Config } from "./config";
55
import { DISC_FETCH_URL, Site } from "./constants";
66
import {
@@ -31,7 +31,6 @@ export const refreshDiscs = async () => {
3131
if (discsToInsert.length >= existingDiscs.length) {
3232
await doDeleteAllDiscs();
3333
await doInsertDiscs(discsToInsert);
34-
await doRevalidateDiscItCache();
3534
} else {
3635
console.log("Database is up-to-date. No further action needed.");
3736
}
@@ -217,18 +216,3 @@ const doInsertDiscs = async (discsToInsert: IDisc[]) => {
217216
throw new Error(`${error} - Error inserting discs into database.`);
218217
}
219218
};
220-
221-
const doRevalidateDiscItCache = async () => {
222-
try {
223-
if (!Config.DISCIT_URL) {
224-
console.log("DISCIT_URL env var is not defined. Skipping DiscIt cache revalidation.");
225-
return;
226-
}
227-
console.log("Revalidating DiscIt cache...");
228-
const { ok, status } = await revalidateDiscItCache();
229-
if (!ok) throw `Bad response status: ${status}`;
230-
console.log("DiscIt cache revalidated.");
231-
} catch (error) {
232-
throw new Error(`${error} - Error revalidating DiscIt cache.`);
233-
}
234-
};

src/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ export interface IDiscCollections {
88
}
99

1010
export interface IConfig {
11-
API_BASE_URL: string;
11+
API_URL: string;
1212
API_KEY: string;
1313
REFRESH_DISCS_START: boolean;
1414
REFRESH_DISCS_CRON: boolean;
15-
DISCIT_URL: string;
1615
BACKUP_DIR: string;
1716
}

0 commit comments

Comments
 (0)