mirror of
https://github.com/documenso/documenso.git
synced 2026-07-27 10:25:00 +10:00
fix: lint project (#2693)
This commit is contained in:
@@ -42,7 +42,7 @@ export type ApiRequestMetadata = {
|
||||
};
|
||||
|
||||
export const extractRequestMetadata = (req: Request): RequestMetadata => {
|
||||
let ip: string | undefined = undefined;
|
||||
let ip: string | undefined;
|
||||
|
||||
try {
|
||||
ip = getIpAddress(req);
|
||||
|
||||
@@ -86,8 +86,7 @@ const calculateLayout = (params: {
|
||||
exceedsHeightWhenWrapped: boolean;
|
||||
hasRoomForMoreThanOneLine: boolean;
|
||||
} => {
|
||||
const { textToRender, fontSize, fontFamily, lineHeight, letterSpacing, baseWidth, baseHeight } =
|
||||
params;
|
||||
const { textToRender, fontSize, fontFamily, lineHeight, letterSpacing, baseWidth, baseHeight } = params;
|
||||
|
||||
// Measure the text without width constraint to get natural width and single-line height.
|
||||
const unwrappedNode = new Konva.Text({
|
||||
@@ -194,8 +193,7 @@ const calculateHorizontalOverflow = (params: OverflowLayoutParams): OverflowLayo
|
||||
* - middle aligned: extends symmetrically up and down toward the closer page edge
|
||||
*/
|
||||
const calculateVerticalOverflow = (params: OverflowLayoutParams): OverflowLayoutResult => {
|
||||
const { verticalAlign, textAlign, baseX, baseY, baseWidth, baseHeight, groupY, pageHeight } =
|
||||
params;
|
||||
const { verticalAlign, textAlign, baseX, baseY, baseWidth, baseHeight, groupY, pageHeight } = params;
|
||||
|
||||
if (verticalAlign === 'bottom') {
|
||||
// Extend upward to page top edge.
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
import { DEFAULT_RECT_BACKGROUND, getRecipientColorStyles } from '@documenso/ui/lib/recipient-colors';
|
||||
import Konva from 'konva';
|
||||
|
||||
import {
|
||||
DEFAULT_RECT_BACKGROUND,
|
||||
getRecipientColorStyles,
|
||||
} from '@documenso/ui/lib/recipient-colors';
|
||||
|
||||
import type { FieldToRender, RenderFieldElementOptions } from './field-renderer';
|
||||
import { calculateFieldPosition } from './field-renderer';
|
||||
|
||||
@@ -12,17 +8,10 @@ export const konvaTextFontFamily =
|
||||
'"Noto Sans", "Noto Sans Japanese", "Noto Sans Chinese", "Noto Sans Korean", sans-serif';
|
||||
export const konvaTextFill = 'black';
|
||||
|
||||
export const upsertFieldGroup = (
|
||||
field: FieldToRender,
|
||||
options: RenderFieldElementOptions,
|
||||
): Konva.Group => {
|
||||
export const upsertFieldGroup = (field: FieldToRender, options: RenderFieldElementOptions): Konva.Group => {
|
||||
const { pageWidth, pageHeight, pageLayer, editable, scale } = options;
|
||||
|
||||
const { fieldX, fieldY, fieldWidth, fieldHeight } = calculateFieldPosition(
|
||||
field,
|
||||
pageWidth,
|
||||
pageHeight,
|
||||
);
|
||||
const { fieldX, fieldY, fieldWidth, fieldHeight } = calculateFieldPosition(field, pageWidth, pageHeight);
|
||||
|
||||
const fieldGroup: Konva.Group =
|
||||
pageLayer.findOne(`#${field.renderId}`) ||
|
||||
@@ -51,10 +40,7 @@ export const upsertFieldGroup = (
|
||||
return fieldGroup;
|
||||
};
|
||||
|
||||
export const upsertFieldRect = (
|
||||
field: FieldToRender,
|
||||
options: RenderFieldElementOptions,
|
||||
): Konva.Rect => {
|
||||
export const upsertFieldRect = (field: FieldToRender, options: RenderFieldElementOptions): Konva.Rect => {
|
||||
const { pageWidth, pageHeight, mode, pageLayer, color } = options;
|
||||
|
||||
const { fieldWidth, fieldHeight } = calculateFieldPosition(field, pageWidth, pageHeight);
|
||||
@@ -80,13 +66,7 @@ export const upsertFieldRect = (
|
||||
return fieldRect;
|
||||
};
|
||||
|
||||
export const createSpinner = ({
|
||||
fieldWidth,
|
||||
fieldHeight,
|
||||
}: {
|
||||
fieldWidth: number;
|
||||
fieldHeight: number;
|
||||
}) => {
|
||||
export const createSpinner = ({ fieldWidth, fieldHeight }: { fieldWidth: number; fieldHeight: number }) => {
|
||||
const loadingGroup = new Konva.Group({
|
||||
name: 'loading-spinner-group',
|
||||
});
|
||||
@@ -139,11 +119,7 @@ type CreateFieldHoverInteractionOptions = {
|
||||
/**
|
||||
* Adds smooth transition-like behavior for hover effects to the field group and rectangle.
|
||||
*/
|
||||
export const createFieldHoverInteraction = ({
|
||||
options,
|
||||
fieldGroup,
|
||||
fieldRect,
|
||||
}: CreateFieldHoverInteractionOptions) => {
|
||||
export const createFieldHoverInteraction = ({ options, fieldGroup, fieldRect }: CreateFieldHoverInteractionOptions) => {
|
||||
const { mode } = options;
|
||||
|
||||
if (mode === 'export' || !options.color) {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import type { FieldType, Signature } from '@prisma/client';
|
||||
import { type Field } from '@prisma/client';
|
||||
import type Konva from 'konva';
|
||||
|
||||
import type { TRecipientColor } from '@documenso/ui/lib/recipient-colors';
|
||||
import type { Field, FieldType, Signature } from '@prisma/client';
|
||||
import type Konva from 'konva';
|
||||
|
||||
import type { TFieldMetaSchema } from '../../types/field-meta';
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ import {
|
||||
upsertFieldGroup,
|
||||
upsertFieldRect,
|
||||
} from './field-generic-items';
|
||||
import { calculateFieldPosition, calculateMultiItemPosition } from './field-renderer';
|
||||
import type { FieldToRender, RenderFieldElementOptions } from './field-renderer';
|
||||
import { calculateFieldPosition, calculateMultiItemPosition } from './field-renderer';
|
||||
|
||||
// Do not change any of these values without consulting with the team.
|
||||
const checkboxFieldPadding = 8;
|
||||
@@ -22,10 +22,7 @@ const calculateCheckboxSize = (fontSize: number) => {
|
||||
return fontSize;
|
||||
};
|
||||
|
||||
export const renderCheckboxFieldElement = (
|
||||
field: FieldToRender,
|
||||
options: RenderFieldElementOptions,
|
||||
) => {
|
||||
export const renderCheckboxFieldElement = (field: FieldToRender, options: RenderFieldElementOptions) => {
|
||||
const { pageWidth, pageHeight, pageLayer, mode, color } = options;
|
||||
|
||||
const { fieldWidth, fieldHeight } = calculateFieldPosition(field, pageWidth, pageHeight);
|
||||
@@ -82,18 +79,17 @@ export const renderCheckboxFieldElement = (
|
||||
groupedItems.forEach((item, i) => {
|
||||
const { squareElement, checkmarkElement, textElement } = item;
|
||||
|
||||
const { itemInputX, itemInputY, textX, textY, textWidth, textHeight } =
|
||||
calculateMultiItemPosition({
|
||||
fieldWidth: rectWidth,
|
||||
fieldHeight: rectHeight,
|
||||
itemCount: checkboxValues.length,
|
||||
itemIndex: i,
|
||||
itemSize: calculateCheckboxSize(fontSize),
|
||||
spacingBetweenItemAndText: spacingBetweenCheckboxAndText,
|
||||
fieldPadding: checkboxFieldPadding,
|
||||
direction: checkboxMeta?.direction || 'vertical',
|
||||
type: 'checkbox',
|
||||
});
|
||||
const { itemInputX, itemInputY, textX, textY, textWidth, textHeight } = calculateMultiItemPosition({
|
||||
fieldWidth: rectWidth,
|
||||
fieldHeight: rectHeight,
|
||||
itemCount: checkboxValues.length,
|
||||
itemIndex: i,
|
||||
itemSize: calculateCheckboxSize(fontSize),
|
||||
spacingBetweenItemAndText: spacingBetweenCheckboxAndText,
|
||||
fieldPadding: checkboxFieldPadding,
|
||||
direction: checkboxMeta?.direction || 'vertical',
|
||||
type: 'checkbox',
|
||||
});
|
||||
|
||||
squareElement.setAttrs({
|
||||
x: itemInputX,
|
||||
@@ -148,18 +144,17 @@ export const renderCheckboxFieldElement = (
|
||||
|
||||
const itemSize = calculateCheckboxSize(fontSize);
|
||||
|
||||
const { itemInputX, itemInputY, textX, textY, textWidth, textHeight } =
|
||||
calculateMultiItemPosition({
|
||||
fieldWidth,
|
||||
fieldHeight,
|
||||
itemCount: checkboxValues.length,
|
||||
itemIndex: index,
|
||||
itemSize,
|
||||
spacingBetweenItemAndText: spacingBetweenCheckboxAndText,
|
||||
fieldPadding: checkboxFieldPadding,
|
||||
direction: checkboxMeta?.direction || 'vertical',
|
||||
type: 'checkbox',
|
||||
});
|
||||
const { itemInputX, itemInputY, textX, textY, textWidth, textHeight } = calculateMultiItemPosition({
|
||||
fieldWidth,
|
||||
fieldHeight,
|
||||
itemCount: checkboxValues.length,
|
||||
itemIndex: index,
|
||||
itemSize,
|
||||
spacingBetweenItemAndText: spacingBetweenCheckboxAndText,
|
||||
fieldPadding: checkboxFieldPadding,
|
||||
direction: checkboxMeta?.direction || 'vertical',
|
||||
type: 'checkbox',
|
||||
});
|
||||
|
||||
const square = new Konva.Rect({
|
||||
internalCheckboxIndex: index,
|
||||
|
||||
@@ -10,8 +10,8 @@ import {
|
||||
upsertFieldGroup,
|
||||
upsertFieldRect,
|
||||
} from './field-generic-items';
|
||||
import { calculateFieldPosition } from './field-renderer';
|
||||
import type { FieldToRender, RenderFieldElementOptions } from './field-renderer';
|
||||
import { calculateFieldPosition } from './field-renderer';
|
||||
|
||||
type CalculateDropdownPositionOptions = {
|
||||
fieldWidth: number;
|
||||
@@ -46,10 +46,7 @@ const calculateDropdownPosition = (options: CalculateDropdownPositionOptions) =>
|
||||
};
|
||||
};
|
||||
|
||||
export const renderDropdownFieldElement = (
|
||||
field: FieldToRender,
|
||||
options: RenderFieldElementOptions,
|
||||
) => {
|
||||
export const renderDropdownFieldElement = (field: FieldToRender, options: RenderFieldElementOptions) => {
|
||||
const { pageWidth, pageHeight, pageLayer, mode, translations, color } = options;
|
||||
|
||||
const { fieldWidth, fieldHeight } = calculateFieldPosition(field, pageWidth, pageHeight);
|
||||
@@ -93,11 +90,10 @@ export const renderDropdownFieldElement = (
|
||||
selectedValue = field.customText;
|
||||
}
|
||||
|
||||
const { arrowX, arrowY, arrowSize, textX, textY, textWidth, textHeight } =
|
||||
calculateDropdownPosition({
|
||||
fieldWidth,
|
||||
fieldHeight,
|
||||
});
|
||||
const { arrowX, arrowY, arrowSize, textX, textY, textWidth, textHeight } = calculateDropdownPosition({
|
||||
fieldWidth,
|
||||
fieldHeight,
|
||||
});
|
||||
|
||||
// Selected value text
|
||||
const selectedText = new Konva.Text({
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import type { TRecipientColor } from '@documenso/ui/lib/recipient-colors';
|
||||
import type { Signature } from '@prisma/client';
|
||||
import { type Field, FieldType } from '@prisma/client';
|
||||
import type Konva from 'konva';
|
||||
import { match } from 'ts-pattern';
|
||||
|
||||
import type { TRecipientColor } from '@documenso/ui/lib/recipient-colors';
|
||||
|
||||
import type { TFieldMetaSchema } from '../../types/field-meta';
|
||||
import { renderCheckboxFieldElement } from './render-checkbox-field';
|
||||
import { renderDropdownFieldElement } from './render-dropdown-field';
|
||||
@@ -79,14 +78,8 @@ export const renderField = ({
|
||||
|
||||
// If the generic text field element array changes, update the `GenericTextFieldTypeMetas` type
|
||||
return match(field.type)
|
||||
.with(
|
||||
FieldType.INITIALS,
|
||||
FieldType.NAME,
|
||||
FieldType.EMAIL,
|
||||
FieldType.DATE,
|
||||
FieldType.TEXT,
|
||||
FieldType.NUMBER,
|
||||
() => renderGenericTextFieldElement(field, options),
|
||||
.with(FieldType.INITIALS, FieldType.NAME, FieldType.EMAIL, FieldType.DATE, FieldType.TEXT, FieldType.NUMBER, () =>
|
||||
renderGenericTextFieldElement(field, options),
|
||||
)
|
||||
.with(FieldType.CHECKBOX, () => renderCheckboxFieldElement(field, options))
|
||||
.with(FieldType.RADIO, () => renderRadioFieldElement(field, options))
|
||||
|
||||
@@ -25,11 +25,7 @@ const DEFAULT_TEXT_X_PADDING = 6;
|
||||
const upsertFieldText = (field: FieldToRender, options: RenderFieldElementOptions) => {
|
||||
const { pageWidth, pageHeight, mode = 'edit', pageLayer, translations } = options;
|
||||
|
||||
const { fieldX, fieldY, fieldWidth, fieldHeight } = calculateFieldPosition(
|
||||
field,
|
||||
pageWidth,
|
||||
pageHeight,
|
||||
);
|
||||
const { fieldX, fieldY, fieldWidth, fieldHeight } = calculateFieldPosition(field, pageWidth, pageHeight);
|
||||
|
||||
const fieldMeta = field.fieldMeta as GenericTextFieldTypeMetas | undefined;
|
||||
|
||||
@@ -157,10 +153,7 @@ const upsertFieldText = (field: FieldToRender, options: RenderFieldElementOption
|
||||
};
|
||||
};
|
||||
|
||||
export const renderGenericTextFieldElement = (
|
||||
field: FieldToRender,
|
||||
options: RenderFieldElementOptions,
|
||||
) => {
|
||||
export const renderGenericTextFieldElement = (field: FieldToRender, options: RenderFieldElementOptions) => {
|
||||
const { mode = 'edit', pageLayer, color } = options;
|
||||
const { pageWidth, pageHeight } = options;
|
||||
const fieldMeta = field.fieldMeta as GenericTextFieldTypeMetas | undefined;
|
||||
|
||||
@@ -40,9 +40,7 @@ export function calculateSnapPositions(
|
||||
stage: Konva.Stage,
|
||||
excludeId?: string,
|
||||
): { horizontal: SnapPoint[]; vertical: SnapPoint[] } {
|
||||
const fieldGroups = stage
|
||||
.find('.field-group')
|
||||
.filter((node): node is Konva.Group => node instanceof Konva.Group);
|
||||
const fieldGroups = stage.find('.field-group').filter((node): node is Konva.Group => node instanceof Konva.Group);
|
||||
const horizontal: SnapPoint[] = [];
|
||||
const vertical: SnapPoint[] = [];
|
||||
|
||||
@@ -71,13 +69,8 @@ export function calculateSnapPositions(
|
||||
return { horizontal, vertical };
|
||||
}
|
||||
|
||||
export function calculateSnapSizes(
|
||||
stage: Konva.Stage,
|
||||
excludeId?: string,
|
||||
): { widths: number[]; heights: number[] } {
|
||||
const fieldGroups = stage
|
||||
.find('.field-group')
|
||||
.filter((node): node is Konva.Group => node instanceof Konva.Group);
|
||||
export function calculateSnapSizes(stage: Konva.Stage, excludeId?: string): { widths: number[]; heights: number[] } {
|
||||
const fieldGroups = stage.find('.field-group').filter((node): node is Konva.Group => node instanceof Konva.Group);
|
||||
const widths: number[] = [];
|
||||
const heights: number[] = [];
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@ import {
|
||||
upsertFieldGroup,
|
||||
upsertFieldRect,
|
||||
} from './field-generic-items';
|
||||
import { calculateFieldPosition, calculateMultiItemPosition } from './field-renderer';
|
||||
import type { FieldToRender, RenderFieldElementOptions } from './field-renderer';
|
||||
import { calculateFieldPosition, calculateMultiItemPosition } from './field-renderer';
|
||||
|
||||
// Do not change any of these values without consulting with the team.
|
||||
const radioFieldPadding = 8;
|
||||
@@ -21,10 +21,7 @@ const calculateRadioSize = (fontSize: number) => {
|
||||
return fontSize;
|
||||
};
|
||||
|
||||
export const renderRadioFieldElement = (
|
||||
field: FieldToRender,
|
||||
options: RenderFieldElementOptions,
|
||||
) => {
|
||||
export const renderRadioFieldElement = (field: FieldToRender, options: RenderFieldElementOptions) => {
|
||||
const { pageWidth, pageHeight, pageLayer, mode, color } = options;
|
||||
|
||||
const radioMeta: TRadioFieldMeta | null = (field.fieldMeta as TRadioFieldMeta) || null;
|
||||
@@ -73,18 +70,17 @@ export const renderRadioFieldElement = (
|
||||
groupedItems.forEach((item, i) => {
|
||||
const { circleElement, checkmarkElement, textElement } = item;
|
||||
|
||||
const { itemInputX, itemInputY, textX, textY, textWidth, textHeight } =
|
||||
calculateMultiItemPosition({
|
||||
fieldWidth: rectWidth,
|
||||
fieldHeight: rectHeight,
|
||||
itemCount: radioValues.length,
|
||||
itemIndex: i,
|
||||
itemSize: calculateRadioSize(fontSize),
|
||||
spacingBetweenItemAndText: spacingBetweenRadioAndText,
|
||||
fieldPadding: radioFieldPadding,
|
||||
type: 'radio',
|
||||
direction: radioMeta?.direction || 'vertical',
|
||||
});
|
||||
const { itemInputX, itemInputY, textX, textY, textWidth, textHeight } = calculateMultiItemPosition({
|
||||
fieldWidth: rectWidth,
|
||||
fieldHeight: rectHeight,
|
||||
itemCount: radioValues.length,
|
||||
itemIndex: i,
|
||||
itemSize: calculateRadioSize(fontSize),
|
||||
spacingBetweenItemAndText: spacingBetweenRadioAndText,
|
||||
fieldPadding: radioFieldPadding,
|
||||
type: 'radio',
|
||||
direction: radioMeta?.direction || 'vertical',
|
||||
});
|
||||
|
||||
circleElement.setAttrs({
|
||||
x: itemInputX,
|
||||
@@ -137,18 +133,17 @@ export const renderRadioFieldElement = (
|
||||
})
|
||||
.exhaustive();
|
||||
|
||||
const { itemInputX, itemInputY, textX, textY, textWidth, textHeight } =
|
||||
calculateMultiItemPosition({
|
||||
fieldWidth,
|
||||
fieldHeight,
|
||||
itemCount: radioValues.length,
|
||||
itemIndex: index,
|
||||
itemSize: calculateRadioSize(fontSize),
|
||||
spacingBetweenItemAndText: spacingBetweenRadioAndText,
|
||||
fieldPadding: radioFieldPadding,
|
||||
type: 'radio',
|
||||
direction: radioMeta?.direction || 'vertical',
|
||||
});
|
||||
const { itemInputX, itemInputY, textX, textY, textWidth, textHeight } = calculateMultiItemPosition({
|
||||
fieldWidth,
|
||||
fieldHeight,
|
||||
itemCount: radioValues.length,
|
||||
itemIndex: index,
|
||||
itemSize: calculateRadioSize(fontSize),
|
||||
spacingBetweenItemAndText: spacingBetweenRadioAndText,
|
||||
fieldPadding: radioFieldPadding,
|
||||
type: 'radio',
|
||||
direction: radioMeta?.direction || 'vertical',
|
||||
});
|
||||
|
||||
// Circle which represents the radio button.
|
||||
const circle = new Konva.Circle({
|
||||
|
||||
@@ -5,16 +5,12 @@ import { AppError } from '../../errors/app-error';
|
||||
import type { TSignatureFieldMeta } from '../../types/field-meta';
|
||||
import { resolveFieldOverflowMode } from '../../types/field-meta';
|
||||
import { calculateOverflowLayout } from './calculate-overflow-layout';
|
||||
import {
|
||||
createFieldHoverInteraction,
|
||||
upsertFieldGroup,
|
||||
upsertFieldRect,
|
||||
} from './field-generic-items';
|
||||
import { calculateFieldPosition } from './field-renderer';
|
||||
import { createFieldHoverInteraction, upsertFieldGroup, upsertFieldRect } from './field-generic-items';
|
||||
import type { FieldToRender, RenderFieldElementOptions } from './field-renderer';
|
||||
import { calculateFieldPosition } from './field-renderer';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
let SkiaImage: any = undefined;
|
||||
let SkiaImage: any;
|
||||
|
||||
void (async () => {
|
||||
if (typeof window === 'undefined') {
|
||||
@@ -71,11 +67,7 @@ const SIGNATURE_IMAGE_CACHE_PIXEL_RATIO = 2;
|
||||
* Build a Konva.Image for a base64 signature, sized to fit within the given
|
||||
* field dimensions. Works in both browser and Node.js (via skia-canvas).
|
||||
*/
|
||||
const createSignatureImage = (
|
||||
signatureImageAsBase64: string,
|
||||
fieldWidth: number,
|
||||
fieldHeight: number,
|
||||
): Konva.Image => {
|
||||
const createSignatureImage = (signatureImageAsBase64: string, fieldWidth: number, fieldHeight: number): Konva.Image => {
|
||||
if (typeof window !== 'undefined') {
|
||||
const img = new Image();
|
||||
|
||||
@@ -120,17 +112,10 @@ const createSignatureImage = (
|
||||
});
|
||||
};
|
||||
|
||||
const createFieldSignature = (
|
||||
field: FieldToRender,
|
||||
options: RenderFieldElementOptions,
|
||||
): FieldSignature => {
|
||||
const createFieldSignature = (field: FieldToRender, options: RenderFieldElementOptions): FieldSignature => {
|
||||
const { pageWidth, pageHeight, mode = 'edit', translations } = options;
|
||||
|
||||
const { fieldX, fieldY, fieldWidth, fieldHeight } = calculateFieldPosition(
|
||||
field,
|
||||
pageWidth,
|
||||
pageHeight,
|
||||
);
|
||||
const { fieldX, fieldY, fieldWidth, fieldHeight } = calculateFieldPosition(field, pageWidth, pageHeight);
|
||||
const fontSize = field.fieldMeta?.fontSize || DEFAULT_SIGNATURE_TEXT_FONT_SIZE;
|
||||
|
||||
const fieldText = new Konva.Text({
|
||||
@@ -230,10 +215,7 @@ const createFieldSignature = (
|
||||
return { node: fieldText, isImageSignature: false, isLabel };
|
||||
};
|
||||
|
||||
export const renderSignatureFieldElement = (
|
||||
field: FieldToRender,
|
||||
options: RenderFieldElementOptions,
|
||||
) => {
|
||||
export const renderSignatureFieldElement = (field: FieldToRender, options: RenderFieldElementOptions) => {
|
||||
const { mode = 'edit', pageLayer, pageWidth, pageHeight, color } = options;
|
||||
|
||||
const isFirstRender = !pageLayer.findOne(`#${field.renderId}`);
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
export const generateTwitterIntent = (text: string, shareUrl: string) => {
|
||||
return `https://twitter.com/intent/tweet?text=${encodeURIComponent(
|
||||
text,
|
||||
)}%0A%0A${encodeURIComponent(shareUrl)}`;
|
||||
return `https://twitter.com/intent/tweet?text=${encodeURIComponent(text)}%0A%0A${encodeURIComponent(shareUrl)}`;
|
||||
};
|
||||
|
||||
@@ -36,13 +36,7 @@ export const generateDatabaseId = (prefix: DatabaseIdPrefix) => prefixedId(prefi
|
||||
|
||||
export const extractLegacyIds = (envelope: Pick<Envelope, 'type' | 'secondaryId'>) => {
|
||||
return {
|
||||
documentId:
|
||||
envelope.type === EnvelopeType.DOCUMENT
|
||||
? mapSecondaryIdToDocumentId(envelope.secondaryId)
|
||||
: null,
|
||||
templateId:
|
||||
envelope.type === EnvelopeType.TEMPLATE
|
||||
? mapSecondaryIdToTemplateId(envelope.secondaryId)
|
||||
: null,
|
||||
documentId: envelope.type === EnvelopeType.DOCUMENT ? mapSecondaryIdToDocumentId(envelope.secondaryId) : null,
|
||||
templateId: envelope.type === EnvelopeType.TEMPLATE ? mapSecondaryIdToTemplateId(envelope.secondaryId) : null,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { env } from '@documenso/lib/utils/env';
|
||||
import { PDF } from '@libpdf/core';
|
||||
import { DocumentDataType } from '@prisma/client';
|
||||
import { base64 } from '@scure/base';
|
||||
import { match } from 'ts-pattern';
|
||||
|
||||
import { env } from '@documenso/lib/utils/env';
|
||||
|
||||
import { AppError } from '../../errors/app-error';
|
||||
import { createDocumentData } from '../../server-only/document-data/create-document-data';
|
||||
import { normalizePdf } from '../../server-only/pdf/normalize-pdf';
|
||||
@@ -52,10 +51,7 @@ export const putPdfFileServerSide = async (file: File, initialData?: string) =>
|
||||
/**
|
||||
* Uploads a pdf file and normalizes it.
|
||||
*/
|
||||
export const putNormalizedPdfFileServerSide = async (
|
||||
file: File,
|
||||
options: { flattenForm?: boolean } = {},
|
||||
) => {
|
||||
export const putNormalizedPdfFileServerSide = async (file: File, options: { flattenForm?: boolean } = {}) => {
|
||||
const buffer = Buffer.from(await file.arrayBuffer());
|
||||
|
||||
const normalized = await normalizePdf(buffer, options);
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
import { env } from '@documenso/lib/utils/env';
|
||||
import type { TGetPresignedPostUrlResponse, TUploadPdfResponse } from '@documenso/remix/server/api/files/files.types';
|
||||
import { DocumentDataType } from '@prisma/client';
|
||||
import { base64 } from '@scure/base';
|
||||
import { match } from 'ts-pattern';
|
||||
|
||||
import { env } from '@documenso/lib/utils/env';
|
||||
import type {
|
||||
TGetPresignedPostUrlResponse,
|
||||
TUploadPdfResponse,
|
||||
} from '@documenso/remix/server/api/files/files.types';
|
||||
|
||||
import { NEXT_PUBLIC_WEBAPP_URL } from '../../constants/app';
|
||||
import { AppError } from '../../errors/app-error';
|
||||
|
||||
@@ -67,24 +63,19 @@ const putFileInDatabase = async (file: File) => {
|
||||
};
|
||||
|
||||
const putFileInS3 = async (file: File) => {
|
||||
const getPresignedUrlResponse = await fetch(
|
||||
`${NEXT_PUBLIC_WEBAPP_URL()}/api/files/presigned-post-url`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
fileName: file.name,
|
||||
contentType: file.type,
|
||||
}),
|
||||
const getPresignedUrlResponse = await fetch(`${NEXT_PUBLIC_WEBAPP_URL()}/api/files/presigned-post-url`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
);
|
||||
body: JSON.stringify({
|
||||
fileName: file.name,
|
||||
contentType: file.type,
|
||||
}),
|
||||
});
|
||||
|
||||
if (!getPresignedUrlResponse.ok) {
|
||||
throw new Error(
|
||||
`Failed to get presigned post url, failed with status code ${getPresignedUrlResponse.status}`,
|
||||
);
|
||||
throw new Error(`Failed to get presigned post url, failed with status code ${getPresignedUrlResponse.status}`);
|
||||
}
|
||||
|
||||
const { url, key }: TGetPresignedPostUrlResponse = await getPresignedUrlResponse.json();
|
||||
@@ -100,9 +91,7 @@ const putFileInS3 = async (file: File) => {
|
||||
});
|
||||
|
||||
if (!reponse.ok) {
|
||||
throw new Error(
|
||||
`Failed to upload file "${file.name}", failed with status code ${reponse.status}`,
|
||||
);
|
||||
throw new Error(`Failed to upload file "${file.name}", failed with status code ${reponse.status}`);
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import {
|
||||
DeleteObjectCommand,
|
||||
GetObjectCommand,
|
||||
PutObjectCommand,
|
||||
S3Client,
|
||||
} from '@aws-sdk/client-s3';
|
||||
import slugify from '@sindresorhus/slugify';
|
||||
import path from 'node:path';
|
||||
|
||||
import { DeleteObjectCommand, GetObjectCommand, PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
|
||||
import { env } from '@documenso/lib/utils/env';
|
||||
import slugify from '@sindresorhus/slugify';
|
||||
|
||||
import { ONE_HOUR, ONE_SECOND } from '../../constants/time';
|
||||
import { alphaid } from '../id';
|
||||
@@ -144,8 +138,7 @@ const getS3Client = () => {
|
||||
throw new Error('Invalid upload transport');
|
||||
}
|
||||
|
||||
const hasCredentials =
|
||||
env('NEXT_PRIVATE_UPLOAD_ACCESS_KEY_ID') && env('NEXT_PRIVATE_UPLOAD_SECRET_ACCESS_KEY');
|
||||
const hasCredentials = env('NEXT_PRIVATE_UPLOAD_ACCESS_KEY_ID') && env('NEXT_PRIVATE_UPLOAD_SECRET_ACCESS_KEY');
|
||||
|
||||
return new S3Client({
|
||||
endpoint: env('NEXT_PRIVATE_UPLOAD_ENDPOINT') || undefined,
|
||||
|
||||
Reference in New Issue
Block a user