Skip to content

Commit 433c0df

Browse files
author
Eirini
committed
fix: removed GET with body from result() call and replaced with POST to prepare for deprecation of GET with body from API.
1 parent 60d59f9 commit 433c0df

5 files changed

Lines changed: 22 additions & 16 deletions

File tree

CHANGES.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
## 1.8.1
1+
## 1.8.2
2+
* Removed the `GET` with body HTTP call that was being made when obtaining the results of a compression and transforming at the same time. Replaced with `POST` in order to prepare for deprecation of `GET` with body interface from API.
23

4+
## 1.8.1
35
* Set minimum node engine to v14 in package.json
46
* Update examples in README
57
* Test the code on node 24

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tinify",
3-
"version": "1.8.1",
3+
"version": "1.8.2",
44
"description": "Node.js client for the Tinify API. Tinify compresses your images intelligently. Read more at https://tinify.com.",
55
"keywords": [
66
"tinify",
@@ -54,4 +54,4 @@
5454
"tslint": "^5.10.0",
5555
"typescript": "^5.7.3"
5656
}
57-
}
57+
}

src/tinify/Source.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ export default class Source {
7777
result(): Result {
7878
const commands = this._commands
7979
const response = this._url.then(url => {
80-
return tinify.client.request("get", url, commands)
80+
if(Object.keys(commands).length === 0){
81+
return tinify.client.request("get", url)
82+
} else {
83+
return tinify.client.request("post", url, commands)
84+
}
8185
})
8286

8387
return new tinify.Result(

test/tinify-source-test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe("Source", function() {
6262

6363
it("should return source with data", function() {
6464
nock("https://api.tinify.com")
65-
.get("/some/location")
65+
.post("/some/location")
6666
.reply(200, "compressed file")
6767

6868
const data = tinify.Source.fromFile(dummyFile).toBuffer()
@@ -86,7 +86,7 @@ describe("Source", function() {
8686

8787
it("should return source with data", function() {
8888
nock("https://api.tinify.com")
89-
.get("/some/location")
89+
.post("/some/location")
9090
.reply(200, "compressed file")
9191

9292
const data = tinify.Source.fromBuffer("png file").toBuffer()
@@ -112,7 +112,7 @@ describe("Source", function() {
112112
.reply(201, {}, {location: "https://api.tinify.com/some/location"})
113113

114114
nock("https://api.tinify.com")
115-
.get("/some/location")
115+
.post("/some/location")
116116
.reply(200, "compressed file")
117117

118118
const data = tinify.Source.fromUrl("http://example.com/test.jpg").toBuffer()
@@ -139,7 +139,7 @@ describe("Source", function() {
139139
.reply(201, {}, {location: "https://api.tinify.com/some/location"})
140140

141141
nock("https://api.tinify.com")
142-
.get("/some/location")
142+
.post("/some/location")
143143
.reply(200, "compressed file")
144144
})
145145

@@ -156,7 +156,7 @@ describe("Source", function() {
156156
.reply(201, {}, {location: "https://api.tinify.com/some/location"})
157157

158158
nock("https://api.tinify.com")
159-
.get("/some/location", '{"preserve":["copyright","location"]}')
159+
.post("/some/location", '{"preserve":["copyright","location"]}')
160160
.reply(200, "copyrighted file")
161161
})
162162

@@ -181,7 +181,7 @@ describe("Source", function() {
181181

182182
it("should include other options if set", function() {
183183
nock("https://api.tinify.com")
184-
.get("/some/location", '{"preserve":["copyright","location"],"resize":{"width":400}}')
184+
.post("/some/location", '{"preserve":["copyright","location"],"resize":{"width":400}}')
185185
.reply(200, "copyrighted resized file")
186186

187187
const data = tinify.Source.fromBuffer("png file").resize({width: 400}).preserve("copyright", "location").toBuffer()
@@ -198,7 +198,7 @@ describe("Source", function() {
198198
.reply(201, {}, {location: "https://api.tinify.com/some/location"})
199199

200200
nock("https://api.tinify.com")
201-
.get("/some/location", '{"resize":{"width":400}}')
201+
.post("/some/location", '{"resize":{"width":400}}')
202202
.reply(200, "small file")
203203
})
204204

@@ -257,7 +257,7 @@ describe("Source", function() {
257257
.reply(201, {}, {location: "https://api.tinify.com/some/location"})
258258

259259
nock("https://api.tinify.com")
260-
.get("/some/location")
260+
.post("/some/location")
261261
.reply(200, "compressed file")
262262
})
263263

@@ -276,7 +276,7 @@ describe("Source", function() {
276276
.reply(201, {}, {location: "https://api.tinify.com/some/location"})
277277

278278
nock("https://api.tinify.com")
279-
.get("/some/location")
279+
.post("/some/location")
280280
.reply(200, "compressed file")
281281
})
282282

test/tinify-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ describe("tinify", function() {
192192
.reply(201, {}, {Location: "https://api.tinify.com/some/location"})
193193

194194
nock("https://api.tinify.com")
195-
.get("/some/location")
195+
.post("/some/location")
196196
.reply(200, "compressed file")
197197
})
198198

@@ -215,7 +215,7 @@ describe("tinify", function() {
215215
.reply(201, {}, {Location: "https://api.tinify.com/some/location"})
216216

217217
nock("https://api.tinify.com")
218-
.get("/some/location")
218+
.post("/some/location")
219219
.reply(200, "compressed file")
220220
})
221221

@@ -238,7 +238,7 @@ describe("tinify", function() {
238238
.reply(201, {}, {Location: "https://api.tinify.com/some/location"})
239239

240240
nock("https://api.tinify.com")
241-
.get("/some/location")
241+
.post("/some/location")
242242
.reply(200, "compressed file")
243243
})
244244

0 commit comments

Comments
 (0)