Skip to content

Commit 45ef99a

Browse files
committed
feat: add storage capacity setting
1 parent 1cec0a4 commit 45ef99a

6 files changed

Lines changed: 59 additions & 0 deletions

File tree

src/composables/useSystemConfig.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { getErrorMessage } from '@/utils/common'
88
import {
99
buildConfigSubmitPayload,
1010
bytesToFileSizeForm,
11+
fileSizeFormToBytes,
1112
secondsToSaveTimeForm,
1213
type FileSizeUnit,
1314
type SaveTimeUnit
@@ -28,6 +29,8 @@ export function useSystemConfig() {
2829
const savedPayloadSnapshot = ref('')
2930
const fileSize = ref(1)
3031
const sizeUnit = ref<FileSizeUnit>('MB')
32+
const storageLimit = ref(0)
33+
const storageLimitUnit = ref<FileSizeUnit>('GB')
3134
const saveTime = ref(1)
3235
const saveTimeUnit = ref<SaveTimeUnit>('天')
3336
const adminSessionDays = ref(30)
@@ -41,6 +44,8 @@ export function useSystemConfig() {
4144
{ value: saveTime.value, unit: saveTimeUnit.value }
4245
)
4346
payload.adminSessionExpire = Math.round(adminSessionDays.value * SECONDS_PER_DAY)
47+
payload.storageLimit =
48+
storageLimit.value === 0 ? 0 : fileSizeFormToBytes(storageLimit.value, storageLimitUnit.value)
4449

4550
if (!payload.admin_token) {
4651
delete payload.admin_token
@@ -169,6 +174,10 @@ export function useSystemConfig() {
169174
fileSize.value = sizeForm.value
170175
sizeUnit.value = sizeForm.unit
171176

177+
const storageLimitForm = bytesToFileSizeForm(nextConfig.storageLimit)
178+
storageLimit.value = storageLimitForm.value
179+
storageLimitUnit.value = storageLimitForm.unit
180+
172181
const saveTimeForm = secondsToSaveTimeForm(nextConfig.max_save_seconds)
173182
saveTime.value = saveTimeForm.value
174183
saveTimeUnit.value = saveTimeForm.unit
@@ -226,6 +235,8 @@ export function useSystemConfig() {
226235
isDirty,
227236
fileSize,
228237
sizeUnit,
238+
storageLimit,
239+
storageLimitUnit,
229240
saveTime,
230241
saveTimeUnit,
231242
adminSessionDays,

src/i18n/locales/en-US.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ export default {
139139
notificationTitle: 'Announcement Title',
140140
notificationContent: 'Announcement Content',
141141
storageSettings: 'Storage',
142+
storageLimit: 'Total Storage Capacity',
143+
storageLimitHelp:
144+
'Active shares and pending uploads share this quota. Set to 0 for unlimited.',
142145
storagePath: 'Storage Path',
143146
storagePathPlaceholder: 'Leave empty for default path',
144147
storageMethod: 'Storage Type',

src/i18n/locales/zh-CN.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ export default {
139139
notificationTitle: '公告标题',
140140
notificationContent: '公告内容',
141141
storageSettings: '存储配置',
142+
storageLimit: '总存储容量上限',
143+
storageLimitHelp: '所有有效分享与未完成上传共同占用容量,设置为 0 表示不限制。',
142144
storagePath: '文件存储路径',
143145
storagePathPlaceholder: '使用默认路径可留空',
144146
storageMethod: '存储方式',

src/types/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export interface ConfigState {
4545
allowed_file_types: string[]
4646
allowedFileTypes?: string[]
4747
storage_path: string
48+
storageLimit: number
4849
uploadMinute: number
4950
max_save_seconds: number
5051
opacity: number

src/utils/config-storage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export const DEFAULT_CONFIG_STATE: ConfigState = {
5454
allowed_file_types: DEFAULT_PUBLIC_CONFIG.allowedFileTypes,
5555
allowedFileTypes: DEFAULT_PUBLIC_CONFIG.allowedFileTypes,
5656
storage_path: '',
57+
storageLimit: 0,
5758
uploadMinute: 1,
5859
max_save_seconds: DEFAULT_PUBLIC_CONFIG.max_save_seconds,
5960
opacity: 0.9,

src/views/manage/SystemSettingsView.vue

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const {
1616
isDirty,
1717
fileSize,
1818
sizeUnit,
19+
storageLimit,
20+
storageLimitUnit,
1921
saveTime,
2022
saveTimeUnit,
2123
adminSessionDays,
@@ -779,6 +781,45 @@ onMounted(() => {
779781
</div>
780782
</div>
781783

784+
<div class="space-y-2">
785+
<label
786+
class="block text-sm font-medium"
787+
:class="[isDarkMode ? 'text-zinc-300' : 'text-zinc-700']"
788+
>
789+
{{ t('admin.settings.storageLimit') }}
790+
</label>
791+
<div class="flex items-center space-x-2">
792+
<input
793+
v-model.number="storageLimit"
794+
type="number"
795+
min="0"
796+
step="1"
797+
class="w-28 rounded-md border px-4 py-2.5 shadow-sm outline-none transition-all duration-200 focus:border-zinc-500 focus:ring-2 focus:ring-zinc-500"
798+
:class="[
799+
isDarkMode
800+
? 'border-white/10 bg-zinc-950/45 text-white hover:border-white/20'
801+
: 'border-zinc-200/80 bg-white/80 text-zinc-950 hover:border-zinc-300'
802+
]"
803+
/>
804+
<select
805+
v-model="storageLimitUnit"
806+
class="rounded-md border px-4 py-2.5 shadow-sm outline-none transition-all duration-200 focus:border-zinc-500 focus:ring-2 focus:ring-zinc-500"
807+
:class="[
808+
isDarkMode
809+
? 'border-white/10 bg-zinc-950/45 text-white hover:border-white/20'
810+
: 'border-zinc-200/80 bg-white/80 text-zinc-950 hover:border-zinc-300'
811+
]"
812+
>
813+
<option value="KB">KB</option>
814+
<option value="MB">MB</option>
815+
<option value="GB">GB</option>
816+
</select>
817+
</div>
818+
<p class="text-xs" :class="[isDarkMode ? 'text-zinc-400' : 'text-zinc-500']">
819+
{{ t('admin.settings.storageLimitHelp') }}
820+
</p>
821+
</div>
822+
782823
<SettingSwitch
783824
:label="t('manage.settings.guestUpload')"
784825
:model-value="config.openUpload"

0 commit comments

Comments
 (0)