( userId: string, path: string, presentedTokens: string[], )
| 81 | |
| 82 | // A lock can be refreshed via a member URI too (e.g. a file inside a Depth: infinity-locked collection). |
| 83 | export function refreshLock( |
| 84 | userId: string, |
| 85 | path: string, |
| 86 | presentedTokens: string[], |
| 87 | ): { token: string; path: string } | null { |
| 88 | const exactLock = locksByKey.get(buildKey(userId, path)); |
| 89 | |
| 90 | if (exactLock && !isExpired(exactLock) && presentedTokens.includes(exactLock.token)) { |
| 91 | exactLock.expiresAt = new Date(Date.now() + LOCK_TIMEOUT_IN_MILLISECONDS); |
| 92 | return { token: exactLock.token, path: exactLock.path }; |
| 93 | } |
| 94 | |
| 95 | for (const ancestorPath of getAncestorPaths(path).reverse()) { |
| 96 | const ancestorLock = locksByKey.get(buildKey(userId, ancestorPath)); |
| 97 | |
| 98 | if ( |
| 99 | ancestorLock && ancestorLock.depth === 'infinity' && !isExpired(ancestorLock) && |
| 100 | presentedTokens.includes(ancestorLock.token) |
| 101 | ) { |
| 102 | ancestorLock.expiresAt = new Date(Date.now() + LOCK_TIMEOUT_IN_MILLISECONDS); |
| 103 | return { token: ancestorLock.token, path: ancestorLock.path }; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | return null; |
| 108 | } |
| 109 | |
| 110 | export function releaseLock(userId: string, path: string, presentedToken: string): boolean { |
| 111 | const key = buildKey(userId, path); |
no test coverage detected