| 1 | import { A, useNavigate, useParams, useSearchParams } from "@solidjs/router"; |
| 2 | import ArrowLeft from "lucide-solid/icons/arrow-left"; |
| 3 | import Folder from "lucide-solid/icons/folder"; |
| 4 | import Plus from "lucide-solid/icons/plus"; |
| 5 | import Search from "lucide-solid/icons/search"; |
| 6 | import { createMemo, createResource, createSignal, For, onMount, Show } from "solid-js"; |
| 7 | import { parseResponse } from "hono/client"; |
| 8 | import { api, query, reason } from "../api.ts"; |
| 9 | import { Checkbox } from "../components/Checkbox.tsx"; |
| 10 | import { Copy } from "../components/Copy.tsx"; |
| 11 | import { showConfirmDialog, showTextDialog } from "../components/Dialog.tsx"; |
| 12 | import { ListPage } from "../components/ListPage.tsx"; |
| 13 | import { lastGood, Loaded, SkeletonRows } from "../components/Loaded.tsx"; |
| 14 | import { TabBar } from "../components/TabBar.tsx"; |
| 15 | import type { AccountSecret, FileAccount, FolderGrant, ShareState, SharedLink } from "../types/shares.ts"; |
| 16 | import { datetime, plural } from "../format.ts"; |
| 17 | import "./Shares.css"; |
| 18 | |
| 19 | export const shares = query("shares", () => parseResponse(api.shares.$get())); |
| 20 | |
| 21 | const RIGHTS = [["r", "read"], ["w", "upload"], ["m", "move / rename"], ["d", "delete"], [".", "hidden files"], ["a", "Copyparty admin"]] as const; |
| 22 | const permissions = (value: string) => RIGHTS.filter(([key]) => value.includes(key)).map(([, label]) => label).join(", "); |
| 23 | const macPath = (path: string, root: string) => path === root || path.startsWith(root + "/") ? "/Volumes/clover" + path.slice(root.length) : path; |
| 24 | const linkUrl = (state: ShareState, key: string) => state.filesUrl ? `${state.filesUrl.replace(/\/$/, "")}/shr/${encodeURIComponent(key)}` : null; |
| 25 | |
| 26 | function Rights(props: { value: string; onChange: (value: string) => void; link?: boolean }) { |
| 27 | return <fieldset class="share-rights"><legend>permissions</legend><div> |
| 28 | <For each={props.link ? RIGHTS.slice(0, 2) : RIGHTS}>{([key, label]) => |
| 29 | <Checkbox checked={props.value.includes(key)} onChange={(checked) => props.onChange(checked ? props.value + key : props.value.replace(key, ""))}>{label}</Checkbox> |
| 30 | }</For> |
| 31 | </div></fieldset>; |
| 32 | } |
| 33 | |
| 34 | function FolderField(props: { value: string; root: string; create?: boolean; onChange: (value: string, existing?: boolean) => void }) { |
| 35 | const browse = () => { |
| 36 | const [path, setPath] = createSignal(props.create && !props.value.endsWith("/") ? props.value.replace(/\/[^/]+$/, "") || props.root : props.value || props.root); |
| 37 | showConfirmDialog({ |
| 38 | title: "Choose folder", confirmLabel: "use folder", |
| 39 | body: () => { |
| 40 | const [folders, { refetch }] = createResource(path, (path) => parseResponse(api.shares.folders.$get({ query: { path } }))); |
| 41 | return <div class="share-picker"> |
| 42 | <label class="field">folder<input class="search" value={path()} onChange={(e) => setPath(e.currentTarget.value)} /></label> |
| 43 | <button type="button" class="button small" disabled={path() === props.root || path() === "/Volumes/clover"} |
| 44 | onClick={() => setPath(path().replace(/\/[^/]+\/?$/, "") || props.root)}>parent folder</button> |
| 45 | <Loaded data={folders} what="folders" retry={refetch} skeleton={<SkeletonRows count={4} />}> |
| 46 | {(data) => <div class="share-picker-list"><For each={data().directories} fallback={<p class="muted">No folders here</p>}> |
| 47 | {(folder) => <button type="button" onClick={() => setPath(macPath(folder.path, props.root))}><Folder size={16} aria-hidden="true" />{folder.name}</button>} |
| 48 | </For></div>} |
| 49 | </Loaded> |
| 50 | </div>; |
| 51 | }, |
| 52 | onConfirm: () => props.onChange(macPath(path(), props.root), true), |
| 53 | }); |
| 54 | }; |
| 55 | return <div class="field">folder<div class="share-folder-field"> |
| 56 | <input aria-label="Folder" class="search" value={props.value} required autocomplete="off" spellcheck={false} |
| 57 | onInput={(event) => props.onChange(event.currentTarget.value)} /> |
| 58 | <button type="button" class="button" onClick={browse}>browse</button> |
| 59 | </div></div>; |
| 60 | } |
| 61 | |
| 62 | function showSecret(result: AccountSecret, returnFocus?: HTMLElement) { |
| 63 | showConfirmDialog({ |
| 64 | title: "Save account password", confirmLabel: "done", |
| 65 | returnFocus, |
| 66 | description: "This password is shown once. Save it before closing.", |
| 67 | body: () => <dl class="kv share-secret"><dt>username</dt><dd><Copy value={result.account.username} /></dd><dt>password</dt><dd><Copy value={result.password} /></dd></dl>, |
| 68 | onConfirm: () => {}, |
| 69 | }); |
| 70 | } |
| 71 | |
| 72 | function editGrant(props: { subject: string; state: ShareState; grant?: FolderGrant; saved: (state: ShareState) => void }) { |
| 73 | const [path, setPath] = createSignal(macPath(props.grant?.path ?? props.state.defaultRoot, props.state.root)); |
| 74 | const [rights, setRights] = createSignal(props.grant?.permissions ?? "r"); |
| 75 | showConfirmDialog({ |
| 76 | title: props.grant ? "Edit folder access" : "Add folder access", confirmLabel: "save access", |
| 77 | returnFocus: document.querySelector<HTMLElement>(".folder-access .card-title button") ?? undefined, |
| 78 | canConfirm: () => !!path().trim() && !!rights(), |
| 79 | body: () => <div class="share-form"> |
| 80 | <FolderField value={path()} root={props.state.root} onChange={setPath} /> |
| 81 | <Rights value={rights()} onChange={setRights} /> |
| 82 | <p class="hint">Folder permissions add to existing access.</p> |
| 83 | </div>, |
| 84 | onConfirm: async () => { |
| 85 | const json = { subject: props.subject, path: path(), permissions: rights() }; |
| 86 | const state = await parseResponse(props.grant |
| 87 | ? api.shares.grants[":id"].$patch({ param: { id: props.grant.id }, json }) |
| 88 | : api.shares.grants.$post({ json })); |
| 89 | props.saved(state); |
| 90 | }, |
| 91 | }); |
| 92 | } |
| 93 | |
| 94 | export function FolderAccess(props: { subject: string; enabled?: boolean }) { |
| 95 | const [state, { mutate, refetch }] = shares.use(); |
| 96 | const ready = lastGood(state); |
| 97 | return <section class="card folder-access"> |
| 98 | <h2 class="card-title">folder access<span class="spacer" /> |
| 99 | <button class="button small" disabled={!ready() || props.enabled === false} onClick={() => editGrant({ subject: props.subject, state: ready()!, saved: mutate })}>add folder</button> |
| 100 | </h2> |
| 101 | <Loaded data={state} what="folder access" retry={refetch} skeleton={<SkeletonRows count={2} />}> |
| 102 | {(data) => <GrantList subject={props.subject} state={data()} saved={mutate} enabled={props.enabled} />} |
| 103 | </Loaded> |
| 104 | </section>; |
| 105 | } |
| 106 | |
| 107 | function GrantList(props: { subject: string; state: ShareState; saved: (state: ShareState) => void; enabled?: boolean }) { |
| 108 | const grants = () => props.state.grants.filter((grant) => grant.subject === props.subject); |
| 109 | const remove = (grant: FolderGrant) => showConfirmDialog({ |
| 110 | title: "Remove folder access?", description: macPath(grant.path, props.state.root), confirmLabel: "remove access", destructive: true, |
| 111 | returnFocus: document.querySelector<HTMLElement>(".folder-access .card-title button") ?? undefined, |
| 112 | onConfirm: async () => props.saved(await parseResponse(api.shares.grants[":id"].$delete({ param: { id: grant.id } }))), |
| 113 | }); |
| 114 | return <div class="share-grants"> |
| 115 | <For each={grants()} fallback={<p class="muted">No folder permissions assigned here</p>}>{(grant) => <div class="share-grant"> |
| 116 | <div><span class="share-path">{macPath(grant.path, props.state.root)}</span><span class="muted">{permissions(grant.permissions)}</span></div> |
| 117 | <button class="button small" aria-label={`Edit access to ${macPath(grant.path, props.state.root)}`} disabled={props.enabled === false} onClick={() => editGrant({ subject: props.subject, state: props.state, grant, saved: props.saved })}>edit</button> |
| 118 | <button class="button small danger" aria-label={`Remove access to ${macPath(grant.path, props.state.root)}`} onClick={() => remove(grant)}>remove</button> |
| 119 | </div>}</For> |
| 120 | <Show when={grants().length}><p class="hint">Folder permissions add to existing access.</p></Show> |
| 121 | </div>; |
| 122 | } |
| 123 | |
| 124 | export function Shares() { |
| 125 | const params = useParams<{ key?: string; id?: string }>(); |
| 126 | const [search, setSearch] = useSearchParams<{ tab?: string; q?: string }>(); |
| 127 | const [state, { refetch, mutate }] = shares.use(); |
| 128 | const navigate = useNavigate(); |
| 129 | const accounts = () => search.tab === "accounts"; |
| 130 | const createAccount = () => { |
| 131 | let credentials: AccountSecret | undefined; |
| 132 | showTextDialog({ |
| 133 | title: "New API account", label: "name", placeholder: "T3Code", confirmLabel: "create account", |
| 134 | onConfirm: async (name) => { |
| 135 | const result = await parseResponse(api.shares.accounts.$post({ json: { name } })); |
| 136 | mutate(result); |
| 137 | navigate(`/shares/accounts/${result.account.id}`); |
| 138 | credentials = result; |
| 139 | }, |
| 140 | onClose: () => { if (credentials) showSecret(credentials, document.querySelector<HTMLElement>(".share-detail-page h1") ?? undefined); }, |
| 141 | }); |
| 142 | }; |
| 143 | return <Loaded data={state} what="shares" retry={refetch} skeleton={<div class="page"><SkeletonRows count={6} /></div>}> |
| 144 | {(data) => <Show when={params.id} keyed fallback={<Show when={params.key} keyed fallback={ |
| 145 | <ListPage id="shares" class="shares-page" flush head={<div class="page-head"><h1>shares</h1><span class="spacer" /> |
| 146 | <Show when={accounts()} fallback={<A class="button primary" href="/shares/new"><Plus size={14} aria-hidden="true" />new share</A>}> |
| 147 | <button class="button primary" onClick={createAccount}><Plus size={14} aria-hidden="true" />new account</button> |
| 148 | </Show> |
| 149 | </div>}> |
| 150 | <div class="shares-toolbar"> |
| 151 | <TabBar label="Share manager"><button aria-pressed={!accounts()} onClick={() => setSearch({ tab: undefined, q: undefined })}>shared links<span class="count">{data().links.length}</span></button> |
| 152 | <button aria-pressed={accounts()} onClick={() => setSearch({ tab: "accounts", q: undefined })}>API accounts<span class="count">{data().accounts.length}</span></button> |
| 153 | </TabBar> |
| 154 | <label class="search-box"><Search size={14} aria-hidden="true" /><input type="search" aria-label="Search shares" placeholder="name or folder" value={search.q ?? ""} onInput={(e) => setSearch({ q: e.currentTarget.value || undefined }, { replace: true })} /></label> |
| 155 | </div> |
| 156 | <div class="fill shares-table"><Show when={accounts()} fallback={<LinkList state={data()} filter={search.q ?? ""} />}> |
| 157 | <AccountList state={data()} filter={search.q ?? ""} create={createAccount} /> |
| 158 | </Show></div> |
| 159 | </ListPage> |
| 160 | }>{(key) => <LinkPage key={key} state={data()} saved={mutate} />}</Show>}> |
| 161 | {(id) => <Show when={data().accounts.find((account) => account.id === id)} fallback={<div class="page empty">This account no longer exists. <A href="/shares?tab=accounts">back to accounts</A></div>}> |
| 162 | {(account) => <AccountPage account={account()} state={data()} saved={mutate} />} |
| 163 | </Show>} |
| 164 | </Show>} |
| 165 | </Loaded>; |
| 166 | } |
| 167 | |
| 168 | function LinkList(props: { state: ShareState; filter: string }) { |
| 169 | const links = () => props.state.links.filter((link) => `${link.name} ${link.path} ${link.key}`.toLowerCase().includes(props.filter.toLowerCase())); |
| 170 | return <Show when={links().length} fallback={<div class="empty">{props.filter ? "No shares match" : "No shared links yet"} <A class="button small" href="/shares/new">new share</A></div>}> |
| 171 | <table class="data"><thead><tr><th>share</th><th>folder</th><th>access</th><th>expires</th><th>public link</th></tr></thead><tbody> |
| 172 | <For each={links()}>{(link) => <tr> |
| 173 | <td><A class="share-name" href={`/shares/${encodeURIComponent(link.key)}`}>{link.name || link.key}</A> |
| 174 | <Show when={link.files.length}><span class="share-detail">{plural(link.files.length, "selected file")}</span></Show> |
| 175 | </td> |
| 176 | <td class="share-path">{macPath(link.path, props.state.root)}</td> |
| 177 | <td>{permissions(link.permissions)}<Show when={link.hasPassword}><span class="share-detail">password protected</span></Show></td> |
| 178 | <td class="share-expiry">{link.expires ? datetime(link.expires) : "never"}</td> |
| 179 | <td><Show when={linkUrl(props.state, link.key)}>{(url) => <Copy value={url()} label="link">copy link</Copy>}</Show></td> |
| 180 | </tr>}</For> |
| 181 | </tbody></table> |
| 182 | </Show>; |
| 183 | } |
| 184 | |
| 185 | function AccountList(props: { state: ShareState; filter: string; create: () => void }) { |
| 186 | const accounts = () => props.state.accounts.filter((account) => `${account.name} ${account.username}`.toLowerCase().includes(props.filter.toLowerCase())); |
| 187 | return <Show when={accounts().length} fallback={<div class="empty">{props.filter ? "No accounts match" : "No API accounts yet"} <button class="button small" onClick={props.create}>new account</button></div>}> |
| 188 | <table class="data"><thead><tr><th>account</th><th>username</th><th>folders</th></tr></thead><tbody> |
| 189 | <For each={accounts()}>{(account) => <tr><td><A class="share-name" href={`/shares/accounts/${account.id}`}>{account.name}</A></td><td><Copy value={account.username} /></td> |
| 190 | <td><For each={props.state.grants.filter((grant) => grant.subject === account.subject)} fallback={<span class="muted">no folders assigned</span>}>{(grant) => <span class="share-account-folder"><span class="share-path">{macPath(grant.path, props.state.root)}</span><span class="muted">{permissions(grant.permissions)}</span></span>}</For></td> |
| 191 | </tr>}</For> |
| 192 | </tbody></table> |
| 193 | </Show>; |
| 194 | } |
| 195 | |
| 196 | function AccountPage(props: { account: FileAccount; state: ShareState; saved: (state: ShareState) => void }) { |
| 197 | const navigate = useNavigate(); |
| 198 | let heading!: HTMLHeadingElement; |
| 199 | onMount(() => heading.focus()); |
| 200 | const rename = () => showTextDialog({ title: "Rename account", label: "name", initialValue: props.account.name, confirmLabel: "save name", |
| 201 | onConfirm: async (name) => props.saved(await parseResponse(api.shares.accounts[":id"].$patch({ param: { id: props.account.id }, json: { name } }))), |
| 202 | }); |
| 203 | const rotate = () => { |
| 204 | let credentials: AccountSecret | undefined; |
| 205 | showConfirmDialog({ title: "Replace account password?", description: "The old password and open sessions stop working.", confirmLabel: "replace password", destructive: true, |
| 206 | onConfirm: async () => { |
| 207 | const result = await parseResponse(api.shares.accounts[":id"].rotate.$post({ param: { id: props.account.id } })); |
| 208 | props.saved(result); credentials = result; |
| 209 | }, |
| 210 | onClose: () => { if (credentials) showSecret(credentials); }, |
| 211 | }); |
| 212 | }; |
| 213 | const remove = () => showConfirmDialog({ title: `Delete ${props.account.name}?`, description: "This account loses access to its folders. The files stay in place.", confirmLabel: "delete account", destructive: true, |
| 214 | onConfirm: async () => { |
| 215 | props.saved(await parseResponse(api.shares.accounts[":id"].$delete({ param: { id: props.account.id } }))); |
| 216 | navigate("/shares?tab=accounts"); |
| 217 | }, |
| 218 | }); |
| 219 | return <div class="page share-detail-page"><div class="page-head"><A class="button icon-only" href="/shares?tab=accounts" aria-label="Back to API accounts"><ArrowLeft size={16} /></A> |
| 220 | <h1 ref={heading} tabindex="-1">{props.account.name}</h1><span class="sub">API account</span><span class="spacer" /><button class="button danger" onClick={remove}>delete account</button></div> |
| 221 | <div class="share-columns"><section class="card"><h2 class="card-title">connection<span class="spacer" /><button class="button small" onClick={rename}>rename</button></h2> |
| 222 | <dl class="kv"><dt>username</dt><dd><Copy value={props.account.username} /></dd><dt>server</dt><dd><Show when={props.state.filesUrl} fallback="unavailable">{(url) => <Copy value={url()} />}</Show></dd></dl> |
| 223 | <p class="hint">Use this account with HTTP, WebDAV, or an AI client.</p><button class="button small" onClick={rotate}>replace password</button> |
| 224 | </section><section class="card folder-access"><h2 class="card-title">folder access<span class="spacer" /><button class="button small" onClick={() => editGrant({ subject: props.account.subject, state: props.state, saved: props.saved })}>add folder</button></h2> |
| 225 | <GrantList subject={props.account.subject} state={props.state} saved={props.saved} /> |
| 226 | </section></div> |
| 227 | </div>; |
| 228 | } |
| 229 | |
| 230 | function LinkPage(props: { key: string; state: ShareState; saved: (state: ShareState) => void }) { |
| 231 | const navigate = useNavigate(); |
| 232 | const original = () => props.state.links.find((link) => link.key === props.key); |
| 233 | const fresh = props.key === "new"; |
| 234 | return <Show when={fresh || original()} fallback={<div class="page empty">This share no longer exists. <A href="/shares">back to shares</A></div>}> |
| 235 | <LinkForm original={original()} fresh={fresh} state={props.state} saved={(state, key) => { props.saved(state); if (fresh) navigate(`/shares/${encodeURIComponent(key)}`); }} /> |
| 236 | </Show>; |
| 237 | } |
| 238 | |
| 239 | function LinkForm(props: { original?: SharedLink; fresh: boolean; state: ShareState; saved: (state: ShareState, key: string) => void }) { |
| 240 | const navigate = useNavigate(); |
| 241 | let heading!: HTMLHeadingElement; |
| 242 | onMount(() => heading.focus()); |
| 243 | const [name, setName] = createSignal(props.original?.name ?? ""); |
| 244 | const [customPath, setCustomPath] = createSignal(""); |
| 245 | const path = () => customPath() || `${macPath(props.state.defaultRoot, props.state.root)}/${name().trim()}`; |
| 246 | const [rights, setRights] = createSignal(props.original?.permissions ?? "r"); |
| 247 | const [createFolder, setCreateFolder] = createSignal(true); |
| 248 | const [password, setPassword] = createSignal<string | null>(null); |
| 249 | const dateValue = (seconds: number) => { |
| 250 | const date = new Date(seconds * 1000); |
| 251 | return new Date(date.getTime() - date.getTimezoneOffset() * 60_000).toISOString().slice(0, 16); |
| 252 | }; |
| 253 | const [expires, setExpires] = createSignal(props.original?.expires ? dateValue(props.original.expires) : ""); |
| 254 | const [pending, setPending] = createSignal(false); |
| 255 | const [error, setError] = createSignal(""); |
| 256 | const dirty = createMemo(() => props.fresh || name() !== props.original?.name || rights() !== props.original?.permissions || password() !== null || expires() !== (props.original?.expires ? dateValue(props.original.expires) : "")); |
| 257 | const save = async () => { |
| 258 | if (pending() || !dirty()) return; |
| 259 | setPending(true); setError(""); |
| 260 | try { |
| 261 | const json = { name: name().trim(), path: props.original?.path ?? path(), permissions: rights(), expires: expires() ? new Date(expires()).getTime() / 1000 : 0, password: password() }; |
| 262 | const result = await parseResponse(props.original |
| 263 | ? api.shares.links[":key"].$patch({ param: { key: props.original.key }, json: { ...json, mode: "retarget" } }) |
| 264 | : api.shares.links.$post({ json: { ...json, createFolder: createFolder() } })); |
| 265 | const key = props.original?.key ?? result.links.find((link) => !props.state.links.some((old) => old.key === link.key))?.key; |
| 266 | if (key) props.saved(result, key); |
| 267 | setPassword(null); |
| 268 | } catch (failure) { setError(reason(failure)); } |
| 269 | finally { setPending(false); } |
| 270 | }; |
| 271 | const changeFolder = () => { |
| 272 | const link = props.original!; |
| 273 | const [destination, setDestination] = createSignal(macPath(link.path, props.state.root)); |
| 274 | const [mode, setMode] = createSignal<"retarget" | "move">("retarget"); |
| 275 | showConfirmDialog({ |
| 276 | title: "Change folder", |
| 277 | get confirmLabel() { return mode() === "move" ? "move folder" : "use folder"; }, |
| 278 | canConfirm: () => !!destination().trim() && destination() !== macPath(link.path, props.state.root), |
| 279 | body: () => <div class="share-form"> |
| 280 | <FolderField value={destination()} root={props.state.root} onChange={setDestination} /> |
| 281 | <fieldset class="share-path-mode"><legend>change folder</legend> |
| 282 | <label><input type="radio" name="path-mode" checked={mode() === "retarget"} onChange={() => setMode("retarget")} />use another folder<span class="hint">Share the files already at the new path</span></label> |
| 283 | <label><input type="radio" name="path-mode" checked={mode() === "move"} onChange={() => setMode("move")} />move files<span class="hint">Move the current folder to the new path</span></label> |
| 284 | </fieldset> |
| 285 | <p class="hint">Public share links stay the same. Other shares inside a moved folder follow it.</p> |
| 286 | </div>, |
| 287 | onConfirm: async () => props.saved(await parseResponse(api.shares.links[":key"].$patch({ param: { key: link.key }, json: { |
| 288 | name: link.name, path: destination(), permissions: link.permissions, expires: link.expires, password: null, mode: mode(), |
| 289 | } })), link.key), |
| 290 | }); |
| 291 | }; |
| 292 | const remove = () => showConfirmDialog({ title: `Delete ${props.original?.name || "share"}?`, description: "The public link stops working. The files stay in place.", confirmLabel: "delete share", destructive: true, |
| 293 | onConfirm: async () => { const state = await parseResponse(api.shares.links[":key"].$delete({ param: { key: props.original!.key } })); props.saved(state, props.original!.key); navigate("/shares"); }, |
| 294 | }); |
| 295 | return <div class="page share-detail-page"><div class="page-head"><A class="button icon-only" href="/shares" aria-label="Back to shares"><ArrowLeft size={16} /></A> |
| 296 | <h1 ref={heading} tabindex="-1">{props.fresh ? "new share" : props.original?.name || props.original?.key}</h1><span class="spacer" /> |
| 297 | <Show when={!props.fresh}><button class="button danger" disabled={pending()} onClick={remove}>delete share</button></Show> |
| 298 | <button form="share-form" type="submit" class="button primary" disabled={!dirty() || pending()} aria-busy={pending()}>{props.fresh ? "create share" : "save changes"}</button></div> |
| 299 | <form id="share-form" class="share-form card" onSubmit={(event) => { event.preventDefault(); void save(); }}> |
| 300 | <fieldset disabled={pending()}> |
| 301 | <label class="field">name<input class="search" required value={name()} placeholder="Name - Description" autocomplete="off" onInput={(event) => setName(event.currentTarget.value)} /></label> |
| 302 | <Show when={props.fresh} fallback={<div class="field">folder<div class="share-current-folder"><span class="share-path">{macPath(props.original!.path, props.state.root)}</span><button type="button" class="button" onClick={changeFolder}>change folder</button></div></div>}> |
| 303 | <FolderField value={path()} root={props.state.root} create={createFolder()} onChange={(value, existing) => { setCustomPath(value); if (existing) setCreateFolder(false); }} /> |
| 304 | <Checkbox checked={createFolder()} onChange={setCreateFolder}>create this folder</Checkbox> |
| 305 | </Show> |
| 306 | <Show when={props.original?.files.length}><div class="field">selected files<ul class="share-selection"><For each={props.original?.files}>{(file) => <li>{file}</li>}</For></ul><span class="hint">This share keeps its file selection when its folder changes</span></div></Show> |
| 307 | <Rights value={rights()} onChange={setRights} link /> |
| 308 | <div class="share-options"><label class="field">expires<input type="datetime-local" class="search" value={expires()} onInput={(event) => setExpires(event.currentTarget.value)} /><span class="hint">Leave empty for no expiry</span></label> |
| 309 | <label class="field">password<input class="search" type="password" autocomplete="new-password" value={password() ?? ""} placeholder={props.original?.hasPassword ? "Keep current password" : "No password"} onInput={(event) => setPassword(event.currentTarget.value)} /> |
| 310 | <Show when={props.original?.hasPassword}><button type="button" class="button small" onClick={() => setPassword("")}>remove password</button></Show> |
| 311 | <Show when={props.original?.hasPassword && password() === ""}><span class="hint">Password will be removed when saved</span></Show> |
| 312 | </label></div> |
| 313 | <Show when={props.original && linkUrl(props.state, props.original.key)}>{(url) => <div class="field">public link<Copy value={url()} /></div>}</Show> |
| 314 | </fieldset> |
| 315 | <Show when={error()}><p class="error" role="alert">{error()}</p></Show> |
| 316 | </form> |
| 317 | </div>; |
| 318 | } |