Skip to content

Commit f2ce55c

Browse files
Finishes the revert
1 parent e7c8f49 commit f2ce55c

File tree

5 files changed

+106
-168
lines changed

5 files changed

+106
-168
lines changed

src/functions/Block.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,13 @@ export async function getBlogBlocks(
1717
offset = 0
1818
): Promise<TumblrFollowerBlog[]> {
1919
// Tumblr API only allows a maximum of 20 blogs per request
20-
if (limit > 20) {
21-
limit = 20;
22-
}
23-
24-
const response = await accessTumblrAPI(token, `blog/${blogIdentifier}/blocks`, {
25-
limit: limit.toString(),
26-
offset: offset.toString(),
27-
});
28-
29-
if (response.meta.status !== 200) {
30-
throw new Error(`Failed to get blocked blogs: ${response.meta.msg}`);
31-
}
32-
33-
return response.response.blocked_tumblelogs;
20+
if (limit > 20) limit = 20;
21+
return await (
22+
await accessTumblrAPI(token, `blog/${blogIdentifier}/blocks`, {
23+
limit: limit.toString(),
24+
offset: offset.toString(),
25+
})
26+
).response.blocked_tumblelogs;
3427
}
3528

3629
/**

src/functions/BlogInfo.ts

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,13 @@ export async function getBlogInfo(
3535
blogIdentifier: string,
3636
responseFields?: BlogInfoResponseFields //TODO: Find a way to make this dynamically return the correct type
3737
): Promise<{ [field: string]: string; thing: string }> {
38-
const response = await accessTumblrAPI(
39-
token,
40-
`blog/${blogIdentifier}/info`,
41-
responseFields ? { fields: responseFields.join(",") } : undefined
42-
);
43-
44-
if (response.meta.status !== 200) {
45-
throw new Error(`Failed to get blog info: ${response.meta.msg}`);
46-
}
47-
48-
return response.response.blog;
38+
return (
39+
await accessTumblrAPI(
40+
token,
41+
`blog/${blogIdentifier}/info`,
42+
responseFields ? { fields: responseFields.join(",") } : undefined
43+
)
44+
).response.blog;
4945
}
5046

5147
/**
@@ -64,20 +60,13 @@ export async function getBlogFollowers(
6460
offset = 0
6561
): Promise<TumblrFollowingBlog[]> {
6662
// Tumblr API only allows a maximum of 20 blogs per request
67-
if (limit > 20) {
68-
limit = 20;
69-
}
70-
71-
const response = await accessTumblrAPI(token, `blog/${blogIdentifier}/followers`, {
72-
limit: limit.toString(),
73-
offset: offset.toString(),
74-
});
75-
76-
if (response.meta.status !== 200) {
77-
throw new Error(`Failed to get blog followers: ${response.meta.msg}`);
78-
}
79-
80-
return response.response.users;
63+
if (limit > 20) limit = 20;
64+
return (
65+
await accessTumblrAPI(token, `blog/${blogIdentifier}/followers`, {
66+
limit: limit.toString(),
67+
offset: offset.toString(),
68+
})
69+
).response.users;
8170
}
8271

8372
/**
@@ -97,17 +86,12 @@ export async function getBlogFollowing(
9786
): Promise<TumblrFollowerBlog[]> {
9887
// Tumblr API only allows a maximum of 20 blogs per request
9988
if (limit > 20) limit = 20;
100-
101-
const response = await accessTumblrAPI(token, `blog/${blogIdentifier}/following`, {
102-
limit: limit.toString(),
103-
offset: offset.toString(),
104-
});
105-
106-
if (response.meta.status !== 200) {
107-
throw new Error(`Failed to get following blogs: ${response.meta.msg}`);
108-
}
109-
110-
return response.response.blogs;
89+
return (
90+
await accessTumblrAPI(token, `blog/${blogIdentifier}/following`, {
91+
limit: limit.toString(),
92+
offset: offset.toString(),
93+
})
94+
).response.blogs;
11195
}
11296

11397
/**
@@ -141,13 +125,9 @@ export async function getBlogFollowedBy(
141125
blogIdentifier: string,
142126
followedBy: string
143127
): Promise<boolean> {
144-
const response = await accessTumblrAPI(token, `blog/${blogIdentifier}/followed_by`, {
145-
query: followedBy,
146-
});
147-
148-
if (response.meta.status !== 200) {
149-
throw new Error(`Failed to get blog followed by: ${response.meta.msg}`);
150-
}
151-
152-
return response.response.followed_by;
128+
return (
129+
await accessTumblrAPI(token, `blog/${blogIdentifier}/followed_by`, {
130+
query: followedBy,
131+
})
132+
).response.followed_by;
153133
}

src/functions/Follow.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,16 @@ import { accessTumblrAPI } from "./AccessTumblrApi";
99
* @link https://www.tumblr.com/docs/en/api/v2#userfollow--follow-a-blog
1010
*/
1111
export async function followBlog(token: string, url: string): Promise<TumblrFollowingBlog> {
12-
const response = await accessTumblrAPI(
13-
token,
14-
`user/follow`,
15-
{
16-
url: url,
17-
},
18-
"POST"
19-
);
20-
21-
if (response.meta.status !== 200) {
22-
throw new Error(`Failed to follow blog: ${response.meta.msg}`);
23-
}
24-
25-
return response.response.blog;
12+
return (
13+
await accessTumblrAPI(
14+
token,
15+
`user/follow`,
16+
{
17+
url: url,
18+
},
19+
"POST"
20+
)
21+
).response.blog;
2622
}
2723

2824
/**

src/functions/Post.ts

Lines changed: 54 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -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

216200
export 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
}

src/functions/UserInfo.ts

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@ import { TumblrFollowerBlog } from "../interfaces";
33
import { accessTumblrAPI } from "./AccessTumblrApi";
44

55
export async function getUserInfo(token: string): Promise<TumblrUserInfo> {
6-
const response = await accessTumblrAPI(token, "user/info");
7-
8-
if (response.meta.status !== 200) {
9-
throw new Error(`Failed to get user info: ${response.meta.msg}`);
10-
}
11-
12-
return response.response.user;
6+
return await (
7+
await accessTumblrAPI(token, "user/info")
8+
).response.user;
139
}
1410

1511
export async function getUserFollowing(
@@ -18,18 +14,11 @@ export async function getUserFollowing(
1814
offset = 0
1915
): Promise<TumblrFollowerBlog[]> {
2016
// Tumblr API only allows a maximum of 20 blogs per request
21-
if (limit > 20) {
22-
limit = 20;
23-
}
24-
25-
const response = await accessTumblrAPI(token, "user/following", {
26-
limit: limit.toString(),
27-
offset: offset.toString(),
28-
});
29-
30-
if (response.meta.status !== 200) {
31-
throw new Error(`Failed to get blogs following: ${response.meta.msg}`);
32-
}
33-
34-
return response.response.blogs;
17+
if (limit > 20) limit = 20;
18+
return await (
19+
await accessTumblrAPI(token, "user/following", {
20+
limit: limit.toString(),
21+
offset: offset.toString(),
22+
})
23+
).response.blogs;
3524
}

0 commit comments

Comments
 (0)