Files
Folo/packages/internal/utils/src/url-builder.ts
T
Innei 059ab9d996 refactor(desktop): update SharePanel and UrlBuilder for improved share URL handling
- Refactored SharePanel to retrieve the share URL directly from the entry data.
- Enhanced UrlBuilder with a new method for generating share URLs that includes view and subscription parameters.
- Updated the shareEntry method to utilize the new structure for better flexibility.

Signed-off-by: Innei <tukon479@gmail.com>
2025-06-06 18:43:45 +08:00

24 lines
717 B
TypeScript

export class UrlBuilder {
constructor(private readonly webUrl: string) {}
protected join(path: string, query?: Record<string, string>) {
const nextUrl = new URL(this.webUrl)
nextUrl.pathname = path
if (query) {
for (const [key, value] of Object.entries(query)) {
nextUrl.searchParams.set(key, value)
}
}
return nextUrl.toString()
}
shareFeed(id: string, view?: number) {
return this.join(`share/feeds/${id}`, view ? { view: view.toString() } : undefined)
}
shareList(id: string, view?: number) {
return this.join(`share/lists/${id}`, view ? { view: view.toString() } : undefined)
}
profile(id: string) {
return this.join(`share/users/${id}`)
}
}