Skip to content

Commit

Permalink
feat: show default options in upload options
Browse files Browse the repository at this point in the history
  • Loading branch information
diced committed Oct 16, 2024
1 parent 3d6aaa4 commit f9b2064
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
20 changes: 14 additions & 6 deletions src/components/pages/serverSettings/parts/ServerSettingsFiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,23 @@ export default function ServerSettingsFiles({
values.filesDefaultExpiration = values.filesDefaultExpiration.trim();
}

if (values.filesDisabledExtensions?.trim() === '' || !values.filesDisabledExtensions) {
if (!values.filesDisabledExtensions) {
// @ts-ignore
values.filesDisabledExtensions = [];
} else {
} else if (
values.filesDisabledExtensions &&
typeof values.filesDisabledExtensions === 'string' &&
values.filesDisabledExtensions.trim() === ''
) {
// @ts-ignore
values.filesDisabledExtensions = values.filesDisabledExtensions
.split(',')
.map((ext) => ext.trim())
.filter((ext) => ext !== '');
values.filesDisabledExtensions = [];
} else {
if (!Array.isArray(values.filesDisabledExtensions))
// @ts-ignore
values.filesDisabledExtensions = values.filesDisabledExtensions
.split(',')
.map((ext) => ext.trim())
.filter((ext) => ext !== '');
}

return settingsOnSubmit(router, form)(values);
Expand Down
25 changes: 23 additions & 2 deletions src/components/pages/upload/UploadOptionsButton.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useConfig } from '@/components/ConfigProvider';
import { Response } from '@/lib/api/response';
import { Folder } from '@/lib/db/models/folder';
import { useUploadOptionsStore } from '@/lib/store/uploadOptions';
Expand Down Expand Up @@ -30,10 +31,14 @@ import {
IconTrashFilled,
IconWriting,
} from '@tabler/icons-react';
import Link from 'next/link';
import { useState } from 'react';
import useSWR from 'swr';
import ms from 'ms';

export default function UploadOptionsButton({ numFiles }: { numFiles: number }) {
const config = useConfig();

const [opened, setOpen] = useState(false);
const [options, ephemeral, setOption, setEphemeral, changes] = useUploadOptionsStore((state) => [
state.options,
Expand Down Expand Up @@ -113,7 +118,23 @@ export default function UploadOptionsButton({ numFiles }: { numFiles: number })
) : null}
</>
}
description='The file will automatically delete itself after this time.'
description={
<>
The file will automatically delete itself after this time.{' '}
{config.files.defaultExpiration ? (
<>
The default expiration time is <b>{ms(config.files.defaultExpiration)}</b> (you can
override this with the below option).
</>
) : (
<>
{'You can set a default expiration time in the '}
<Link href='/dashboard/admin/settings'>settings</Link>
{'.'}
</>
)}
</>
}
leftSection={<IconAlarmFilled size='1rem' />}
value={options.deletesAt}
onChange={(value) => setOption('deletesAt', value || 'never')}
Expand All @@ -129,7 +150,7 @@ export default function UploadOptionsButton({ numFiles }: { numFiles: number })

<Select
data={[
{ value: 'default', label: 'Default' },
{ value: 'default', label: `Default (${config.files.defaultFormat})` },
{ value: 'random', label: 'Random' },
{ value: 'date', label: 'Date' },
{ value: 'uuid', label: 'UUID' },
Expand Down
4 changes: 2 additions & 2 deletions src/server/routes/api/server/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ export default fastifyPlugin(
.transform((value) =>
typeof value === 'string' ? value.split(',').map((ext) => ext.trim()) : value,
),
filesMaxFileSize: zMs,
filesMaxFileSize: zBytes,

filesDefaultExpiration: zBytes,
filesDefaultExpiration: zMs,
filesAssumeMimetypes: z.boolean(),
filesDefaultDateFormat: z.string(),
filesRemoveGpsMetadata: z.boolean(),
Expand Down

0 comments on commit f9b2064

Please sign in to comment.