Skip to content

Commit 07f81c5

Browse files
committed
api/reddit: clean up duplicated headers
1 parent f5df78f commit 07f81c5

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

api/src/processing/services/reddit.js

+8-11
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,23 @@ async function getAccessToken() {
5151
export default async function(obj) {
5252
let params = obj;
5353
const accessToken = await getAccessToken();
54+
const headers = {
55+
'user-agent': genericUserAgent,
56+
authorization: accessToken && `Bearer ${accessToken}`,
57+
accept: 'application/json'
58+
};
5459

5560
if (params.shortId) {
5661
params = await resolveRedirectingURL(
5762
`https://www.reddit.com/video/${params.shortId}`,
58-
obj.dispatcher,
59-
{'User-Agent': genericUserAgent, 'Authorization': `Bearer ${accessToken}`}
63+
obj.dispatcher, headers
6064
);
6165
}
6266

6367
if (!params.id && params.shareId) {
6468
params = await resolveRedirectingURL(
6569
`https://www.reddit.com/r/${params.sub}/s/${params.shareId}`,
66-
obj.dispatcher,
67-
{'User-Agent': genericUserAgent}
70+
obj.dispatcher, headers
6871
);
6972
}
7073

@@ -75,13 +78,7 @@ export default async function(obj) {
7578
if (accessToken) url.hostname = 'oauth.reddit.com';
7679

7780
let data = await fetch(
78-
url, {
79-
headers: {
80-
'User-Agent': genericUserAgent,
81-
accept: 'application/json',
82-
authorization: accessToken && `Bearer ${accessToken}`
83-
}
84-
}
81+
url, { headers }
8582
).then(r => r.json()).catch(() => {});
8683

8784
if (!data || !Array.isArray(data)) {

0 commit comments

Comments
 (0)