MCPcopy Create free account
hub / github.com/bewcloud/bewcloud / refreshLock

Function refreshLock

lib/interfaces/webdav-locks.ts:83–108  ·  view source on GitHub ↗
(
  userId: string,
  path: string,
  presentedTokens: string[],
)

Source from the content-addressed store, hash-verified

81
82// A lock can be refreshed via a member URI too (e.g. a file inside a Depth: infinity-locked collection).
83export 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
110export function releaseLock(userId: string, path: string, presentedToken: string): boolean {
111 const key = buildKey(userId, path);

Callers 1

handlerFunction · 0.90

Calls 4

buildKeyFunction · 0.85
isExpiredFunction · 0.85
getAncestorPathsFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected