Skip to content

Commit e3c39a0

Browse files
fix: check empty Account only with type 'onedrive' (#962)
1 parent 4ed2523 commit e3c39a0

5 files changed

Lines changed: 11 additions & 4 deletions

File tree

packages/helix-shared-tokencache/src/MemCachePlugin.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export class MemCachePlugin {
3030
this.log = opts.log || console;
3131
this.key = opts.key;
3232
this.base = opts.base;
33+
this.type = opts.type;
3334
this.caches = opts.caches || caches;
3435
}
3536

@@ -83,13 +84,13 @@ export class MemCachePlugin {
8384
* @param {TokenCacheContext} cacheContext
8485
*/
8586
async afterCacheAccess(cacheContext) {
86-
const { log } = this;
87+
const { log, type } = this;
8788

8889
if (!cacheContext.cacheHasChanged) {
8990
return false;
9091
}
9192
const data = JSON.parse(cacheContext.tokenCache.serialize());
92-
if (Object.keys(data.Account ?? {}).length === 0) {
93+
if (type === 'onedrive' && Object.keys(data.Account ?? {}).length === 0) {
9394
log.info('mem: write token cache done, ignoring empty data', this.key);
9495
return false;
9596
}

packages/helix-shared-tokencache/src/S3CachePlugin.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export class S3CachePlugin {
4040
this.key = opts.key;
4141
this.secret = opts.secret;
4242
this.readOnly = opts.readOnly || false;
43+
this.type = opts.type;
4344
this.s3 = new S3Client();
4445
this.meta = null;
4546
this.data = null;
@@ -140,7 +141,7 @@ export class S3CachePlugin {
140141
}
141142

142143
async afterCacheAccess(cacheContext) {
143-
const { log } = this;
144+
const { log, type } = this;
144145

145146
if (!cacheContext.cacheHasChanged) {
146147
return false;
@@ -149,7 +150,7 @@ export class S3CachePlugin {
149150
await this.#loadData();
150151
}
151152
const data = JSON.parse(cacheContext.tokenCache.serialize());
152-
if (Object.keys(data.Account ?? {}).length === 0) {
153+
if (type === 'onedrive' && Object.keys(data.Account ?? {}).length === 0) {
153154
log.info('s3: write token cache, ignoring empty data', this.key);
154155
return false;
155156
}

packages/helix-shared-tokencache/src/getCachePlugin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export async function getCachePlugin(opts, type) {
7979
log,
8080
key: basePlugin.key,
8181
base: basePlugin,
82+
type,
8283
};
8384
if (process.env.HELIX_ONEDRIVE_LOCAL_AUTH_CACHE) {
8485
cacheOpts.caches = new Map();

packages/helix-shared-tokencache/test/mem-cache-plugin.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ describe('MemCachePlugin Test', () => {
115115
log: console,
116116
key: 'foobar-key',
117117
caches,
118+
type: 'onedrive',
118119
});
119120

120121
const ctx = new MockTokenCacheContext({
@@ -132,6 +133,7 @@ describe('MemCachePlugin Test', () => {
132133
log: console,
133134
key: 'foobar-key',
134135
caches,
136+
type: 'onedrive',
135137
});
136138

137139
const ctx = new MockTokenCacheContext({

packages/helix-shared-tokencache/test/s3-cache-plugin.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ describe('S3CachePlugin Test', () => {
219219
bucket: 'test-bucket',
220220
key: 'myproject/auth-default/json',
221221
secret: '',
222+
type: 'onedrive',
222223
});
223224

224225
nock('https://test-bucket.s3.us-east-1.amazonaws.com')
@@ -240,6 +241,7 @@ describe('S3CachePlugin Test', () => {
240241
bucket: 'test-bucket',
241242
key: 'myproject/auth-default/json',
242243
secret: '',
244+
type: 'onedrive',
243245
});
244246

245247
nock('https://test-bucket.s3.us-east-1.amazonaws.com')

0 commit comments

Comments
 (0)