From 437d779fcb5e704f8b555ac3198247166ef478f1 Mon Sep 17 00:00:00 2001 From: Andrei Jiroh Halili Date: Fri, 26 Jul 2024 14:37:38 +0800 Subject: [PATCH] chore(global): format all the things via Prettier Off-Arcade session work btw Signed-off-by: Andrei Jiroh Halili --- apps/cfw-email-router/package.json | 2 +- apps/cfw-email-router/src/worker.js | 6 +-- apps/golinks/README.md | 8 ++-- apps/golinks/package.json | 26 ++++++------ apps/golinks/src/main.ts | 66 ++++++++++++++--------------- package.json | 8 ++-- packages/lib/README.md | 2 +- packages/lib/deno.json | 8 ++-- packages/lib/logging.ts | 14 +++--- packages/lib/mod.ts | 6 +-- 10 files changed, 73 insertions(+), 73 deletions(-) diff --git a/apps/cfw-email-router/package.json b/apps/cfw-email-router/package.json index a14729c..c4e94d2 100644 --- a/apps/cfw-email-router/package.json +++ b/apps/cfw-email-router/package.json @@ -8,6 +8,6 @@ "start": "wrangler dev" }, "devDependencies": { - "wrangler": "^3.60.0" + "wrangler": "^3.66.0" } } diff --git a/apps/cfw-email-router/src/worker.js b/apps/cfw-email-router/src/worker.js index f8d6955..656f3ef 100644 --- a/apps/cfw-email-router/src/worker.js +++ b/apps/cfw-email-router/src/worker.js @@ -1,4 +1,4 @@ -import logops from "../../../packages/lib/mod"; +import { debug } from '../../../packages/lib/logging'; export default { async email(message, env, ctx) { @@ -16,8 +16,8 @@ export default { const emailUsername = message.headers.get('to').replace(regex, subst); if (block.indexOf(message.headers.get('from')) == -1) { - logops.debug(`handling ${message.from}'s message with subject "${message.headers.get('subject')}"`, `incoming-email`) - logops.debug(`parsed email username:${emailUsername}`, `email-parser`) + debug(`handling ${message.from}'s message with subject "${message.headers.get('subject')}"`, `incoming-email`); + debug(`parsed email username:${emailUsername}`, `email-parser`); switch (emailUsername) { case 'ajhalili2006': await message.forward(env.MAIN_ADDRESS); diff --git a/apps/golinks/README.md b/apps/golinks/README.md index 1021a50..b88a67d 100644 --- a/apps/golinks/README.md +++ b/apps/golinks/README.md @@ -12,7 +12,7 @@ This whole server is currently implemented as a Cloudflare Worker, with two sepe If you are going to deploy your own using this codebase, complete the checklist to get things started. -* [ ] Create two KV namespaces, one for regular golinks and another for wikilinks-styled ones. -* [ ] Replace the KV namespace IDs with the ones you created in `wrangler.toml`. -* [ ] Update routes in `wrangler.toml` to use your own domain and adjust as needed. -* [ ] Sign in to CLI and deploy: `yarn wrangler login && yarn deploy` +- [ ] Create two KV namespaces, one for regular golinks and another for wikilinks-styled ones. +- [ ] Replace the KV namespace IDs with the ones you created in `wrangler.toml`. +- [ ] Update routes in `wrangler.toml` to use your own domain and adjust as needed. +- [ ] Sign in to CLI and deploy: `yarn wrangler login && yarn deploy` diff --git a/apps/golinks/package.json b/apps/golinks/package.json index a7065ba..be98eba 100644 --- a/apps/golinks/package.json +++ b/apps/golinks/package.json @@ -1,15 +1,15 @@ { - "name": "golinks", - "version": "0.0.0", - "private": true, - "scripts": { - "deploy": "wrangler deploy", - "dev": "wrangler dev", - "start": "wrangler dev" - }, - "devDependencies": { - "@cloudflare/workers-types": "^4.20240605.0", - "typescript": "^5.4.5", - "wrangler": "^3.60.0" - } + "name": "golinks", + "version": "0.0.0", + "private": true, + "scripts": { + "deploy": "wrangler deploy", + "dev": "wrangler dev", + "start": "wrangler dev" + }, + "devDependencies": { + "@cloudflare/workers-types": "^4.20240605.0", + "typescript": "^5.4.5", + "wrangler": "^3.60.0" + } } diff --git a/apps/golinks/src/main.ts b/apps/golinks/src/main.ts index 13e7f72..0b5c22d 100644 --- a/apps/golinks/src/main.ts +++ b/apps/golinks/src/main.ts @@ -1,38 +1,38 @@ export default { - async fetch(request, env, ctx): Promise { - const linksDb = env.links; - const wikilinks = env.wikilinks; + async fetch(request, env, ctx): Promise { + const linksDb = env.links; + const wikilinks = env.wikilinks; - function rmTrailingSlashes(str) { - let i = str.length; - while (str[--i] === '/'); - return str.slice(0, i + 1); - } + function rmTrailingSlashes(str) { + let i = str.length; + while (str[--i] === "/"); + return str.slice(0, i + 1); + } - // parse URL for detection - const url = new URL(request.url); - console.log(`request URL - ${url}`); - const { pathname, hostname, search } = url; + // parse URL for detection + const url = new URL(request.url); + console.log(`request URL - ${url}`); + const { pathname, hostname, search } = url; - if (hostname == 'wiki.andreijiroh.xyz' || (hostname == 'andreijiroh.xyz' && pathname.startsWith('/go/'))) { - const wikiLinkNoTrailingSlash = rmTrailingSlashes(pathname); - const wikiLinkRegExp = new RegExp('\\/go\\/', 'gm'); - const resultingRedirect = await wikilinks.get(wikiLinkNoTrailingSlash.replace(wikiLinkRegExp, '')); - if (resultingRedirect === null) { - return new Response('golink does not exist on database', { - status: 404, - }); - } - console.log(`[wikilinks] redirecting to ${resultingRedirect}`); - return Response.redirect(resultingRedirect, 301); - } else { - const redirectUrl = await linksDb.get(pathname); - if (redirectUrl === null) { - console.log(`golink doesn't exist for ${pathname}, redirecting to landing page instead`); - return Response.redirect(`https://wiki.andreijiroh.xyz/garden/golinks`, 301); - } - console.log(`[go] redirecting to ${redirectUrl}`); - return Response.redirect(redirectUrl, 301); - } - }, + if (hostname == "wiki.andreijiroh.xyz" || (hostname == "andreijiroh.xyz" && pathname.startsWith("/go/"))) { + const wikiLinkNoTrailingSlash = rmTrailingSlashes(pathname); + const wikiLinkRegExp = new RegExp("\\/go\\/", "gm"); + const resultingRedirect = await wikilinks.get(wikiLinkNoTrailingSlash.replace(wikiLinkRegExp, "")); + if (resultingRedirect === null) { + return new Response("golink does not exist on database", { + status: 404, + }); + } + console.log(`[wikilinks] redirecting to ${resultingRedirect}`); + return Response.redirect(resultingRedirect, 301); + } else { + const redirectUrl = await linksDb.get(pathname); + if (redirectUrl === null) { + console.log(`golink doesn't exist for ${pathname}, redirecting to landing page instead`); + return Response.redirect(`https://wiki.andreijiroh.xyz/garden/golinks`, 301); + } + console.log(`[go] redirecting to ${redirectUrl}`); + return Response.redirect(redirectUrl, 301); + } + }, }; diff --git a/package.json b/package.json index 7ba1808..0fad018 100644 --- a/package.json +++ b/package.json @@ -25,13 +25,13 @@ "homepage": "https://github.com/andreijiroh-dev/api-servers#readme", "packageManager": "yarn@4.3.1", "devDependencies": { - "@cloudflare/workers-types": "^4.20240712.0", - "@types/node": "^20.14.11", + "@cloudflare/workers-types": "^4.20240722.0", + "@types/node": "^20.14.12", "@yarnpkg/sdks": "^3.1.3", "prettier": "^3.3.3", "ts-node": "^10.9.2", - "typescript": "^5.5.3", - "wrangler": "^3.65.0", + "typescript": "^5.5.4", + "wrangler": "^3.66.0", "yarn-upgrade-all": "^0.7.2" } } diff --git a/packages/lib/README.md b/packages/lib/README.md index 2c36e96..0d33696 100644 --- a/packages/lib/README.md +++ b/packages/lib/README.md @@ -14,5 +14,5 @@ yarn add @ajhalili2006/api-servers-lib // or via JSR in Deno // see https://jsr.io/docs/npm-compatibility if you want to use // JSR as part of your npm/yarn/pnpm workflow -import * as stdlib from "jsr:@ajahlili2006/api-servers-lib" +import * as stdlib from "jsr:@ajahlili2006/api-servers-lib"; ``` diff --git a/packages/lib/deno.json b/packages/lib/deno.json index 39f6dab..b1a9b31 100644 --- a/packages/lib/deno.json +++ b/packages/lib/deno.json @@ -1,5 +1,5 @@ { - "name": "@ajhalili2006/api-servers-lib", - "version": "0.1.0", - "exports": "./mod.ts" - } \ No newline at end of file + "name": "@ajhalili2006/api-servers-lib", + "version": "0.1.0", + "exports": "./mod.ts" +} diff --git a/packages/lib/logging.ts b/packages/lib/logging.ts index c8084c2..dcc1da3 100644 --- a/packages/lib/logging.ts +++ b/packages/lib/logging.ts @@ -2,18 +2,18 @@ * @module * This module provides basic logging functions with an option to add * an prefix for easy observability. - * + * * @example * ```ts * import { logops } from "@ajhalili2006/api-servers-lib" - * + * * logops.debug("test", "lab") // [debug] lab: test * logops.log("laboratory") // [log] laboratory * ``` */ export function log(msg: string, prefix?: string): void { - console.log(prefix ? `[log] ${prefix}: ${msg}` : `[debug] ${msg}`) + console.log(prefix ? `[log] ${prefix}: ${msg}` : `[debug] ${msg}`); } /* @@ -23,10 +23,10 @@ export function log(msg: string, prefix?: string): void { * @param {string} prefix Optional log prefix */ export function debug(msg: string, prefix?: string): void { - console.debug(prefix ? `${prefix}: ${msg}` : `${msg}`); - console.log(prefix ? `[debug] ${prefix}: ${msg}` : `[debug] ${msg}`) + console.debug(prefix ? `${prefix}: ${msg}` : `${msg}`); + console.log(prefix ? `[debug] ${prefix}: ${msg}` : `[debug] ${msg}`); } export function error(msg: string, prefix?: string) { - console.error(prefix ? `[error] ${prefix}: ${msg}` : `[error] ${msg}`); -} \ No newline at end of file + console.error(prefix ? `[error] ${prefix}: ${msg}` : `[error] ${msg}`); +} diff --git a/packages/lib/mod.ts b/packages/lib/mod.ts index b9c53e6..37a9ed3 100644 --- a/packages/lib/mod.ts +++ b/packages/lib/mod.ts @@ -1,5 +1,5 @@ -import * as logops from "./logging" +import * as logops from "./logging"; export default { - logops -} \ No newline at end of file + logops, +}; -- knotmirror 0.0.1