Skip to content

Commit 9e79b42

Browse files
authored
feat: add custom share ID input and permission (#472)
- Add ID input field in create/edit share forms - Add ID input in quick share dialog with maxLength=64 - Add new_id field to ShareUpdate type for renaming - Add customize_share_id permission (bit 15) - Add i18n strings for ID placeholder and permission label
1 parent 157a3e6 commit 9e79b42

6 files changed

Lines changed: 30 additions & 4 deletions

File tree

src/lang/en/shares.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"expires": "Expiration time",
33
"id": "ID",
4+
"id_placeholder": "Custom ID (optional, leave empty for random)",
45
"accessed": "Access count",
56
"max_accessed": "Maximum access count",
67
"pwd": "Share code",

src/lang/en/users.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"ftp_manage": "FTP manage",
1515
"read_archives": "Read archives",
1616
"decompress": "Decompress",
17-
"share": "Share"
17+
"share": "Share",
18+
"customize_share_id": "Customize share ID"
1819
},
1920
"username": "Username",
2021
"password": "Password",

src/pages/home/toolbar/Share.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ export const Share = () => {
123123
<Match when={link() === ""}>
124124
<ModalBody>
125125
<VStack spacing="$1" alignItems="flex-start">
126+
<Text size="sm">{t("shares.id")}</Text>
127+
<Input
128+
size="sm"
129+
value={share.id ?? ""}
130+
maxLength={64}
131+
placeholder={t("shares.id_placeholder")}
132+
onInput={(e) => {
133+
setShare("id", e.currentTarget.value)
134+
}}
135+
/>
126136
<Text size="sm">{t("shares.remark")}</Text>
127137
<Textarea
128138
size="sm"

src/pages/manage/shares/AddOrEdit.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,20 @@ const AddOrEdit = () => {
4545
<MaybeLoading loading={id ? shareLoading() : false}>
4646
<Heading mb="$2">{t(`global.${id ? "edit" : "add"}`)}</Heading>
4747
<ResponsiveGrid>
48-
<Show when={id}>
49-
<Item name="id" type={Type.String} value={id} valid readonly={true} />
50-
</Show>
48+
<Item
49+
name="id"
50+
type={Type.String}
51+
value={id ? ((share as ShareUpdate).new_id ?? id) : (share.id ?? "")}
52+
valid
53+
placeholder={id ? id : t("shares.id_placeholder")}
54+
onChange={(v) => {
55+
if (id) {
56+
setShare({ ...share, new_id: v } as any)
57+
} else {
58+
setShare({ ...share, id: v } as any)
59+
}
60+
}}
61+
/>
5162
<Item
5263
name="files"
5364
type={Type.MultiPath}

src/types/share.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ExtractFolder, OrderBy, OrderDirection } from "~/types/storage"
22

33
export interface Share {
4+
id?: string
45
expires: string | null
56
pwd: string
67
max_accessed: number
@@ -16,6 +17,7 @@ export interface Share {
1617

1718
export interface ShareUpdate extends Share {
1819
id: string
20+
new_id: string
1921
accessed: number
2022
}
2123

src/types/user.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export const UserPermissions = [
3333
"read_archives",
3434
"decompress",
3535
"share",
36+
"customize_share_id",
3637
] as const
3738

3839
export const UserMethods = {

0 commit comments

Comments
 (0)