Skip to content

Commit

Permalink
refactor(golinks): 🎨 move around some functions from src/lib/db.ts to…
Browse files Browse the repository at this point in the history
… src/lib/utils.ts

This is needed to trigger the CI deploys as needed

Signed-off-by: Andrei Jiroh Halili <[email protected]>
  • Loading branch information
ajhalili2006 committed Jul 18, 2024
1 parent 8f57c2d commit 34c7ea3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
4 changes: 2 additions & 2 deletions apps/golinks-v2/src/api/golinks.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { OpenAPIRoute, Num, Bool, Str, contentJson } from "chanfana";
import { z } from "zod";
import { GoLinks } from "types";
import { addGoLink, generateSlug, getGoLinks } from "lib/db";
import { addGoLink, getGoLinks } from "lib/db";
import { adminApiKey } from "lib/constants";
import { Context } from "hono";
import { checkToken } from "./auth";
import { generateSlug } from "lib/utils";

export class GoLinkCreate extends OpenAPIRoute {
schema = {
Expand Down
21 changes: 1 addition & 20 deletions apps/golinks-v2/src/lib/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,7 @@ import { DiscordInviteLink, GoLink, Prisma, PrismaClient } from "@prisma/client"
import { PrismaD1 } from "@prisma/adapter-d1";
import { Env, EnvBindings } from "../types";
import { Str } from "chanfana";
const PAGE_SIZE = 10;

function getOffset(page: number): number {
return Math.max(0, page) * PAGE_SIZE;
}

/**
* Generate a slug for use in URLs
* @param {number} length
* @returns {string}
*/
export function generateSlug(length: number) {
var result = "";
var characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var charactersLength = characters.length;
for (var i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
import { getOffset, PAGE_SIZE } from "./utils";

/**
* Get a list of golinks in batches of 10 from database.
Expand Down
15 changes: 15 additions & 0 deletions apps/golinks-v2/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export const PAGE_SIZE = 10;

export function getOffset(page: number): number {
return Math.max(0, page) * PAGE_SIZE;
}

export function generateSlug(length: number) {
var result = "";
var characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var charactersLength = characters.length;
for (var i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}

0 comments on commit 34c7ea3

Please sign in to comment.