forked from mrgeneralgoo/picgo-plugin-compress-webp-lossless
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐞: { Fixed configuration issues, TinyPngWeb is disabled and an except…
…ion is thrown} 📝 : 1. Change compress-webp-lossless to compress-next fix : 🐞 About config 2.. Fixed an unreadable configuration problem 3. Change the configuration to use compress-next 🐞 About TinyPngWeb 4. TinyPngWeb cannot used and return 404(not found) or 413(too large if > 1MB or maybe less). So I break by throwing an exception
- Loading branch information
1 parent
662bc52
commit 0d7c562
Showing
9 changed files
with
57 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
import { IPicGo } from 'picgo'; | ||
import { getImageInfo } from '../../utils'; | ||
import { CommonParams, ImageInfo } from '../../interface'; | ||
import Tinypng from './tinypng'; | ||
import TinyPng from './tinypng'; | ||
|
||
// Interface for Tinypng options | ||
export interface ITinypngOptions { | ||
// Interface for TinyPng options | ||
export interface ITinyPngOptions { | ||
key: string; | ||
} | ||
|
||
/** | ||
* Function to compress image using Tinypng API key | ||
* Function to compress image using TinyPng API key | ||
* @param ctx The PicGo instance. | ||
* @param imageUrl The URL of the image to be compressed. | ||
* @returns A Promise that resolves to an ImageInfo object containing information about the compressed image. | ||
*/ | ||
export function TinypngKeyCompress(ctx: IPicGo, { imageUrl, key }: CommonParams & ITinypngOptions): Promise<ImageInfo> { | ||
return Tinypng.init({ ctx, keys: key!.split(',') }) | ||
export function TinyPngKeyCompress(ctx: IPicGo, { imageUrl, key }: CommonParams & ITinyPngOptions): Promise<ImageInfo> { | ||
return TinyPng.init({ ctx, keys: key!.split(',') }) | ||
.then(() => { | ||
return Tinypng.upload(imageUrl); | ||
return TinyPng.upload(imageUrl); | ||
}) | ||
.then((buffer) => { | ||
ctx.log.info('Tinypng upload successful'); | ||
ctx.log.info('TinyPng upload successful'); | ||
return getImageInfo(imageUrl, buffer); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,20 @@ import { TINYPNG_WEBUPLOAD_URL } from '../config'; | |
import { getImageBuffer, getImageInfo } from '../utils'; | ||
|
||
/** | ||
* Compress image using TinypngWeb service | ||
* Compress image using TinyPngWeb service | ||
* @param ctx The PicGo instance. | ||
* @param imageUrl The URL of the image to be compressed. | ||
* @returns A Promise that resolves to an ImageInfo object containing information about the compressed image. | ||
*/ | ||
export function TinypngCompress(ctx: IPicGo, { imageUrl }: CommonParams): Promise<ImageInfo> { | ||
export function TinyPngCompress(ctx: IPicGo, { imageUrl }: CommonParams): Promise<ImageInfo> { | ||
/** | ||
* This cannot use and return 404(not found) or 413(too large) error, so I break the code here. | ||
* @author: 李宗霖 <email: [email protected]> or <github: https://github.com/supine0703> | ||
*/ | ||
throw new Error('Please set the TinyPNG API Key. TinyPngWeb is cannot use, maybe you can try?'); | ||
|
||
return getImageBuffer(ctx, imageUrl).then((buffer) => { | ||
ctx.log.info('TinypngWeb compression started'); | ||
ctx.log.info('TinyPngWeb compression started'); | ||
return ctx | ||
.request({ | ||
url: TINYPNG_WEBUPLOAD_URL, | ||
|
@@ -22,12 +28,12 @@ export function TinypngCompress(ctx: IPicGo, { imageUrl }: CommonParams): Promis | |
}) | ||
.then((resp) => { | ||
if (resp.headers.location) { | ||
ctx.log.info('TinypngWeb compression successful: ' + resp.headers.location); | ||
ctx.log.info('Downloading Tinypng image'); | ||
ctx.log.info('TinyPngWeb compression successful:', resp.headers.location); | ||
ctx.log.info('Downloading TinyPng image'); | ||
return getImageBuffer(ctx, resp.headers.location); | ||
} | ||
// If compression failed, throw an error | ||
throw new Error('TinypngWeb upload failed'); | ||
throw new Error('TinyPngWeb upload failed'); | ||
}) | ||
.then((buffer) => { | ||
return getImageInfo(imageUrl, buffer); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters