update: add siteConfig argument to set replace value

This commit is contained in:
mbaharip
2025-01-21 22:05:06 +07:00
parent 3944f3f5f8
commit 1926fedf68
2 changed files with 26 additions and 15 deletions
+12 -8
View File
@@ -1,7 +1,7 @@
import { decodeBase64url, encodeBase64url } from "@oslojs/encoding";
import { GoogleAuth } from "google-auth-library";
import { JSONClient } from "google-auth-library/build/src/auth/googleauth";
import { drive_v3, google } from "googleapis";
import { decodeBase64, decodeBase64url, encodeBase64, encodeBase64url } from "@oslojs/encoding";
import { type GoogleAuth } from "google-auth-library";
import { type JSONClient } from "google-auth-library/build/src/auth/googleauth";
import { type drive_v3, google } from "googleapis";
import "server-only";
class EncryptionService {
@@ -58,12 +58,16 @@ class EncryptionService {
}
}
const base64Encode = (text: string) => {
type B64Type = "url" | "standard";
export const base64Encode = (text: string, type: B64Type = "url") => {
const data = new TextEncoder().encode(text);
if (type === "standard") return encodeBase64(data);
return encodeBase64url(data);
};
const base64Decode = <T = unknown>(encoded: string): T => {
const decoded = decodeBase64url(encoded);
export const base64Decode = <T = unknown>(encoded: string, type: B64Type = "url"): T => {
let decoded: Uint8Array<ArrayBufferLike>;
if (type === "standard") decoded = decodeBase64(encoded);
else decoded = decodeBase64url(encoded);
return new TextDecoder().decode(decoded) as T;
};
@@ -106,7 +110,7 @@ class GoogleDriveService {
version: "v3",
auth: this.auth,
fetchImplementation: (url, init) =>
fetch(url, {
fetch(url as string | URL, {
...init,
cache: "no-store",
}),
+14 -7
View File
@@ -1,8 +1,8 @@
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
import { z } from "zod";
import { type z } from "zod";
import { Schema_Breadcrumb } from "~/types/schema";
import { Schema_Breadcrumb, Schema_Config_Site } from "~/types/schema";
import config from "config";
@@ -10,19 +10,26 @@ export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
export function formatFooterContent(text: string[]): string {
export function formatFooterContent(
text: { value: string }[],
siteConfig?: z.infer<typeof Schema_Config_Site>,
): string {
const data = siteConfig ?? config.siteConfig;
const formatMap = {
year: new Date().getFullYear().toString(),
repository: "[Source Code](https://github.com/mbaharip/next-gdrive-index)",
poweredBy: `Powered by [next-gdrive-index v${config.version}](https://github.com/mbaharip/next-gdrive-index)`,
author: config.siteConfig.siteAuthor ?? "mbaharip",
author: data.siteAuthor ?? "mbaharip",
version: config.version ?? "0.0.0",
siteName: config.siteConfig.siteName ?? "next-gdrive-index",
handle: config.siteConfig.twitterHandle ?? "@__mbaharip__",
siteName: data.siteName ?? "next-gdrive-index",
handle: data.twitterHandle ?? "@__mbaharip__",
creator: "mbaharip",
};
return text.join("\n").replace(/{{\s*(\w+)\s*}}/g, (_, key) => formatMap[key as keyof typeof formatMap] ?? "");
return text
.map((item) => item.value.trim())
.join("\n")
.replace(/{{\s*(\w+)\s*}}/g, (_, key) => formatMap[key as keyof typeof formatMap] ?? "");
}
export function formatDate(date: string | number | Date, options?: Intl.DateTimeFormatOptions): string {