enso/app/gui2/ydoc-server/auth.ts

23 lines
449 B
TypeScript
Raw Normal View History

/**
* @file Utility methods for ydoc server authentication.
*/
export type ConnectionData = {
lsUrl: string
doc: string
user: string
}
const docNameRegex = /^[a-z0-9/-]+$/i
export function docName(pathname: string) {
const prefix = '/project/'
if (pathname != null && pathname.startsWith(prefix)) {
const docName = pathname.slice(prefix.length)
if (docNameRegex.test(docName)) {
return docName
}
}
return null
}