合并主分支
解决简单冲突
This commit is contained in:
@@ -51,5 +51,6 @@ export * from './http';
|
||||
export * from './llm/narrativeLanguage';
|
||||
export * from './llm/parsers';
|
||||
export * from './stores/createProfileWalletStore';
|
||||
export * from './utils/signedReadUrlCache';
|
||||
|
||||
// should not export component, instead, they should be ref by relative path
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { describe, expect, test } from 'vitest';
|
||||
|
||||
import {
|
||||
parseSignedReadUrlExpiresAtMs,
|
||||
shouldReuseSignedReadUrlCacheEntry,
|
||||
} from './signedReadUrlCache';
|
||||
|
||||
describe('signedReadUrlCache', () => {
|
||||
test('只在签名地址距离过期超过安全窗口时复用', () => {
|
||||
const nowMs = Date.parse('2099-01-01T00:00:00Z');
|
||||
const entry = {
|
||||
signedUrl: 'https://signed.example.com/frame.png',
|
||||
expiresAtMs: parseSignedReadUrlExpiresAtMs('2099-01-01T00:05:00Z'),
|
||||
};
|
||||
|
||||
expect(shouldReuseSignedReadUrlCacheEntry(entry, nowMs)).toBe(true);
|
||||
expect(shouldReuseSignedReadUrlCacheEntry(entry, nowMs + 269_999)).toBe(
|
||||
true,
|
||||
);
|
||||
expect(shouldReuseSignedReadUrlCacheEntry(entry, nowMs + 270_000)).toBe(
|
||||
false,
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,26 @@
|
||||
export const SIGNED_READ_URL_CACHE_SAFETY_WINDOW_MS = 30 * 1000;
|
||||
|
||||
export type SignedReadUrlCacheEntry = {
|
||||
signedUrl: string;
|
||||
expiresAtMs: number;
|
||||
};
|
||||
|
||||
export function parseSignedReadUrlExpiresAtMs(expiresAt: string) {
|
||||
if (!expiresAt) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const parsed = Date.parse(expiresAt);
|
||||
return Number.isFinite(parsed) ? parsed : 0;
|
||||
}
|
||||
|
||||
export function shouldReuseSignedReadUrlCacheEntry(
|
||||
entry: SignedReadUrlCacheEntry | undefined,
|
||||
nowMs = Date.now(),
|
||||
) {
|
||||
if (!entry) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return entry.expiresAtMs - SIGNED_READ_URL_CACHE_SAFETY_WINDOW_MS > nowMs;
|
||||
}
|
||||
Reference in New Issue
Block a user