37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
|
/**
|
||
|
* @file optimize.ts
|
||
|
*
|
||
|
* @summary Raycast command to optimize selected images.
|
||
|
*
|
||
|
* Created at : 2023-07-06 14:55:16
|
||
|
* Last modified : 2023-07-18 18:48:32
|
||
|
*/
|
||
|
|
||
|
import { showToast, Toast } from "@raycast/api";
|
||
|
|
||
|
import optimize from "./operations/optimizeOperation";
|
||
|
import { getSelectedImages } from "./utilities/utils";
|
||
|
import runOperation from "./operations/runOperation";
|
||
|
|
||
|
export default async function Command(props: { arguments: { optimizationFactor: string } }) {
|
||
|
const { optimizationFactor } = props.arguments;
|
||
|
|
||
|
let optimizationValue = 100;
|
||
|
if (optimizationFactor != "") {
|
||
|
optimizationValue = parseFloat(optimizationFactor);
|
||
|
if (!optimizationValue) {
|
||
|
await showToast({ title: "Invalid optimization factor", style: Toast.Style.Failure });
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const selectedImages = await getSelectedImages();
|
||
|
await runOperation({
|
||
|
operation: () => optimize(selectedImages, optimizationValue),
|
||
|
selectedImages,
|
||
|
inProgressMessage: "Optimization in progress...",
|
||
|
successMessage: "Optimized",
|
||
|
failureMessage: "Failed to optimize",
|
||
|
});
|
||
|
}
|