Unify creditCosts.ts files (#5952)

Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
This commit is contained in:
James Brunton
2026-03-16 22:05:02 +00:00
committed by GitHub
parent dbff05814f
commit 7f9bbebe5b
8 changed files with 48 additions and 140 deletions

View File

@@ -9,10 +9,10 @@ import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
public class PDFExtractImagesRequest extends PDFWithImageFormatRequest {
@Schema(
description =
"Boolean to enable/disable the saving of duplicate images, true to enable"
+ " duplicates",
defaultValue = "false")
private Boolean allowDuplicates;
// @Schema(
// description =
// "Boolean to enable/disable the saving of duplicate images, true to enable"
// + " duplicates",
// defaultValue = "false")
// private Boolean allowDuplicates;
}

View File

@@ -1,5 +1,5 @@
import { useTranslation } from 'react-i18next';
import { Stack, Select, Checkbox } from '@mantine/core';
import { Stack, Select } from '@mantine/core';
import { ExtractImagesParameters } from '@app/hooks/tools/extractImages/useExtractImagesParameters';
import { Z_INDEX_AUTOMATE_DROPDOWN } from "@app/styles/zIndex";
@@ -35,12 +35,12 @@ const ExtractImagesSettings = ({
comboboxProps={{ withinPortal: true, zIndex: Z_INDEX_AUTOMATE_DROPDOWN }}
/>
<Checkbox
{/* <Checkbox
label={t('extractImages.allowDuplicates', 'Allow Duplicate Images')}
checked={parameters.allowDuplicates}
onChange={(event) => onParameterChange('allowDuplicates', event.currentTarget.checked)}
disabled={disabled}
/>
/> */}
</Stack>
);
};

View File

@@ -10,7 +10,7 @@ export const buildExtractImagesFormData = (parameters: ExtractImagesParameters,
const formData = new FormData();
formData.append("fileInput", file);
formData.append("format", parameters.format);
formData.append("allowDuplicates", parameters.allowDuplicates.toString());
// formData.append("allowDuplicates", parameters.allowDuplicates.toString());
return formData;
};

View File

@@ -2,12 +2,12 @@ import { useBaseParameters } from '@app/hooks/tools/shared/useBaseParameters';
export interface ExtractImagesParameters {
format: 'png' | 'jpg' | 'gif';
allowDuplicates: boolean;
// allowDuplicates: boolean;
}
export const defaultParameters: ExtractImagesParameters = {
format: 'png',
allowDuplicates: false,
// allowDuplicates: false,
};
export const useExtractImagesParameters = () => {

View File

@@ -1,92 +0,0 @@
import { ToolId } from '@app/types/toolId'
// Credit costs based on ResourceWeight enum from backend
export const CREDIT_COSTS = {
NONE: 0,
SMALL: 1,
MEDIUM: 3,
LARGE: 5,
XLARGE: 10
} as const
/**
* Mapping of tool IDs to their credit costs
* Based on backend ResourceWeight annotations
*/
export const TOOL_CREDIT_COSTS: Record<ToolId, number> = {
// No cost operations (0 credits)
showJS: CREDIT_COSTS.NONE,
devApi: CREDIT_COSTS.NONE,
devFolderScanning: CREDIT_COSTS.NONE,
devSsoGuide: CREDIT_COSTS.NONE,
devAirgapped: CREDIT_COSTS.NONE,
// Small operations (1 credit)
rotate: CREDIT_COSTS.SMALL,
removePages: CREDIT_COSTS.SMALL,
addText: CREDIT_COSTS.SMALL,
addPassword: CREDIT_COSTS.SMALL,
removePassword: CREDIT_COSTS.SMALL,
changePermissions: CREDIT_COSTS.SMALL,
flatten: CREDIT_COSTS.SMALL,
repair: CREDIT_COSTS.SMALL,
unlockPDFForms: CREDIT_COSTS.SMALL,
crop: CREDIT_COSTS.SMALL,
addPageNumbers: CREDIT_COSTS.SMALL,
extractPages: CREDIT_COSTS.SMALL,
reorganizePages: CREDIT_COSTS.SMALL,
scalePages: CREDIT_COSTS.SMALL,
editTableOfContents: CREDIT_COSTS.SMALL,
sign: CREDIT_COSTS.SMALL,
annotate: CREDIT_COSTS.SMALL,
formFill: CREDIT_COSTS.SMALL,
removeAnnotations: CREDIT_COSTS.SMALL,
removeImage: CREDIT_COSTS.SMALL,
scannerImageSplit: CREDIT_COSTS.SMALL,
adjustContrast: CREDIT_COSTS.SMALL,
multiTool: CREDIT_COSTS.SMALL,
compare: CREDIT_COSTS.SMALL,
addAttachments: CREDIT_COSTS.SMALL,
getPdfInfo: CREDIT_COSTS.MEDIUM,
validateSignature: CREDIT_COSTS.SMALL,
read: CREDIT_COSTS.SMALL,
// Medium operations (3 credits)
split: CREDIT_COSTS.MEDIUM,
merge: CREDIT_COSTS.MEDIUM,
pdfTextEditor: CREDIT_COSTS.MEDIUM,
changeMetadata: CREDIT_COSTS.MEDIUM,
watermark: CREDIT_COSTS.MEDIUM,
bookletImposition: CREDIT_COSTS.MEDIUM,
pdfToSinglePage: CREDIT_COSTS.MEDIUM,
removeBlanks: CREDIT_COSTS.MEDIUM,
autoRename: CREDIT_COSTS.MEDIUM,
sanitize: CREDIT_COSTS.MEDIUM,
addImage: CREDIT_COSTS.MEDIUM,
addStamp: CREDIT_COSTS.MEDIUM,
extractImages: CREDIT_COSTS.MEDIUM,
overlayPdfs: CREDIT_COSTS.MEDIUM,
pageLayout: CREDIT_COSTS.MEDIUM,
redact: CREDIT_COSTS.MEDIUM,
removeCertSign: CREDIT_COSTS.MEDIUM,
scannerEffect: CREDIT_COSTS.MEDIUM,
replaceColor: CREDIT_COSTS.MEDIUM,
// Large operations (5 credits)
compress: CREDIT_COSTS.LARGE,
convert: CREDIT_COSTS.LARGE,
ocr: CREDIT_COSTS.LARGE,
certSign: CREDIT_COSTS.LARGE,
// Extra large operations (10 credits)
automate: CREDIT_COSTS.XLARGE,
}
/**
* Get the credit cost for a specific tool
* @param toolId - The tool identifier
* @returns The credit cost for the tool, defaults to MEDIUM if not found
*/
export const getToolCreditCost = (toolId: ToolId): number => {
return TOOL_CREDIT_COSTS[toolId] ?? CREDIT_COSTS.MEDIUM
}

View File

@@ -70,21 +70,21 @@ Feature: API Validation
| 1 | 10 | 2 | 10 |
@extract-images
Scenario Outline: Extract Image Scans duplicates
Given I use an example file at "exampleFiles/images.pdf" as parameter "fileInput"
And the request data includes
| parameter | value |
| format | <format> |
When I send the API request to the endpoint "/api/v1/misc/extract-images"
Then the response content type should be "application/octet-stream"
And the response file should have extension ".zip"
And the response ZIP should contain 2 files
And the response file should have size greater than 0
And the response status code should be 200
Examples:
| format |
| png |
| gif |
| jpeg |
# @extract-images
# Scenario Outline: Extract Image Scans duplicates
# Given I use an example file at "exampleFiles/images.pdf" as parameter "fileInput"
# And the request data includes
# | parameter | value |
# | format | <format> |
# When I send the API request to the endpoint "/api/v1/misc/extract-images"
# Then the response content type should be "application/octet-stream"
# And the response file should have extension ".zip"
# And the response ZIP should contain 2 files
# And the response file should have size greater than 0
# And the response status code should be 200
#
# Examples:
# | format |
# | png |
# | gif |
# | jpeg |

View File

@@ -231,21 +231,21 @@ Feature: General PDF Operations API Validation
And the response file should have size greater than 200
@remove-image-pdf @positive
Scenario: remove-image-pdf strips images from a PDF containing images
Given I generate a PDF file as "fileInput"
And the pdf contains 3 images of size 100x100 on 2 pages
When I send the API request to the endpoint "/api/v1/general/remove-image-pdf"
Then the response content type should be "application/pdf"
And the response status code should be 200
And the response file should have size greater than 0
@remove-image-pdf @positive
Scenario: remove-image-pdf on a plain text PDF returns a PDF
Given I generate a PDF file as "fileInput"
And the pdf contains 3 pages with random text
When I send the API request to the endpoint "/api/v1/general/remove-image-pdf"
Then the response content type should be "application/pdf"
And the response status code should be 200
And the response file should have size greater than 0
# @remove-image-pdf @positive
# Scenario: remove-image-pdf strips images from a PDF containing images
# Given I generate a PDF file as "fileInput"
# And the pdf contains 3 images of size 100x100 on 2 pages
# When I send the API request to the endpoint "/api/v1/general/remove-image-pdf"
# Then the response content type should be "application/pdf"
# And the response status code should be 200
# And the response file should have size greater than 0
#
#
# @remove-image-pdf @positive
# Scenario: remove-image-pdf on a plain text PDF returns a PDF
# Given I generate a PDF file as "fileInput"
# And the pdf contains 3 pages with random text
# When I send the API request to the endpoint "/api/v1/general/remove-image-pdf"
# Then the response content type should be "application/pdf"
# And the response status code should be 200
# And the response file should have size greater than 0