Skip to content

Commit

Permalink
Improve legacy photo post special handling (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal authored Aug 18, 2023
1 parent 9d23608 commit 926edfb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# tumblr.js

[![Build Status](https://github.com/tumblr/tumblr.js/actions/workflows/ci.yaml/badge.svg)](https://github.com/tumblr/tumblr.js/actions/workflows/ci.yaml)
[![CI](https://github.com/tumblr/tumblr.js/actions/workflows/ci.yaml/badge.svg)](https://github.com/tumblr/tumblr.js/actions/workflows/ci.yaml)

The official JavaScript client library for the [Tumblr API](http://www.tumblr.com/docs/api/v2).
Check out the [detailed documentation here](https://tumblr.github.io/tumblr.js/index.html).
Expand Down
15 changes: 14 additions & 1 deletion lib/tumblr.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,20 @@ class TumblrClient {
if (data.has('data') || data.has('data64')) {
const form = new FormData();

const isLegacyPhotoPost = url.pathname.endsWith('/post') && data.get('type') === 'photo';
// Legacy photo posts may need special handling to transform the data array of images so form-data can handle it
let isLegacyPhotoPost = false;
if (data.get('type') === 'photo') {
// Check for `/v2/blog/BLOG_ID/post`
const pathParts = (
url.pathname.endsWith('/') ? url.pathname.slice(0, -1) : url.pathname
).split('/');

isLegacyPhotoPost =
pathParts.length === 5 &&
pathParts[1].toLowerCase() === 'v2' &&
pathParts[2].toLowerCase() === 'blog' &&
pathParts[4].toLowerCase() === 'post';
}

for (const [key, value] of data.entries()) {
// Legacy photo post creation has a special case to accept `data`.
Expand Down

0 comments on commit 926edfb

Please sign in to comment.