@@ -13,19 +13,15 @@ export async function CreatePost(
1313 blogIdentifier : string ,
1414 postDetails : NewPostDetails
1515) : Promise < string | undefined > {
16- const response = await accessTumblrAPI (
17- token ,
18- `blog/${ blogIdentifier } /posts` ,
19- //TODO: This is a hacky way to do this. Find a better way to make this into a string array.
20- JSON . parse ( JSON . stringify ( postDetails ) ) ,
21- "POST"
22- ) ;
23-
24- if ( response . meta . status !== 201 ) {
25- throw new Error ( `Failed to create post: ${ response . meta . msg } ` ) ;
26- }
27-
28- return response . response . id ;
16+ return (
17+ await accessTumblrAPI (
18+ token ,
19+ `blog/${ blogIdentifier } /posts` ,
20+ //TODO: This is a hacky way to do this. Find a better way to make this into a string array.
21+ JSON . parse ( JSON . stringify ( postDetails ) ) ,
22+ "POST"
23+ )
24+ ) . response . id ;
2925}
3026
3127/**
@@ -41,19 +37,15 @@ export async function EditPost(
4137 postId : string ,
4238 postDetails : NewPostDetails
4339) : Promise < string | undefined > {
44- const response = await accessTumblrAPI (
45- token ,
46- `blog/${ blogIdentifier } /posts/${ postId } ` ,
47- //TODO: This is a hacky way to do this. Find a better way to make this into a string array.
48- JSON . parse ( JSON . stringify ( postDetails ) ) ,
49- "PUT"
50- ) ;
51-
52- if ( response . meta . status !== 200 ) {
53- throw new Error ( `Failed to edit post: ${ response . meta . msg } ` ) ;
54- }
55-
56- return response . response . id ;
40+ return (
41+ await accessTumblrAPI (
42+ token ,
43+ `blog/${ blogIdentifier } /posts/${ postId } ` ,
44+ //TODO: This is a hacky way to do this. Find a better way to make this into a string array.
45+ JSON . parse ( JSON . stringify ( postDetails ) ) ,
46+ "PUT"
47+ )
48+ ) . response . id ;
5749}
5850
5951/**
@@ -75,21 +67,17 @@ export async function FetchPostNeue(
7567 postId : string ,
7668 postFormat : "npf" | "legacy" = "npf"
7769) : Promise < TumblrPost > {
78- const response = await accessTumblrAPI (
79- token ,
80- `blog/${ blogIdentifier } /posts/${ postId } ` ,
81- {
82- post_format : postFormat ,
83- } ,
84- "GET" ,
85- "https://www.tumblr.com/api/v2/" // Yes, getting posts needs to be done on a different API endpoint for some reason. Ask Tumblr why.
86- ) ;
87-
88- if ( response . meta . status !== 200 ) {
89- throw new Error ( `Failed to fetch post: ${ response . meta . msg } ` ) ;
90- }
91-
92- return response . response ;
70+ return (
71+ await accessTumblrAPI (
72+ token ,
73+ `blog/${ blogIdentifier } /posts/${ postId } ` ,
74+ {
75+ post_format : postFormat ,
76+ } ,
77+ "GET" ,
78+ "https://www.tumblr.com/api/v2/" // Yes, getting posts needs to be done on a different API endpoint for some reason. Ask Tumblr why.
79+ )
80+ ) . response ;
9381}
9482
9583/**
@@ -196,21 +184,17 @@ export async function FetchPosts<PostType extends TumblrPost = TumblrPost>(
196184 type : type ,
197185 } ;
198186
199- const response = await accessTumblrAPI (
200- token ,
201- `blog/${ blogIdentifier } /posts` ,
202- //TODO: This is a hacky way to do this. Find a better way to make this into a string array.
203- JSON . parse ( JSON . stringify ( args ) ) ,
204- "GET" ,
205- "https://www.tumblr.com/api/v2/" , // Yes, getting posts needs to be done on a different API endpoint for some reason. Ask Tumblr why.
206- basicAuth
207- ) ;
208-
209- if ( response . meta . status !== 200 ) {
210- throw new Error ( `Failed to fetch posts: ${ response . meta . msg } ` ) ;
211- }
212-
213- return response . response . posts as PostType [ ] ;
187+ return (
188+ await accessTumblrAPI (
189+ token ,
190+ `blog/${ blogIdentifier } /posts` ,
191+ //TODO: This is a hacky way to do this. Find a better way to make this into a string array.
192+ JSON . parse ( JSON . stringify ( args ) ) ,
193+ "GET" ,
194+ "https://www.tumblr.com/api/v2/" , // Yes, getting posts needs to be done on a different API endpoint for some reason. Ask Tumblr why.
195+ basicAuth
196+ )
197+ ) . response . posts as PostType [ ] ;
214198}
215199
216200export async function GetNotes (
@@ -221,22 +205,18 @@ export async function GetNotes(
221205 mode : "all" | "likes" | "conversation" | "rollup" | "reblogs_with_tags" = "all" ,
222206 basicAuth = false
223207) {
224- const response = await accessTumblrAPI (
225- token ,
226- `blog/${ blogIdentifier } /notes` ,
227- {
228- id : id . toString ( ) ,
229- mode,
230- before_timestamp : beforeTimestamp . toString ( ) ,
231- } ,
232- "GET" ,
233- undefined ,
234- basicAuth
235- ) ;
236-
237- if ( response . meta . status !== 200 ) {
238- throw new Error ( `Failed to fetch notes: ${ response . meta . msg } ` ) ;
239- }
240-
241- return response . response as TumblrNoteResponse ;
208+ return (
209+ await accessTumblrAPI (
210+ token ,
211+ `blog/${ blogIdentifier } /notes` ,
212+ {
213+ id : id . toString ( ) ,
214+ mode,
215+ before_timestamp : beforeTimestamp . toString ( ) ,
216+ } ,
217+ "GET" ,
218+ undefined ,
219+ basicAuth
220+ )
221+ ) . response as TumblrNoteResponse ;
242222}
0 commit comments