refactor: compress pdf

This commit is contained in:
Ibrahima G. Coulibaly 2025-04-03 01:44:58 +00:00
commit 37be76254a
3 changed files with 71 additions and 83 deletions

143
.idea/workspace.xml generated
View file

@ -4,17 +4,10 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="fix: stars button width for 1k+ 😊"> <list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="feat: compress pdf">
<change afterPath="$PROJECT_DIR$/src/pages/tools/pdf/compress-pdf/index.tsx" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/pages/tools/pdf/compress-pdf/meta.ts" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/pages/tools/pdf/compress-pdf/service.test.ts" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/pages/tools/pdf/compress-pdf/service.ts" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/pages/tools/pdf/compress-pdf/types.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/package-lock.json" beforeDir="false" afterPath="$PROJECT_DIR$/package-lock.json" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/lib/worker-init.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/lib/worker-init.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/pages/tools/pdf/compress-pdf/service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/tools/pdf/compress-pdf/service.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/tools/pdf/index.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/tools/pdf/index.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/vite.config.ts" beforeDir="false" afterPath="$PROJECT_DIR$/vite.config.ts" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -50,94 +43,94 @@
&quot;state&quot;: &quot;OPEN&quot; &quot;state&quot;: &quot;OPEN&quot;
} }
}</component> }</component>
<component name="GitHubPullRequestState"><![CDATA[{ <component name="GitHubPullRequestState">{
"prStates": [ &quot;prStates&quot;: [
{ {
"id": { &quot;id&quot;: {
"id": "PR_kwDOMJIfts51PkS9", &quot;id&quot;: &quot;PR_kwDOMJIfts51PkS9&quot;,
"number": 22 &quot;number&quot;: 22
}, },
"lastSeen": 1741207144695 &quot;lastSeen&quot;: 1741207144695
}, },
{ {
"id": { &quot;id&quot;: {
"id": "PR_kwDOMJIfts6NiNYl", &quot;id&quot;: &quot;PR_kwDOMJIfts6NiNYl&quot;,
"number": 32 &quot;number&quot;: 32
}, },
"lastSeen": 1741209723869 &quot;lastSeen&quot;: 1741209723869
}, },
{ {
"id": { &quot;id&quot;: {
"id": "PR_kwDOMJIfts6Nheyd", &quot;id&quot;: &quot;PR_kwDOMJIfts6Nheyd&quot;,
"number": 31 &quot;number&quot;: 31
}, },
"lastSeen": 1741213371410 &quot;lastSeen&quot;: 1741213371410
}, },
{ {
"id": { &quot;id&quot;: {
"id": "PR_kwDOMJIfts6NmRBs", &quot;id&quot;: &quot;PR_kwDOMJIfts6NmRBs&quot;,
"number": 33 &quot;number&quot;: 33
}, },
"lastSeen": 1741282429036 &quot;lastSeen&quot;: 1741282429036
}, },
{ {
"id": { &quot;id&quot;: {
"id": "PR_kwDOMJIfts5zyFTs", &quot;id&quot;: &quot;PR_kwDOMJIfts5zyFTs&quot;,
"number": 15 &quot;number&quot;: 15
}, },
"lastSeen": 1741535540953 &quot;lastSeen&quot;: 1741535540953
}, },
{ {
"id": { &quot;id&quot;: {
"id": "PR_kwDOMJIfts6QQB3c", &quot;id&quot;: &quot;PR_kwDOMJIfts6QQB3c&quot;,
"number": 59 &quot;number&quot;: 59
}, },
"lastSeen": 1743018960900 &quot;lastSeen&quot;: 1743018960900
}, },
{ {
"id": { &quot;id&quot;: {
"id": "PR_kwDOMJIfts6QMPEg", &quot;id&quot;: &quot;PR_kwDOMJIfts6QMPEg&quot;,
"number": 58 &quot;number&quot;: 58
}, },
"lastSeen": 1743019452983 &quot;lastSeen&quot;: 1743019452983
}, },
{ {
"id": { &quot;id&quot;: {
"id": "PR_kwDOMJIfts6QZvRI", &quot;id&quot;: &quot;PR_kwDOMJIfts6QZvRI&quot;,
"number": 61 &quot;number&quot;: 61
}, },
"lastSeen": 1743103196866 &quot;lastSeen&quot;: 1743103196866
}, },
{ {
"id": { &quot;id&quot;: {
"id": "PR_kwDOMJIfts6QqPrQ", &quot;id&quot;: &quot;PR_kwDOMJIfts6QqPrQ&quot;,
"number": 73 &quot;number&quot;: 73
}, },
"lastSeen": 1743265865001 &quot;lastSeen&quot;: 1743265865001
}, },
{ {
"id": { &quot;id&quot;: {
"id": "PR_kwDOMJIfts6Qp5nI", &quot;id&quot;: &quot;PR_kwDOMJIfts6Qp5nI&quot;,
"number": 72 &quot;number&quot;: 72
}, },
"lastSeen": 1743338472110 &quot;lastSeen&quot;: 1743338472110
}, },
{ {
"id": { &quot;id&quot;: {
"id": "PR_kwDOMJIfts6QsjlS", &quot;id&quot;: &quot;PR_kwDOMJIfts6QsjlS&quot;,
"number": 76 &quot;number&quot;: 76
}, },
"lastSeen": 1743352150953 &quot;lastSeen&quot;: 1743352150953
}, },
{ {
"id": { &quot;id&quot;: {
"id": "PR_kwDOMJIfts6Q0JBe", &quot;id&quot;: &quot;PR_kwDOMJIfts6Q0JBe&quot;,
"number": 82 &quot;number&quot;: 82
}, },
"lastSeen": 1743470267269 &quot;lastSeen&quot;: 1743470267269
} }
] ]
}]]></component> }</component>
<component name="GithubPullRequestsUISettings">{ <component name="GithubPullRequestsUISettings">{
&quot;selectedUrlAndAccountId&quot;: { &quot;selectedUrlAndAccountId&quot;: {
&quot;url&quot;: &quot;https://github.com/iib0011/omni-tools.git&quot;, &quot;url&quot;: &quot;https://github.com/iib0011/omni-tools.git&quot;,
@ -190,10 +183,10 @@
"Vitest.replaceText function (regexp mode).should return the original text when passed an invalid regexp.executor": "Run", "Vitest.replaceText function (regexp mode).should return the original text when passed an invalid regexp.executor": "Run",
"Vitest.replaceText function.executor": "Run", "Vitest.replaceText function.executor": "Run",
"Vitest.timeBetweenDates.executor": "Run", "Vitest.timeBetweenDates.executor": "Run",
"git-widget-placeholder": "main", "git-widget-placeholder": "compression",
"ignore.virus.scanning.warn.message": "true", "ignore.virus.scanning.warn.message": "true",
"kotlin-language-version-configured": "true", "kotlin-language-version-configured": "true",
"last_opened_file_path": "C:/Users/Ibrahima/IdeaProjects/omni-tools/@types", "last_opened_file_path": "C:/Users/Ibrahima/IdeaProjects/omni-tools/src",
"node.js.detected.package.eslint": "true", "node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true", "node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)", "node.js.selected.package.eslint": "(autodetect)",
@ -227,11 +220,11 @@
</component> </component>
<component name="RecentsManager"> <component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS"> <key name="CopyFile.RECENT_KEYS">
<recent name="C:\Users\Ibrahima\IdeaProjects\omni-tools\src" />
<recent name="C:\Users\Ibrahima\IdeaProjects\omni-tools\@types" /> <recent name="C:\Users\Ibrahima\IdeaProjects\omni-tools\@types" />
<recent name="C:\Users\Ibrahima\IdeaProjects\omni-tools\public\assets" /> <recent name="C:\Users\Ibrahima\IdeaProjects\omni-tools\public\assets" />
<recent name="C:\Users\Ibrahima\IdeaProjects\omni-tools\src\components\input" /> <recent name="C:\Users\Ibrahima\IdeaProjects\omni-tools\src\components\input" />
<recent name="C:\Users\Ibrahima\IdeaProjects\omni-tools\.husky" /> <recent name="C:\Users\Ibrahima\IdeaProjects\omni-tools\.husky" />
<recent name="C:\Users\Ibrahima\IdeaProjects\omni-tools\src\assets" />
</key> </key>
<key name="MoveFile.RECENT_KEYS"> <key name="MoveFile.RECENT_KEYS">
<recent name="C:\Users\Ibrahima\IdeaProjects\omni-tools\@types" /> <recent name="C:\Users\Ibrahima\IdeaProjects\omni-tools\@types" />
@ -415,14 +408,6 @@
<workItem from="1743397561176" duration="25000" /> <workItem from="1743397561176" duration="25000" />
<workItem from="1743458576265" duration="13083000" /> <workItem from="1743458576265" duration="13083000" />
</task> </task>
<task id="LOCAL-00133" summary="chore: remove prettify test">
<option name="closed" value="true" />
<created>1740662016902</created>
<option name="number" value="00133" />
<option name="presentableId" value="LOCAL-00133" />
<option name="project" value="LOCAL" />
<updated>1740662016902</updated>
</task>
<task id="LOCAL-00134" summary="chore: prettify json in home"> <task id="LOCAL-00134" summary="chore: prettify json in home">
<option name="closed" value="true" /> <option name="closed" value="true" />
<created>1740662154978</created> <created>1740662154978</created>
@ -807,7 +792,15 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1743470832619</updated> <updated>1743470832619</updated>
</task> </task>
<option name="localTasksCounter" value="182" /> <task id="LOCAL-00182" summary="feat: compress pdf">
<option name="closed" value="true" />
<created>1743644598841</created>
<option name="number" value="00182" />
<option name="presentableId" value="LOCAL-00182" />
<option name="project" value="LOCAL" />
<updated>1743644598841</updated>
</task>
<option name="localTasksCounter" value="183" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@ -854,7 +847,6 @@
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" /> <option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
<option name="CHECK_NEW_TODO" value="false" /> <option name="CHECK_NEW_TODO" value="false" />
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" /> <option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
<MESSAGE value="feat: missing tools" />
<MESSAGE value="refactor: use ToolContent" /> <MESSAGE value="refactor: use ToolContent" />
<MESSAGE value="fix: prettify json" /> <MESSAGE value="fix: prettify json" />
<MESSAGE value="refactor: sum" /> <MESSAGE value="refactor: sum" />
@ -879,7 +871,8 @@
<MESSAGE value="docs: github trendings" /> <MESSAGE value="docs: github trendings" />
<MESSAGE value="docs: optimize" /> <MESSAGE value="docs: optimize" />
<MESSAGE value="fix: stars button width for 1k+ " /> <MESSAGE value="fix: stars button width for 1k+ " />
<option name="LAST_COMMIT_MESSAGE" value="fix: stars button width for 1k+ " /> <MESSAGE value="feat: compress pdf" />
<option name="LAST_COMMIT_MESSAGE" value="feat: compress pdf" />
</component> </component>
<component name="XSLT-Support.FileAssociations.UIState"> <component name="XSLT-Support.FileAssociations.UIState">
<expand /> <expand />

View file

@ -1,9 +1,4 @@
export async function _GSPS2PDF( export async function compressWithGhostScript(dataStruct) {
dataStruct,
responseCallback,
progressCallback,
statusUpdateCallback
) {
const worker = new Worker( const worker = new Worker(
new URL('./background-worker.js', import.meta.url), new URL('./background-worker.js', import.meta.url),
{ type: 'module' } { type: 'module' }

View file

@ -1,5 +1,5 @@
import { InitialValuesType } from './types'; import { InitialValuesType } from './types';
import { _GSPS2PDF } from '../../../../lib/worker-init'; import { compressWithGhostScript } from '../../../../lib/worker-init';
/** /**
* Compresses a PDF file using either Ghostscript WASM (preferred) * Compresses a PDF file using either Ghostscript WASM (preferred)
@ -19,7 +19,7 @@ export async function compressPdf(
} }
const dataObject = { psDataURL: URL.createObjectURL(pdfFile) }; const dataObject = { psDataURL: URL.createObjectURL(pdfFile) };
const compressedFileUrl: string = await _GSPS2PDF(dataObject); const compressedFileUrl: string = await compressWithGhostScript(dataObject);
return await loadPDFData(compressedFileUrl, pdfFile.name); return await loadPDFData(compressedFileUrl, pdfFile.name);
} }