Files
zooqueen 84dfb5d9d2 feat: start a document from pasted content or a link
A document no longer has to come off this machine. Paste text or Markdown and
it is rendered to a PDF; give a link and the server fetches it, including a
GitHub file page, which it reads as the file that page shows.

Every source resolves to bytes in one place and is created by envelope.create,
the same call an upload makes, so the editor and everything past it cannot tell
them apart. The upload button and the drop zone now share that one creation
path rather than each carrying a copy.

The server dials http(s) only, and never an address that resolves inside the
cluster — checked on the hostname, on every address it resolves to, and again
on each redirect. It reads at most the upload limit and requires the bytes to
be a PDF.
2026-08-14 02:50:07 -07:00

37 lines
1.6 KiB
TypeScript

import type { MessageDescriptor } from '@lingui/core';
import { msg } from '@lingui/core/macro';
import { EnvelopeType } from '@prisma/client';
import { match } from 'ts-pattern';
import { APP_DOCUMENT_UPLOAD_SIZE_LIMIT } from '@hanzo/esign-lib/constants/app';
import { AppError, AppErrorCode } from '@hanzo/esign-lib/errors/app-error';
import { ImportError } from '@hanzo/esign-lib/universal/import';
/**
* Why an upload failed, worded for the thing being uploaded. Every upload
* entry point reads its toast from here, so a template says "template".
*/
export const uploadErrorMessage = (err: unknown, type: EnvelopeType): MessageDescriptor =>
match(AppError.parseError(err).code)
.with('INVALID_DOCUMENT_FILE', () => msg`You cannot upload encrypted PDFs.`)
.with(ImportError.url, () => msg`That address cannot be read. Use a public http(s) link.`)
.with(ImportError.fetch, () => msg`We could not reach that address.`)
.with(ImportError.pdf, () => msg`That address does not lead to a PDF.`)
.with(
ImportError.size,
() => msg`That document is larger than ${APP_DOCUMENT_UPLOAD_SIZE_LIMIT}MB.`,
)
.with(
AppErrorCode.LIMIT_EXCEEDED,
() => msg`You have reached your document limit for this month. Please upgrade your plan.`,
)
.with(
'ENVELOPE_ITEM_LIMIT_EXCEEDED',
() => msg`You have reached the limit of the number of files per envelope.`,
)
.otherwise(() =>
type === EnvelopeType.TEMPLATE
? msg`An error occurred while uploading your template.`
: msg`An error occurred while uploading your document.`,
);