+ image ready for insert
+ ${escapeHtml(record.name)}
+ ${escapeHtml(snippet)}
+
+
+ `;
+}
+
+async function handleInsertImage() {
+ if (!(imageInput instanceof HTMLInputElement)) {
+ return;
+ }
+
+ const file = imageInput.files?.[0];
+ if (!file) {
+ showUploadError("image file is required.");
+ return;
+ }
+
+ if (!isAllowedImageFile(file)) {
+ showUploadError("unsupported image type.");
+ return;
+ }
+
+ if (file.size > MAX_IMAGE_BYTES) {
+ showUploadError("image is too large. maximum size per image is 25MB.");
+ return;
+ }
+
+ setUploadLoadingState(true);
+
+ try {
+ const { totalBytes } = await getImageUsageStats();
+ if (totalBytes + file.size > MAX_STORAGE_BYTES) {
+ showUploadError("image upload limit reached. maximum total image capacity is 25GB.");
+ return;
+ }
+
+ const record = {
+ id: makeImageId(),
+ name: file.name || "image",
+ mimeType: file.type || "application/octet-stream",
+ sizeBytes: file.size,
+ createdAt: Date.now(),
+ blob: file,
+ };
+
+ await saveImageRecord(record);
+ showUploadResult(record);
+ imageInput.value = "";
+ } catch (error) {
+ const message =
+ error instanceof Error && error.message
+ ? error.message
+ : "image upload failed.";
+ showUploadError(message);
+ } finally {
+ setUploadLoadingState(false);
+ }
+}
+
+function showConvertError(message) {
+ if (!(resultContainer instanceof HTMLElement)) {
+ return;
+ }
+
+ resultContainer.innerHTML = `
+ simple markdown to pdf export.
-