Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and Feature dump #324

Merged
merged 22 commits into from
Mar 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
44739aa
fix: create default admin user with superAdmin
TacticalTechJay Mar 11, 2023
893e22f
fix: potential permission conflicts
TacticalTechJay Mar 11, 2023
37b208c
fix: allow admin removal
TacticalTechJay Mar 11, 2023
d7c432a
fix: keep original administrator perm
TacticalTechJay Mar 12, 2023
c3a816f
fix: properly handle "unique" characters
TacticalTechJay Mar 12, 2023
038fcf0
Merge branch 'diced:trunk' into trunk
TacticalTechJay Mar 12, 2023
9aef2ff
fix: getting a real url for webhooks
TacticalTechJay Mar 12, 2023
145ae53
feat&fix: add audio preview for view route, mute and autoplay by default
TacticalTechJay Mar 12, 2023
c831a6b
feat: add meta tags for potential audio embedding
TacticalTechJay Mar 12, 2023
f6d6eb7
fix: add more meta tags onto image for detail
TacticalTechJay Mar 12, 2023
84cea65
feat: compression
TacticalTechJay Mar 13, 2023
b10c6a7
fix: appropriately size images & center non-previewables
TacticalTechJay Mar 13, 2023
d6c9228
chore: update dep
TacticalTechJay Mar 13, 2023
f91e778
chore: remove package-lock.json
TacticalTechJay Mar 13, 2023
838b18a
fix: include the favorited prop in api/user/recent
TacticalTechJay Mar 15, 2023
0d321e5
fix: include folder id prop in api/user/files
TacticalTechJay Mar 15, 2023
4b4198a
fix: extend timeout
TacticalTechJay Mar 16, 2023
327e6af
fix: use 'compress' instead of 'nocompress' to avoid confusion
TacticalTechJay Mar 16, 2023
c4e9ca6
fix: shut 🤌
TacticalTechJay Mar 16, 2023
17a2053
fix: large close button for visibility
TacticalTechJay Mar 16, 2023
860d8ab
fix: contain large images in a scrolly thing
TacticalTechJay Mar 16, 2023
2e4a052
fix: octt->octet
diced Mar 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"fflate": "^0.7.4",
"find-my-way": "^7.5.0",
"katex": "^0.16.4",
"mantine-datatable": "^1.8.6",
"mantine-datatable": "2.0.1",
"minio": "^7.0.32",
"ms": "canary",
"multer": "^1.4.5-lts.1",
Expand Down
8 changes: 5 additions & 3 deletions src/components/File/FileModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default function FileModal({
refresh,
reducedActions = false,
exifEnabled,
compress,
}: {
open: boolean;
setOpen: (open: boolean) => void;
Expand All @@ -58,6 +59,7 @@ export default function FileModal({
refresh: () => void;
reducedActions?: boolean;
exifEnabled?: boolean;
compress: boolean;
}) {
const deleteFile = useFileDelete();
const favoriteFile = useFileFavorite();
Expand Down Expand Up @@ -215,11 +217,11 @@ export default function FileModal({
<Stack>
<Type
file={file}
src={`/r/${encodeURI(file.name)}`}
src={`/r/${encodeURI(file.name)}?compress=${compress}`}
alt={file.name}
popup
sx={{ minHeight: 200 }}
style={{ minHeight: 200 }}
sx={{ minHeight: 200, overflowY: 'scroll', maxHeight: 500 }}
style={{ minHeight: 200, overflowY: 'scroll', maxHeight: 500 }}
disableMediaPreview={false}
overrideRender={overrideRender}
setOverrideRender={setOverrideRender}
Expand Down
7 changes: 4 additions & 3 deletions src/components/File/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default function File({
exifEnabled,
refreshImages,
reducedActions = false,
onDash,
}) {
const [open, setOpen] = useState(false);
const deleteFile = useFileDelete();
Expand All @@ -57,9 +58,10 @@ export default function File({
refresh={refresh}
reducedActions={reducedActions}
exifEnabled={exifEnabled}
compress={onDash}
/>

<Card sx={{ maxWidth: '100%', height: '100%' }} shadow='md'>
<Card sx={{ maxWidth: '100%', height: '100%' }} shadow='md' onClick={() => setOpen(true)}>
<Card.Section>
<LoadingOverlay visible={loading} />
<Type
Expand All @@ -78,9 +80,8 @@ export default function File({
width: '100%',
cursor: 'pointer',
}}
src={`/r/${encodeURI(image.name)}`}
src={`/r/${encodeURI(image.name)}?compress=${onDash}`}
alt={image.name}
onClick={() => setOpen(true)}
disableMediaPreview={disableMediaPreview}
/>
</Card.Section>
Expand Down
3 changes: 2 additions & 1 deletion src/components/Theming.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export default function ZiplineTheming({ Component, pageProps, ...props }) {
},
Modal: {
defaultProps: {
closeButtonProps: { size: 'lg' },
centered: true,
transitionProps: {
exitDuration: 100,
Expand All @@ -118,7 +119,7 @@ export default function ZiplineTheming({ Component, pageProps, ...props }) {
},
LoadingOverlay: {
defaultProps: {
overlayProps: {
overlayprops: {
blur: 3,
color: theme.colorScheme === 'dark' ? theme.colors.dark[6] : 'white',
},
Expand Down
6 changes: 4 additions & 2 deletions src/components/Type.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ function Placeholder({ text, Icon, ...props }) {
);

return (
<Box sx={{ height: 200 }} {...props}>
<Center sx={{ height: 200 }}>
<Box sx={{ height: 320 }} {...props}>
<Center sx={{ height: 320 }}>
<PlaceholderContent text={text} Icon={Icon} />
</Center>
</Box>
Expand Down Expand Up @@ -158,6 +158,8 @@ export default function Type({ file, popup = false, disableMediaPreview, ...prop
image: (
<Image
placeholder={<PlaceholderContent Icon={IconPhotoCancel} text={'Image failed to load...'} />}
height={320}
fit='contain'
{...props}
/>
),
Expand Down
3 changes: 2 additions & 1 deletion src/components/pages/Dashboard/RecentFiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import File from 'components/File';
import MutedText from 'components/MutedText';
import { useRecent } from 'lib/queries/files';

export default function RecentFiles({ disableMediaPreview, exifEnabled }) {
export default function RecentFiles({ disableMediaPreview, exifEnabled, compress }) {
const recent = useRecent('media');

return (
Expand All @@ -25,6 +25,7 @@ export default function RecentFiles({ disableMediaPreview, exifEnabled }) {
disableMediaPreview={disableMediaPreview}
exifEnabled={exifEnabled}
refreshImages={recent.refetch}
onDash={compress}
/>
))
) : (
Expand Down
5 changes: 3 additions & 2 deletions src/components/pages/Dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { useRecoilValue } from 'recoil';
import RecentFiles from './RecentFiles';
import { StatCards } from './StatCards';

export default function Dashboard({ disableMediaPreview, exifEnabled }) {
export default function Dashboard({ disableMediaPreview, exifEnabled, compress }) {
const user = useRecoilValue(userSelector);

const recent = useRecent('media');
Expand Down Expand Up @@ -138,6 +138,7 @@ export default function Dashboard({ disableMediaPreview, exifEnabled }) {
refresh={() => files.refetch()}
reducedActions={false}
exifEnabled={exifEnabled}
compress={compress}
/>
)}

Expand All @@ -148,7 +149,7 @@ export default function Dashboard({ disableMediaPreview, exifEnabled }) {

<StatCards />

<RecentFiles disableMediaPreview={disableMediaPreview} exifEnabled={exifEnabled} />
<RecentFiles disableMediaPreview={disableMediaPreview} exifEnabled={exifEnabled} compress={compress} />

<Box my='sm'>
<Title>Files</Title>
Expand Down
3 changes: 2 additions & 1 deletion src/components/pages/Files/FilePagation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useRouter } from 'next/router';
import { useEffect, useState } from 'react';
import { useRecoilState } from 'recoil';

export default function FilePagation({ disableMediaPreview, exifEnabled, queryPage }) {
export default function FilePagation({ disableMediaPreview, exifEnabled, queryPage, compress }) {
const [checked, setChecked] = useRecoilState(showNonMediaSelector);
const [numPages, setNumPages] = useState(Number(queryPage)); // just set it to the queryPage, since the req may have not loaded yet
const [page, setPage] = useState(Number(queryPage));
Expand Down Expand Up @@ -75,6 +75,7 @@ export default function FilePagation({ disableMediaPreview, exifEnabled, queryPa
disableMediaPreview={disableMediaPreview}
exifEnabled={exifEnabled}
refreshImages={pages.refetch}
onDash={compress}
/>
</div>
))
Expand Down
4 changes: 3 additions & 1 deletion src/components/pages/Files/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Link from 'next/link';
import { useEffect, useState } from 'react';
import FilePagation from './FilePagation';

export default function Files({ disableMediaPreview, exifEnabled, queryPage }) {
export default function Files({ disableMediaPreview, exifEnabled, queryPage, compress }) {
const [favoritePage, setFavoritePage] = useState(1);
const [favoriteNumPages, setFavoriteNumPages] = useState(0);
const favoritePages = usePaginatedFiles(favoritePage, 'media', true);
Expand Down Expand Up @@ -50,6 +50,7 @@ export default function Files({ disableMediaPreview, exifEnabled, queryPage }) {
disableMediaPreview={disableMediaPreview}
exifEnabled={exifEnabled}
refreshImages={favoritePages.refetch}
onDash={compress}
/>
</div>
))
Expand All @@ -75,6 +76,7 @@ export default function Files({ disableMediaPreview, exifEnabled, queryPage }) {
disableMediaPreview={disableMediaPreview}
exifEnabled={exifEnabled}
queryPage={queryPage}
compress={compress}
/>
</>
);
Expand Down
10 changes: 9 additions & 1 deletion src/components/pages/Folders/ViewFolderFilesModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ import File from 'components/File';
import MutedText from 'components/MutedText';
import { useFolder } from 'lib/queries/folders';

export default function ViewFolderFilesModal({ open, setOpen, folderId, disableMediaPreview, exifEnabled }) {
export default function ViewFolderFilesModal({
open,
setOpen,
folderId,
disableMediaPreview,
exifEnabled,
compress,
}) {
if (!folderId) return null;

const folder = useFolder(folderId, true);
Expand All @@ -26,6 +33,7 @@ export default function ViewFolderFilesModal({ open, setOpen, folderId, disableM
image={file}
exifEnabled={exifEnabled}
refreshImages={folder.refetch}
onDash={compress}
/>
))}
</SimpleGrid>
Expand Down
3 changes: 2 additions & 1 deletion src/components/pages/Folders/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { useEffect, useState } from 'react';
import CreateFolderModal from './CreateFolderModal';
import ViewFolderFilesModal from './ViewFolderFilesModal';

export default function Folders({ disableMediaPreview, exifEnabled }) {
export default function Folders({ disableMediaPreview, exifEnabled, compress }) {
const folders = useFolders();
const [createOpen, setCreateOpen] = useState(false);
const [createWithFile, setCreateWithFile] = useState(null);
Expand Down Expand Up @@ -113,6 +113,7 @@ export default function Folders({ disableMediaPreview, exifEnabled }) {
folderId={activeFolderId}
disableMediaPreview={disableMediaPreview}
exifEnabled={exifEnabled}
compress={compress}
/>

<Group mb='md'>
Expand Down
7 changes: 7 additions & 0 deletions src/lib/config/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ export interface ConfigCore {
port: number;
database_url: string;
logger: boolean;
compression: ConfigCompression;

stats_interval: number;
invites_interval: number;
}

export interface ConfigCompression {
enabled: boolean;
threshold: number;
on_dashboard: boolean;
}

export interface ConfigDatasource {
type: 'local' | 's3' | 'supabase';
local: ConfigLocalDatasource;
Expand Down
3 changes: 3 additions & 0 deletions src/lib/config/readConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ export default function readConfig() {
map('CORE_LOGGER', 'boolean', 'core.logger'),
map('CORE_STATS_INTERVAL', 'number', 'core.stats_interval'),
map('CORE_INVITES_INTERVAL', 'number', 'core.invites_interval'),
map('CORE_COMPRESSION_ENABLED', 'boolean', 'core.compression.enabled'),
map('CORE_COMPRESSION_THRESHOLD', 'human-to-byte', 'core.compression.threshold'),
map('CORE_COMPRESSION_ON_DASHBOARD', 'boolean', 'core.compression.on_dashboard'),

map('DATASOURCE_TYPE', 'string', 'datasource.type'),

Expand Down
10 changes: 10 additions & 0 deletions src/lib/config/validateConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ const validator = s.object({
logger: s.boolean.default(false),
stats_interval: s.number.default(1800),
invites_interval: s.number.default(1800),
compression: s
.object({
enabled: s.boolean.default(false),
threshold: s.number.default(2048),
on_dashboard: s.boolean.default(true),
})
.default({
enabled: false,
on_dashboard: false,
}),
}),
datasource: s
.object({
Expand Down
2 changes: 1 addition & 1 deletion src/lib/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function parseContent(
image: content.embed.image,
}
: null,
url: args[3],
url: args.link,
};
}

Expand Down
1 change: 1 addition & 0 deletions src/lib/middleware/getServerSideProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const getServerSideProps: GetServerSideProps<ServerSideProps> = async (ct
max_size: config.chunks.max_size,
totp_enabled: config.mfa.totp_enabled,
exif_enabled: config.exif.enabled,
compress: config.core.compression.on_dashboard,
} as ServerSideProps,
};

Expand Down
12 changes: 11 additions & 1 deletion src/lib/utils/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,21 @@ export function parseString(str: string, value: ParseValue) {
continue;
}

if (matches.groups.prop in ['password', 'avatar']) {
if (['password', 'avatar'].includes(matches.groups.prop)) {
str = replaceCharsFromString(str, '{unknown_property}', matches.index, re.lastIndex);
re.lastIndex = matches.index;
continue;
}
if (['originalName', 'name'].includes(matches.groups.prop)) {
str = replaceCharsFromString(
str,
decodeURIComponent(escape(getV[matches.groups.prop])),
matches.index,
re.lastIndex
);
re.lastIndex = matches.index;
continue;
}

const v = getV[matches.groups.prop];

Expand Down
1 change: 1 addition & 0 deletions src/pages/api/auth/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ async function handler(req: NextApiReq, res: NextApiRes) {
username: 'administrator',
password: await hashPassword('password'),
token: createToken(),
superAdmin: true,
administrator: true,
},
});
Expand Down
9 changes: 7 additions & 2 deletions src/pages/api/user/[id].ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,14 @@ async function handler(req: NextApiReq, res: NextApiRes, user: UserExtended) {
return res.json(newTarget);
});
} else if (req.method === 'PATCH') {
if (target.administrator && !user.superAdmin) return res.forbidden('cannot modify administrator');
if (
(target.administrator && !user.superAdmin) ||
(target.administrator && user.administrator && !user.superAdmin)
)
return res.forbidden('cannot modify administrator');

logger.debug(`attempting to update user ${id} with ${JSON.stringify(req.body)}`);
logger.debug(`user ${id} has ${!req.body.administrator} in administrator`);

if (req.body.password) {
const hashed = await hashPassword(req.body.password);
Expand All @@ -84,7 +89,7 @@ async function handler(req: NextApiReq, res: NextApiRes, user: UserExtended) {
});
}

if (req.body.administrator) {
if (typeof req.body.administrator != 'undefined') {
await prisma.user.update({
where: { id: target.id },
data: { administrator: req.body.administrator },
Expand Down
1 change: 1 addition & 0 deletions src/pages/api/user/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ async function handler(req: NextApiReq, res: NextApiRes, user: UserExtended) {
id: true,
favorite: true,
views: true,
folderId: true,
maxViews: true,
size: true,
},
Expand Down
1 change: 1 addition & 0 deletions src/pages/api/user/recent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ async function handler(req: NextApiReq, res: NextApiRes, user: UserExtended) {
maxViews: true,
folderId: true,
size: true,
favorite: true,
},
});

Expand Down
1 change: 1 addition & 0 deletions src/pages/dashboard/files.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default function FilesPage(props) {
disableMediaPreview={props.disable_media_preview}
exifEnabled={props.exif_enabled}
queryPage={props.queryPage}
compress={props.compress}
/>
</Layout>
</>
Expand Down
6 changes: 5 additions & 1 deletion src/pages/dashboard/folders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export default function FilesPage(props) {
</Head>

<Layout props={props}>
<Folders disableMediaPreview={props.disable_media_preview} exifEnabled={props.exif_enabled} />
<Folders
disableMediaPreview={props.disable_media_preview}
exifEnabled={props.exif_enabled}
compress={props.compress}
/>
</Layout>
</>
);
Expand Down
Loading