Skip to content

Commit

Permalink
v0.6.3 documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
cletqui committed Jul 4, 2024
1 parent 69b1d1b commit 4fec349
Show file tree
Hide file tree
Showing 12 changed files with 291 additions and 168 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ npm run deploy
## TODO

- [ ] Write `README.md`
- [ ] Write GitHub App description
- [ ] Improve GUI
- [x] add additional info about the repo
- [x] implement dark/light themes
Expand Down
6 changes: 6 additions & 0 deletions public/static/script.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* Retrieves the value of a cookie by name.
* @function getCookie
* @param {string} name - The name of the cookie to retrieve.
* @returns {string|undefined} The value of the cookie if found, otherwise undefined.
*/
function getCookie(name) {
const match = document.cookie.match(new RegExp(`(?:^|; )${name}=([^;]*)`));
return match ? match[1] : undefined;
Expand Down
14 changes: 7 additions & 7 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Context, Hono } from "hono";
import { Suspense } from "hono/jsx";
import { logger } from "hono/logger";
import { Octokit } from "octokit";

import { renderer, Loader, RepositoryContainer } from "./utils/renderer";
import { getOctokitInstance, handleMaxId } from "./utils/octokit";
import { handleTokens, refreshToken } from "./utils/tokens";
import { handleMaxId } from "./utils/octokit";
import { handleTokens } from "./utils/tokens";

import api from "./routes/api";
import github from "./routes/github";
Expand All @@ -25,6 +26,7 @@ export type Variables = {
expires_in?: string;
refresh_token?: string;
state: string;
octokit: Octokit;
};

/* APP */
Expand All @@ -33,9 +35,8 @@ const app = new Hono<{ Bindings: Bindings; Variables: Variables }>();
/* MIDDLEWARES */
app.use(logger());
app.use(renderer);
app.use("/", handleMaxId());
app.use("/", handleTokens());
app.use("/", refreshToken());
app.use("/", handleMaxId);
app.use("/", handleTokens);

/* ROUTES */
app.route("/api", api);
Expand All @@ -50,8 +51,7 @@ app.get(
async (
c: Context<{ Bindings: Bindings; Variables: Variables }>
): Promise<Response> => {
const octokit = getOctokitInstance(c);
const { max_id } = c.var;
const { max_id, octokit } = c.var;
return c.render(
<Suspense fallback={<Loader />}>
<RepositoryContainer octokit={octokit} maxId={max_id.id} />
Expand Down
21 changes: 7 additions & 14 deletions src/routes/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,19 @@ import { cors } from "hono/cors";

import { Bindings, Variables } from "..";
import { handleMaxId } from "../utils/octokit";
import { handleTokens, refreshToken } from "../utils/tokens";
import {
apiAuth,
getOctokitInstance,
getRandomRepository,
getRepository,
} from "../utils/octokit";
import { handleTokens } from "../utils/tokens";
import { apiAuth, getRandomRepository, getRepository } from "../utils/octokit";

/* APP */
const app = new Hono<{ Bindings: Bindings; Variables: Variables }>();

/* MIDDLEWARES */
app.use(handleMaxId());
app.use(handleTokens());
app.use(refreshToken());
app.use(apiAuth());
app.use(poweredBy());
app.use(prettyJSON());
app.use(cors({ origin: "*", allowMethods: ["GET"], credentials: true }));
app.use(handleMaxId);
app.use(handleTokens);
app.use(apiAuth);

/* ENDPOINTS */
app.get(
Expand All @@ -38,8 +32,7 @@ app.get(
async (
c: Context<{ Bindings: Bindings; Variables: Variables }>
): Promise<Response> => {
const octokit = getOctokitInstance(c);
const { max_id } = c.var;
const { max_id, octokit } = c.var;
try {
const repository = await getRandomRepository(octokit, max_id.id);
return c.json(repository);
Expand All @@ -55,7 +48,7 @@ app.get(
c: Context<{ Bindings: Bindings; Variables: Variables }>
): Promise<Response> => {
const { id } = c.req.param();
const octokit = getOctokitInstance(c);
const { octokit } = c.var;
try {
const repository = await getRepository(octokit, Number(id));
const { id: repositoryId } = repository;
Expand Down
9 changes: 4 additions & 5 deletions src/routes/github.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ import { Context, Hono } from "hono";

import { Bindings, Variables } from "..";
import { generateState, handleState } from "../utils/state";
import { handleAccess, handleRefresh } from "../utils/tokens";
import { handleAccess } from "../utils/tokens";

/* APP */
const app = new Hono<{ Bindings: Bindings; Variables: Variables }>();

/* MIDDLEWARES */
app.use("/login", generateState());
app.use("/callback", handleState());
app.use("/callback", handleRefresh());
app.use("/access_token", handleAccess());
app.use("/login", generateState);
app.use("/callback", handleState);
app.use("/access_token", handleAccess);

/* ENDPOINTS */
app.get(
Expand Down
10 changes: 5 additions & 5 deletions src/routes/id.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Context, Hono } from "hono";

import { Bindings, Variables } from "..";
import { handleTokens, refreshToken } from "../utils/tokens";
import { getMaxId, getOctokitInstance } from "../utils/octokit";
import { handleTokens } from "../utils/tokens";
import { getMaxId, handleMaxId } from "../utils/octokit";
import { setCookie } from "hono/cookie";

/* APP */
const app = new Hono<{ Bindings: Bindings; Variables: Variables }>();

/* MIDDLEWARES */
app.use(handleTokens());
app.use(refreshToken());
app.use(handleMaxId)
app.use(handleTokens);

/* ENDPOINTS */
app.get(
Expand All @@ -21,8 +21,8 @@ app.get(
const {
max_id: { id, timestamp: old },
access_token,
octokit,
} = c.var;
const octokit = getOctokitInstance(c);
const update = access_token ? await getMaxId(octokit, id) : id;
const timestamp = access_token ? new Date().getTime() : old;
setCookie(c, "max_id", `{ "id": ${update}, "timestamp": ${timestamp} }`, {
Expand Down
9 changes: 4 additions & 5 deletions src/routes/template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@ import { Context, Hono } from "hono";
import { Suspense } from "hono/jsx";

import { Bindings, Variables } from "..";
import { handleTokens, refreshToken } from "../utils/tokens";
import { handleTokens } from "../utils/tokens";
import { Loader, Container } from "../utils/renderer";
import { getOctokitInstance, getRepos } from "../utils/octokit";
import { getRepos } from "../utils/octokit";

/* APP */
const app = new Hono<{ Bindings: Bindings; Variables: Variables }>();

/* MIDDLEWARES */
app.use(handleTokens());
app.use(refreshToken());
app.use(handleTokens);

/* ENDPOINTS */
app.get(
"/",
async (
c: Context<{ Bindings: Bindings; Variables: Variables }>
): Promise<Response> => {
const octokit = getOctokitInstance(c);
const { octokit } = c.var;
const owner = "cletqui";
const repo = "petithub";
const { data: repository } = await getRepos(octokit, owner, repo);
Expand Down
Loading

0 comments on commit 4fec349

Please sign in to comment.