ken_nogi/PleasanterSystem/dbbackup/lib/tokenRefresher.js
Kenichiro NOGI ed33892f08 chore: 作業中の変更を整理しコミット(複数プロジェクト分)
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-02 11:09:50 +09:00

24 lines
670 B
JavaScript

"use strict";
/*
* LINE WORKSアクセストークンの有効期限切れ対策。長時間かかるアップロードループの
* 途中でトークンが失効しないよう、一定時間(thresholdMs)ごとに再取得する。
*/
function createTokenRefresher({ getUserAccessToken, thresholdMs = 50 * 60 * 1000, now = Date.now }) {
let token = null;
let fetchedAt = 0;
async function getToken() {
if (!token || now() - fetchedAt >= thresholdMs) {
token = await getUserAccessToken();
fetchedAt = now();
}
return token;
}
return { getToken };
}
module.exports = { createTokenRefresher };