Skip to content

Commit

Permalink
feat: store redgifs token to avoid hitting rate limit (#1302)
Browse files Browse the repository at this point in the history
Co-authored-by: yadue <admin@yadue.eu>
  • Loading branch information
yadue and yadue authored Feb 5, 2024
1 parent e327a98 commit 018d24a
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions plugins/redgifs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ hoverZoomPlugins.push({
name:'redgifs.com',
version:'0.4',
prepareImgLinks:function (callback) {
var self = this;
var res = [];
var name = this.name;

var apiUrl = 'https://api.redgifs.com/v2';
var tempToken;

$.get(`${apiUrl}/auth/temporary`, function(data) {
if (data && data.token) {
tempToken = data.token;
}
});
if (!self.redgifsToken) {
$.get(`${apiUrl}/auth/temporary`, function(data) {
if (data && data.token) {
self.redgifsToken = data.token;
}
});
}

$('a[href*="redgifs.com/"]').one('mouseenter', function () {
const link = $(this);
Expand All @@ -24,7 +25,7 @@ hoverZoomPlugins.push({
url: `${apiUrl}/gifs/${gfyId}`,
headers: [{
header: 'Authorization',
value: `Bearer ${tempToken}`,
value: `Bearer ${self.redgifsToken}`,
}],
}, (response) => {
let data;
Expand Down

0 comments on commit 018d24a

Please sign in to comment.