refactor: consolidate shared application helpers
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
"use client";
|
||||
|
||||
type FlushSave = () => Promise<void>;
|
||||
|
||||
const pendingSaves = new Set<FlushSave>();
|
||||
|
||||
export function registerPendingSave(flush: FlushSave) {
|
||||
pendingSaves.add(flush);
|
||||
return () => {
|
||||
pendingSaves.delete(flush);
|
||||
};
|
||||
}
|
||||
|
||||
export async function flushPendingSaves() {
|
||||
await Promise.all([...pendingSaves].map((flush) => flush()));
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { cdnImageResponse } from "@/lib/cdn-response";
|
||||
import {
|
||||
cdnImageResponse,
|
||||
MAX_FORM_ANSWER_IMAGE_BYTES,
|
||||
validateImageUploadFile,
|
||||
} from "@/lib/cdn-images";
|
||||
|
||||
@@ -27,3 +27,20 @@ export function validateImageUploadFile(file: Pick<File, "name" | "type" | "size
|
||||
export function cdnUrl(id: string | null | undefined) {
|
||||
return id ? `/cdn/${id}` : "";
|
||||
}
|
||||
|
||||
export type CdnResponseRecord = {
|
||||
data: Buffer;
|
||||
type: string;
|
||||
size: number;
|
||||
};
|
||||
|
||||
export function cdnImageResponse(record: CdnResponseRecord) {
|
||||
return new Response(new Uint8Array(record.data), {
|
||||
headers: {
|
||||
"Content-Type": record.type,
|
||||
"Content-Length": String(record.size),
|
||||
"Cache-Control": "public, max-age=31536000, immutable",
|
||||
"X-Content-Type-Options": "nosniff",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
export type CdnResponseRecord = {
|
||||
data: Buffer;
|
||||
type: string;
|
||||
size: number;
|
||||
};
|
||||
|
||||
export function cdnImageResponse(record: CdnResponseRecord) {
|
||||
return new Response(new Uint8Array(record.data), {
|
||||
headers: {
|
||||
"Content-Type": record.type,
|
||||
"Content-Length": String(record.size),
|
||||
"Cache-Control": "public, max-age=31536000, immutable",
|
||||
"X-Content-Type-Options": "nosniff",
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
export function getErrorMessage(error: unknown, fallback: string) {
|
||||
return error instanceof Error ? error.message : fallback;
|
||||
}
|
||||
+5
-1
@@ -5,6 +5,10 @@ export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
}
|
||||
|
||||
export function getErrorMessage(error: unknown, fallback: string) {
|
||||
return error instanceof Error ? error.message : fallback;
|
||||
}
|
||||
|
||||
export const stripHtml = (html: string) => {
|
||||
return (html || "").replace(/<[^>]*>?/gm, '').trim();
|
||||
};
|
||||
@@ -17,4 +21,4 @@ export const copyToClipboard = async (text: string): Promise<boolean> => {
|
||||
console.error("Copy error:", error);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user