- Add express-pouchdb for self-hosted PouchDB sync server - Public databases (/db/public/:db) accessible without auth - Add auth middleware for public/private database access - Simplify share button to copy current URL to clipboard - Move feature config from static JSON to dynamic API endpoint - Add PouchDB sync to PouchData class for real-time collaboration - Fix Express 5 compatibility by patching req.query - Skip express.json() for /pouchdb routes (stream handling) - Remove unused PouchdbPersistenceManager and old share system 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
58 lines
1.7 KiB
TypeScript
58 lines
1.7 KiB
TypeScript
export function getPath(): string {
|
|
const path = window.location.pathname.split('/');
|
|
// Handle /db/public/:db or /db/private/:db patterns
|
|
if (path.length >= 4 && path[1] === 'db') {
|
|
return path[3];
|
|
}
|
|
// Legacy pattern /db/:db
|
|
if (path.length == 3 && path[1]) {
|
|
return path[2];
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Check if the current path is a public database
|
|
* Public paths: /db/public/:db
|
|
* Private paths: /db/private/:db
|
|
*/
|
|
export function isPublicPath(): boolean {
|
|
const path = window.location.pathname.split('/');
|
|
return path.length >= 3 && path[1] === 'db' && path[2] === 'public';
|
|
}
|
|
|
|
/**
|
|
* Get the database type from the current path
|
|
*/
|
|
export function getDbType(): 'public' | 'private' | null {
|
|
const path = window.location.pathname.split('/');
|
|
if (path.length >= 3 && path[1] === 'db') {
|
|
if (path[2] === 'public') return 'public';
|
|
if (path[2] === 'private') return 'private';
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Get the full database path for PouchDB sync
|
|
* Returns: public-{dbname} or private-{dbname}
|
|
* Uses dash separator instead of slash for express-pouchdb compatibility
|
|
*/
|
|
export function getRemoteDbPath(): string | null {
|
|
const path = window.location.pathname.split('/');
|
|
if (path.length >= 4 && path[1] === 'db') {
|
|
const type = path[2]; // 'public' or 'private'
|
|
const dbName = path[3];
|
|
return `${type}-${dbName}`;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export function getParameter(name: string) {
|
|
const searchParams = new URLSearchParams(window.location.search);
|
|
return searchParams.get(name);
|
|
}
|
|
|
|
export function viewOnly(): boolean {
|
|
return getParameter('viewonly') == 'true';
|
|
} |